blob: 2e92d00fc21fbed7e65315ab6762540bd59bbca0 [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),
Sean Callanan7375f3e2014-12-09 21:18:59 +0000101 m_value_checksum(),
Greg Clayton288bdf92010-09-02 02:59:18 +0000102 m_value_is_valid (false),
103 m_value_did_change (false),
104 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000105 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000106 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000107 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000108 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000109 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000110 m_is_getting_summary(false),
Enrico Granatae29df232014-12-09 19:51:20 +0000111 m_did_calculate_complete_objc_class_type(false),
112 m_is_synthetic_children_generated(parent.m_is_synthetic_children_generated)
Jim Ingham6035b672011-03-31 00:19:25 +0000113{
Jim Ingham58b59f92011-04-22 23:53:53 +0000114 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000115}
116
117//----------------------------------------------------------------------
118// ValueObject constructor
119//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000120ValueObject::ValueObject (ExecutionContextScope *exe_scope,
121 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000122 UserID (++g_value_obj_uid), // Unique identifier for every value object
123 m_parent (NULL),
Enrico Granata4873e522013-04-11 22:48:58 +0000124 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000125 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000126 m_name (),
127 m_data (),
128 m_value (),
129 m_error (),
130 m_value_str (),
131 m_old_value_str (),
132 m_location_str (),
133 m_summary_str (),
134 m_object_desc_str (),
Enrico Granata744794a2014-09-05 21:46:22 +0000135 m_validation_result(),
Jim Ingham58b59f92011-04-22 23:53:53 +0000136 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000137 m_children (),
138 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000139 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000140 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000141 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000142 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +0000143 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000144 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +0000145 m_type_summary_sp(),
146 m_type_format_sp(),
147 m_synthetic_children_sp(),
Enrico Granata744794a2014-09-05 21:46:22 +0000148 m_type_validator_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000149 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000150 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Sean Callanan7375f3e2014-12-09 21:18:59 +0000151 m_value_checksum(),
Jim Ingham6035b672011-03-31 00:19:25 +0000152 m_value_is_valid (false),
153 m_value_did_change (false),
154 m_children_count_valid (false),
155 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000156 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000157 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000158 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000159 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000160 m_is_getting_summary(false),
Enrico Granatae29df232014-12-09 19:51:20 +0000161 m_did_calculate_complete_objc_class_type(false),
162 m_is_synthetic_children_generated(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000163{
Jim Ingham58b59f92011-04-22 23:53:53 +0000164 m_manager = new ValueObjectManager();
165 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000166}
167
168//----------------------------------------------------------------------
169// Destructor
170//----------------------------------------------------------------------
171ValueObject::~ValueObject ()
172{
173}
174
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000175bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000176ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000177{
Enrico Granata4becb372011-06-29 22:27:15 +0000178
Enrico Granata9128ee22011-09-06 19:20:51 +0000179 bool did_change_formats = false;
180
Enrico Granata0a3958e2011-07-02 00:25:22 +0000181 if (update_format)
Enrico Granata5548cb52013-01-28 23:47:25 +0000182 did_change_formats = UpdateFormatsIfNeeded();
Enrico Granata4becb372011-06-29 22:27:15 +0000183
Greg Claytonb71f3842010-10-05 03:13:51 +0000184 // If this is a constant value, then our success is predicated on whether
185 // we have an error or not
186 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000187 {
Enrico Granatab1c6c482013-10-09 00:33:55 +0000188 // if you are constant, things might still have changed behind your back
189 // (e.g. you are a frozen object and things have changed deeper than you cared to freeze-dry yourself)
190 // in this case, your value has not changed, but "computed" entries might have, so you might now have
191 // a different summary, or a different object description. clear these so we will recompute them
Enrico Granata9128ee22011-09-06 19:20:51 +0000192 if (update_format && !did_change_formats)
Enrico Granatab1c6c482013-10-09 00:33:55 +0000193 ClearUserVisibleData(eClearUserVisibleDataItemsSummary | eClearUserVisibleDataItemsDescription);
Greg Claytonb71f3842010-10-05 03:13:51 +0000194 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000195 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000196
Sean Callanan7375f3e2014-12-09 21:18:59 +0000197 bool first_update = IsChecksumEmpty();
Jim Ingham6035b672011-03-31 00:19:25 +0000198
199 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000200 {
Jim Ingham6035b672011-03-31 00:19:25 +0000201 m_update_point.SetUpdated();
202
203 // Save the old value using swap to avoid a string copy which
204 // also will clear our m_value_str
205 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000206 {
Jim Ingham6035b672011-03-31 00:19:25 +0000207 m_old_value_valid = false;
208 }
209 else
210 {
211 m_old_value_valid = true;
212 m_old_value_str.swap (m_value_str);
Enrico Granata86cc9822012-03-19 22:58:49 +0000213 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham6035b672011-03-31 00:19:25 +0000214 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000215
Enrico Granataf2bbf712011-07-15 02:26:42 +0000216 ClearUserVisibleData();
217
Greg Claytonefbc7d22012-03-09 04:23:44 +0000218 if (IsInScope())
Jim Ingham6035b672011-03-31 00:19:25 +0000219 {
Greg Claytonefbc7d22012-03-09 04:23:44 +0000220 const bool value_was_valid = GetValueIsValid();
221 SetValueDidChange (false);
222
223 m_error.Clear();
224
225 // Call the pure virtual function to update the value
Sean Callanan7375f3e2014-12-09 21:18:59 +0000226
227 bool need_compare_checksums = false;
228 llvm::SmallVector<uint8_t, 16> old_checksum;
229
230 if (!first_update && CanProvideValue())
231 {
232 need_compare_checksums = true;
233 old_checksum.resize(m_value_checksum.size());
234 std::copy(m_value_checksum.begin(), m_value_checksum.end(), old_checksum.begin());
235 }
236
Greg Claytonefbc7d22012-03-09 04:23:44 +0000237 bool success = UpdateValue ();
238
239 SetValueIsValid (success);
240
Sean Callanan7375f3e2014-12-09 21:18:59 +0000241 if (success)
242 {
243 const uint64_t max_checksum_size = 128;
244 m_data.Checksum(m_value_checksum,
245 max_checksum_size);
246 }
247 else
248 {
249 need_compare_checksums = false;
250 m_value_checksum.clear();
251 }
252
253 assert (old_checksum.empty() == !need_compare_checksums);
254
Greg Claytonefbc7d22012-03-09 04:23:44 +0000255 if (first_update)
256 SetValueDidChange (false);
257 else if (!m_value_did_change && success == false)
258 {
259 // The value wasn't gotten successfully, so we mark this
260 // as changed if the value used to be valid and now isn't
261 SetValueDidChange (value_was_valid);
262 }
Sean Callanan7375f3e2014-12-09 21:18:59 +0000263 else if (need_compare_checksums)
264 {
265 SetValueDidChange(memcmp(&old_checksum[0], &m_value_checksum[0], m_value_checksum.size()));
266 }
267
Greg Claytonefbc7d22012-03-09 04:23:44 +0000268 }
269 else
270 {
271 m_error.SetErrorString("out of scope");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000272 }
273 }
274 return m_error.Success();
275}
276
Enrico Granata9128ee22011-09-06 19:20:51 +0000277bool
Enrico Granata5548cb52013-01-28 23:47:25 +0000278ValueObject::UpdateFormatsIfNeeded()
Enrico Granata4becb372011-06-29 22:27:15 +0000279{
Greg Clayton5160ce52013-03-27 23:08:40 +0000280 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000281 if (log)
Enrico Granatad2284832012-10-17 22:23:56 +0000282 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000283 GetName().GetCString(), static_cast<void*>(this),
284 m_last_format_mgr_revision,
285 DataVisualization::GetCurrentRevision());
286
Enrico Granata9128ee22011-09-06 19:20:51 +0000287 bool any_change = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000288
Enrico Granata5548cb52013-01-28 23:47:25 +0000289 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()))
Enrico Granata4becb372011-06-29 22:27:15 +0000290 {
Enrico Granataa0db6ed2014-04-09 21:06:11 +0000291 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
292 any_change = true;
293
Enrico Granata852cc952013-10-08 19:03:22 +0000294 SetValueFormat(DataVisualization::GetFormat (*this, eNoDynamicValues));
Enrico Granata5548cb52013-01-28 23:47:25 +0000295 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000296#ifndef LLDB_DISABLE_PYTHON
Enrico Granata5548cb52013-01-28 23:47:25 +0000297 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000298#endif
Enrico Granata744794a2014-09-05 21:46:22 +0000299 SetValidator(DataVisualization::GetValidator(*this, GetDynamicValueType()));
Enrico Granata4becb372011-06-29 22:27:15 +0000300 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000301
Enrico Granata9128ee22011-09-06 19:20:51 +0000302 return any_change;
Enrico Granata4becb372011-06-29 22:27:15 +0000303}
304
Jim Ingham16e0c682011-08-12 23:34:31 +0000305void
306ValueObject::SetNeedsUpdate ()
307{
308 m_update_point.SetNeedsUpdate();
309 // We have to clear the value string here so ConstResult children will notice if their values are
310 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000311 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000312}
313
Enrico Granata13ac0e22012-10-17 19:03:34 +0000314void
Enrico Granatae3e91512012-10-22 18:18:36 +0000315ValueObject::ClearDynamicTypeInformation ()
Enrico Granata13ac0e22012-10-17 19:03:34 +0000316{
Enrico Granata38c54632013-10-30 00:04:29 +0000317 m_children_count_valid = false;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000318 m_did_calculate_complete_objc_class_type = false;
Enrico Granatae3e91512012-10-22 18:18:36 +0000319 m_last_format_mgr_revision = 0;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000320 m_override_type = ClangASTType();
Enrico Granatae3e91512012-10-22 18:18:36 +0000321 SetValueFormat(lldb::TypeFormatImplSP());
322 SetSummaryFormat(lldb::TypeSummaryImplSP());
323 SetSyntheticChildren(lldb::SyntheticChildrenSP());
Enrico Granata13ac0e22012-10-17 19:03:34 +0000324}
325
Sean Callanan72772842012-02-22 23:57:45 +0000326ClangASTType
327ValueObject::MaybeCalculateCompleteType ()
328{
Greg Clayton57ee3062013-07-11 22:46:58 +0000329 ClangASTType clang_type(GetClangTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000330
Sean Callanan72772842012-02-22 23:57:45 +0000331 if (m_did_calculate_complete_objc_class_type)
332 {
333 if (m_override_type.IsValid())
334 return m_override_type;
335 else
Greg Clayton57ee3062013-07-11 22:46:58 +0000336 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000337 }
338
Greg Clayton57ee3062013-07-11 22:46:58 +0000339 ClangASTType class_type;
340 bool is_pointer_type = false;
Sean Callanan72772842012-02-22 23:57:45 +0000341
Greg Clayton57ee3062013-07-11 22:46:58 +0000342 if (clang_type.IsObjCObjectPointerType(&class_type))
Sean Callanan72772842012-02-22 23:57:45 +0000343 {
344 is_pointer_type = true;
345 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000346 else if (clang_type.IsObjCObjectOrInterfaceType())
Sean Callanan72772842012-02-22 23:57:45 +0000347 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000348 class_type = clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000349 }
350 else
351 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000352 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000353 }
354
355 m_did_calculate_complete_objc_class_type = true;
356
Greg Clayton57ee3062013-07-11 22:46:58 +0000357 if (class_type)
Sean Callanan72772842012-02-22 23:57:45 +0000358 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000359 ConstString class_name (class_type.GetConstTypeName());
Sean Callanan72772842012-02-22 23:57:45 +0000360
Greg Clayton57ee3062013-07-11 22:46:58 +0000361 if (class_name)
362 {
363 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
364
365 if (process_sp)
366 {
367 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
368
369 if (objc_language_runtime)
370 {
371 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name);
372
373 if (complete_objc_class_type_sp)
374 {
375 ClangASTType complete_class(complete_objc_class_type_sp->GetClangFullType());
376
377 if (complete_class.GetCompleteType())
378 {
379 if (is_pointer_type)
380 {
381 m_override_type = complete_class.GetPointerType();
382 }
383 else
384 {
385 m_override_type = complete_class;
386 }
387
388 if (m_override_type.IsValid())
389 return m_override_type;
390 }
391 }
392 }
393 }
394 }
Sean Callanan72772842012-02-22 23:57:45 +0000395 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000396 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000397}
398
Greg Clayton57ee3062013-07-11 22:46:58 +0000399ClangASTType
Sean Callanan72772842012-02-22 23:57:45 +0000400ValueObject::GetClangType ()
401{
Greg Clayton57ee3062013-07-11 22:46:58 +0000402 return MaybeCalculateCompleteType();
Sean Callanan72772842012-02-22 23:57:45 +0000403}
404
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000405TypeImpl
406ValueObject::GetTypeImpl ()
407{
408 return TypeImpl(GetClangType());
409}
410
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000411DataExtractor &
412ValueObject::GetDataExtractor ()
413{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000414 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000415 return m_data;
416}
417
418const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000419ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000420{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000421 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000422 return m_error;
423}
424
425const ConstString &
426ValueObject::GetName() const
427{
428 return m_name;
429}
430
431const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000432ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000433{
Enrico Granata82fabf82013-04-30 20:45:04 +0000434 return GetLocationAsCStringImpl(m_value,
435 m_data);
436}
437
438const char *
439ValueObject::GetLocationAsCStringImpl (const Value& value,
440 const DataExtractor& data)
441{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000442 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000443 {
444 if (m_location_str.empty())
445 {
446 StreamString sstr;
Enrico Granata82fabf82013-04-30 20:45:04 +0000447
448 Value::ValueType value_type = value.GetValueType();
449
450 switch (value_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000451 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000452 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +0000453 case Value::eValueTypeVector:
Enrico Granata82fabf82013-04-30 20:45:04 +0000454 if (value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000455 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000456 RegisterInfo *reg_info = value.GetRegisterInfo();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000457 if (reg_info)
458 {
459 if (reg_info->name)
460 m_location_str = reg_info->name;
461 else if (reg_info->alt_name)
462 m_location_str = reg_info->alt_name;
Enrico Granata82fabf82013-04-30 20:45:04 +0000463 if (m_location_str.empty())
464 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000465 }
466 }
Enrico Granata82fabf82013-04-30 20:45:04 +0000467 if (m_location_str.empty())
468 m_location_str = (value_type == Value::eValueTypeVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000469 break;
470
471 case Value::eValueTypeLoadAddress:
472 case Value::eValueTypeFileAddress:
473 case Value::eValueTypeHostAddress:
474 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000475 uint32_t addr_nibble_size = data.GetAddressByteSize() * 2;
476 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000477 m_location_str.swap(sstr.GetString());
478 }
479 break;
480 }
481 }
482 }
483 return m_location_str.c_str();
484}
485
486Value &
487ValueObject::GetValue()
488{
489 return m_value;
490}
491
492const Value &
493ValueObject::GetValue() const
494{
495 return m_value;
496}
497
498bool
Jim Ingham6035b672011-03-31 00:19:25 +0000499ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000500{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000501 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
502 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000503 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000504 Value tmp_value(m_value);
Greg Clayton57ee3062013-07-11 22:46:58 +0000505 scalar = tmp_value.ResolveValue(&exe_ctx);
Greg Claytondcad5022011-12-29 01:26:56 +0000506 if (scalar.IsValid())
507 {
508 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
509 if (bitfield_bit_size)
510 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
511 return true;
512 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000513 }
Greg Claytondcad5022011-12-29 01:26:56 +0000514 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000515}
516
517bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000518ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000519{
Greg Clayton288bdf92010-09-02 02:59:18 +0000520 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000521}
522
523
524void
525ValueObject::SetValueIsValid (bool b)
526{
Greg Clayton288bdf92010-09-02 02:59:18 +0000527 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000528}
529
530bool
Jim Ingham6035b672011-03-31 00:19:25 +0000531ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000532{
Greg Clayton288bdf92010-09-02 02:59:18 +0000533 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000534}
535
536void
537ValueObject::SetValueDidChange (bool value_changed)
538{
Greg Clayton288bdf92010-09-02 02:59:18 +0000539 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000540}
541
542ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000543ValueObject::GetChildAtIndex (size_t idx, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000544{
545 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000546 // We may need to update our value if we are dynamic
547 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000548 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000549 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000550 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000551 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000552 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000553 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000554 // No we haven't created the child at this index, so lets have our
555 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000556 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000557 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000558
Enrico Granata9d60f602012-03-09 03:09:58 +0000559 ValueObject* child = m_children.GetChildAtIndex(idx);
560 if (child != NULL)
561 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000562 }
563 return child_sp;
564}
565
Enrico Granata3309d882013-01-12 01:00:22 +0000566ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000567ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
568 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000569{
570 if (idxs.size() == 0)
571 return GetSP();
572 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000573 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000574 {
575 root = root->GetChildAtIndex(idx, true);
576 if (!root)
577 {
578 if (index_of_error)
579 *index_of_error = idx;
580 return root;
581 }
582 }
583 return root;
584}
585
586ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000587ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
588 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000589{
590 if (idxs.size() == 0)
591 return GetSP();
592 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000593 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000594 {
595 root = root->GetChildAtIndex(idx.first, idx.second);
596 if (!root)
597 {
598 if (index_of_error)
599 *index_of_error = idx.first;
600 return root;
601 }
602 }
603 return root;
604}
605
606lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000607ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
608 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000609{
610 if (idxs.size() == 0)
611 return GetSP();
612 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000613 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000614 {
615 root = root->GetChildAtIndex(idx, true);
616 if (!root)
617 {
618 if (index_of_error)
619 *index_of_error = idx;
620 return root;
621 }
622 }
623 return root;
624}
625
626lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000627ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
628 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000629{
630 if (idxs.size() == 0)
631 return GetSP();
632 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000633 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000634 {
635 root = root->GetChildAtIndex(idx.first, idx.second);
636 if (!root)
637 {
638 if (index_of_error)
639 *index_of_error = idx.first;
640 return root;
641 }
642 }
643 return root;
644}
645
Enrico Granatae2e220a2013-09-12 00:48:47 +0000646lldb::ValueObjectSP
647ValueObject::GetChildAtNamePath (const std::initializer_list<ConstString> &names,
648 ConstString* name_of_error)
649{
650 if (names.size() == 0)
651 return GetSP();
652 ValueObjectSP root(GetSP());
653 for (ConstString name : names)
654 {
655 root = root->GetChildMemberWithName(name, true);
656 if (!root)
657 {
658 if (name_of_error)
659 *name_of_error = name;
660 return root;
661 }
662 }
663 return root;
664}
665
666lldb::ValueObjectSP
667ValueObject::GetChildAtNamePath (const std::vector<ConstString> &names,
668 ConstString* name_of_error)
669{
670 if (names.size() == 0)
671 return GetSP();
672 ValueObjectSP root(GetSP());
673 for (ConstString name : names)
674 {
675 root = root->GetChildMemberWithName(name, true);
676 if (!root)
677 {
678 if (name_of_error)
679 *name_of_error = name;
680 return root;
681 }
682 }
683 return root;
684}
685
686lldb::ValueObjectSP
687ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names,
688 ConstString* name_of_error)
689{
690 if (names.size() == 0)
691 return GetSP();
692 ValueObjectSP root(GetSP());
693 for (std::pair<ConstString, bool> name : names)
694 {
695 root = root->GetChildMemberWithName(name.first, name.second);
696 if (!root)
697 {
698 if (name_of_error)
699 *name_of_error = name.first;
700 return root;
701 }
702 }
703 return root;
704}
705
706lldb::ValueObjectSP
707ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names,
708 ConstString* name_of_error)
709{
710 if (names.size() == 0)
711 return GetSP();
712 ValueObjectSP root(GetSP());
713 for (std::pair<ConstString, bool> name : names)
714 {
715 root = root->GetChildMemberWithName(name.first, name.second);
716 if (!root)
717 {
718 if (name_of_error)
719 *name_of_error = name.first;
720 return root;
721 }
722 }
723 return root;
724}
725
Greg Claytonc7bece562013-01-25 18:06:21 +0000726size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000727ValueObject::GetIndexOfChildWithName (const ConstString &name)
728{
729 bool omit_empty_base_classes = true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000730 return GetClangType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000731}
732
733ValueObjectSP
734ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
735{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000736 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000737 // classes (which really aren't part of the expression path), so we
738 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000739 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000740
Greg Claytondea8cb42011-06-29 22:09:02 +0000741 // We may need to update our value if we are dynamic
742 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000743 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000744
745 std::vector<uint32_t> child_indexes;
Greg Claytondea8cb42011-06-29 22:09:02 +0000746 bool omit_empty_base_classes = true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000747 const size_t num_child_indexes = GetClangType().GetIndexOfChildMemberWithName (name.GetCString(),
748 omit_empty_base_classes,
749 child_indexes);
Greg Claytondea8cb42011-06-29 22:09:02 +0000750 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000751 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000752 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
753 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
754
755 child_sp = GetChildAtIndex(*pos, can_create);
756 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000757 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000758 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000759 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000760 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
761 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000762 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000763 else
764 {
765 child_sp.reset();
766 }
767
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000768 }
769 }
770 return child_sp;
771}
772
773
Greg Claytonc7bece562013-01-25 18:06:21 +0000774size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000775ValueObject::GetNumChildren ()
776{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000777 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000778 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000779 {
780 SetNumChildren (CalculateNumChildren());
781 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000782 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000783}
Greg Clayton4a792072012-10-23 01:50:10 +0000784
785bool
786ValueObject::MightHaveChildren()
787{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000788 bool has_children = false;
Greg Clayton2452ab72013-02-08 22:02:02 +0000789 const uint32_t type_info = GetTypeInfo();
790 if (type_info)
Greg Clayton4a792072012-10-23 01:50:10 +0000791 {
Enrico Granata622be232014-10-21 20:52:14 +0000792 if (type_info & (eTypeHasChildren |
793 eTypeIsPointer |
794 eTypeIsReference))
Greg Clayton4a792072012-10-23 01:50:10 +0000795 has_children = true;
796 }
797 else
798 {
799 has_children = GetNumChildren () > 0;
800 }
801 return has_children;
802}
803
804// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000805void
Greg Claytonc7bece562013-01-25 18:06:21 +0000806ValueObject::SetNumChildren (size_t num_children)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000807{
Greg Clayton288bdf92010-09-02 02:59:18 +0000808 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000809 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000810}
811
812void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000813ValueObject::SetName (const ConstString &name)
814{
815 m_name = name;
816}
817
Jim Ingham58b59f92011-04-22 23:53:53 +0000818ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000819ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000820{
Jim Ingham2eec4872011-05-07 00:10:58 +0000821 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000822
Greg Claytondea8cb42011-06-29 22:09:02 +0000823 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000824 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000825 std::string child_name_str;
826 uint32_t child_byte_size = 0;
827 int32_t child_byte_offset = 0;
828 uint32_t child_bitfield_bit_size = 0;
829 uint32_t child_bitfield_bit_offset = 0;
830 bool child_is_base_class = false;
831 bool child_is_deref_of_parent = false;
832
833 const bool transparent_pointers = synthetic_array_member == false;
Greg Clayton57ee3062013-07-11 22:46:58 +0000834 ClangASTType child_clang_type;
Greg Claytondea8cb42011-06-29 22:09:02 +0000835
Greg Claytoncc4d0142012-02-17 07:49:44 +0000836 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000837
Greg Clayton57ee3062013-07-11 22:46:58 +0000838 child_clang_type = GetClangType().GetChildClangTypeAtIndex (&exe_ctx,
Greg Clayton57ee3062013-07-11 22:46:58 +0000839 idx,
840 transparent_pointers,
841 omit_empty_base_classes,
842 ignore_array_bounds,
843 child_name_str,
844 child_byte_size,
845 child_byte_offset,
846 child_bitfield_bit_size,
847 child_bitfield_bit_offset,
848 child_is_base_class,
Greg Clayton759e7442014-07-19 00:12:57 +0000849 child_is_deref_of_parent,
850 this);
Greg Clayton4ef877f2012-12-06 02:33:54 +0000851 if (child_clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000852 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000853 if (synthetic_index)
854 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000855
Greg Claytondea8cb42011-06-29 22:09:02 +0000856 ConstString child_name;
857 if (!child_name_str.empty())
858 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000859
Greg Claytondea8cb42011-06-29 22:09:02 +0000860 valobj = new ValueObjectChild (*this,
Greg Claytondea8cb42011-06-29 22:09:02 +0000861 child_clang_type,
862 child_name,
863 child_byte_size,
864 child_byte_offset,
865 child_bitfield_bit_size,
866 child_bitfield_bit_offset,
867 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000868 child_is_deref_of_parent,
869 eAddressTypeInvalid);
870 //if (valobj)
871 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
872 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000873
Jim Ingham58b59f92011-04-22 23:53:53 +0000874 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000875}
876
Enrico Granata0c489f52012-03-01 04:24:26 +0000877bool
878ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
879 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000880{
Enrico Granatac1247f52014-11-06 21:23:20 +0000881 return GetSummaryAsCString(summary_ptr, destination, TypeSummaryOptions());
882}
883
884bool
885ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
886 std::string& destination,
887 const TypeSummaryOptions& options)
888{
Enrico Granata0c489f52012-03-01 04:24:26 +0000889 destination.clear();
890
891 // ideally we would like to bail out if passing NULL, but if we do so
892 // we end up not providing the summary for function pointers anymore
893 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
894 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000895
896 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000897
898 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
899 // information that we might care to see in a crash log. might be useful in very specific situations though.
900 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
901 GetTypeName().GetCString(),
902 GetName().GetCString(),
903 summary_ptr->GetDescription().c_str());*/
904
Enrico Granataff0f23d2014-12-10 02:00:45 +0000905 if (UpdateValueIfNeeded (false) && summary_ptr)
Enrico Granata0c489f52012-03-01 04:24:26 +0000906 {
Enrico Granataff0f23d2014-12-10 02:00:45 +0000907 if (HasSyntheticValue())
908 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
909 summary_ptr->FormatObject(this, destination, options);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000910 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000911 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000912 return !destination.empty();
913}
914
915const char *
916ValueObject::GetSummaryAsCString ()
917{
918 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
919 {
920 GetSummaryAsCString(GetSummaryFormat().get(),
Enrico Granatac1247f52014-11-06 21:23:20 +0000921 m_summary_str,
Enrico Granata49bfafb2014-11-18 23:36:25 +0000922 TypeSummaryOptions());
Enrico Granata0c489f52012-03-01 04:24:26 +0000923 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000924 if (m_summary_str.empty())
925 return NULL;
926 return m_summary_str.c_str();
927}
928
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000929bool
Enrico Granata49bfafb2014-11-18 23:36:25 +0000930ValueObject::GetSummaryAsCString (std::string& destination,
931 const TypeSummaryOptions& options)
932{
933 return GetSummaryAsCString(GetSummaryFormat().get(),
934 destination,
935 options);
936}
937
938bool
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000939ValueObject::IsCStringContainer(bool check_pointer)
940{
Greg Clayton57ee3062013-07-11 22:46:58 +0000941 ClangASTType pointee_or_element_clang_type;
942 const Flags type_flags (GetTypeInfo (&pointee_or_element_clang_type));
Enrico Granata622be232014-10-21 20:52:14 +0000943 bool is_char_arr_ptr (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Greg Clayton57ee3062013-07-11 22:46:58 +0000944 pointee_or_element_clang_type.IsCharType ());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000945 if (!is_char_arr_ptr)
946 return false;
947 if (!check_pointer)
948 return true;
Enrico Granata622be232014-10-21 20:52:14 +0000949 if (type_flags.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000950 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000951 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000952 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000953 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000954 return (cstr_address != LLDB_INVALID_ADDRESS);
955}
956
Enrico Granata9128ee22011-09-06 19:20:51 +0000957size_t
958ValueObject::GetPointeeData (DataExtractor& data,
959 uint32_t item_idx,
960 uint32_t item_count)
961{
Greg Clayton57ee3062013-07-11 22:46:58 +0000962 ClangASTType pointee_or_element_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +0000963 const uint32_t type_info = GetTypeInfo (&pointee_or_element_clang_type);
Enrico Granata622be232014-10-21 20:52:14 +0000964 const bool is_pointer_type = type_info & eTypeIsPointer;
965 const bool is_array_type = type_info & eTypeIsArray;
Greg Clayton2452ab72013-02-08 22:02:02 +0000966 if (!(is_pointer_type || is_array_type))
Enrico Granata9128ee22011-09-06 19:20:51 +0000967 return 0;
968
969 if (item_count == 0)
970 return 0;
971
Greg Clayton57ee3062013-07-11 22:46:58 +0000972 const uint64_t item_type_size = pointee_or_element_clang_type.GetByteSize();
Enrico Granata9128ee22011-09-06 19:20:51 +0000973 const uint64_t bytes = item_count * item_type_size;
Enrico Granata9128ee22011-09-06 19:20:51 +0000974 const uint64_t offset = item_idx * item_type_size;
975
976 if (item_idx == 0 && item_count == 1) // simply a deref
977 {
Greg Clayton2452ab72013-02-08 22:02:02 +0000978 if (is_pointer_type)
Enrico Granata9128ee22011-09-06 19:20:51 +0000979 {
980 Error error;
981 ValueObjectSP pointee_sp = Dereference(error);
982 if (error.Fail() || pointee_sp.get() == NULL)
983 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +0000984 return pointee_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +0000985 }
986 else
987 {
988 ValueObjectSP child_sp = GetChildAtIndex(0, true);
989 if (child_sp.get() == NULL)
990 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +0000991 Error error;
992 return child_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +0000993 }
994 return true;
995 }
996 else /* (items > 1) */
997 {
998 Error error;
999 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
1000 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
1001
1002 AddressType addr_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001003 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001004
Enrico Granata9128ee22011-09-06 19:20:51 +00001005 switch (addr_type)
1006 {
1007 case eAddressTypeFile:
1008 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001009 ModuleSP module_sp (GetModule());
1010 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001011 {
Enrico Granata9c2efe32012-08-07 01:49:34 +00001012 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +00001013 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001014 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001015 ExecutionContext exe_ctx (GetExecutionContextRef());
1016 Target* target = exe_ctx.GetTargetPtr();
1017 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +00001018 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001019 heap_buf_ptr->SetByteSize(bytes);
1020 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
1021 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +00001022 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001023 data.SetData(data_sp);
1024 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +00001025 }
1026 }
1027 }
1028 }
1029 break;
1030 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +00001031 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001032 ExecutionContext exe_ctx (GetExecutionContextRef());
1033 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +00001034 if (process)
1035 {
1036 heap_buf_ptr->SetByteSize(bytes);
1037 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
Enrico Granata5e1480c2013-10-30 17:52:44 +00001038 if (error.Success() || bytes_read > 0)
Enrico Granata9128ee22011-09-06 19:20:51 +00001039 {
1040 data.SetData(data_sp);
1041 return bytes_read;
1042 }
1043 }
1044 }
1045 break;
1046 case eAddressTypeHost:
1047 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001048 const uint64_t max_bytes = GetClangType().GetByteSize();
Greg Clayton2452ab72013-02-08 22:02:02 +00001049 if (max_bytes > offset)
1050 {
1051 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
1052 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
1053 data.SetData(data_sp);
1054 return bytes_read;
1055 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001056 }
1057 break;
1058 case eAddressTypeInvalid:
Enrico Granata9128ee22011-09-06 19:20:51 +00001059 break;
1060 }
1061 }
1062 return 0;
1063}
1064
Greg Claytonfaac1112013-03-14 18:31:44 +00001065uint64_t
Sean Callanan866e91c2014-02-28 22:27:53 +00001066ValueObject::GetData (DataExtractor& data, Error &error)
Enrico Granata9128ee22011-09-06 19:20:51 +00001067{
1068 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001069 ExecutionContext exe_ctx (GetExecutionContextRef());
Sean Callanan866e91c2014-02-28 22:27:53 +00001070 error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001071 if (error.Fail())
Sean Callananed185ab2013-04-19 19:47:32 +00001072 {
1073 if (m_data.GetByteSize())
1074 {
1075 data = m_data;
1076 return data.GetByteSize();
1077 }
1078 else
1079 {
1080 return 0;
1081 }
1082 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001083 data.SetAddressByteSize(m_data.GetAddressByteSize());
1084 data.SetByteOrder(m_data.GetByteOrder());
1085 return data.GetByteSize();
1086}
1087
Sean Callanan389823e2013-04-13 01:21:23 +00001088bool
1089ValueObject::SetData (DataExtractor &data, Error &error)
1090{
1091 error.Clear();
1092 // Make sure our value is up to date first so that our location and location
1093 // type is valid.
1094 if (!UpdateValueIfNeeded(false))
1095 {
1096 error.SetErrorString("unable to read value");
1097 return false;
1098 }
1099
1100 uint64_t count = 0;
Greg Clayton57ee3062013-07-11 22:46:58 +00001101 const Encoding encoding = GetClangType().GetEncoding(count);
Sean Callanan389823e2013-04-13 01:21:23 +00001102
1103 const size_t byte_size = GetByteSize();
1104
1105 Value::ValueType value_type = m_value.GetValueType();
1106
1107 switch (value_type)
1108 {
1109 case Value::eValueTypeScalar:
1110 {
1111 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1112
1113 if (!set_error.Success())
1114 {
1115 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1116 return false;
1117 }
1118 }
1119 break;
1120 case Value::eValueTypeLoadAddress:
1121 {
1122 // If it is a load address, then the scalar value is the storage location
1123 // of the data, and we have to shove this value down to that load location.
1124 ExecutionContext exe_ctx (GetExecutionContextRef());
1125 Process *process = exe_ctx.GetProcessPtr();
1126 if (process)
1127 {
1128 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1129 size_t bytes_written = process->WriteMemory(target_addr,
1130 data.GetDataStart(),
1131 byte_size,
1132 error);
1133 if (!error.Success())
1134 return false;
1135 if (bytes_written != byte_size)
1136 {
1137 error.SetErrorString("unable to write value to memory");
1138 return false;
1139 }
1140 }
1141 }
1142 break;
1143 case Value::eValueTypeHostAddress:
1144 {
1145 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1146 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1147 m_data.SetData(buffer_sp, 0);
1148 data.CopyByteOrderedData (0,
1149 byte_size,
1150 const_cast<uint8_t *>(m_data.GetDataStart()),
1151 byte_size,
1152 m_data.GetByteOrder());
1153 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1154 }
1155 break;
1156 case Value::eValueTypeFileAddress:
1157 case Value::eValueTypeVector:
1158 break;
1159 }
1160
1161 // If we have reached this point, then we have successfully changed the value.
1162 SetNeedsUpdate();
1163 return true;
1164}
1165
Enrico Granata9128ee22011-09-06 19:20:51 +00001166// will compute strlen(str), but without consuming more than
1167// maxlen bytes out of str (this serves the purpose of reading
1168// chunks of a string without having to worry about
1169// missing NULL terminators in the chunk)
1170// of course, if strlen(str) > maxlen, the function will return
1171// maxlen_value (which should be != maxlen, because that allows you
1172// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1173static uint32_t
1174strlen_or_inf (const char* str,
1175 uint32_t maxlen,
1176 uint32_t maxlen_value)
1177{
1178 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +00001179 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +00001180 {
Greg Clayton8dd5c172011-10-05 22:19:51 +00001181 while(*str)
1182 {
1183 len++;str++;
Greg Clayton2452ab72013-02-08 22:02:02 +00001184 if (len >= maxlen)
Greg Clayton8dd5c172011-10-05 22:19:51 +00001185 return maxlen_value;
1186 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001187 }
1188 return len;
1189}
1190
Enrico Granata2206b482014-10-30 18:27:31 +00001191static bool
1192CopyStringDataToBufferSP(const StreamString& source,
1193 lldb::DataBufferSP& destination)
1194{
1195 destination.reset(new DataBufferHeap(source.GetSize()+1,0));
1196 memcpy(destination->GetBytes(), source.GetString().c_str(), source.GetSize());
1197 return true;
1198}
1199
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001200size_t
Enrico Granata2206b482014-10-30 18:27:31 +00001201ValueObject::ReadPointedString (lldb::DataBufferSP& buffer_sp,
Greg Claytoncc4d0142012-02-17 07:49:44 +00001202 Error& error,
1203 uint32_t max_length,
1204 bool honor_array,
1205 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001206{
Enrico Granata2206b482014-10-30 18:27:31 +00001207 StreamString s;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001208 ExecutionContext exe_ctx (GetExecutionContextRef());
1209 Target* target = exe_ctx.GetTargetPtr();
Enrico Granata2206b482014-10-30 18:27:31 +00001210
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001211 if (!target)
1212 {
1213 s << "<no target to read from>";
1214 error.SetErrorString("no target to read from");
Enrico Granata2206b482014-10-30 18:27:31 +00001215 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001216 return 0;
1217 }
1218
1219 if (max_length == 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001220 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001221
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001222 size_t bytes_read = 0;
1223 size_t total_bytes_read = 0;
1224
Greg Clayton57ee3062013-07-11 22:46:58 +00001225 ClangASTType clang_type = GetClangType();
1226 ClangASTType elem_or_pointee_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001227 const Flags type_flags (GetTypeInfo (&elem_or_pointee_clang_type));
Enrico Granata622be232014-10-21 20:52:14 +00001228 if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Greg Clayton57ee3062013-07-11 22:46:58 +00001229 elem_or_pointee_clang_type.IsCharType ())
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001230 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001231 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1232 AddressType cstr_address_type = eAddressTypeInvalid;
1233
1234 size_t cstr_len = 0;
1235 bool capped_data = false;
Enrico Granata622be232014-10-21 20:52:14 +00001236 if (type_flags.Test (eTypeIsArray))
Greg Claytoncc4d0142012-02-17 07:49:44 +00001237 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001238 // We have an array
Greg Clayton57ee3062013-07-11 22:46:58 +00001239 uint64_t array_size = 0;
1240 if (clang_type.IsArrayType(NULL, &array_size, NULL))
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001241 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001242 cstr_len = array_size;
1243 if (cstr_len > max_length)
1244 {
1245 capped_data = true;
1246 cstr_len = max_length;
1247 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001248 }
1249 cstr_address = GetAddressOf (true, &cstr_address_type);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001250 }
1251 else
1252 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001253 // We have a pointer
1254 cstr_address = GetPointerValue (&cstr_address_type);
1255 }
1256
1257 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1258 {
1259 s << "<invalid address>";
1260 error.SetErrorString("invalid address");
Enrico Granata2206b482014-10-30 18:27:31 +00001261 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001262 return 0;
1263 }
Enrico Granata2206b482014-10-30 18:27:31 +00001264
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001265 Address cstr_so_addr (cstr_address);
1266 DataExtractor data;
1267 if (cstr_len > 0 && honor_array)
1268 {
1269 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1270 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1271 GetPointeeData(data, 0, cstr_len);
Enrico Granata2206b482014-10-30 18:27:31 +00001272
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001273 if ((bytes_read = data.GetByteSize()) > 0)
1274 {
1275 total_bytes_read = bytes_read;
Enrico Granata2206b482014-10-30 18:27:31 +00001276 for (size_t offset = 0; offset < bytes_read; offset++)
1277 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001278 if (capped_data)
1279 s << "...";
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001280 }
1281 }
1282 else
1283 {
1284 cstr_len = max_length;
1285 const size_t k_max_buf_size = 64;
Enrico Granata2206b482014-10-30 18:27:31 +00001286
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001287 size_t offset = 0;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001288
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001289 int cstr_len_displayed = -1;
1290 bool capped_cstr = false;
1291 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1292 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1293 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001294 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001295 total_bytes_read += bytes_read;
1296 const char *cstr = data.PeekCStr(0);
1297 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1298 if (len > k_max_buf_size)
1299 len = k_max_buf_size;
Enrico Granata2206b482014-10-30 18:27:31 +00001300
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001301 if (cstr_len_displayed < 0)
1302 cstr_len_displayed = len;
Enrico Granata2206b482014-10-30 18:27:31 +00001303
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001304 if (len == 0)
1305 break;
1306 cstr_len_displayed += len;
1307 if (len > bytes_read)
1308 len = bytes_read;
1309 if (len > cstr_len)
1310 len = cstr_len;
1311
Enrico Granata2206b482014-10-30 18:27:31 +00001312 for (size_t offset = 0; offset < bytes_read; offset++)
1313 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001314
1315 if (len < k_max_buf_size)
1316 break;
1317
1318 if (len >= cstr_len)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001319 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001320 capped_cstr = true;
1321 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001322 }
Enrico Granata2206b482014-10-30 18:27:31 +00001323
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001324 cstr_len -= len;
1325 offset += len;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001326 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001327
1328 if (cstr_len_displayed >= 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001329 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001330 if (capped_cstr)
1331 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001332 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001333 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001334 }
1335 else
1336 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001337 error.SetErrorString("not a string object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001338 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001339 }
Enrico Granata2206b482014-10-30 18:27:31 +00001340 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001341 return total_bytes_read;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001342}
1343
Enrico Granata744794a2014-09-05 21:46:22 +00001344std::pair<TypeValidatorResult, std::string>
1345ValueObject::GetValidationStatus ()
1346{
1347 if (!UpdateValueIfNeeded(true))
1348 return {TypeValidatorResult::Success,""}; // not the validator's job to discuss update problems
1349
1350 if (m_validation_result.hasValue())
1351 return m_validation_result.getValue();
1352
1353 if (!m_type_validator_sp)
1354 return {TypeValidatorResult::Success,""}; // no validator no failure
1355
1356 auto outcome = m_type_validator_sp->FormatObject(this);
1357
1358 return (m_validation_result = {outcome.m_result,outcome.m_message}).getValue();
1359}
1360
Jim Ingham53c47f12010-09-10 23:12:17 +00001361const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001362ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001363{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001364
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001365 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001366 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001367
1368 if (!m_object_desc_str.empty())
1369 return m_object_desc_str.c_str();
1370
Greg Claytoncc4d0142012-02-17 07:49:44 +00001371 ExecutionContext exe_ctx (GetExecutionContextRef());
1372 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001373 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001374 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001375
Jim Ingham53c47f12010-09-10 23:12:17 +00001376 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001377
Greg Claytonafacd142011-09-02 01:15:17 +00001378 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001379 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1380
Jim Inghama2cf2632010-12-23 02:29:54 +00001381 if (runtime == NULL)
1382 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001383 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Greg Clayton57ee3062013-07-11 22:46:58 +00001384 ClangASTType clang_type = GetClangType();
1385 if (clang_type)
Jim Inghama2cf2632010-12-23 02:29:54 +00001386 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001387 bool is_signed;
Greg Clayton57ee3062013-07-11 22:46:58 +00001388 if (clang_type.IsIntegerType (is_signed) || clang_type.IsPointerType ())
Jim Inghamb7603bb2011-03-18 00:05:18 +00001389 {
Greg Claytonafacd142011-09-02 01:15:17 +00001390 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001391 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001392 }
1393 }
1394
Jim Ingham8d543de2011-03-31 23:01:21 +00001395 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001396 {
1397 m_object_desc_str.append (s.GetData());
1398 }
Sean Callanan672ad942010-10-23 00:18:49 +00001399
1400 if (m_object_desc_str.empty())
1401 return NULL;
1402 else
1403 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001404}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001405
Enrico Granata0c489f52012-03-01 04:24:26 +00001406bool
Enrico Granata4939b982013-12-22 09:24:22 +00001407ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format,
1408 std::string& destination)
1409{
1410 if (UpdateValueIfNeeded(false))
1411 return format.FormatObject(this,destination);
1412 else
1413 return false;
1414}
1415
1416bool
Enrico Granata0c489f52012-03-01 04:24:26 +00001417ValueObject::GetValueAsCString (lldb::Format format,
1418 std::string& destination)
1419{
Enrico Granata30f287f2013-12-28 08:44:02 +00001420 return GetValueAsCString(TypeFormatImpl_Format(format),destination);
Enrico Granata0c489f52012-03-01 04:24:26 +00001421}
1422
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001423const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001424ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001425{
Enrico Granatab294fd22013-05-31 19:18:19 +00001426 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001427 {
Enrico Granata4939b982013-12-22 09:24:22 +00001428 lldb::TypeFormatImplSP format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001429 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001430 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001431 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001432 if (m_type_format_sp)
Enrico Granata4939b982013-12-22 09:24:22 +00001433 format_sp = m_type_format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001434 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001435 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001436 if (m_is_bitfield_for_scalar)
1437 my_format = eFormatUnsigned;
1438 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001439 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001440 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001441 {
1442 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1443 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001444 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001445 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001446 else
1447 {
Enrico Granatad07cfd32014-10-08 18:27:36 +00001448 my_format = GetValue().GetClangType().GetFormat();
Enrico Granata0c489f52012-03-01 04:24:26 +00001449 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001450 }
1451 }
1452 }
Enrico Granatab294fd22013-05-31 19:18:19 +00001453 if (my_format != m_last_format || m_value_str.empty())
Enrico Granata297e69f2012-03-06 23:21:16 +00001454 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001455 m_last_format = my_format;
Enrico Granata4939b982013-12-22 09:24:22 +00001456 if (!format_sp)
Enrico Granata30f287f2013-12-28 08:44:02 +00001457 format_sp.reset(new TypeFormatImpl_Format(my_format));
Enrico Granata4939b982013-12-22 09:24:22 +00001458 if (GetValueAsCString(*format_sp.get(), m_value_str))
Enrico Granata297e69f2012-03-06 23:21:16 +00001459 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001460 if (!m_value_did_change && m_old_value_valid)
1461 {
1462 // The value was gotten successfully, so we consider the
1463 // value as changed if the value string differs
1464 SetValueDidChange (m_old_value_str != m_value_str);
1465 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001466 }
1467 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001468 }
1469 if (m_value_str.empty())
1470 return NULL;
1471 return m_value_str.c_str();
1472}
1473
Enrico Granatac3e320a2011-08-02 17:27:39 +00001474// if > 8bytes, 0 is returned. this method should mostly be used
1475// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001476uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001477ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001478{
1479 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001480 if (CanProvideValue())
Enrico Granatac3e320a2011-08-02 17:27:39 +00001481 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001482 Scalar scalar;
1483 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001484 {
1485 if (success)
1486 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001487 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001488 }
1489 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001490 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001491
1492 if (success)
1493 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001494 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001495}
1496
Enrico Granatad7373f62013-10-31 18:57:50 +00001497int64_t
1498ValueObject::GetValueAsSigned (int64_t fail_value, bool *success)
1499{
1500 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001501 if (CanProvideValue())
Enrico Granatad7373f62013-10-31 18:57:50 +00001502 {
1503 Scalar scalar;
1504 if (ResolveValue (scalar))
1505 {
1506 if (success)
1507 *success = true;
1508 return scalar.SLongLong(fail_value);
1509 }
1510 // fallthrough, otherwise...
1511 }
1512
1513 if (success)
1514 *success = false;
1515 return fail_value;
1516}
1517
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001518// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1519// this call up to date by returning true for your new special cases. We will eventually move
1520// to checking this call result before trying to display special cases
1521bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001522ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1523 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001524{
Greg Clayton57ee3062013-07-11 22:46:58 +00001525 Flags flags(GetTypeInfo());
Enrico Granata622be232014-10-21 20:52:14 +00001526 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001527 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001528 {
1529 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001530 (custom_format == eFormatCString ||
1531 custom_format == eFormatCharArray ||
1532 custom_format == eFormatChar ||
1533 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001534 return true;
1535
Enrico Granata622be232014-10-21 20:52:14 +00001536 if (flags.Test(eTypeIsArray))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001537 {
Greg Claytonafacd142011-09-02 01:15:17 +00001538 if ((custom_format == eFormatBytes) ||
1539 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001540 return true;
1541
Greg Claytonafacd142011-09-02 01:15:17 +00001542 if ((custom_format == eFormatVectorOfChar) ||
1543 (custom_format == eFormatVectorOfFloat32) ||
1544 (custom_format == eFormatVectorOfFloat64) ||
1545 (custom_format == eFormatVectorOfSInt16) ||
1546 (custom_format == eFormatVectorOfSInt32) ||
1547 (custom_format == eFormatVectorOfSInt64) ||
1548 (custom_format == eFormatVectorOfSInt8) ||
1549 (custom_format == eFormatVectorOfUInt128) ||
1550 (custom_format == eFormatVectorOfUInt16) ||
1551 (custom_format == eFormatVectorOfUInt32) ||
1552 (custom_format == eFormatVectorOfUInt64) ||
1553 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001554 return true;
1555 }
1556 }
1557 return false;
1558}
1559
Enrico Granata9fc19442011-07-06 02:13:41 +00001560bool
1561ValueObject::DumpPrintableRepresentation(Stream& s,
1562 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001563 Format custom_format,
Enrico Granata0dba9b32014-01-08 01:36:59 +00001564 PrintableRepresentationSpecialCases special,
1565 bool do_dump_error)
Enrico Granata9fc19442011-07-06 02:13:41 +00001566{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001567
Greg Clayton57ee3062013-07-11 22:46:58 +00001568 Flags flags(GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001569
Enrico Granata86cc9822012-03-19 22:58:49 +00001570 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1571 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1572
1573 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001574 {
Enrico Granata622be232014-10-21 20:52:14 +00001575 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001576 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001577 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001578 // when being asked to get a printable display an array or pointer type directly,
1579 // try to "do the right thing"
1580
1581 if (IsCStringContainer(true) &&
1582 (custom_format == eFormatCString ||
1583 custom_format == eFormatCharArray ||
1584 custom_format == eFormatChar ||
1585 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001586 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001587 Error error;
Enrico Granata2206b482014-10-30 18:27:31 +00001588 lldb::DataBufferSP buffer_sp;
1589 ReadPointedString(buffer_sp,
Enrico Granata86cc9822012-03-19 22:58:49 +00001590 error,
1591 0,
1592 (custom_format == eFormatVectorOfChar) ||
1593 (custom_format == eFormatCharArray));
Enrico Granataebdc1ac2014-11-05 21:20:48 +00001594 lldb_private::formatters::ReadBufferAndDumpToStreamOptions options(*this);
Enrico Granata2206b482014-10-30 18:27:31 +00001595 options.SetData(DataExtractor(buffer_sp, lldb::eByteOrderInvalid, 8)); // none of this matters for a string - pass some defaults
1596 options.SetStream(&s);
1597 options.SetPrefixToken(0);
1598 options.SetQuote('"');
1599 options.SetSourceSize(buffer_sp->GetByteSize());
Enrico Granata2206b482014-10-30 18:27:31 +00001600 lldb_private::formatters::ReadBufferAndDumpToStream<lldb_private::formatters::StringElementType::ASCII>(options);
Enrico Granata86cc9822012-03-19 22:58:49 +00001601 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001602 }
1603
Enrico Granata86cc9822012-03-19 22:58:49 +00001604 if (custom_format == eFormatEnum)
1605 return false;
1606
1607 // this only works for arrays, because I have no way to know when
1608 // the pointed memory ends, and no special \0 end of data marker
Enrico Granata622be232014-10-21 20:52:14 +00001609 if (flags.Test(eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001610 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001611 if ((custom_format == eFormatBytes) ||
1612 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001613 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001614 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001615
1616 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001617 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001618 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001619
1620 if (low)
1621 s << ',';
1622
1623 ValueObjectSP child = GetChildAtIndex(low,true);
1624 if (!child.get())
1625 {
1626 s << "<invalid child>";
1627 continue;
1628 }
1629 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1630 }
1631
1632 s << ']';
1633
1634 return true;
1635 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001636
Enrico Granata86cc9822012-03-19 22:58:49 +00001637 if ((custom_format == eFormatVectorOfChar) ||
1638 (custom_format == eFormatVectorOfFloat32) ||
1639 (custom_format == eFormatVectorOfFloat64) ||
1640 (custom_format == eFormatVectorOfSInt16) ||
1641 (custom_format == eFormatVectorOfSInt32) ||
1642 (custom_format == eFormatVectorOfSInt64) ||
1643 (custom_format == eFormatVectorOfSInt8) ||
1644 (custom_format == eFormatVectorOfUInt128) ||
1645 (custom_format == eFormatVectorOfUInt16) ||
1646 (custom_format == eFormatVectorOfUInt32) ||
1647 (custom_format == eFormatVectorOfUInt64) ||
1648 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1649 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001650 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001651
1652 Format format = FormatManager::GetSingleItemFormat(custom_format);
1653
1654 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001655 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001656 {
1657
1658 if (low)
1659 s << ',';
1660
1661 ValueObjectSP child = GetChildAtIndex(low,true);
1662 if (!child.get())
1663 {
1664 s << "<invalid child>";
1665 continue;
1666 }
1667 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1668 }
1669
1670 s << ']';
1671
1672 return true;
1673 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001674 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001675
1676 if ((custom_format == eFormatBoolean) ||
1677 (custom_format == eFormatBinary) ||
1678 (custom_format == eFormatChar) ||
1679 (custom_format == eFormatCharPrintable) ||
1680 (custom_format == eFormatComplexFloat) ||
1681 (custom_format == eFormatDecimal) ||
1682 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001683 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001684 (custom_format == eFormatFloat) ||
1685 (custom_format == eFormatOctal) ||
1686 (custom_format == eFormatOSType) ||
1687 (custom_format == eFormatUnicode16) ||
1688 (custom_format == eFormatUnicode32) ||
1689 (custom_format == eFormatUnsigned) ||
1690 (custom_format == eFormatPointer) ||
1691 (custom_format == eFormatComplexInteger) ||
1692 (custom_format == eFormatComplex) ||
1693 (custom_format == eFormatDefault)) // use the [] operator
1694 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001695 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001696 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001697
1698 if (only_special)
1699 return false;
1700
Enrico Granata86cc9822012-03-19 22:58:49 +00001701 bool var_success = false;
1702
1703 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001704 const char *cstr = NULL;
Enrico Granata2c75f112013-06-21 00:04:51 +00001705
1706 // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1707 // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1708 // area for cases where our desired output is not backed by some other longer-term storage
Greg Claytonc7bece562013-01-25 18:06:21 +00001709 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001710
Enrico Granata465f4bc2014-02-15 01:24:44 +00001711 if (custom_format != eFormatInvalid)
Enrico Granata86cc9822012-03-19 22:58:49 +00001712 SetFormat(custom_format);
1713
1714 switch(val_obj_display)
1715 {
1716 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001717 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001718 break;
1719
1720 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001721 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001722 break;
1723
1724 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001725 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001726 break;
1727
1728 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001729 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001730 break;
1731
1732 case eValueObjectRepresentationStyleChildrenCount:
Deepak Panickal99fbc072014-03-03 15:39:47 +00001733 strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren());
Greg Claytonc7bece562013-01-25 18:06:21 +00001734 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001735 break;
1736
1737 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001738 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001739 break;
Enrico Granata2c75f112013-06-21 00:04:51 +00001740
1741 case eValueObjectRepresentationStyleName:
1742 cstr = GetName().AsCString();
1743 break;
1744
1745 case eValueObjectRepresentationStyleExpressionPath:
1746 GetExpressionPath(strm, false);
1747 cstr = strm.GetString().c_str();
1748 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001749 }
1750
Greg Claytonc7bece562013-01-25 18:06:21 +00001751 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001752 {
1753 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001754 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001755 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1756 {
Enrico Granatad07cfd32014-10-08 18:27:36 +00001757 if (!CanProvideValue())
Enrico Granata86cc9822012-03-19 22:58:49 +00001758 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001759 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1760 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001761 }
1762 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001763 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001764 }
1765 }
1766
Greg Claytonc7bece562013-01-25 18:06:21 +00001767 if (cstr)
1768 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001769 else
1770 {
1771 if (m_error.Fail())
Enrico Granata0dba9b32014-01-08 01:36:59 +00001772 {
1773 if (do_dump_error)
1774 s.Printf("<%s>", m_error.AsCString());
1775 else
1776 return false;
1777 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001778 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1779 s.PutCString("<no summary available>");
1780 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1781 s.PutCString("<no value available>");
1782 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1783 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1784 else
1785 s.PutCString("<no printable representation>");
1786 }
1787
1788 // we should only return false here if we could not do *anything*
1789 // even if we have an error message as output, that's a success
1790 // from our callers' perspective, so return true
1791 var_success = true;
Enrico Granata465f4bc2014-02-15 01:24:44 +00001792
1793 if (custom_format != eFormatInvalid)
1794 SetFormat(eFormatDefault);
Enrico Granata86cc9822012-03-19 22:58:49 +00001795 }
1796
Enrico Granataf4efecd2011-07-12 22:56:10 +00001797 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001798}
1799
Greg Clayton737b9322010-09-13 03:32:57 +00001800addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001801ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001802{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001803 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001804 return LLDB_INVALID_ADDRESS;
1805
Greg Clayton73b472d2010-10-27 03:32:59 +00001806 switch (m_value.GetValueType())
1807 {
1808 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001809 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001810 if (scalar_is_load_address)
1811 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001812 if(address_type)
1813 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001814 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1815 }
1816 break;
1817
1818 case Value::eValueTypeLoadAddress:
1819 case Value::eValueTypeFileAddress:
1820 case Value::eValueTypeHostAddress:
1821 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001822 if(address_type)
1823 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001824 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1825 }
1826 break;
1827 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001828 if (address_type)
1829 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001830 return LLDB_INVALID_ADDRESS;
1831}
1832
1833addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001834ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001835{
Greg Claytonafacd142011-09-02 01:15:17 +00001836 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001837 if(address_type)
1838 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001839
Enrico Granatac3e320a2011-08-02 17:27:39 +00001840 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001841 return address;
1842
Greg Clayton73b472d2010-10-27 03:32:59 +00001843 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001844 {
1845 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001846 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001847 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001848 break;
1849
Enrico Granata9128ee22011-09-06 19:20:51 +00001850 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001851 case Value::eValueTypeLoadAddress:
1852 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001853 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001854 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001855 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001856 }
1857 break;
1858 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001859
Enrico Granata9128ee22011-09-06 19:20:51 +00001860 if (address_type)
1861 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001862
Greg Clayton737b9322010-09-13 03:32:57 +00001863 return address;
1864}
1865
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001866bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001867ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001868{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001869 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001870 // Make sure our value is up to date first so that our location and location
1871 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001872 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001873 {
1874 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001875 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001876 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001877
Greg Claytonfaac1112013-03-14 18:31:44 +00001878 uint64_t count = 0;
Greg Clayton57ee3062013-07-11 22:46:58 +00001879 const Encoding encoding = GetClangType().GetEncoding (count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001880
Greg Claytonb1320972010-07-14 00:18:15 +00001881 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001882
Jim Ingham16e0c682011-08-12 23:34:31 +00001883 Value::ValueType value_type = m_value.GetValueType();
1884
1885 if (value_type == Value::eValueTypeScalar)
1886 {
1887 // If the value is already a scalar, then let the scalar change itself:
1888 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1889 }
1890 else if (byte_size <= Scalar::GetMaxByteSize())
1891 {
1892 // If the value fits in a scalar, then make a new scalar and again let the
1893 // scalar code do the conversion, then figure out where to put the new value.
1894 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001895 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1896 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001897 {
Jim Ingham4b536182011-08-09 02:12:22 +00001898 switch (value_type)
1899 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001900 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001901 {
1902 // If it is a load address, then the scalar value is the storage location
1903 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001904 ExecutionContext exe_ctx (GetExecutionContextRef());
1905 Process *process = exe_ctx.GetProcessPtr();
1906 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001907 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001908 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001909 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1910 new_scalar,
1911 byte_size,
1912 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001913 if (!error.Success())
1914 return false;
1915 if (bytes_written != byte_size)
1916 {
1917 error.SetErrorString("unable to write value to memory");
1918 return false;
1919 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001920 }
1921 }
Jim Ingham4b536182011-08-09 02:12:22 +00001922 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001923 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001924 {
1925 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1926 DataExtractor new_data;
1927 new_data.SetByteOrder (m_data.GetByteOrder());
1928
1929 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1930 m_data.SetData(buffer_sp, 0);
1931 bool success = new_scalar.GetData(new_data);
1932 if (success)
1933 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001934 new_data.CopyByteOrderedData (0,
1935 byte_size,
1936 const_cast<uint8_t *>(m_data.GetDataStart()),
1937 byte_size,
1938 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001939 }
1940 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1941
1942 }
Jim Ingham4b536182011-08-09 02:12:22 +00001943 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001944 case Value::eValueTypeFileAddress:
1945 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001946 case Value::eValueTypeVector:
1947 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001948 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001949 }
1950 else
1951 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001952 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001953 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001954 }
1955 else
1956 {
1957 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001958 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001959 return false;
1960 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001961
1962 // If we have reached this point, then we have successfully changed the value.
1963 SetNeedsUpdate();
1964 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001965}
1966
Greg Clayton81e871e2012-02-04 02:27:34 +00001967bool
1968ValueObject::GetDeclaration (Declaration &decl)
1969{
1970 decl.Clear();
1971 return false;
1972}
1973
Greg Clayton84db9102012-03-26 23:03:23 +00001974ConstString
1975ValueObject::GetTypeName()
1976{
Greg Clayton57ee3062013-07-11 22:46:58 +00001977 return GetClangType().GetConstTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00001978}
1979
1980ConstString
Enrico Granatae8daa2f2014-05-17 19:14:17 +00001981ValueObject::GetDisplayTypeName()
1982{
1983 return GetTypeName();
1984}
1985
1986ConstString
Greg Clayton84db9102012-03-26 23:03:23 +00001987ValueObject::GetQualifiedTypeName()
1988{
Greg Clayton57ee3062013-07-11 22:46:58 +00001989 return GetClangType().GetConstQualifiedTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00001990}
1991
1992
Greg Claytonafacd142011-09-02 01:15:17 +00001993LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001994ValueObject::GetObjectRuntimeLanguage ()
1995{
Greg Clayton57ee3062013-07-11 22:46:58 +00001996 return GetClangType().GetMinimumLanguage ();
Jim Ingham5a369122010-09-28 01:25:32 +00001997}
1998
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001999void
Jim Ingham58b59f92011-04-22 23:53:53 +00002000ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002001{
Jim Ingham58b59f92011-04-22 23:53:53 +00002002 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002003}
2004
2005ValueObjectSP
2006ValueObject::GetSyntheticChild (const ConstString &key) const
2007{
2008 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00002009 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002010 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00002011 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002012 return synthetic_child_sp;
2013}
2014
Greg Clayton2452ab72013-02-08 22:02:02 +00002015uint32_t
Greg Clayton57ee3062013-07-11 22:46:58 +00002016ValueObject::GetTypeInfo (ClangASTType *pointee_or_element_clang_type)
Greg Clayton2452ab72013-02-08 22:02:02 +00002017{
Greg Clayton57ee3062013-07-11 22:46:58 +00002018 return GetClangType().GetTypeInfo (pointee_or_element_clang_type);
Greg Clayton2452ab72013-02-08 22:02:02 +00002019}
2020
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002021bool
2022ValueObject::IsPointerType ()
2023{
Greg Clayton57ee3062013-07-11 22:46:58 +00002024 return GetClangType().IsPointerType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002025}
2026
Jim Inghamb7603bb2011-03-18 00:05:18 +00002027bool
Greg Claytondaf515f2011-07-09 20:12:33 +00002028ValueObject::IsArrayType ()
2029{
Greg Clayton57ee3062013-07-11 22:46:58 +00002030 return GetClangType().IsArrayType (NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00002031}
2032
2033bool
Enrico Granata9fc19442011-07-06 02:13:41 +00002034ValueObject::IsScalarType ()
2035{
Greg Clayton57ee3062013-07-11 22:46:58 +00002036 return GetClangType().IsScalarType ();
Enrico Granata9fc19442011-07-06 02:13:41 +00002037}
2038
2039bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00002040ValueObject::IsIntegerType (bool &is_signed)
2041{
Greg Clayton57ee3062013-07-11 22:46:58 +00002042 return GetClangType().IsIntegerType (is_signed);
Jim Inghamb7603bb2011-03-18 00:05:18 +00002043}
Greg Clayton73b472d2010-10-27 03:32:59 +00002044
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002045bool
2046ValueObject::IsPointerOrReferenceType ()
2047{
Greg Clayton57ee3062013-07-11 22:46:58 +00002048 return GetClangType().IsPointerOrReferenceType ();
Greg Clayton007d5be2011-05-30 00:49:24 +00002049}
2050
2051bool
Greg Claytondea8cb42011-06-29 22:09:02 +00002052ValueObject::IsPossibleDynamicType ()
2053{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002054 ExecutionContext exe_ctx (GetExecutionContextRef());
2055 Process *process = exe_ctx.GetProcessPtr();
2056 if (process)
2057 return process->IsPossibleDynamicValue(*this);
2058 else
Greg Clayton57ee3062013-07-11 22:46:58 +00002059 return GetClangType().IsPossibleDynamicType (NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00002060}
2061
Enrico Granata9e7b3882012-12-13 23:50:33 +00002062bool
2063ValueObject::IsObjCNil ()
2064{
Enrico Granata622be232014-10-21 20:52:14 +00002065 const uint32_t mask = eTypeIsObjC | eTypeIsPointer;
Greg Clayton57ee3062013-07-11 22:46:58 +00002066 bool isObjCpointer = (((GetClangType().GetTypeInfo(NULL)) & mask) == mask);
Enrico Granata7277d202013-03-15 23:33:15 +00002067 if (!isObjCpointer)
2068 return false;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002069 bool canReadValue = true;
2070 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
Enrico Granata7277d202013-03-15 23:33:15 +00002071 return canReadValue && isZero;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002072}
2073
Greg Claytonafacd142011-09-02 01:15:17 +00002074ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002075ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002076{
Greg Clayton2452ab72013-02-08 22:02:02 +00002077 const uint32_t type_info = GetTypeInfo ();
Enrico Granata622be232014-10-21 20:52:14 +00002078 if (type_info & eTypeIsArray)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002079 return GetSyntheticArrayMemberFromArray(index, can_create);
2080
Enrico Granata622be232014-10-21 20:52:14 +00002081 if (type_info & eTypeIsPointer)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002082 return GetSyntheticArrayMemberFromPointer(index, can_create);
2083
2084 return ValueObjectSP();
2085
2086}
2087
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002088ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002089ValueObject::GetSyntheticArrayMemberFromPointer (size_t index, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002090{
2091 ValueObjectSP synthetic_child_sp;
2092 if (IsPointerType ())
2093 {
2094 char index_str[64];
Deepak Panickal99fbc072014-03-03 15:39:47 +00002095 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002096 ConstString index_const_str(index_str);
2097 // Check if we have already created a synthetic array member in this
2098 // valid object. If we have we will re-use it.
2099 synthetic_child_sp = GetSyntheticChild (index_const_str);
2100 if (!synthetic_child_sp)
2101 {
Jim Ingham58b59f92011-04-22 23:53:53 +00002102 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002103 // We haven't made a synthetic array member for INDEX yet, so
2104 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00002105 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002106
2107 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00002108 if (synthetic_child)
2109 {
2110 AddSyntheticChild(index_const_str, synthetic_child);
2111 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002112 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00002113 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00002114 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002115 }
2116 }
2117 return synthetic_child_sp;
2118}
Jim Ingham22777012010-09-23 02:01:19 +00002119
Greg Claytondaf515f2011-07-09 20:12:33 +00002120// This allows you to create an array member using and index
2121// that doesn't not fall in the normal bounds of the array.
2122// Many times structure can be defined as:
2123// struct Collection
2124// {
2125// uint32_t item_count;
2126// Item item_array[0];
2127// };
2128// The size of the "item_array" is 1, but many times in practice
2129// there are more items in "item_array".
2130
2131ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002132ValueObject::GetSyntheticArrayMemberFromArray (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00002133{
2134 ValueObjectSP synthetic_child_sp;
2135 if (IsArrayType ())
2136 {
2137 char index_str[64];
Deepak Panickal99fbc072014-03-03 15:39:47 +00002138 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
Greg Claytondaf515f2011-07-09 20:12:33 +00002139 ConstString index_const_str(index_str);
2140 // Check if we have already created a synthetic array member in this
2141 // valid object. If we have we will re-use it.
2142 synthetic_child_sp = GetSyntheticChild (index_const_str);
2143 if (!synthetic_child_sp)
2144 {
2145 ValueObject *synthetic_child;
2146 // We haven't made a synthetic array member for INDEX yet, so
2147 // lets make one and cache it for any future reference.
2148 synthetic_child = CreateChildAtIndex(0, true, index);
2149
2150 // Cache the value if we got one back...
2151 if (synthetic_child)
2152 {
2153 AddSyntheticChild(index_const_str, synthetic_child);
2154 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002155 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00002156 synthetic_child_sp->m_is_array_item_for_pointer = true;
2157 }
2158 }
2159 }
2160 return synthetic_child_sp;
2161}
2162
Enrico Granata9fc19442011-07-06 02:13:41 +00002163ValueObjectSP
2164ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2165{
2166 ValueObjectSP synthetic_child_sp;
2167 if (IsScalarType ())
2168 {
2169 char index_str[64];
2170 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2171 ConstString index_const_str(index_str);
2172 // Check if we have already created a synthetic array member in this
2173 // valid object. If we have we will re-use it.
2174 synthetic_child_sp = GetSyntheticChild (index_const_str);
2175 if (!synthetic_child_sp)
2176 {
Enrico Granata9fc19442011-07-06 02:13:41 +00002177 // We haven't made a synthetic array member for INDEX yet, so
2178 // lets make one and cache it for any future reference.
Greg Clayton57ee3062013-07-11 22:46:58 +00002179 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
2180 GetClangType(),
2181 index_const_str,
2182 GetByteSize(),
2183 0,
2184 to-from+1,
2185 from,
2186 false,
2187 false,
2188 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002189
2190 // Cache the value if we got one back...
2191 if (synthetic_child)
2192 {
2193 AddSyntheticChild(index_const_str, synthetic_child);
2194 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002195 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002196 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2197 }
2198 }
2199 }
2200 return synthetic_child_sp;
2201}
2202
Greg Claytonafacd142011-09-02 01:15:17 +00002203ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00002204ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
2205{
2206
2207 ValueObjectSP synthetic_child_sp;
2208
2209 char name_str[64];
2210 snprintf(name_str, sizeof(name_str), "@%i", offset);
2211 ConstString name_const_str(name_str);
2212
2213 // Check if we have already created a synthetic array member in this
2214 // valid object. If we have we will re-use it.
2215 synthetic_child_sp = GetSyntheticChild (name_const_str);
2216
2217 if (synthetic_child_sp.get())
2218 return synthetic_child_sp;
2219
2220 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002221 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002222
2223 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
Greg Clayton57ee3062013-07-11 22:46:58 +00002224 type,
Enrico Granata6f3533f2011-07-29 19:53:35 +00002225 name_const_str,
Greg Clayton57ee3062013-07-11 22:46:58 +00002226 type.GetByteSize(),
Enrico Granata6f3533f2011-07-29 19:53:35 +00002227 offset,
2228 0,
2229 0,
2230 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002231 false,
2232 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002233 if (synthetic_child)
2234 {
2235 AddSyntheticChild(name_const_str, synthetic_child);
2236 synthetic_child_sp = synthetic_child->GetSP();
2237 synthetic_child_sp->SetName(name_const_str);
2238 synthetic_child_sp->m_is_child_at_offset = true;
2239 }
2240 return synthetic_child_sp;
2241}
2242
Enrico Granata32556cd2014-08-26 20:54:04 +00002243ValueObjectSP
Enrico Granata59953f02014-08-26 21:35:30 +00002244ValueObject::GetSyntheticBase (uint32_t offset, const ClangASTType& type, bool can_create)
Enrico Granata32556cd2014-08-26 20:54:04 +00002245{
2246 ValueObjectSP synthetic_child_sp;
2247
2248 char name_str[64];
2249 snprintf(name_str, sizeof(name_str), "%s", type.GetTypeName().AsCString("<unknown>"));
2250 ConstString name_const_str(name_str);
2251
2252 // Check if we have already created a synthetic array member in this
2253 // valid object. If we have we will re-use it.
2254 synthetic_child_sp = GetSyntheticChild (name_const_str);
2255
2256 if (synthetic_child_sp.get())
2257 return synthetic_child_sp;
2258
2259 if (!can_create)
2260 return ValueObjectSP();
2261
Enrico Granata32556cd2014-08-26 20:54:04 +00002262 const bool is_base_class = true;
2263
2264 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2265 type,
2266 name_const_str,
2267 type.GetByteSize(),
2268 offset,
2269 0,
2270 0,
2271 is_base_class,
2272 false,
2273 eAddressTypeInvalid);
2274 if (synthetic_child)
2275 {
2276 AddSyntheticChild(name_const_str, synthetic_child);
2277 synthetic_child_sp = synthetic_child->GetSP();
2278 synthetic_child_sp->SetName(name_const_str);
2279 }
2280 return synthetic_child_sp;
2281}
2282
2283
Enrico Granatad55546b2011-07-22 00:16:08 +00002284// your expression path needs to have a leading . or ->
2285// (unless it somehow "looks like" an array, in which case it has
2286// a leading [ symbol). while the [ is meaningful and should be shown
2287// to the user, . and -> are just parser design, but by no means
2288// added information for the user.. strip them off
2289static const char*
2290SkipLeadingExpressionPathSeparators(const char* expression)
2291{
2292 if (!expression || !expression[0])
2293 return expression;
2294 if (expression[0] == '.')
2295 return expression+1;
2296 if (expression[0] == '-' && expression[1] == '>')
2297 return expression+2;
2298 return expression;
2299}
2300
Greg Claytonafacd142011-09-02 01:15:17 +00002301ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002302ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2303{
2304 ValueObjectSP synthetic_child_sp;
2305 ConstString name_const_string(expression);
2306 // Check if we have already created a synthetic array member in this
2307 // valid object. If we have we will re-use it.
2308 synthetic_child_sp = GetSyntheticChild (name_const_string);
2309 if (!synthetic_child_sp)
2310 {
2311 // We haven't made a synthetic array member for expression yet, so
2312 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002313 synthetic_child_sp = GetValueForExpressionPath(expression,
2314 NULL, NULL, NULL,
2315 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
Enrico Granatad55546b2011-07-22 00:16:08 +00002316
2317 // Cache the value if we got one back...
2318 if (synthetic_child_sp.get())
2319 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002320 // 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 +00002321 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002322 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002323 }
2324 }
2325 return synthetic_child_sp;
2326}
2327
2328void
Enrico Granata86cc9822012-03-19 22:58:49 +00002329ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002330{
Enrico Granata86cc9822012-03-19 22:58:49 +00002331 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002332 return;
2333
Enrico Granatac5bc4122012-03-27 02:35:13 +00002334 TargetSP target_sp(GetTargetSP());
Enrico Granata5d5f60c2013-09-24 22:58:37 +00002335 if (target_sp && target_sp->GetEnableSyntheticValue() == false)
Enrico Granatac5bc4122012-03-27 02:35:13 +00002336 {
2337 m_synthetic_value = NULL;
2338 return;
2339 }
2340
Enrico Granatae3e91512012-10-22 18:18:36 +00002341 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2342
Enrico Granata5548cb52013-01-28 23:47:25 +00002343 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002344 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002345
Enrico Granata0c489f52012-03-01 04:24:26 +00002346 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002347 return;
2348
Enrico Granatae3e91512012-10-22 18:18:36 +00002349 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2350 return;
2351
Enrico Granata86cc9822012-03-19 22:58:49 +00002352 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002353}
2354
Jim Ingham78a685a2011-04-16 00:01:13 +00002355void
Greg Claytonafacd142011-09-02 01:15:17 +00002356ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002357{
Greg Claytonafacd142011-09-02 01:15:17 +00002358 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002359 return;
2360
Jim Ingham58b59f92011-04-22 23:53:53 +00002361 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002362 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002363 ExecutionContext exe_ctx (GetExecutionContextRef());
2364 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002365 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002366 {
2367 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002368 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002369 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002370 }
2371}
2372
Jim Ingham58b59f92011-04-22 23:53:53 +00002373ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002374ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002375{
Greg Claytonafacd142011-09-02 01:15:17 +00002376 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002377 return ValueObjectSP();
2378
2379 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002380 {
Jim Ingham2837b762011-05-04 03:43:18 +00002381 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002382 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002383 if (m_dynamic_value)
2384 return m_dynamic_value->GetSP();
2385 else
2386 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002387}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002388
Jim Ingham60dbabb2011-12-08 19:44:08 +00002389ValueObjectSP
2390ValueObject::GetStaticValue()
2391{
2392 return GetSP();
2393}
2394
Enrico Granata886147f2012-05-08 18:47:08 +00002395lldb::ValueObjectSP
2396ValueObject::GetNonSyntheticValue ()
2397{
2398 return GetSP();
2399}
2400
Enrico Granatad55546b2011-07-22 00:16:08 +00002401ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002402ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002403{
Enrico Granata86cc9822012-03-19 22:58:49 +00002404 if (use_synthetic == false)
2405 return ValueObjectSP();
2406
Enrico Granatad55546b2011-07-22 00:16:08 +00002407 CalculateSyntheticValue(use_synthetic);
2408
2409 if (m_synthetic_value)
2410 return m_synthetic_value->GetSP();
2411 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002412 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002413}
2414
Greg Claytone221f822011-01-21 01:59:00 +00002415bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002416ValueObject::HasSyntheticValue()
2417{
Enrico Granata5548cb52013-01-28 23:47:25 +00002418 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002419
Enrico Granata0c489f52012-03-01 04:24:26 +00002420 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002421 return false;
2422
Enrico Granata86cc9822012-03-19 22:58:49 +00002423 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002424
2425 if (m_synthetic_value)
2426 return true;
2427 else
2428 return false;
2429}
2430
2431bool
Greg Claytone221f822011-01-21 01:59:00 +00002432ValueObject::GetBaseClassPath (Stream &s)
2433{
2434 if (IsBaseClass())
2435 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002436 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Clayton57ee3062013-07-11 22:46:58 +00002437 ClangASTType clang_type = GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002438 std::string cxx_class_name;
Greg Clayton57ee3062013-07-11 22:46:58 +00002439 bool this_had_base_class = clang_type.GetCXXClassName (cxx_class_name);
Greg Claytone221f822011-01-21 01:59:00 +00002440 if (this_had_base_class)
2441 {
2442 if (parent_had_base_class)
2443 s.PutCString("::");
2444 s.PutCString(cxx_class_name.c_str());
2445 }
2446 return parent_had_base_class || this_had_base_class;
2447 }
2448 return false;
2449}
2450
2451
2452ValueObject *
2453ValueObject::GetNonBaseClassParent()
2454{
Jim Ingham78a685a2011-04-16 00:01:13 +00002455 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002456 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002457 if (GetParent()->IsBaseClass())
2458 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002459 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002460 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002461 }
2462 return NULL;
2463}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002464
Enrico Granataa3c8f042014-08-19 22:29:08 +00002465
2466bool
2467ValueObject::IsBaseClass (uint32_t& depth)
2468{
2469 if (!IsBaseClass())
2470 {
2471 depth = 0;
2472 return false;
2473 }
2474 if (GetParent())
2475 {
2476 GetParent()->IsBaseClass(depth);
2477 depth = depth + 1;
2478 return true;
2479 }
2480 // TODO: a base of no parent? weird..
2481 depth = 1;
2482 return true;
2483}
2484
Greg Clayton1d3afba2010-10-05 00:00:42 +00002485void
Enrico Granata4becb372011-06-29 22:27:15 +00002486ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002487{
Enrico Granata986fa5f2014-12-09 21:41:16 +00002488 // synthetic children do not actually "exist" as part of the hierarchy, and sometimes they are consed up in ways
2489 // that don't make sense from an underlying language/API standpoint. So, use a special code path here to return
2490 // something that can hopefully be used in expression
2491 if (m_is_synthetic_children_generated)
2492 {
2493 UpdateValueIfNeeded();
2494
2495 if (m_value.GetValueType() == Value::eValueTypeLoadAddress)
2496 {
2497 if (IsPointerOrReferenceType())
2498 {
2499 s.Printf("((%s)0x%" PRIx64 ")",
2500 GetTypeName().AsCString("void"),
2501 GetValueAsUnsigned(0));
2502 return;
2503 }
2504 else
2505 {
2506 uint64_t load_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
2507 if (load_addr != LLDB_INVALID_ADDRESS)
2508 {
2509 s.Printf("(*( (%s *)0x%" PRIx64 "))",
2510 GetTypeName().AsCString("void"),
2511 load_addr);
2512 return;
2513 }
2514 }
2515 }
2516
2517 if (CanProvideValue())
2518 {
2519 s.Printf("((%s)%s)",
2520 GetTypeName().AsCString("void"),
2521 GetValueAsCString());
2522 return;
2523 }
2524
2525 return;
2526 }
2527
Greg Claytone221f822011-01-21 01:59:00 +00002528 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002529
Enrico Granata86cc9822012-03-19 22:58:49 +00002530 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002531 {
Enrico Granata4becb372011-06-29 22:27:15 +00002532 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2533 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2534 // the eHonorPointers mode is meant to produce strings in this latter format
2535 s.PutCString("*(");
2536 }
Greg Claytone221f822011-01-21 01:59:00 +00002537
Enrico Granata4becb372011-06-29 22:27:15 +00002538 ValueObject* parent = GetParent();
2539
2540 if (parent)
2541 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002542
2543 // if we are a deref_of_parent just because we are synthetic array
2544 // members made up to allow ptr[%d] syntax to work in variable
2545 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002546 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002547 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002548
Greg Claytone221f822011-01-21 01:59:00 +00002549 if (!IsBaseClass())
2550 {
2551 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002552 {
Greg Claytone221f822011-01-21 01:59:00 +00002553 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2554 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002555 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002556 ClangASTType non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002557 if (non_base_class_parent_clang_type)
2558 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002559 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002560 {
2561 s.PutCString("->");
2562 }
Enrico Granata4becb372011-06-29 22:27:15 +00002563 else
2564 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002565 const uint32_t non_base_class_parent_type_info = non_base_class_parent_clang_type.GetTypeInfo();
2566
Enrico Granata622be232014-10-21 20:52:14 +00002567 if (non_base_class_parent_type_info & eTypeIsPointer)
Enrico Granata4becb372011-06-29 22:27:15 +00002568 {
2569 s.PutCString("->");
2570 }
Enrico Granata622be232014-10-21 20:52:14 +00002571 else if ((non_base_class_parent_type_info & eTypeHasChildren) &&
2572 !(non_base_class_parent_type_info & eTypeIsArray))
Enrico Granata4becb372011-06-29 22:27:15 +00002573 {
2574 s.PutChar('.');
2575 }
Greg Claytone221f822011-01-21 01:59:00 +00002576 }
2577 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002578 }
Greg Claytone221f822011-01-21 01:59:00 +00002579
2580 const char *name = GetName().GetCString();
2581 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002582 {
Greg Claytone221f822011-01-21 01:59:00 +00002583 if (qualify_cxx_base_classes)
2584 {
2585 if (GetBaseClassPath (s))
2586 s.PutCString("::");
2587 }
2588 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002589 }
2590 }
2591 }
2592
Enrico Granata86cc9822012-03-19 22:58:49 +00002593 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002594 {
Greg Claytone221f822011-01-21 01:59:00 +00002595 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002596 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002597}
2598
Greg Claytonafacd142011-09-02 01:15:17 +00002599ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002600ValueObject::GetValueForExpressionPath(const char* expression,
2601 const char** first_unparsed,
2602 ExpressionPathScanEndReason* reason_to_stop,
2603 ExpressionPathEndResultType* final_value_type,
2604 const GetValueForExpressionPathOptions& options,
2605 ExpressionPathAftermath* final_task_on_target)
2606{
2607
2608 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002609 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2610 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002611 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002612
2613 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2614 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2615 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2616 final_value_type ? final_value_type : &dummy_final_value_type,
2617 options,
2618 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2619
Enrico Granata86cc9822012-03-19 22:58:49 +00002620 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002621 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002622
Enrico Granata86cc9822012-03-19 22:58:49 +00002623 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 +00002624 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002625 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002626 {
2627 Error error;
2628 ValueObjectSP final_value = ret_val->Dereference(error);
2629 if (error.Fail() || !final_value.get())
2630 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002631 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002632 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002633 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002634 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002635 return ValueObjectSP();
2636 }
2637 else
2638 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002639 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002640 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002641 return final_value;
2642 }
2643 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002644 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002645 {
2646 Error error;
2647 ValueObjectSP final_value = ret_val->AddressOf(error);
2648 if (error.Fail() || !final_value.get())
2649 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002650 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002651 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002652 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002653 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002654 return ValueObjectSP();
2655 }
2656 else
2657 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002658 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002659 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002660 return final_value;
2661 }
2662 }
2663 }
2664 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2665}
2666
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002667int
2668ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002669 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002670 const char** first_unparsed,
2671 ExpressionPathScanEndReason* reason_to_stop,
2672 ExpressionPathEndResultType* final_value_type,
2673 const GetValueForExpressionPathOptions& options,
2674 ExpressionPathAftermath* final_task_on_target)
2675{
2676 const char* dummy_first_unparsed;
2677 ExpressionPathScanEndReason dummy_reason_to_stop;
2678 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002679 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002680
2681 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2682 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2683 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2684 final_value_type ? final_value_type : &dummy_final_value_type,
2685 options,
2686 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2687
2688 if (!ret_val.get()) // if there are errors, I add nothing to the list
2689 return 0;
2690
Enrico Granata86ea8d82012-03-29 01:34:34 +00002691 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002692 {
2693 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002694 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002695 {
2696 list->Append(ret_val);
2697 return 1;
2698 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002699 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 +00002700 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002701 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002702 {
2703 Error error;
2704 ValueObjectSP final_value = ret_val->Dereference(error);
2705 if (error.Fail() || !final_value.get())
2706 {
Greg Clayton23f59502012-07-17 03:23:13 +00002707 if (reason_to_stop)
2708 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2709 if (final_value_type)
2710 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002711 return 0;
2712 }
2713 else
2714 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002715 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002716 list->Append(final_value);
2717 return 1;
2718 }
2719 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002720 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002721 {
2722 Error error;
2723 ValueObjectSP final_value = ret_val->AddressOf(error);
2724 if (error.Fail() || !final_value.get())
2725 {
Greg Clayton23f59502012-07-17 03:23:13 +00002726 if (reason_to_stop)
2727 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2728 if (final_value_type)
2729 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002730 return 0;
2731 }
2732 else
2733 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002734 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002735 list->Append(final_value);
2736 return 1;
2737 }
2738 }
2739 }
2740 }
2741 else
2742 {
2743 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2744 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2745 ret_val,
2746 list,
2747 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2748 final_value_type ? final_value_type : &dummy_final_value_type,
2749 options,
2750 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2751 }
2752 // in any non-covered case, just do the obviously right thing
2753 list->Append(ret_val);
2754 return 1;
2755}
2756
Greg Claytonafacd142011-09-02 01:15:17 +00002757ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002758ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2759 const char** first_unparsed,
2760 ExpressionPathScanEndReason* reason_to_stop,
2761 ExpressionPathEndResultType* final_result,
2762 const GetValueForExpressionPathOptions& options,
2763 ExpressionPathAftermath* what_next)
2764{
2765 ValueObjectSP root = GetSP();
2766
2767 if (!root.get())
2768 return ValueObjectSP();
2769
2770 *first_unparsed = expression_cstr;
2771
2772 while (true)
2773 {
2774
2775 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2776
Greg Clayton57ee3062013-07-11 22:46:58 +00002777 ClangASTType root_clang_type = root->GetClangType();
2778 ClangASTType pointee_clang_type;
2779 Flags pointee_clang_type_info;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002780
Greg Clayton57ee3062013-07-11 22:46:58 +00002781 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002782 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00002783 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002784
2785 if (!expression_cstr || *expression_cstr == '\0')
2786 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002787 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002788 return root;
2789 }
2790
2791 switch (*expression_cstr)
2792 {
2793 case '-':
2794 {
2795 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granata622be232014-10-21 20:52:14 +00002796 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 +00002797 {
2798 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002799 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2800 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002801 return ValueObjectSP();
2802 }
Enrico Granata622be232014-10-21 20:52:14 +00002803 if (root_clang_type_info.Test(eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2804 root_clang_type_info.Test(eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002805 options.m_no_fragile_ivar)
2806 {
2807 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002808 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2809 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002810 return ValueObjectSP();
2811 }
2812 if (expression_cstr[1] != '>')
2813 {
2814 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002815 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2816 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002817 return ValueObjectSP();
2818 }
2819 expression_cstr++; // skip the -
2820 }
2821 case '.': // or fallthrough from ->
2822 {
2823 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granata622be232014-10-21 20:52:14 +00002824 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 +00002825 {
2826 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002827 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2828 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002829 return ValueObjectSP();
2830 }
2831 expression_cstr++; // skip .
2832 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2833 ConstString child_name;
2834 if (!next_separator) // if no other separator just expand this last layer
2835 {
2836 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002837 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2838
2839 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002840 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002841 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002842 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2843 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002844 return child_valobj_sp;
2845 }
2846 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2847 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002848 if (root->IsSynthetic())
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002849 {
2850 *first_unparsed = expression_cstr;
Enrico Granatad07cfd32014-10-08 18:27:36 +00002851 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchSyntheticChild;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002852 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2853 return ValueObjectSP();
2854 }
2855
2856 child_valobj_sp = root->GetSyntheticValue();
Enrico Granata86cc9822012-03-19 22:58:49 +00002857 if (child_valobj_sp.get())
2858 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002859 }
2860
2861 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2862 // so we hit the "else" branch, and return an error
2863 if(child_valobj_sp.get()) // if it worked, just return
2864 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002865 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002866 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2867 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002868 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002869 }
2870 else
2871 {
2872 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002873 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2874 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002875 return ValueObjectSP();
2876 }
2877 }
2878 else // other layers do expand
2879 {
2880 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002881 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2882 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002883 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002884 root = child_valobj_sp;
2885 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002886 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002887 continue;
2888 }
2889 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2890 {
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002891 if (root->IsSynthetic())
2892 {
2893 *first_unparsed = expression_cstr;
2894 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2895 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2896 return ValueObjectSP();
2897 }
2898
Enrico Granata86cc9822012-03-19 22:58:49 +00002899 child_valobj_sp = root->GetSyntheticValue(true);
2900 if (child_valobj_sp)
2901 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002902 }
2903
2904 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2905 // so we hit the "else" branch, and return an error
2906 if(child_valobj_sp.get()) // if it worked, move on
2907 {
2908 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002909 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002910 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002911 continue;
2912 }
2913 else
2914 {
2915 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002916 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2917 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002918 return ValueObjectSP();
2919 }
2920 }
2921 break;
2922 }
2923 case '[':
2924 {
Enrico Granata622be232014-10-21 20:52:14 +00002925 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 +00002926 {
Enrico Granata622be232014-10-21 20:52:14 +00002927 if (!root_clang_type_info.Test(eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002928 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002929 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2930 {
2931 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002932 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2933 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002934 return ValueObjectSP();
2935 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002936 }
2937 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2938 {
2939 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002940 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2941 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002942 return ValueObjectSP();
2943 }
2944 }
2945 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2946 {
Enrico Granata622be232014-10-21 20:52:14 +00002947 if (!root_clang_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002948 {
2949 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002950 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2951 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002952 return ValueObjectSP();
2953 }
2954 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2955 {
2956 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002957 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2958 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002959 return root;
2960 }
2961 }
2962 const char *separator_position = ::strchr(expression_cstr+1,'-');
2963 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2964 if (!close_bracket_position) // if there is no ], this is a syntax error
2965 {
2966 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002967 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2968 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002969 return ValueObjectSP();
2970 }
2971 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2972 {
2973 char *end = NULL;
2974 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2975 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2976 {
2977 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002978 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2979 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002980 return ValueObjectSP();
2981 }
2982 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2983 {
Enrico Granata622be232014-10-21 20:52:14 +00002984 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002985 {
2986 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002987 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2988 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002989 return root;
2990 }
2991 else
2992 {
2993 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002994 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2995 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002996 return ValueObjectSP();
2997 }
2998 }
2999 // from here on we do have a valid index
Enrico Granata622be232014-10-21 20:52:14 +00003000 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003001 {
Greg Claytondaf515f2011-07-09 20:12:33 +00003002 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
3003 if (!child_valobj_sp)
3004 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003005 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00003006 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
3007 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00003008 if (child_valobj_sp)
3009 {
3010 root = child_valobj_sp;
3011 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003012 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00003013 continue;
3014 }
3015 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003016 {
3017 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003018 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3019 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003020 return ValueObjectSP();
3021 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003022 }
Enrico Granata622be232014-10-21 20:52:14 +00003023 else if (root_clang_type_info.Test(eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003024 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003025 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 +00003026 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003027 {
3028 Error error;
3029 root = root->Dereference(error);
3030 if (error.Fail() || !root.get())
3031 {
3032 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003033 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3034 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003035 return ValueObjectSP();
3036 }
3037 else
3038 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003039 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003040 continue;
3041 }
3042 }
3043 else
3044 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003045 if (root->GetClangType().GetMinimumLanguage() == eLanguageTypeObjC
Enrico Granata622be232014-10-21 20:52:14 +00003046 && pointee_clang_type_info.AllClear(eTypeIsPointer)
Greg Clayton84db9102012-03-26 23:03:23 +00003047 && root->HasSyntheticValue()
3048 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00003049 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003050 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003051 }
3052 else
3053 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003054 if (!root.get())
3055 {
3056 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003057 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3058 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003059 return ValueObjectSP();
3060 }
3061 else
3062 {
3063 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003064 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003065 continue;
3066 }
3067 }
3068 }
Enrico Granata622be232014-10-21 20:52:14 +00003069 else if (root_clang_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003070 {
3071 root = root->GetSyntheticBitFieldChild(index, index, true);
3072 if (!root.get())
3073 {
3074 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003075 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3076 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003077 return ValueObjectSP();
3078 }
3079 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3080 {
3081 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003082 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3083 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003084 return root;
3085 }
3086 }
Enrico Granata622be232014-10-21 20:52:14 +00003087 else if (root_clang_type_info.Test(eTypeIsVector))
Enrico Granata08a1bb82013-06-19 00:00:45 +00003088 {
3089 root = root->GetChildAtIndex(index, true);
3090 if (!root.get())
3091 {
3092 *first_unparsed = expression_cstr;
3093 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3094 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3095 return ValueObjectSP();
3096 }
3097 else
3098 {
3099 *first_unparsed = end+1; // skip ]
3100 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3101 continue;
3102 }
3103 }
Enrico Granata86cc9822012-03-19 22:58:49 +00003104 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00003105 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003106 if (root->HasSyntheticValue())
3107 root = root->GetSyntheticValue();
3108 else if (!root->IsSynthetic())
3109 {
3110 *first_unparsed = expression_cstr;
3111 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3112 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3113 return ValueObjectSP();
3114 }
3115 // if we are here, then root itself is a synthetic VO.. should be good to go
3116
Enrico Granata27b625e2011-08-09 01:04:56 +00003117 if (!root.get())
3118 {
3119 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003120 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3121 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3122 return ValueObjectSP();
3123 }
3124 root = root->GetChildAtIndex(index, true);
3125 if (!root.get())
3126 {
3127 *first_unparsed = expression_cstr;
3128 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3129 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003130 return ValueObjectSP();
3131 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00003132 else
3133 {
3134 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003135 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00003136 continue;
3137 }
Enrico Granata27b625e2011-08-09 01:04:56 +00003138 }
3139 else
3140 {
3141 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003142 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3143 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003144 return ValueObjectSP();
3145 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003146 }
3147 else // we have a low and a high index
3148 {
3149 char *end = NULL;
3150 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3151 if (!end || end != separator_position) // if something weird is in our way return an error
3152 {
3153 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003154 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3155 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003156 return ValueObjectSP();
3157 }
3158 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3159 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3160 {
3161 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003162 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3163 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003164 return ValueObjectSP();
3165 }
3166 if (index_lower > index_higher) // swap indices if required
3167 {
3168 unsigned long temp = index_lower;
3169 index_lower = index_higher;
3170 index_higher = temp;
3171 }
Enrico Granata622be232014-10-21 20:52:14 +00003172 if (root_clang_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003173 {
3174 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3175 if (!root.get())
3176 {
3177 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003178 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3179 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003180 return ValueObjectSP();
3181 }
3182 else
3183 {
3184 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003185 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3186 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003187 return root;
3188 }
3189 }
Enrico Granata622be232014-10-21 20:52:14 +00003190 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 +00003191 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granata622be232014-10-21 20:52:14 +00003192 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003193 {
3194 Error error;
3195 root = root->Dereference(error);
3196 if (error.Fail() || !root.get())
3197 {
3198 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003199 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3200 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003201 return ValueObjectSP();
3202 }
3203 else
3204 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003205 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003206 continue;
3207 }
3208 }
3209 else
3210 {
3211 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003212 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3213 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003214 return root;
3215 }
3216 }
3217 break;
3218 }
3219 default: // some non-separator is in the way
3220 {
3221 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003222 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3223 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003224 return ValueObjectSP();
3225 break;
3226 }
3227 }
3228 }
3229}
3230
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003231int
3232ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3233 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00003234 ValueObjectSP root,
3235 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003236 ExpressionPathScanEndReason* reason_to_stop,
3237 ExpressionPathEndResultType* final_result,
3238 const GetValueForExpressionPathOptions& options,
3239 ExpressionPathAftermath* what_next)
3240{
3241 if (!root.get())
3242 return 0;
3243
3244 *first_unparsed = expression_cstr;
3245
3246 while (true)
3247 {
3248
3249 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3250
Greg Clayton57ee3062013-07-11 22:46:58 +00003251 ClangASTType root_clang_type = root->GetClangType();
3252 ClangASTType pointee_clang_type;
3253 Flags pointee_clang_type_info;
3254 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003255 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00003256 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003257
3258 if (!expression_cstr || *expression_cstr == '\0')
3259 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003260 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003261 list->Append(root);
3262 return 1;
3263 }
3264
3265 switch (*expression_cstr)
3266 {
3267 case '[':
3268 {
Enrico Granata622be232014-10-21 20:52:14 +00003269 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 +00003270 {
Enrico Granata622be232014-10-21 20:52:14 +00003271 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 +00003272 {
3273 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003274 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3275 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003276 return 0;
3277 }
3278 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3279 {
3280 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003281 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3282 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003283 return 0;
3284 }
3285 }
3286 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3287 {
Enrico Granata622be232014-10-21 20:52:14 +00003288 if (!root_clang_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003289 {
3290 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003291 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3292 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003293 return 0;
3294 }
3295 else // expand this into list
3296 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003297 const size_t max_index = root->GetNumChildren() - 1;
3298 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003299 {
3300 ValueObjectSP child =
3301 root->GetChildAtIndex(index, true);
3302 list->Append(child);
3303 }
3304 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003305 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3306 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003307 return max_index; // tell me number of items I added to the VOList
3308 }
3309 }
3310 const char *separator_position = ::strchr(expression_cstr+1,'-');
3311 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3312 if (!close_bracket_position) // if there is no ], this is a syntax error
3313 {
3314 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003315 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3316 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003317 return 0;
3318 }
3319 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3320 {
3321 char *end = NULL;
3322 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3323 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3324 {
3325 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003326 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3327 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003328 return 0;
3329 }
3330 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3331 {
Enrico Granata622be232014-10-21 20:52:14 +00003332 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003333 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003334 const size_t max_index = root->GetNumChildren() - 1;
3335 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003336 {
3337 ValueObjectSP child =
3338 root->GetChildAtIndex(index, true);
3339 list->Append(child);
3340 }
3341 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003342 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3343 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003344 return max_index; // tell me number of items I added to the VOList
3345 }
3346 else
3347 {
3348 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003349 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3350 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003351 return 0;
3352 }
3353 }
3354 // from here on we do have a valid index
Enrico Granata622be232014-10-21 20:52:14 +00003355 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003356 {
3357 root = root->GetChildAtIndex(index, true);
3358 if (!root.get())
3359 {
3360 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003361 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3362 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003363 return 0;
3364 }
3365 else
3366 {
3367 list->Append(root);
3368 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003369 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3370 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003371 return 1;
3372 }
3373 }
Enrico Granata622be232014-10-21 20:52:14 +00003374 else if (root_clang_type_info.Test(eTypeIsPointer))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003375 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003376 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 +00003377 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003378 {
3379 Error error;
3380 root = root->Dereference(error);
3381 if (error.Fail() || !root.get())
3382 {
3383 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003384 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3385 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003386 return 0;
3387 }
3388 else
3389 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003390 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003391 continue;
3392 }
3393 }
3394 else
3395 {
3396 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3397 if (!root.get())
3398 {
3399 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003400 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3401 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003402 return 0;
3403 }
3404 else
3405 {
3406 list->Append(root);
3407 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003408 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3409 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003410 return 1;
3411 }
3412 }
3413 }
3414 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3415 {
3416 root = root->GetSyntheticBitFieldChild(index, index, true);
3417 if (!root.get())
3418 {
3419 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003420 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3421 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003422 return 0;
3423 }
3424 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3425 {
3426 list->Append(root);
3427 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003428 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3429 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003430 return 1;
3431 }
3432 }
3433 }
3434 else // we have a low and a high index
3435 {
3436 char *end = NULL;
3437 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3438 if (!end || end != separator_position) // if something weird is in our way return an error
3439 {
3440 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003441 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3442 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003443 return 0;
3444 }
3445 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3446 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3447 {
3448 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003449 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3450 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003451 return 0;
3452 }
3453 if (index_lower > index_higher) // swap indices if required
3454 {
3455 unsigned long temp = index_lower;
3456 index_lower = index_higher;
3457 index_higher = temp;
3458 }
Enrico Granata622be232014-10-21 20:52:14 +00003459 if (root_clang_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003460 {
3461 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3462 if (!root.get())
3463 {
3464 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003465 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3466 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003467 return 0;
3468 }
3469 else
3470 {
3471 list->Append(root);
3472 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003473 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3474 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003475 return 1;
3476 }
3477 }
Enrico Granata622be232014-10-21 20:52:14 +00003478 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 +00003479 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granata622be232014-10-21 20:52:14 +00003480 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003481 {
3482 Error error;
3483 root = root->Dereference(error);
3484 if (error.Fail() || !root.get())
3485 {
3486 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003487 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3488 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003489 return 0;
3490 }
3491 else
3492 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003493 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003494 continue;
3495 }
3496 }
3497 else
3498 {
Johnny Chen44805302011-07-19 19:48:13 +00003499 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003500 index <= index_higher; index++)
3501 {
3502 ValueObjectSP child =
3503 root->GetChildAtIndex(index, true);
3504 list->Append(child);
3505 }
3506 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003507 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3508 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003509 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3510 }
3511 }
3512 break;
3513 }
3514 default: // some non-[ separator, or something entirely wrong, is in the way
3515 {
3516 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003517 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3518 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003519 return 0;
3520 break;
3521 }
3522 }
3523 }
3524}
3525
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003526void
3527ValueObject::LogValueObject (Log *log)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003528{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003529 if (log)
3530 return LogValueObject (log, DumpValueObjectOptions::DefaultOptions());
Greg Clayton1d3afba2010-10-05 00:00:42 +00003531}
3532
Enrico Granata0c489f52012-03-01 04:24:26 +00003533void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003534ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003535{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003536 if (log)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003537 {
3538 StreamString s;
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003539 Dump (s, options);
Greg Claytonf830dbb2012-03-22 18:15:37 +00003540 if (s.GetSize())
3541 log->PutCString(s.GetData());
3542 }
3543}
3544
3545void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003546ValueObject::Dump (Stream &s)
Enrico Granata0c489f52012-03-01 04:24:26 +00003547{
3548
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003549 ValueObjectPrinter printer(this,&s,DumpValueObjectOptions::DefaultOptions());
3550 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003551}
3552
3553void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003554ValueObject::Dump (Stream &s,
3555 const DumpValueObjectOptions& options)
Enrico Granata0c489f52012-03-01 04:24:26 +00003556{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003557 ValueObjectPrinter printer(this,&s,options);
3558 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003559}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003560
3561ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003562ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003563{
3564 ValueObjectSP valobj_sp;
3565
Enrico Granatac3e320a2011-08-02 17:27:39 +00003566 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003567 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003568 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003569
3570 DataExtractor data;
3571 data.SetByteOrder (m_data.GetByteOrder());
3572 data.SetAddressByteSize(m_data.GetAddressByteSize());
3573
Enrico Granata9f1e2042012-04-24 22:15:37 +00003574 if (IsBitfield())
3575 {
3576 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
Greg Clayton57ee3062013-07-11 22:46:58 +00003577 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Enrico Granata9f1e2042012-04-24 22:15:37 +00003578 }
3579 else
Greg Clayton57ee3062013-07-11 22:46:58 +00003580 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003581
3582 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003583 GetClangType(),
3584 name,
3585 data,
3586 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003587 }
Jim Ingham6035b672011-03-31 00:19:25 +00003588
3589 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003590 {
Greg Claytoneeb15652013-12-10 23:16:40 +00003591 ExecutionContext exe_ctx (GetExecutionContextRef());
3592 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003593 }
3594 return valobj_sp;
3595}
3596
Enrico Granata538a88a2014-10-09 18:24:30 +00003597ValueObjectSP
3598ValueObject::GetQualifiedRepresentationIfAvailable (lldb::DynamicValueType dynValue,
3599 bool synthValue)
3600{
3601 ValueObjectSP result_sp(GetSP());
3602
3603 switch (dynValue)
3604 {
3605 case lldb::eDynamicCanRunTarget:
3606 case lldb::eDynamicDontRunTarget:
3607 {
3608 if (!result_sp->IsDynamic())
3609 {
3610 if (result_sp->GetDynamicValue(dynValue))
3611 result_sp = result_sp->GetDynamicValue(dynValue);
3612 }
3613 }
3614 break;
3615 case lldb::eNoDynamicValues:
Enrico Granata538a88a2014-10-09 18:24:30 +00003616 {
3617 if (result_sp->IsDynamic())
3618 {
3619 if (result_sp->GetStaticValue())
3620 result_sp = result_sp->GetStaticValue();
3621 }
3622 }
3623 break;
3624 }
3625
3626 if (synthValue)
3627 {
3628 if (!result_sp->IsSynthetic())
3629 {
3630 if (result_sp->GetSyntheticValue())
3631 result_sp = result_sp->GetSyntheticValue();
3632 }
3633 }
3634 else
3635 {
3636 if (result_sp->IsSynthetic())
3637 {
3638 if (result_sp->GetNonSyntheticValue())
3639 result_sp = result_sp->GetNonSyntheticValue();
3640 }
3641 }
3642
3643 return result_sp;
3644}
3645
Greg Clayton759e7442014-07-19 00:12:57 +00003646lldb::addr_t
3647ValueObject::GetCPPVTableAddress (AddressType &address_type)
3648{
3649 ClangASTType pointee_type;
3650 ClangASTType this_type(GetClangType());
3651 uint32_t type_info = this_type.GetTypeInfo(&pointee_type);
3652 if (type_info)
3653 {
3654 bool ptr_or_ref = false;
Enrico Granata622be232014-10-21 20:52:14 +00003655 if (type_info & (eTypeIsPointer | eTypeIsReference))
Greg Clayton759e7442014-07-19 00:12:57 +00003656 {
3657 ptr_or_ref = true;
3658 type_info = pointee_type.GetTypeInfo();
3659 }
3660
Enrico Granata622be232014-10-21 20:52:14 +00003661 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus;
Greg Clayton759e7442014-07-19 00:12:57 +00003662 if ((type_info & cpp_class) == cpp_class)
3663 {
3664 if (ptr_or_ref)
3665 {
3666 address_type = GetAddressTypeOfChildren();
3667 return GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
3668 }
3669 else
3670 return GetAddressOf (false, &address_type);
3671 }
3672 }
3673
3674 address_type = eAddressTypeInvalid;
3675 return LLDB_INVALID_ADDRESS;
3676}
3677
Greg Claytonafacd142011-09-02 01:15:17 +00003678ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003679ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003680{
Jim Ingham58b59f92011-04-22 23:53:53 +00003681 if (m_deref_valobj)
3682 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003683
Greg Clayton54979cd2010-12-15 05:08:08 +00003684 const bool is_pointer_type = IsPointerType();
3685 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003686 {
3687 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003688 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003689
3690 std::string child_name_str;
3691 uint32_t child_byte_size = 0;
3692 int32_t child_byte_offset = 0;
3693 uint32_t child_bitfield_bit_size = 0;
3694 uint32_t child_bitfield_bit_offset = 0;
3695 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003696 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003697 const bool transparent_pointers = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00003698 ClangASTType clang_type = GetClangType();
3699 ClangASTType child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003700
Greg Claytoncc4d0142012-02-17 07:49:44 +00003701 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003702
Greg Clayton57ee3062013-07-11 22:46:58 +00003703 child_clang_type = clang_type.GetChildClangTypeAtIndex (&exe_ctx,
Greg Clayton57ee3062013-07-11 22:46:58 +00003704 0,
3705 transparent_pointers,
3706 omit_empty_base_classes,
3707 ignore_array_bounds,
3708 child_name_str,
3709 child_byte_size,
3710 child_byte_offset,
3711 child_bitfield_bit_size,
3712 child_bitfield_bit_offset,
3713 child_is_base_class,
Greg Clayton759e7442014-07-19 00:12:57 +00003714 child_is_deref_of_parent,
3715 this);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003716 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003717 {
3718 ConstString child_name;
3719 if (!child_name_str.empty())
3720 child_name.SetCString (child_name_str.c_str());
3721
Jim Ingham58b59f92011-04-22 23:53:53 +00003722 m_deref_valobj = new ValueObjectChild (*this,
Jim Ingham58b59f92011-04-22 23:53:53 +00003723 child_clang_type,
3724 child_name,
3725 child_byte_size,
3726 child_byte_offset,
3727 child_bitfield_bit_size,
3728 child_bitfield_bit_offset,
3729 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003730 child_is_deref_of_parent,
3731 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003732 }
3733 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003734
Jim Ingham58b59f92011-04-22 23:53:53 +00003735 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003736 {
3737 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003738 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003739 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003740 else
3741 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003742 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003743 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003744
3745 if (is_pointer_type)
3746 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3747 else
3748 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003749 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003750 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003751}
3752
Greg Claytonafacd142011-09-02 01:15:17 +00003753ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003754ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003755{
Jim Ingham78a685a2011-04-16 00:01:13 +00003756 if (m_addr_of_valobj_sp)
3757 return m_addr_of_valobj_sp;
3758
Greg Claytone0d378b2011-03-24 21:19:54 +00003759 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003760 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003761 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003762 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003763 if (addr != LLDB_INVALID_ADDRESS)
3764 {
3765 switch (address_type)
3766 {
3767 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003768 {
3769 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003770 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003771 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3772 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003773 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003774
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003775 case eAddressTypeFile:
3776 case eAddressTypeLoad:
3777 case eAddressTypeHost:
3778 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003779 ClangASTType clang_type = GetClangType();
3780 if (clang_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003781 {
3782 std::string name (1, '&');
3783 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003784 ExecutionContext exe_ctx (GetExecutionContextRef());
3785 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00003786 clang_type.GetPointerType(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003787 ConstString (name.c_str()),
3788 addr,
3789 eAddressTypeInvalid,
3790 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003791 }
3792 }
3793 break;
3794 }
3795 }
Sean Callananed185ab2013-04-19 19:47:32 +00003796 else
3797 {
3798 StreamString expr_path_strm;
3799 GetExpressionPath(expr_path_strm, true);
3800 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3801 }
3802
Jim Ingham78a685a2011-04-16 00:01:13 +00003803 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003804}
3805
Greg Clayton9a142cf2012-02-03 05:34:10 +00003806ValueObjectSP
3807ValueObject::Cast (const ClangASTType &clang_ast_type)
3808{
Greg Clayton81e871e2012-02-04 02:27:34 +00003809 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003810}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003811
Greg Claytonafacd142011-09-02 01:15:17 +00003812ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003813ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3814{
Greg Claytonafacd142011-09-02 01:15:17 +00003815 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003816 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003817 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003818
3819 if (ptr_value != LLDB_INVALID_ADDRESS)
3820 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003821 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003822 ExecutionContext exe_ctx (GetExecutionContextRef());
3823 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003824 name,
3825 ptr_addr,
3826 clang_ast_type);
3827 }
3828 return valobj_sp;
3829}
3830
Greg Claytonafacd142011-09-02 01:15:17 +00003831ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003832ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3833{
Greg Claytonafacd142011-09-02 01:15:17 +00003834 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003835 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003836 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003837
3838 if (ptr_value != LLDB_INVALID_ADDRESS)
3839 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003840 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003841 ExecutionContext exe_ctx (GetExecutionContextRef());
3842 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003843 name,
3844 ptr_addr,
3845 type_sp);
3846 }
3847 return valobj_sp;
3848}
3849
Jim Ingham6035b672011-03-31 00:19:25 +00003850ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003851 m_mod_id(),
3852 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003853 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003854{
3855}
3856
3857ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003858 m_mod_id(),
3859 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003860 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003861{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003862 ExecutionContext exe_ctx(exe_scope);
3863 TargetSP target_sp (exe_ctx.GetTargetSP());
3864 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003865 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003866 m_exe_ctx_ref.SetTargetSP (target_sp);
3867 ProcessSP process_sp (exe_ctx.GetProcessSP());
3868 if (!process_sp)
3869 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003870
Greg Claytoncc4d0142012-02-17 07:49:44 +00003871 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003872 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003873 m_mod_id = process_sp->GetModID();
3874 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003875
Greg Claytoncc4d0142012-02-17 07:49:44 +00003876 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003877
Greg Claytoncc4d0142012-02-17 07:49:44 +00003878 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003879 {
3880 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003881 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003882 }
Jim Ingham6035b672011-03-31 00:19:25 +00003883
Greg Claytoncc4d0142012-02-17 07:49:44 +00003884 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003885 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003886 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003887
Jason Molendab57e4a12013-11-04 09:33:30 +00003888 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003889 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003890 {
3891 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003892 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003893 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003894 if (frame_sp)
3895 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003896 }
3897 }
3898 }
Jim Ingham6035b672011-03-31 00:19:25 +00003899}
3900
3901ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003902 m_mod_id(),
3903 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003904 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003905{
3906}
3907
3908ValueObject::EvaluationPoint::~EvaluationPoint ()
3909{
3910}
3911
Jim Ingham6035b672011-03-31 00:19:25 +00003912// This function checks the EvaluationPoint against the current process state. If the current
3913// state matches the evaluation point, or the evaluation point is already invalid, then we return
3914// false, meaning "no change". If the current state is different, we update our state, and return
3915// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3916// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003917// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003918
3919bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003920ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003921{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003922
3923 // 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 +00003924 const bool thread_and_frame_only_if_stopped = true;
3925 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
Jim Ingham73ca05a2011-12-17 01:35:57 +00003926
Greg Claytoncc4d0142012-02-17 07:49:44 +00003927 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003928 return false;
3929
Jim Ingham6035b672011-03-31 00:19:25 +00003930 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003931 Process *process = exe_ctx.GetProcessPtr();
3932 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003933 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003934
Jim Ingham6035b672011-03-31 00:19:25 +00003935 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003936 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003937
Jim Ingham78a685a2011-04-16 00:01:13 +00003938 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3939 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003940 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003941 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003942
Greg Clayton23f59502012-07-17 03:23:13 +00003943 bool changed = false;
3944 const bool was_valid = m_mod_id.IsValid();
3945 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003946 {
3947 if (m_mod_id == current_mod_id)
3948 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003949 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003950 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003951 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003952 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003953 else
3954 {
3955 m_mod_id = current_mod_id;
3956 m_needs_update = true;
3957 changed = true;
3958 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003959 }
Jim Ingham6035b672011-03-31 00:19:25 +00003960
Jim Ingham73ca05a2011-12-17 01:35:57 +00003961 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3962 // That way we'll be sure to return a valid exe_scope.
3963 // 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 +00003964
Greg Claytoncc4d0142012-02-17 07:49:44 +00003965 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003966 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003967 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3968 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003969 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003970 if (m_exe_ctx_ref.HasFrameRef())
3971 {
Jason Molendab57e4a12013-11-04 09:33:30 +00003972 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003973 if (!frame_sp)
3974 {
3975 // We used to have a frame, but now it is gone
3976 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003977 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00003978 }
3979 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003980 }
Jim Ingham6035b672011-03-31 00:19:25 +00003981 else
3982 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003983 // We used to have a thread, but now it is gone
3984 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003985 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00003986 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003987
Jim Ingham6035b672011-03-31 00:19:25 +00003988 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003989 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003990}
3991
Jim Ingham61be0902011-05-02 18:13:59 +00003992void
3993ValueObject::EvaluationPoint::SetUpdated ()
3994{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003995 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3996 if (process_sp)
3997 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003998 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003999}
4000
4001
Enrico Granataf2bbf712011-07-15 02:26:42 +00004002
4003void
Enrico Granata86cc9822012-03-19 22:58:49 +00004004ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004005{
Enrico Granata86cc9822012-03-19 22:58:49 +00004006 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4007 m_value_str.clear();
4008
4009 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4010 m_location_str.clear();
4011
4012 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
Enrico Granata86cc9822012-03-19 22:58:49 +00004013 m_summary_str.clear();
Enrico Granata86cc9822012-03-19 22:58:49 +00004014
4015 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4016 m_object_desc_str.clear();
4017
4018 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4019 {
4020 if (m_synthetic_value)
4021 m_synthetic_value = NULL;
4022 }
Enrico Granata744794a2014-09-05 21:46:22 +00004023
4024 if ((clear_mask & eClearUserVisibleDataItemsValidator) == eClearUserVisibleDataItemsValidator)
4025 m_validation_result.reset();
Johnny Chen44805302011-07-19 19:48:13 +00004026}
Enrico Granata9128ee22011-09-06 19:20:51 +00004027
4028SymbolContextScope *
4029ValueObject::GetSymbolContextScope()
4030{
4031 if (m_parent)
4032 {
4033 if (!m_parent->IsPointerOrReferenceType())
4034 return m_parent->GetSymbolContextScope();
4035 }
4036 return NULL;
4037}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004038
4039lldb::ValueObjectSP
4040ValueObject::CreateValueObjectFromExpression (const char* name,
4041 const char* expression,
4042 const ExecutionContext& exe_ctx)
4043{
4044 lldb::ValueObjectSP retval_sp;
4045 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4046 if (!target_sp)
4047 return retval_sp;
4048 if (!expression || !*expression)
4049 return retval_sp;
4050 target_sp->EvaluateExpression (expression,
4051 exe_ctx.GetFrameSP().get(),
4052 retval_sp);
4053 if (retval_sp && name && *name)
4054 retval_sp->SetName(ConstString(name));
4055 return retval_sp;
4056}
4057
4058lldb::ValueObjectSP
4059ValueObject::CreateValueObjectFromAddress (const char* name,
4060 uint64_t address,
4061 const ExecutionContext& exe_ctx,
4062 ClangASTType type)
4063{
Greg Clayton57ee3062013-07-11 22:46:58 +00004064 if (type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004065 {
Greg Clayton57ee3062013-07-11 22:46:58 +00004066 ClangASTType pointer_type(type.GetPointerType());
4067 if (pointer_type)
4068 {
4069 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4070 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4071 pointer_type,
4072 ConstString(name),
4073 buffer,
4074 lldb::endian::InlHostByteOrder(),
4075 exe_ctx.GetAddressByteSize()));
4076 if (ptr_result_valobj_sp)
4077 {
4078 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4079 Error err;
4080 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4081 if (ptr_result_valobj_sp && name && *name)
4082 ptr_result_valobj_sp->SetName(ConstString(name));
4083 }
4084 return ptr_result_valobj_sp;
4085 }
Enrico Granatab2698cd2012-09-13 18:27:09 +00004086 }
Greg Clayton57ee3062013-07-11 22:46:58 +00004087 return lldb::ValueObjectSP();
Enrico Granatab2698cd2012-09-13 18:27:09 +00004088}
4089
4090lldb::ValueObjectSP
4091ValueObject::CreateValueObjectFromData (const char* name,
Enrico Granata7ca1c762014-03-31 23:02:25 +00004092 const DataExtractor& data,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004093 const ExecutionContext& exe_ctx,
4094 ClangASTType type)
4095{
4096 lldb::ValueObjectSP new_value_sp;
4097 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004098 type,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004099 ConstString(name),
4100 data,
4101 LLDB_INVALID_ADDRESS);
4102 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4103 if (new_value_sp && name && *name)
4104 new_value_sp->SetName(ConstString(name));
4105 return new_value_sp;
4106}
Enrico Granata4873e522013-04-11 22:48:58 +00004107
4108ModuleSP
4109ValueObject::GetModule ()
4110{
4111 ValueObject* root(GetRoot());
4112 if (root != this)
4113 return root->GetModule();
4114 return lldb::ModuleSP();
4115}
4116
4117ValueObject*
4118ValueObject::GetRoot ()
4119{
4120 if (m_root)
4121 return m_root;
4122 ValueObject* parent = m_parent;
4123 if (!parent)
4124 return (m_root = this);
4125 while (parent->m_parent)
4126 {
4127 if (parent->m_root)
4128 return (m_root = parent->m_root);
4129 parent = parent->m_parent;
4130 }
4131 return (m_root = parent);
4132}
4133
4134AddressType
4135ValueObject::GetAddressTypeOfChildren()
4136{
4137 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
4138 {
4139 ValueObject* root(GetRoot());
4140 if (root != this)
4141 return root->GetAddressTypeOfChildren();
4142 }
4143 return m_address_type_of_ptr_or_ref_children;
4144}
4145
4146lldb::DynamicValueType
4147ValueObject::GetDynamicValueType ()
4148{
4149 ValueObject* with_dv_info = this;
4150 while (with_dv_info)
4151 {
4152 if (with_dv_info->HasDynamicValueTypeInfo())
4153 return with_dv_info->GetDynamicValueTypeImpl();
4154 with_dv_info = with_dv_info->m_parent;
4155 }
4156 return lldb::eNoDynamicValues;
4157}
Enrico Granata39d51412013-05-31 17:43:40 +00004158
Enrico Granata4873e522013-04-11 22:48:58 +00004159lldb::Format
4160ValueObject::GetFormat () const
4161{
4162 const ValueObject* with_fmt_info = this;
4163 while (with_fmt_info)
4164 {
4165 if (with_fmt_info->m_format != lldb::eFormatDefault)
4166 return with_fmt_info->m_format;
4167 with_fmt_info = with_fmt_info->m_parent;
4168 }
4169 return m_format;
4170}
Enrico Granatad07cfd32014-10-08 18:27:36 +00004171
Enrico Granatac1247f52014-11-06 21:23:20 +00004172lldb::LanguageType
4173ValueObject::GetPreferredDisplayLanguage ()
4174{
4175 lldb::LanguageType type = lldb::eLanguageTypeUnknown;
4176 if (GetRoot())
4177 {
4178 if (GetRoot() == this)
4179 {
4180 if (StackFrameSP frame_sp = GetFrameSP())
4181 {
4182 const SymbolContext& sc(frame_sp->GetSymbolContext(eSymbolContextCompUnit));
4183 if (CompileUnit* cu = sc.comp_unit)
4184 type = cu->GetLanguage();
4185 }
4186 }
4187 else
4188 {
4189 type = GetRoot()->GetPreferredDisplayLanguage();
4190 }
4191 }
4192 return type;
4193}
4194
Enrico Granatad07cfd32014-10-08 18:27:36 +00004195bool
4196ValueObject::CanProvideValue ()
4197{
Sean Callanan7375f3e2014-12-09 21:18:59 +00004198 // we need to support invalid types as providers of values because some bare-board
4199 // debugging scenarios have no notion of types, but still manage to have raw numeric
4200 // values for things like registers. sigh.
4201 const ClangASTType &type(GetClangType());
4202 return (false == type.IsValid()) || (0 != (type.GetTypeInfo() & eTypeHasValue));
4203}
4204
4205bool
4206ValueObject::IsChecksumEmpty ()
4207{
4208 return m_value_checksum.empty();
Enrico Granatad07cfd32014-10-08 18:27:36 +00004209}
Enrico Granata0c10a852014-12-08 23:13:56 +00004210
4211ValueObjectSP
4212ValueObject::Persist ()
4213{
4214 if (!UpdateValueIfNeeded())
4215 return nullptr;
4216
4217 TargetSP target_sp(GetTargetSP());
4218 if (!target_sp)
4219 return nullptr;
4220
4221 ConstString name(target_sp->GetPersistentVariables().GetNextPersistentVariableName());
4222
4223 ClangExpressionVariableSP clang_var_sp(new ClangExpressionVariable(target_sp.get(), GetValue(), name));
4224 if (clang_var_sp)
4225 {
4226 clang_var_sp->m_live_sp = clang_var_sp->m_frozen_sp;
4227 clang_var_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
4228 target_sp->GetPersistentVariables().AddVariable(clang_var_sp);
4229 }
4230
4231 return clang_var_sp->GetValueObject();
4232}
Enrico Granatae29df232014-12-09 19:51:20 +00004233
4234bool
4235ValueObject::IsSyntheticChildrenGenerated ()
4236{
4237 return m_is_synthetic_children_generated;
4238}
4239
4240void
4241ValueObject::SetSyntheticChildrenGenerated (bool b)
4242{
4243 m_is_synthetic_children_generated = b;
4244}