blob: 98c05c32744fd24cc04fccaa62b93e03efbcab48 [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
10#include "lldb/Core/ValueObject.h"
11
12// C Includes
Greg Claytonf5e56de2010-09-14 23:36:40 +000013#include <stdlib.h>
14
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015// C++ Includes
16// Other libraries and framework includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "llvm/Support/raw_ostream.h"
18
19// Project includes
20#include "lldb/Core/DataBufferHeap.h"
Enrico Granata4becb372011-06-29 22:27:15 +000021#include "lldb/Core/Debugger.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000022#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000023#include "lldb/Core/Module.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024#include "lldb/Core/StreamString.h"
Enrico Granata21fd13f2012-10-27 02:05:48 +000025#include "lldb/Core/ValueObjectCast.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026#include "lldb/Core/ValueObjectChild.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000027#include "lldb/Core/ValueObjectConstResult.h"
Jim Ingham78a685a2011-04-16 00:01:13 +000028#include "lldb/Core/ValueObjectDynamicValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Core/ValueObjectList.h"
Greg Claytonb2dcc362011-05-05 23:32:56 +000030#include "lldb/Core/ValueObjectMemory.h"
Enrico Granatad55546b2011-07-22 00:16:08 +000031#include "lldb/Core/ValueObjectSyntheticFilter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032
Enrico Granata5548cb52013-01-28 23:47:25 +000033#include "lldb/DataFormatters/DataVisualization.h"
Enrico Granata2206b482014-10-30 18:27:31 +000034#include "lldb/DataFormatters/StringPrinter.h"
Enrico Granata4d93b8c2013-09-30 19:11:51 +000035#include "lldb/DataFormatters/ValueObjectPrinter.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000036
Sean Callanan30e33972015-09-03 00:48:23 +000037#include "Plugins/ExpressionParser/Clang/ClangExpressionVariable.h"
Sean Callanan4dbb2712015-09-25 20:35:58 +000038#include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h"
Enrico Granata0c10a852014-12-08 23:13:56 +000039
Greg Clayton7fb56d02011-02-01 01:31:41 +000040#include "lldb/Host/Endian.h"
41
Enrico Granata61a80ba2011-08-12 16:42:31 +000042#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granataf2bbf712011-07-15 02:26:42 +000043
Greg Claytona1e5dc82015-08-11 22:53:00 +000044#include "lldb/Symbol/CompilerType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000045#include "lldb/Symbol/ClangASTContext.h"
Enrico Granatac1247f52014-11-06 21:23:20 +000046#include "lldb/Symbol/CompileUnit.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000047#include "lldb/Symbol/Type.h"
48
Jim Ingham53c47f12010-09-10 23:12:17 +000049#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000050#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000051#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052#include "lldb/Target/Process.h"
53#include "lldb/Target/RegisterContext.h"
Greg Claytond5944cd2013-12-06 01:12:00 +000054#include "lldb/Target/SectionLoadList.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000055#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057
58using namespace lldb;
59using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000060using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061
Greg Claytonafacd142011-09-02 01:15:17 +000062static user_id_t g_value_obj_uid = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063
64//----------------------------------------------------------------------
65// ValueObject constructor
66//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000067ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000068 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000069 m_parent (&parent),
Enrico Granata4873e522013-04-11 22:48:58 +000070 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +000071 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000072 m_name (),
73 m_data (),
74 m_value (),
75 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000076 m_value_str (),
77 m_old_value_str (),
78 m_location_str (),
79 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000080 m_object_desc_str (),
Enrico Granata744794a2014-09-05 21:46:22 +000081 m_validation_result(),
Jim Ingham58b59f92011-04-22 23:53:53 +000082 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000083 m_children (),
84 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000085 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000086 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000087 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000088 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +000089 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000090 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +000091 m_type_summary_sp(),
92 m_type_format_sp(),
93 m_synthetic_children_sp(),
Enrico Granata744794a2014-09-05 21:46:22 +000094 m_type_validator_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +000095 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +000096 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
Sean Callanan7375f3e2014-12-09 21:18:59 +000097 m_value_checksum(),
Enrico Granataed3228a2015-01-21 01:47:13 +000098 m_preferred_display_language(lldb::eLanguageTypeUnknown),
Greg Clayton288bdf92010-09-02 02:59:18 +000099 m_value_is_valid (false),
100 m_value_did_change (false),
101 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000102 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000103 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000104 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000105 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000106 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000107 m_is_getting_summary(false),
Enrico Granatae29df232014-12-09 19:51:20 +0000108 m_did_calculate_complete_objc_class_type(false),
109 m_is_synthetic_children_generated(parent.m_is_synthetic_children_generated)
Jim Ingham6035b672011-03-31 00:19:25 +0000110{
Jim Ingham58b59f92011-04-22 23:53:53 +0000111 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000112}
113
114//----------------------------------------------------------------------
115// ValueObject constructor
116//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000117ValueObject::ValueObject (ExecutionContextScope *exe_scope,
118 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000119 UserID (++g_value_obj_uid), // Unique identifier for every value object
120 m_parent (NULL),
Enrico Granata4873e522013-04-11 22:48:58 +0000121 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000122 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000123 m_name (),
124 m_data (),
125 m_value (),
126 m_error (),
127 m_value_str (),
128 m_old_value_str (),
129 m_location_str (),
130 m_summary_str (),
131 m_object_desc_str (),
Enrico Granata744794a2014-09-05 21:46:22 +0000132 m_validation_result(),
Jim Ingham58b59f92011-04-22 23:53:53 +0000133 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000134 m_children (),
135 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000136 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000137 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000138 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000139 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +0000140 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000141 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +0000142 m_type_summary_sp(),
143 m_type_format_sp(),
144 m_synthetic_children_sp(),
Enrico Granata744794a2014-09-05 21:46:22 +0000145 m_type_validator_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000146 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000147 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Sean Callanan7375f3e2014-12-09 21:18:59 +0000148 m_value_checksum(),
Enrico Granataed3228a2015-01-21 01:47:13 +0000149 m_preferred_display_language(lldb::eLanguageTypeUnknown),
Jim Ingham6035b672011-03-31 00:19:25 +0000150 m_value_is_valid (false),
151 m_value_did_change (false),
152 m_children_count_valid (false),
153 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000154 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000155 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000156 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000157 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000158 m_is_getting_summary(false),
Enrico Granatae29df232014-12-09 19:51:20 +0000159 m_did_calculate_complete_objc_class_type(false),
160 m_is_synthetic_children_generated(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000161{
Jim Ingham58b59f92011-04-22 23:53:53 +0000162 m_manager = new ValueObjectManager();
163 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000164}
165
166//----------------------------------------------------------------------
167// Destructor
168//----------------------------------------------------------------------
169ValueObject::~ValueObject ()
170{
171}
172
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000173bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000174ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000175{
Enrico Granata4becb372011-06-29 22:27:15 +0000176
Enrico Granata9128ee22011-09-06 19:20:51 +0000177 bool did_change_formats = false;
178
Enrico Granata0a3958e2011-07-02 00:25:22 +0000179 if (update_format)
Enrico Granata5548cb52013-01-28 23:47:25 +0000180 did_change_formats = UpdateFormatsIfNeeded();
Enrico Granata4becb372011-06-29 22:27:15 +0000181
Greg Claytonb71f3842010-10-05 03:13:51 +0000182 // If this is a constant value, then our success is predicated on whether
183 // we have an error or not
184 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000185 {
Enrico Granatab1c6c482013-10-09 00:33:55 +0000186 // if you are constant, things might still have changed behind your back
187 // (e.g. you are a frozen object and things have changed deeper than you cared to freeze-dry yourself)
188 // in this case, your value has not changed, but "computed" entries might have, so you might now have
189 // a different summary, or a different object description. clear these so we will recompute them
Enrico Granata9128ee22011-09-06 19:20:51 +0000190 if (update_format && !did_change_formats)
Enrico Granatab1c6c482013-10-09 00:33:55 +0000191 ClearUserVisibleData(eClearUserVisibleDataItemsSummary | eClearUserVisibleDataItemsDescription);
Greg Claytonb71f3842010-10-05 03:13:51 +0000192 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000193 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000194
Sean Callanan7375f3e2014-12-09 21:18:59 +0000195 bool first_update = IsChecksumEmpty();
Jim Ingham6035b672011-03-31 00:19:25 +0000196
Enrico Granatabb642e52015-05-16 01:27:00 +0000197 if (NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000198 {
Jim Ingham6035b672011-03-31 00:19:25 +0000199 m_update_point.SetUpdated();
200
201 // Save the old value using swap to avoid a string copy which
202 // also will clear our m_value_str
203 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000204 {
Jim Ingham6035b672011-03-31 00:19:25 +0000205 m_old_value_valid = false;
206 }
207 else
208 {
209 m_old_value_valid = true;
210 m_old_value_str.swap (m_value_str);
Enrico Granata86cc9822012-03-19 22:58:49 +0000211 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham6035b672011-03-31 00:19:25 +0000212 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000213
Enrico Granataf2bbf712011-07-15 02:26:42 +0000214 ClearUserVisibleData();
215
Greg Claytonefbc7d22012-03-09 04:23:44 +0000216 if (IsInScope())
Jim Ingham6035b672011-03-31 00:19:25 +0000217 {
Greg Claytonefbc7d22012-03-09 04:23:44 +0000218 const bool value_was_valid = GetValueIsValid();
219 SetValueDidChange (false);
220
221 m_error.Clear();
222
223 // Call the pure virtual function to update the value
Sean Callanan7375f3e2014-12-09 21:18:59 +0000224
225 bool need_compare_checksums = false;
226 llvm::SmallVector<uint8_t, 16> old_checksum;
227
228 if (!first_update && CanProvideValue())
229 {
230 need_compare_checksums = true;
231 old_checksum.resize(m_value_checksum.size());
232 std::copy(m_value_checksum.begin(), m_value_checksum.end(), old_checksum.begin());
233 }
234
Greg Claytonefbc7d22012-03-09 04:23:44 +0000235 bool success = UpdateValue ();
236
237 SetValueIsValid (success);
238
Sean Callanan7375f3e2014-12-09 21:18:59 +0000239 if (success)
240 {
241 const uint64_t max_checksum_size = 128;
242 m_data.Checksum(m_value_checksum,
243 max_checksum_size);
244 }
245 else
246 {
247 need_compare_checksums = false;
248 m_value_checksum.clear();
249 }
250
Enrico Granata20c321c2015-01-08 19:11:43 +0000251 assert (!need_compare_checksums || (!old_checksum.empty() && !m_value_checksum.empty()));
252
Greg Claytonefbc7d22012-03-09 04:23:44 +0000253 if (first_update)
254 SetValueDidChange (false);
255 else if (!m_value_did_change && success == false)
256 {
257 // The value wasn't gotten successfully, so we mark this
258 // as changed if the value used to be valid and now isn't
259 SetValueDidChange (value_was_valid);
260 }
Sean Callanan7375f3e2014-12-09 21:18:59 +0000261 else if (need_compare_checksums)
262 {
263 SetValueDidChange(memcmp(&old_checksum[0], &m_value_checksum[0], m_value_checksum.size()));
264 }
265
Greg Claytonefbc7d22012-03-09 04:23:44 +0000266 }
267 else
268 {
269 m_error.SetErrorString("out of scope");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000270 }
271 }
272 return m_error.Success();
273}
274
Enrico Granata9128ee22011-09-06 19:20:51 +0000275bool
Enrico Granata5548cb52013-01-28 23:47:25 +0000276ValueObject::UpdateFormatsIfNeeded()
Enrico Granata4becb372011-06-29 22:27:15 +0000277{
Greg Clayton5160ce52013-03-27 23:08:40 +0000278 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000279 if (log)
Enrico Granatad2284832012-10-17 22:23:56 +0000280 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000281 GetName().GetCString(), static_cast<void*>(this),
282 m_last_format_mgr_revision,
283 DataVisualization::GetCurrentRevision());
284
Enrico Granata9128ee22011-09-06 19:20:51 +0000285 bool any_change = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000286
Enrico Granata5548cb52013-01-28 23:47:25 +0000287 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()))
Enrico Granata4becb372011-06-29 22:27:15 +0000288 {
Enrico Granataa0db6ed2014-04-09 21:06:11 +0000289 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
290 any_change = true;
291
Enrico Granata852cc952013-10-08 19:03:22 +0000292 SetValueFormat(DataVisualization::GetFormat (*this, eNoDynamicValues));
Enrico Granata5548cb52013-01-28 23:47:25 +0000293 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000294#ifndef LLDB_DISABLE_PYTHON
Enrico Granata5548cb52013-01-28 23:47:25 +0000295 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000296#endif
Enrico Granata744794a2014-09-05 21:46:22 +0000297 SetValidator(DataVisualization::GetValidator(*this, GetDynamicValueType()));
Enrico Granata4becb372011-06-29 22:27:15 +0000298 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000299
Enrico Granata9128ee22011-09-06 19:20:51 +0000300 return any_change;
Enrico Granata4becb372011-06-29 22:27:15 +0000301}
302
Jim Ingham16e0c682011-08-12 23:34:31 +0000303void
304ValueObject::SetNeedsUpdate ()
305{
306 m_update_point.SetNeedsUpdate();
307 // We have to clear the value string here so ConstResult children will notice if their values are
308 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000309 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000310}
311
Enrico Granata13ac0e22012-10-17 19:03:34 +0000312void
Enrico Granatae3e91512012-10-22 18:18:36 +0000313ValueObject::ClearDynamicTypeInformation ()
Enrico Granata13ac0e22012-10-17 19:03:34 +0000314{
Enrico Granata38c54632013-10-30 00:04:29 +0000315 m_children_count_valid = false;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000316 m_did_calculate_complete_objc_class_type = false;
Enrico Granatae3e91512012-10-22 18:18:36 +0000317 m_last_format_mgr_revision = 0;
Greg Claytona1e5dc82015-08-11 22:53:00 +0000318 m_override_type = CompilerType();
Enrico Granatae3e91512012-10-22 18:18:36 +0000319 SetValueFormat(lldb::TypeFormatImplSP());
320 SetSummaryFormat(lldb::TypeSummaryImplSP());
321 SetSyntheticChildren(lldb::SyntheticChildrenSP());
Enrico Granata13ac0e22012-10-17 19:03:34 +0000322}
323
Greg Claytona1e5dc82015-08-11 22:53:00 +0000324CompilerType
Sean Callanan72772842012-02-22 23:57:45 +0000325ValueObject::MaybeCalculateCompleteType ()
326{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000327 CompilerType compiler_type(GetCompilerTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000328
Sean Callanan72772842012-02-22 23:57:45 +0000329 if (m_did_calculate_complete_objc_class_type)
330 {
331 if (m_override_type.IsValid())
332 return m_override_type;
333 else
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000334 return compiler_type;
Sean Callanan72772842012-02-22 23:57:45 +0000335 }
336
Greg Claytona1e5dc82015-08-11 22:53:00 +0000337 CompilerType class_type;
Greg Clayton57ee3062013-07-11 22:46:58 +0000338 bool is_pointer_type = false;
Sean Callanan72772842012-02-22 23:57:45 +0000339
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000340 if (ClangASTContext::IsObjCObjectPointerType(compiler_type, &class_type))
Sean Callanan72772842012-02-22 23:57:45 +0000341 {
342 is_pointer_type = true;
343 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000344 else if (ClangASTContext::IsObjCObjectOrInterfaceType(compiler_type))
Sean Callanan72772842012-02-22 23:57:45 +0000345 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000346 class_type = compiler_type;
Sean Callanan72772842012-02-22 23:57:45 +0000347 }
348 else
349 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000350 return compiler_type;
Sean Callanan72772842012-02-22 23:57:45 +0000351 }
352
353 m_did_calculate_complete_objc_class_type = true;
354
Greg Clayton57ee3062013-07-11 22:46:58 +0000355 if (class_type)
Sean Callanan72772842012-02-22 23:57:45 +0000356 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000357 ConstString class_name (class_type.GetConstTypeName());
Sean Callanan72772842012-02-22 23:57:45 +0000358
Greg Clayton57ee3062013-07-11 22:46:58 +0000359 if (class_name)
360 {
361 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
362
363 if (process_sp)
364 {
365 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
366
367 if (objc_language_runtime)
368 {
369 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name);
370
371 if (complete_objc_class_type_sp)
372 {
Greg Clayton99558cc42015-08-24 23:46:31 +0000373 CompilerType complete_class(complete_objc_class_type_sp->GetFullCompilerType ());
Greg Clayton57ee3062013-07-11 22:46:58 +0000374
375 if (complete_class.GetCompleteType())
376 {
377 if (is_pointer_type)
378 {
379 m_override_type = complete_class.GetPointerType();
380 }
381 else
382 {
383 m_override_type = complete_class;
384 }
385
386 if (m_override_type.IsValid())
387 return m_override_type;
388 }
389 }
390 }
391 }
392 }
Sean Callanan72772842012-02-22 23:57:45 +0000393 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000394 return compiler_type;
Sean Callanan72772842012-02-22 23:57:45 +0000395}
396
Greg Claytona1e5dc82015-08-11 22:53:00 +0000397CompilerType
Greg Clayton99558cc42015-08-24 23:46:31 +0000398ValueObject::GetCompilerType ()
Sean Callanan72772842012-02-22 23:57:45 +0000399{
Greg Clayton57ee3062013-07-11 22:46:58 +0000400 return MaybeCalculateCompleteType();
Sean Callanan72772842012-02-22 23:57:45 +0000401}
402
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000403TypeImpl
404ValueObject::GetTypeImpl ()
405{
Greg Clayton99558cc42015-08-24 23:46:31 +0000406 return TypeImpl(GetCompilerType());
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000407}
408
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000409DataExtractor &
410ValueObject::GetDataExtractor ()
411{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000412 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000413 return m_data;
414}
415
416const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000417ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000418{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000419 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000420 return m_error;
421}
422
423const ConstString &
424ValueObject::GetName() const
425{
426 return m_name;
427}
428
429const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000430ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000431{
Enrico Granata82fabf82013-04-30 20:45:04 +0000432 return GetLocationAsCStringImpl(m_value,
433 m_data);
434}
435
436const char *
437ValueObject::GetLocationAsCStringImpl (const Value& value,
438 const DataExtractor& data)
439{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000440 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000441 {
442 if (m_location_str.empty())
443 {
444 StreamString sstr;
Enrico Granata82fabf82013-04-30 20:45:04 +0000445
446 Value::ValueType value_type = value.GetValueType();
447
448 switch (value_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000449 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000450 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +0000451 case Value::eValueTypeVector:
Enrico Granata82fabf82013-04-30 20:45:04 +0000452 if (value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000453 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000454 RegisterInfo *reg_info = value.GetRegisterInfo();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000455 if (reg_info)
456 {
457 if (reg_info->name)
458 m_location_str = reg_info->name;
459 else if (reg_info->alt_name)
460 m_location_str = reg_info->alt_name;
Enrico Granata82fabf82013-04-30 20:45:04 +0000461 if (m_location_str.empty())
462 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000463 }
464 }
Enrico Granata82fabf82013-04-30 20:45:04 +0000465 if (m_location_str.empty())
466 m_location_str = (value_type == Value::eValueTypeVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000467 break;
468
469 case Value::eValueTypeLoadAddress:
470 case Value::eValueTypeFileAddress:
471 case Value::eValueTypeHostAddress:
472 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000473 uint32_t addr_nibble_size = data.GetAddressByteSize() * 2;
474 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000475 m_location_str.swap(sstr.GetString());
476 }
477 break;
478 }
479 }
480 }
481 return m_location_str.c_str();
482}
483
484Value &
485ValueObject::GetValue()
486{
487 return m_value;
488}
489
490const Value &
491ValueObject::GetValue() const
492{
493 return m_value;
494}
495
496bool
Jim Ingham6035b672011-03-31 00:19:25 +0000497ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000498{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000499 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
500 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000501 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000502 Value tmp_value(m_value);
Greg Clayton57ee3062013-07-11 22:46:58 +0000503 scalar = tmp_value.ResolveValue(&exe_ctx);
Greg Claytondcad5022011-12-29 01:26:56 +0000504 if (scalar.IsValid())
505 {
506 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
507 if (bitfield_bit_size)
508 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
509 return true;
510 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000511 }
Greg Claytondcad5022011-12-29 01:26:56 +0000512 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000513}
514
515bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000516ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000517{
Greg Clayton288bdf92010-09-02 02:59:18 +0000518 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000519}
520
521
522void
523ValueObject::SetValueIsValid (bool b)
524{
Greg Clayton288bdf92010-09-02 02:59:18 +0000525 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000526}
527
528bool
Jim Ingham6035b672011-03-31 00:19:25 +0000529ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000530{
Greg Clayton288bdf92010-09-02 02:59:18 +0000531 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000532}
533
534void
535ValueObject::SetValueDidChange (bool value_changed)
536{
Greg Clayton288bdf92010-09-02 02:59:18 +0000537 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000538}
539
540ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000541ValueObject::GetChildAtIndex (size_t idx, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000542{
543 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000544 // We may need to update our value if we are dynamic
545 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000546 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000547 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000548 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000549 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000550 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000551 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000552 // No we haven't created the child at this index, so lets have our
553 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000554 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000555 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000556
Enrico Granata9d60f602012-03-09 03:09:58 +0000557 ValueObject* child = m_children.GetChildAtIndex(idx);
558 if (child != NULL)
559 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000560 }
561 return child_sp;
562}
563
Enrico Granata3309d882013-01-12 01:00:22 +0000564ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000565ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
566 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000567{
568 if (idxs.size() == 0)
569 return GetSP();
570 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000571 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000572 {
573 root = root->GetChildAtIndex(idx, true);
574 if (!root)
575 {
576 if (index_of_error)
577 *index_of_error = idx;
578 return root;
579 }
580 }
581 return root;
582}
583
584ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000585ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
586 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000587{
588 if (idxs.size() == 0)
589 return GetSP();
590 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000591 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000592 {
593 root = root->GetChildAtIndex(idx.first, idx.second);
594 if (!root)
595 {
596 if (index_of_error)
597 *index_of_error = idx.first;
598 return root;
599 }
600 }
601 return root;
602}
603
604lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000605ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
606 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000607{
608 if (idxs.size() == 0)
609 return GetSP();
610 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000611 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000612 {
613 root = root->GetChildAtIndex(idx, true);
614 if (!root)
615 {
616 if (index_of_error)
617 *index_of_error = idx;
618 return root;
619 }
620 }
621 return root;
622}
623
624lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000625ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
626 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000627{
628 if (idxs.size() == 0)
629 return GetSP();
630 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000631 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000632 {
633 root = root->GetChildAtIndex(idx.first, idx.second);
634 if (!root)
635 {
636 if (index_of_error)
637 *index_of_error = idx.first;
638 return root;
639 }
640 }
641 return root;
642}
643
Enrico Granatae2e220a2013-09-12 00:48:47 +0000644lldb::ValueObjectSP
645ValueObject::GetChildAtNamePath (const std::initializer_list<ConstString> &names,
646 ConstString* name_of_error)
647{
648 if (names.size() == 0)
649 return GetSP();
650 ValueObjectSP root(GetSP());
651 for (ConstString name : names)
652 {
653 root = root->GetChildMemberWithName(name, true);
654 if (!root)
655 {
656 if (name_of_error)
657 *name_of_error = name;
658 return root;
659 }
660 }
661 return root;
662}
663
664lldb::ValueObjectSP
665ValueObject::GetChildAtNamePath (const std::vector<ConstString> &names,
666 ConstString* name_of_error)
667{
668 if (names.size() == 0)
669 return GetSP();
670 ValueObjectSP root(GetSP());
671 for (ConstString name : names)
672 {
673 root = root->GetChildMemberWithName(name, true);
674 if (!root)
675 {
676 if (name_of_error)
677 *name_of_error = name;
678 return root;
679 }
680 }
681 return root;
682}
683
684lldb::ValueObjectSP
685ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names,
686 ConstString* name_of_error)
687{
688 if (names.size() == 0)
689 return GetSP();
690 ValueObjectSP root(GetSP());
691 for (std::pair<ConstString, bool> name : names)
692 {
693 root = root->GetChildMemberWithName(name.first, name.second);
694 if (!root)
695 {
696 if (name_of_error)
697 *name_of_error = name.first;
698 return root;
699 }
700 }
701 return root;
702}
703
704lldb::ValueObjectSP
705ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names,
706 ConstString* name_of_error)
707{
708 if (names.size() == 0)
709 return GetSP();
710 ValueObjectSP root(GetSP());
711 for (std::pair<ConstString, bool> name : names)
712 {
713 root = root->GetChildMemberWithName(name.first, name.second);
714 if (!root)
715 {
716 if (name_of_error)
717 *name_of_error = name.first;
718 return root;
719 }
720 }
721 return root;
722}
723
Greg Claytonc7bece562013-01-25 18:06:21 +0000724size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000725ValueObject::GetIndexOfChildWithName (const ConstString &name)
726{
727 bool omit_empty_base_classes = true;
Greg Clayton99558cc42015-08-24 23:46:31 +0000728 return GetCompilerType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000729}
730
731ValueObjectSP
732ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
733{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000734 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000735 // classes (which really aren't part of the expression path), so we
736 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000737 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000738
Greg Claytondea8cb42011-06-29 22:09:02 +0000739 // We may need to update our value if we are dynamic
740 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000741 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000742
743 std::vector<uint32_t> child_indexes;
Greg Claytondea8cb42011-06-29 22:09:02 +0000744 bool omit_empty_base_classes = true;
Greg Clayton99558cc42015-08-24 23:46:31 +0000745 const size_t num_child_indexes = GetCompilerType().GetIndexOfChildMemberWithName (name.GetCString(),
Greg Clayton57ee3062013-07-11 22:46:58 +0000746 omit_empty_base_classes,
747 child_indexes);
Greg Claytondea8cb42011-06-29 22:09:02 +0000748 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000749 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000750 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
751 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
752
753 child_sp = GetChildAtIndex(*pos, can_create);
754 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000755 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000756 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000757 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000758 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
759 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000760 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000761 else
762 {
763 child_sp.reset();
764 }
765
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000766 }
767 }
768 return child_sp;
769}
770
771
Greg Claytonc7bece562013-01-25 18:06:21 +0000772size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000773ValueObject::GetNumChildren ()
774{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000775 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000776 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000777 {
778 SetNumChildren (CalculateNumChildren());
779 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000780 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000781}
Greg Clayton4a792072012-10-23 01:50:10 +0000782
783bool
784ValueObject::MightHaveChildren()
785{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000786 bool has_children = false;
Greg Clayton2452ab72013-02-08 22:02:02 +0000787 const uint32_t type_info = GetTypeInfo();
788 if (type_info)
Greg Clayton4a792072012-10-23 01:50:10 +0000789 {
Enrico Granata622be232014-10-21 20:52:14 +0000790 if (type_info & (eTypeHasChildren |
791 eTypeIsPointer |
792 eTypeIsReference))
Greg Clayton4a792072012-10-23 01:50:10 +0000793 has_children = true;
794 }
795 else
796 {
797 has_children = GetNumChildren () > 0;
798 }
799 return has_children;
800}
801
802// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000803void
Greg Claytonc7bece562013-01-25 18:06:21 +0000804ValueObject::SetNumChildren (size_t num_children)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000805{
Greg Clayton288bdf92010-09-02 02:59:18 +0000806 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000807 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000808}
809
810void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000811ValueObject::SetName (const ConstString &name)
812{
813 m_name = name;
814}
815
Jim Ingham58b59f92011-04-22 23:53:53 +0000816ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000817ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000818{
Jim Ingham2eec4872011-05-07 00:10:58 +0000819 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000820
Greg Claytondea8cb42011-06-29 22:09:02 +0000821 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000822 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000823 std::string child_name_str;
824 uint32_t child_byte_size = 0;
825 int32_t child_byte_offset = 0;
826 uint32_t child_bitfield_bit_size = 0;
827 uint32_t child_bitfield_bit_offset = 0;
828 bool child_is_base_class = false;
829 bool child_is_deref_of_parent = false;
830
831 const bool transparent_pointers = synthetic_array_member == false;
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000832 CompilerType child_compiler_type;
Greg Claytondea8cb42011-06-29 22:09:02 +0000833
Greg Claytoncc4d0142012-02-17 07:49:44 +0000834 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000835
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000836 child_compiler_type = GetCompilerType().GetChildCompilerTypeAtIndex (&exe_ctx,
837 idx,
838 transparent_pointers,
839 omit_empty_base_classes,
840 ignore_array_bounds,
841 child_name_str,
842 child_byte_size,
843 child_byte_offset,
844 child_bitfield_bit_size,
845 child_bitfield_bit_offset,
846 child_is_base_class,
847 child_is_deref_of_parent,
848 this);
849 if (child_compiler_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000850 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000851 if (synthetic_index)
852 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000853
Greg Claytondea8cb42011-06-29 22:09:02 +0000854 ConstString child_name;
855 if (!child_name_str.empty())
856 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000857
Greg Claytondea8cb42011-06-29 22:09:02 +0000858 valobj = new ValueObjectChild (*this,
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000859 child_compiler_type,
Greg Claytondea8cb42011-06-29 22:09:02 +0000860 child_name,
861 child_byte_size,
862 child_byte_offset,
863 child_bitfield_bit_size,
864 child_bitfield_bit_offset,
865 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000866 child_is_deref_of_parent,
867 eAddressTypeInvalid);
868 //if (valobj)
869 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
870 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000871
Jim Ingham58b59f92011-04-22 23:53:53 +0000872 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000873}
874
Enrico Granata0c489f52012-03-01 04:24:26 +0000875bool
876ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
877 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000878{
Enrico Granatac1247f52014-11-06 21:23:20 +0000879 return GetSummaryAsCString(summary_ptr, destination, TypeSummaryOptions());
880}
881
882bool
883ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
884 std::string& destination,
885 const TypeSummaryOptions& options)
886{
Enrico Granata0c489f52012-03-01 04:24:26 +0000887 destination.clear();
888
889 // ideally we would like to bail out if passing NULL, but if we do so
890 // we end up not providing the summary for function pointers anymore
891 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
892 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000893
894 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000895
896 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
897 // information that we might care to see in a crash log. might be useful in very specific situations though.
898 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
899 GetTypeName().GetCString(),
900 GetName().GetCString(),
901 summary_ptr->GetDescription().c_str());*/
902
Enrico Granataff0f23d2014-12-10 02:00:45 +0000903 if (UpdateValueIfNeeded (false) && summary_ptr)
Enrico Granata0c489f52012-03-01 04:24:26 +0000904 {
Enrico Granataff0f23d2014-12-10 02:00:45 +0000905 if (HasSyntheticValue())
906 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
907 summary_ptr->FormatObject(this, destination, options);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000908 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000909 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000910 return !destination.empty();
911}
912
913const char *
914ValueObject::GetSummaryAsCString ()
915{
916 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
917 {
918 GetSummaryAsCString(GetSummaryFormat().get(),
Enrico Granatac1247f52014-11-06 21:23:20 +0000919 m_summary_str,
Enrico Granata49bfafb2014-11-18 23:36:25 +0000920 TypeSummaryOptions());
Enrico Granata0c489f52012-03-01 04:24:26 +0000921 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000922 if (m_summary_str.empty())
923 return NULL;
924 return m_summary_str.c_str();
925}
926
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000927bool
Enrico Granata49bfafb2014-11-18 23:36:25 +0000928ValueObject::GetSummaryAsCString (std::string& destination,
929 const TypeSummaryOptions& options)
930{
931 return GetSummaryAsCString(GetSummaryFormat().get(),
932 destination,
933 options);
934}
935
936bool
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000937ValueObject::IsCStringContainer(bool check_pointer)
938{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000939 CompilerType pointee_or_element_compiler_type;
940 const Flags type_flags (GetTypeInfo (&pointee_or_element_compiler_type));
Enrico Granata622be232014-10-21 20:52:14 +0000941 bool is_char_arr_ptr (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000942 pointee_or_element_compiler_type.IsCharType ());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000943 if (!is_char_arr_ptr)
944 return false;
945 if (!check_pointer)
946 return true;
Enrico Granata622be232014-10-21 20:52:14 +0000947 if (type_flags.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000948 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000949 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000950 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000951 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000952 return (cstr_address != LLDB_INVALID_ADDRESS);
953}
954
Enrico Granata9128ee22011-09-06 19:20:51 +0000955size_t
956ValueObject::GetPointeeData (DataExtractor& data,
957 uint32_t item_idx,
958 uint32_t item_count)
959{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000960 CompilerType pointee_or_element_compiler_type;
961 const uint32_t type_info = GetTypeInfo (&pointee_or_element_compiler_type);
Enrico Granata622be232014-10-21 20:52:14 +0000962 const bool is_pointer_type = type_info & eTypeIsPointer;
963 const bool is_array_type = type_info & eTypeIsArray;
Greg Clayton2452ab72013-02-08 22:02:02 +0000964 if (!(is_pointer_type || is_array_type))
Enrico Granata9128ee22011-09-06 19:20:51 +0000965 return 0;
966
967 if (item_count == 0)
968 return 0;
969
Enrico Granata951bdd52015-01-28 01:09:45 +0000970 ExecutionContext exe_ctx (GetExecutionContextRef());
971
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000972 const uint64_t item_type_size = pointee_or_element_compiler_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
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 Clayton99558cc42015-08-24 23:46:31 +00001048 const uint64_t max_bytes = GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope());
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);
Siva Chandrae32f2b52015-05-05 00:41:35 +00001052 addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1053 if (addr == LLDB_INVALID_ADDRESS)
1054 break;
Greg Clayton2452ab72013-02-08 22:02:02 +00001055 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
1056 data.SetData(data_sp);
1057 return bytes_read;
1058 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001059 }
1060 break;
1061 case eAddressTypeInvalid:
Enrico Granata9128ee22011-09-06 19:20:51 +00001062 break;
1063 }
1064 }
1065 return 0;
1066}
1067
Greg Claytonfaac1112013-03-14 18:31:44 +00001068uint64_t
Sean Callanan866e91c2014-02-28 22:27:53 +00001069ValueObject::GetData (DataExtractor& data, Error &error)
Enrico Granata9128ee22011-09-06 19:20:51 +00001070{
1071 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001072 ExecutionContext exe_ctx (GetExecutionContextRef());
Sean Callanan866e91c2014-02-28 22:27:53 +00001073 error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001074 if (error.Fail())
Sean Callananed185ab2013-04-19 19:47:32 +00001075 {
1076 if (m_data.GetByteSize())
1077 {
1078 data = m_data;
1079 return data.GetByteSize();
1080 }
1081 else
1082 {
1083 return 0;
1084 }
1085 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001086 data.SetAddressByteSize(m_data.GetAddressByteSize());
1087 data.SetByteOrder(m_data.GetByteOrder());
1088 return data.GetByteSize();
1089}
1090
Sean Callanan389823e2013-04-13 01:21:23 +00001091bool
1092ValueObject::SetData (DataExtractor &data, Error &error)
1093{
1094 error.Clear();
1095 // Make sure our value is up to date first so that our location and location
1096 // type is valid.
1097 if (!UpdateValueIfNeeded(false))
1098 {
1099 error.SetErrorString("unable to read value");
1100 return false;
1101 }
1102
1103 uint64_t count = 0;
Greg Clayton99558cc42015-08-24 23:46:31 +00001104 const Encoding encoding = GetCompilerType().GetEncoding(count);
Sean Callanan389823e2013-04-13 01:21:23 +00001105
1106 const size_t byte_size = GetByteSize();
1107
1108 Value::ValueType value_type = m_value.GetValueType();
1109
1110 switch (value_type)
1111 {
1112 case Value::eValueTypeScalar:
1113 {
1114 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1115
1116 if (!set_error.Success())
1117 {
1118 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1119 return false;
1120 }
1121 }
1122 break;
1123 case Value::eValueTypeLoadAddress:
1124 {
1125 // If it is a load address, then the scalar value is the storage location
1126 // of the data, and we have to shove this value down to that load location.
1127 ExecutionContext exe_ctx (GetExecutionContextRef());
1128 Process *process = exe_ctx.GetProcessPtr();
1129 if (process)
1130 {
1131 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1132 size_t bytes_written = process->WriteMemory(target_addr,
1133 data.GetDataStart(),
1134 byte_size,
1135 error);
1136 if (!error.Success())
1137 return false;
1138 if (bytes_written != byte_size)
1139 {
1140 error.SetErrorString("unable to write value to memory");
1141 return false;
1142 }
1143 }
1144 }
1145 break;
1146 case Value::eValueTypeHostAddress:
1147 {
1148 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1149 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1150 m_data.SetData(buffer_sp, 0);
1151 data.CopyByteOrderedData (0,
1152 byte_size,
1153 const_cast<uint8_t *>(m_data.GetDataStart()),
1154 byte_size,
1155 m_data.GetByteOrder());
1156 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1157 }
1158 break;
1159 case Value::eValueTypeFileAddress:
1160 case Value::eValueTypeVector:
1161 break;
1162 }
1163
1164 // If we have reached this point, then we have successfully changed the value.
1165 SetNeedsUpdate();
1166 return true;
1167}
1168
Enrico Granata9128ee22011-09-06 19:20:51 +00001169// will compute strlen(str), but without consuming more than
1170// maxlen bytes out of str (this serves the purpose of reading
1171// chunks of a string without having to worry about
1172// missing NULL terminators in the chunk)
1173// of course, if strlen(str) > maxlen, the function will return
1174// maxlen_value (which should be != maxlen, because that allows you
1175// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1176static uint32_t
1177strlen_or_inf (const char* str,
1178 uint32_t maxlen,
1179 uint32_t maxlen_value)
1180{
1181 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +00001182 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +00001183 {
Greg Clayton8dd5c172011-10-05 22:19:51 +00001184 while(*str)
1185 {
1186 len++;str++;
Greg Clayton2452ab72013-02-08 22:02:02 +00001187 if (len >= maxlen)
Greg Clayton8dd5c172011-10-05 22:19:51 +00001188 return maxlen_value;
1189 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001190 }
1191 return len;
1192}
1193
Enrico Granata2206b482014-10-30 18:27:31 +00001194static bool
1195CopyStringDataToBufferSP(const StreamString& source,
1196 lldb::DataBufferSP& destination)
1197{
1198 destination.reset(new DataBufferHeap(source.GetSize()+1,0));
1199 memcpy(destination->GetBytes(), source.GetString().c_str(), source.GetSize());
1200 return true;
1201}
1202
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001203size_t
Enrico Granata2206b482014-10-30 18:27:31 +00001204ValueObject::ReadPointedString (lldb::DataBufferSP& buffer_sp,
Greg Claytoncc4d0142012-02-17 07:49:44 +00001205 Error& error,
1206 uint32_t max_length,
1207 bool honor_array,
1208 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001209{
Enrico Granata2206b482014-10-30 18:27:31 +00001210 StreamString s;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001211 ExecutionContext exe_ctx (GetExecutionContextRef());
1212 Target* target = exe_ctx.GetTargetPtr();
Enrico Granata2206b482014-10-30 18:27:31 +00001213
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001214 if (!target)
1215 {
1216 s << "<no target to read from>";
1217 error.SetErrorString("no target to read from");
Enrico Granata2206b482014-10-30 18:27:31 +00001218 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001219 return 0;
1220 }
1221
1222 if (max_length == 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001223 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001224
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001225 size_t bytes_read = 0;
1226 size_t total_bytes_read = 0;
1227
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001228 CompilerType compiler_type = GetCompilerType();
1229 CompilerType elem_or_pointee_compiler_type;
1230 const Flags type_flags (GetTypeInfo (&elem_or_pointee_compiler_type));
Enrico Granata622be232014-10-21 20:52:14 +00001231 if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001232 elem_or_pointee_compiler_type.IsCharType ())
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001233 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001234 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1235 AddressType cstr_address_type = eAddressTypeInvalid;
1236
1237 size_t cstr_len = 0;
1238 bool capped_data = false;
Enrico Granata622be232014-10-21 20:52:14 +00001239 if (type_flags.Test (eTypeIsArray))
Greg Claytoncc4d0142012-02-17 07:49:44 +00001240 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001241 // We have an array
Greg Clayton57ee3062013-07-11 22:46:58 +00001242 uint64_t array_size = 0;
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001243 if (compiler_type.IsArrayType(NULL, &array_size, NULL))
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001244 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001245 cstr_len = array_size;
1246 if (cstr_len > max_length)
1247 {
1248 capped_data = true;
1249 cstr_len = max_length;
1250 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001251 }
1252 cstr_address = GetAddressOf (true, &cstr_address_type);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001253 }
1254 else
1255 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001256 // We have a pointer
1257 cstr_address = GetPointerValue (&cstr_address_type);
1258 }
1259
1260 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1261 {
1262 s << "<invalid address>";
1263 error.SetErrorString("invalid address");
Enrico Granata2206b482014-10-30 18:27:31 +00001264 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001265 return 0;
1266 }
Enrico Granata2206b482014-10-30 18:27:31 +00001267
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001268 Address cstr_so_addr (cstr_address);
1269 DataExtractor data;
1270 if (cstr_len > 0 && honor_array)
1271 {
1272 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1273 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1274 GetPointeeData(data, 0, cstr_len);
Enrico Granata2206b482014-10-30 18:27:31 +00001275
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001276 if ((bytes_read = data.GetByteSize()) > 0)
1277 {
1278 total_bytes_read = bytes_read;
Enrico Granata2206b482014-10-30 18:27:31 +00001279 for (size_t offset = 0; offset < bytes_read; offset++)
1280 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001281 if (capped_data)
1282 s << "...";
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001283 }
1284 }
1285 else
1286 {
1287 cstr_len = max_length;
1288 const size_t k_max_buf_size = 64;
Enrico Granata2206b482014-10-30 18:27:31 +00001289
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001290 size_t offset = 0;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001291
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001292 int cstr_len_displayed = -1;
1293 bool capped_cstr = false;
1294 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1295 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1296 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001297 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001298 total_bytes_read += bytes_read;
1299 const char *cstr = data.PeekCStr(0);
1300 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1301 if (len > k_max_buf_size)
1302 len = k_max_buf_size;
Enrico Granata2206b482014-10-30 18:27:31 +00001303
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001304 if (cstr_len_displayed < 0)
1305 cstr_len_displayed = len;
Enrico Granata2206b482014-10-30 18:27:31 +00001306
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001307 if (len == 0)
1308 break;
1309 cstr_len_displayed += len;
1310 if (len > bytes_read)
1311 len = bytes_read;
1312 if (len > cstr_len)
1313 len = cstr_len;
1314
Enrico Granata2206b482014-10-30 18:27:31 +00001315 for (size_t offset = 0; offset < bytes_read; offset++)
1316 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001317
1318 if (len < k_max_buf_size)
1319 break;
1320
1321 if (len >= cstr_len)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001322 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001323 capped_cstr = true;
1324 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001325 }
Enrico Granata2206b482014-10-30 18:27:31 +00001326
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001327 cstr_len -= len;
1328 offset += len;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001329 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001330
1331 if (cstr_len_displayed >= 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001332 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001333 if (capped_cstr)
1334 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001335 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001336 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001337 }
1338 else
1339 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001340 error.SetErrorString("not a string object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001341 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001342 }
Enrico Granata2206b482014-10-30 18:27:31 +00001343 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001344 return total_bytes_read;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001345}
1346
Enrico Granata744794a2014-09-05 21:46:22 +00001347std::pair<TypeValidatorResult, std::string>
1348ValueObject::GetValidationStatus ()
1349{
1350 if (!UpdateValueIfNeeded(true))
1351 return {TypeValidatorResult::Success,""}; // not the validator's job to discuss update problems
1352
1353 if (m_validation_result.hasValue())
1354 return m_validation_result.getValue();
1355
1356 if (!m_type_validator_sp)
1357 return {TypeValidatorResult::Success,""}; // no validator no failure
1358
1359 auto outcome = m_type_validator_sp->FormatObject(this);
1360
1361 return (m_validation_result = {outcome.m_result,outcome.m_message}).getValue();
1362}
1363
Jim Ingham53c47f12010-09-10 23:12:17 +00001364const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001365ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001366{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001367
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001368 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001369 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001370
1371 if (!m_object_desc_str.empty())
1372 return m_object_desc_str.c_str();
1373
Greg Claytoncc4d0142012-02-17 07:49:44 +00001374 ExecutionContext exe_ctx (GetExecutionContextRef());
1375 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001376 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001377 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001378
Jim Ingham53c47f12010-09-10 23:12:17 +00001379 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001380
Greg Claytonafacd142011-09-02 01:15:17 +00001381 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001382 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1383
Jim Inghama2cf2632010-12-23 02:29:54 +00001384 if (runtime == NULL)
1385 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001386 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001387 CompilerType compiler_type = GetCompilerType();
1388 if (compiler_type)
Jim Inghama2cf2632010-12-23 02:29:54 +00001389 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001390 bool is_signed;
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001391 if (compiler_type.IsIntegerType (is_signed) || compiler_type.IsPointerType ())
Jim Inghamb7603bb2011-03-18 00:05:18 +00001392 {
Greg Claytonafacd142011-09-02 01:15:17 +00001393 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001394 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001395 }
1396 }
1397
Jim Ingham8d543de2011-03-31 23:01:21 +00001398 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001399 {
1400 m_object_desc_str.append (s.GetData());
1401 }
Sean Callanan672ad942010-10-23 00:18:49 +00001402
1403 if (m_object_desc_str.empty())
1404 return NULL;
1405 else
1406 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001407}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001408
Enrico Granata0c489f52012-03-01 04:24:26 +00001409bool
Enrico Granata4939b982013-12-22 09:24:22 +00001410ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format,
1411 std::string& destination)
1412{
1413 if (UpdateValueIfNeeded(false))
1414 return format.FormatObject(this,destination);
1415 else
1416 return false;
1417}
1418
1419bool
Enrico Granata0c489f52012-03-01 04:24:26 +00001420ValueObject::GetValueAsCString (lldb::Format format,
1421 std::string& destination)
1422{
Enrico Granata30f287f2013-12-28 08:44:02 +00001423 return GetValueAsCString(TypeFormatImpl_Format(format),destination);
Enrico Granata0c489f52012-03-01 04:24:26 +00001424}
1425
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001426const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001427ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001428{
Enrico Granatab294fd22013-05-31 19:18:19 +00001429 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001430 {
Enrico Granata4939b982013-12-22 09:24:22 +00001431 lldb::TypeFormatImplSP format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001432 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001433 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001434 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001435 if (m_type_format_sp)
Enrico Granata4939b982013-12-22 09:24:22 +00001436 format_sp = m_type_format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001437 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001438 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001439 if (m_is_bitfield_for_scalar)
1440 my_format = eFormatUnsigned;
1441 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001442 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001443 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001444 {
1445 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1446 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001447 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001448 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001449 else
1450 {
Greg Clayton99558cc42015-08-24 23:46:31 +00001451 my_format = GetValue().GetCompilerType().GetFormat();
Enrico Granata0c489f52012-03-01 04:24:26 +00001452 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001453 }
1454 }
1455 }
Enrico Granatab294fd22013-05-31 19:18:19 +00001456 if (my_format != m_last_format || m_value_str.empty())
Enrico Granata297e69f2012-03-06 23:21:16 +00001457 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001458 m_last_format = my_format;
Enrico Granata4939b982013-12-22 09:24:22 +00001459 if (!format_sp)
Enrico Granata30f287f2013-12-28 08:44:02 +00001460 format_sp.reset(new TypeFormatImpl_Format(my_format));
Enrico Granata4939b982013-12-22 09:24:22 +00001461 if (GetValueAsCString(*format_sp.get(), m_value_str))
Enrico Granata297e69f2012-03-06 23:21:16 +00001462 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001463 if (!m_value_did_change && m_old_value_valid)
1464 {
1465 // The value was gotten successfully, so we consider the
1466 // value as changed if the value string differs
1467 SetValueDidChange (m_old_value_str != m_value_str);
1468 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001469 }
1470 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001471 }
1472 if (m_value_str.empty())
1473 return NULL;
1474 return m_value_str.c_str();
1475}
1476
Enrico Granatac3e320a2011-08-02 17:27:39 +00001477// if > 8bytes, 0 is returned. this method should mostly be used
1478// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001479uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001480ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001481{
1482 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001483 if (CanProvideValue())
Enrico Granatac3e320a2011-08-02 17:27:39 +00001484 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001485 Scalar scalar;
1486 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001487 {
1488 if (success)
1489 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001490 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001491 }
1492 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001493 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001494
1495 if (success)
1496 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001497 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001498}
1499
Enrico Granatad7373f62013-10-31 18:57:50 +00001500int64_t
1501ValueObject::GetValueAsSigned (int64_t fail_value, bool *success)
1502{
1503 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001504 if (CanProvideValue())
Enrico Granatad7373f62013-10-31 18:57:50 +00001505 {
1506 Scalar scalar;
1507 if (ResolveValue (scalar))
1508 {
1509 if (success)
1510 *success = true;
Tamas Berghammer5a9919f2015-01-23 10:54:21 +00001511 return scalar.SLongLong(fail_value);
Enrico Granatad7373f62013-10-31 18:57:50 +00001512 }
1513 // fallthrough, otherwise...
1514 }
1515
1516 if (success)
1517 *success = false;
Tamas Berghammer5a9919f2015-01-23 10:54:21 +00001518 return fail_value;
Enrico Granatad7373f62013-10-31 18:57:50 +00001519}
1520
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001521// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1522// this call up to date by returning true for your new special cases. We will eventually move
1523// to checking this call result before trying to display special cases
1524bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001525ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1526 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001527{
Greg Clayton57ee3062013-07-11 22:46:58 +00001528 Flags flags(GetTypeInfo());
Enrico Granata622be232014-10-21 20:52:14 +00001529 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001530 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001531 {
1532 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001533 (custom_format == eFormatCString ||
1534 custom_format == eFormatCharArray ||
1535 custom_format == eFormatChar ||
1536 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001537 return true;
1538
Enrico Granata622be232014-10-21 20:52:14 +00001539 if (flags.Test(eTypeIsArray))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001540 {
Greg Claytonafacd142011-09-02 01:15:17 +00001541 if ((custom_format == eFormatBytes) ||
1542 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001543 return true;
1544
Greg Claytonafacd142011-09-02 01:15:17 +00001545 if ((custom_format == eFormatVectorOfChar) ||
1546 (custom_format == eFormatVectorOfFloat32) ||
1547 (custom_format == eFormatVectorOfFloat64) ||
1548 (custom_format == eFormatVectorOfSInt16) ||
1549 (custom_format == eFormatVectorOfSInt32) ||
1550 (custom_format == eFormatVectorOfSInt64) ||
1551 (custom_format == eFormatVectorOfSInt8) ||
1552 (custom_format == eFormatVectorOfUInt128) ||
1553 (custom_format == eFormatVectorOfUInt16) ||
1554 (custom_format == eFormatVectorOfUInt32) ||
1555 (custom_format == eFormatVectorOfUInt64) ||
1556 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001557 return true;
1558 }
1559 }
1560 return false;
1561}
1562
Enrico Granata9fc19442011-07-06 02:13:41 +00001563bool
1564ValueObject::DumpPrintableRepresentation(Stream& s,
1565 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001566 Format custom_format,
Enrico Granata0dba9b32014-01-08 01:36:59 +00001567 PrintableRepresentationSpecialCases special,
1568 bool do_dump_error)
Enrico Granata9fc19442011-07-06 02:13:41 +00001569{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001570
Greg Clayton57ee3062013-07-11 22:46:58 +00001571 Flags flags(GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001572
Enrico Granata86cc9822012-03-19 22:58:49 +00001573 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1574 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1575
1576 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001577 {
Enrico Granata622be232014-10-21 20:52:14 +00001578 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001579 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001580 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001581 // when being asked to get a printable display an array or pointer type directly,
1582 // try to "do the right thing"
1583
1584 if (IsCStringContainer(true) &&
1585 (custom_format == eFormatCString ||
1586 custom_format == eFormatCharArray ||
1587 custom_format == eFormatChar ||
1588 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001589 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001590 Error error;
Enrico Granata2206b482014-10-30 18:27:31 +00001591 lldb::DataBufferSP buffer_sp;
1592 ReadPointedString(buffer_sp,
Enrico Granata86cc9822012-03-19 22:58:49 +00001593 error,
1594 0,
1595 (custom_format == eFormatVectorOfChar) ||
1596 (custom_format == eFormatCharArray));
Enrico Granataac494532015-09-09 22:30:24 +00001597 lldb_private::formatters::StringPrinter::ReadBufferAndDumpToStreamOptions options(*this);
Enrico Granata2206b482014-10-30 18:27:31 +00001598 options.SetData(DataExtractor(buffer_sp, lldb::eByteOrderInvalid, 8)); // none of this matters for a string - pass some defaults
1599 options.SetStream(&s);
1600 options.SetPrefixToken(0);
1601 options.SetQuote('"');
1602 options.SetSourceSize(buffer_sp->GetByteSize());
Enrico Granataac494532015-09-09 22:30:24 +00001603 formatters::StringPrinter::ReadBufferAndDumpToStream<lldb_private::formatters::StringPrinter::StringElementType::ASCII>(options);
Enrico Granata86cc9822012-03-19 22:58:49 +00001604 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001605 }
1606
Enrico Granata86cc9822012-03-19 22:58:49 +00001607 if (custom_format == eFormatEnum)
1608 return false;
1609
1610 // this only works for arrays, because I have no way to know when
1611 // the pointed memory ends, and no special \0 end of data marker
Enrico Granata622be232014-10-21 20:52:14 +00001612 if (flags.Test(eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001613 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001614 if ((custom_format == eFormatBytes) ||
1615 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001616 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001617 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001618
1619 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001620 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001621 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001622
1623 if (low)
1624 s << ',';
1625
1626 ValueObjectSP child = GetChildAtIndex(low,true);
1627 if (!child.get())
1628 {
1629 s << "<invalid child>";
1630 continue;
1631 }
1632 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1633 }
1634
1635 s << ']';
1636
1637 return true;
1638 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001639
Enrico Granata86cc9822012-03-19 22:58:49 +00001640 if ((custom_format == eFormatVectorOfChar) ||
1641 (custom_format == eFormatVectorOfFloat32) ||
1642 (custom_format == eFormatVectorOfFloat64) ||
1643 (custom_format == eFormatVectorOfSInt16) ||
1644 (custom_format == eFormatVectorOfSInt32) ||
1645 (custom_format == eFormatVectorOfSInt64) ||
1646 (custom_format == eFormatVectorOfSInt8) ||
1647 (custom_format == eFormatVectorOfUInt128) ||
1648 (custom_format == eFormatVectorOfUInt16) ||
1649 (custom_format == eFormatVectorOfUInt32) ||
1650 (custom_format == eFormatVectorOfUInt64) ||
1651 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1652 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001653 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001654
1655 Format format = FormatManager::GetSingleItemFormat(custom_format);
1656
1657 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001658 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001659 {
1660
1661 if (low)
1662 s << ',';
1663
1664 ValueObjectSP child = GetChildAtIndex(low,true);
1665 if (!child.get())
1666 {
1667 s << "<invalid child>";
1668 continue;
1669 }
1670 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1671 }
1672
1673 s << ']';
1674
1675 return true;
1676 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001677 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001678
1679 if ((custom_format == eFormatBoolean) ||
1680 (custom_format == eFormatBinary) ||
1681 (custom_format == eFormatChar) ||
1682 (custom_format == eFormatCharPrintable) ||
1683 (custom_format == eFormatComplexFloat) ||
1684 (custom_format == eFormatDecimal) ||
1685 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001686 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001687 (custom_format == eFormatFloat) ||
1688 (custom_format == eFormatOctal) ||
1689 (custom_format == eFormatOSType) ||
1690 (custom_format == eFormatUnicode16) ||
1691 (custom_format == eFormatUnicode32) ||
1692 (custom_format == eFormatUnsigned) ||
1693 (custom_format == eFormatPointer) ||
1694 (custom_format == eFormatComplexInteger) ||
1695 (custom_format == eFormatComplex) ||
1696 (custom_format == eFormatDefault)) // use the [] operator
1697 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001698 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001699 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001700
1701 if (only_special)
1702 return false;
1703
Enrico Granata86cc9822012-03-19 22:58:49 +00001704 bool var_success = false;
1705
1706 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001707 const char *cstr = NULL;
Enrico Granata2c75f112013-06-21 00:04:51 +00001708
1709 // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1710 // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1711 // area for cases where our desired output is not backed by some other longer-term storage
Greg Claytonc7bece562013-01-25 18:06:21 +00001712 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001713
Enrico Granata465f4bc2014-02-15 01:24:44 +00001714 if (custom_format != eFormatInvalid)
Enrico Granata86cc9822012-03-19 22:58:49 +00001715 SetFormat(custom_format);
1716
1717 switch(val_obj_display)
1718 {
1719 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001720 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001721 break;
1722
1723 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001724 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001725 break;
1726
1727 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001728 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001729 break;
1730
1731 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001732 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001733 break;
1734
1735 case eValueObjectRepresentationStyleChildrenCount:
Deepak Panickal99fbc072014-03-03 15:39:47 +00001736 strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren());
Greg Claytonc7bece562013-01-25 18:06:21 +00001737 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001738 break;
1739
1740 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001741 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001742 break;
Enrico Granata2c75f112013-06-21 00:04:51 +00001743
1744 case eValueObjectRepresentationStyleName:
1745 cstr = GetName().AsCString();
1746 break;
1747
1748 case eValueObjectRepresentationStyleExpressionPath:
1749 GetExpressionPath(strm, false);
1750 cstr = strm.GetString().c_str();
1751 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001752 }
1753
Greg Claytonc7bece562013-01-25 18:06:21 +00001754 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001755 {
1756 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001757 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001758 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1759 {
Enrico Granatad07cfd32014-10-08 18:27:36 +00001760 if (!CanProvideValue())
Enrico Granata86cc9822012-03-19 22:58:49 +00001761 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001762 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1763 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001764 }
1765 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001766 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001767 }
1768 }
1769
Greg Claytonc7bece562013-01-25 18:06:21 +00001770 if (cstr)
1771 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001772 else
1773 {
1774 if (m_error.Fail())
Enrico Granata0dba9b32014-01-08 01:36:59 +00001775 {
1776 if (do_dump_error)
1777 s.Printf("<%s>", m_error.AsCString());
1778 else
1779 return false;
1780 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001781 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1782 s.PutCString("<no summary available>");
1783 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1784 s.PutCString("<no value available>");
1785 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1786 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1787 else
1788 s.PutCString("<no printable representation>");
1789 }
1790
1791 // we should only return false here if we could not do *anything*
1792 // even if we have an error message as output, that's a success
1793 // from our callers' perspective, so return true
1794 var_success = true;
Enrico Granata465f4bc2014-02-15 01:24:44 +00001795
1796 if (custom_format != eFormatInvalid)
1797 SetFormat(eFormatDefault);
Enrico Granata86cc9822012-03-19 22:58:49 +00001798 }
1799
Enrico Granataf4efecd2011-07-12 22:56:10 +00001800 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001801}
1802
Greg Clayton737b9322010-09-13 03:32:57 +00001803addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001804ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001805{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001806 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001807 return LLDB_INVALID_ADDRESS;
1808
Greg Clayton73b472d2010-10-27 03:32:59 +00001809 switch (m_value.GetValueType())
1810 {
1811 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001812 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001813 if (scalar_is_load_address)
1814 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001815 if(address_type)
1816 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001817 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1818 }
1819 break;
1820
1821 case Value::eValueTypeLoadAddress:
1822 case Value::eValueTypeFileAddress:
Greg Clayton73b472d2010-10-27 03:32:59 +00001823 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001824 if(address_type)
1825 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001826 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1827 }
1828 break;
Siva Chandraa3747a92015-05-04 19:43:34 +00001829 case Value::eValueTypeHostAddress:
Siva Chandrae32f2b52015-05-05 00:41:35 +00001830 {
1831 if(address_type)
1832 *address_type = m_value.GetValueAddressType ();
1833 return LLDB_INVALID_ADDRESS;
1834 }
Siva Chandraa3747a92015-05-04 19:43:34 +00001835 break;
Greg Clayton73b472d2010-10-27 03:32:59 +00001836 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001837 if (address_type)
1838 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001839 return LLDB_INVALID_ADDRESS;
1840}
1841
1842addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001843ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001844{
Greg Claytonafacd142011-09-02 01:15:17 +00001845 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001846 if(address_type)
1847 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001848
Enrico Granatac3e320a2011-08-02 17:27:39 +00001849 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001850 return address;
1851
Greg Clayton73b472d2010-10-27 03:32:59 +00001852 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001853 {
1854 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001855 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001856 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001857 break;
1858
Enrico Granata9128ee22011-09-06 19:20:51 +00001859 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001860 case Value::eValueTypeLoadAddress:
1861 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001862 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001863 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001864 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001865 }
1866 break;
1867 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001868
Enrico Granata9128ee22011-09-06 19:20:51 +00001869 if (address_type)
1870 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001871
Greg Clayton737b9322010-09-13 03:32:57 +00001872 return address;
1873}
1874
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001875bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001876ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001877{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001878 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001879 // Make sure our value is up to date first so that our location and location
1880 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001881 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001882 {
1883 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001884 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001885 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001886
Greg Claytonfaac1112013-03-14 18:31:44 +00001887 uint64_t count = 0;
Greg Clayton99558cc42015-08-24 23:46:31 +00001888 const Encoding encoding = GetCompilerType().GetEncoding (count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001889
Greg Claytonb1320972010-07-14 00:18:15 +00001890 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001891
Jim Ingham16e0c682011-08-12 23:34:31 +00001892 Value::ValueType value_type = m_value.GetValueType();
1893
1894 if (value_type == Value::eValueTypeScalar)
1895 {
1896 // If the value is already a scalar, then let the scalar change itself:
1897 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1898 }
Sagar Thakur8536fd12015-08-20 09:12:46 +00001899 else if (byte_size <= 16)
Jim Ingham16e0c682011-08-12 23:34:31 +00001900 {
1901 // If the value fits in a scalar, then make a new scalar and again let the
1902 // scalar code do the conversion, then figure out where to put the new value.
1903 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001904 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1905 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001906 {
Jim Ingham4b536182011-08-09 02:12:22 +00001907 switch (value_type)
1908 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001909 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001910 {
1911 // If it is a load address, then the scalar value is the storage location
1912 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001913 ExecutionContext exe_ctx (GetExecutionContextRef());
1914 Process *process = exe_ctx.GetProcessPtr();
1915 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001916 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001917 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001918 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1919 new_scalar,
1920 byte_size,
1921 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001922 if (!error.Success())
1923 return false;
1924 if (bytes_written != byte_size)
1925 {
1926 error.SetErrorString("unable to write value to memory");
1927 return false;
1928 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001929 }
1930 }
Jim Ingham4b536182011-08-09 02:12:22 +00001931 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001932 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001933 {
1934 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1935 DataExtractor new_data;
1936 new_data.SetByteOrder (m_data.GetByteOrder());
1937
1938 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1939 m_data.SetData(buffer_sp, 0);
1940 bool success = new_scalar.GetData(new_data);
1941 if (success)
1942 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001943 new_data.CopyByteOrderedData (0,
1944 byte_size,
1945 const_cast<uint8_t *>(m_data.GetDataStart()),
1946 byte_size,
1947 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001948 }
1949 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1950
1951 }
Jim Ingham4b536182011-08-09 02:12:22 +00001952 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001953 case Value::eValueTypeFileAddress:
1954 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001955 case Value::eValueTypeVector:
1956 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001957 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001958 }
1959 else
1960 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001961 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001962 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001963 }
1964 else
1965 {
1966 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001967 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001968 return false;
1969 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001970
1971 // If we have reached this point, then we have successfully changed the value.
1972 SetNeedsUpdate();
1973 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001974}
1975
Greg Clayton81e871e2012-02-04 02:27:34 +00001976bool
1977ValueObject::GetDeclaration (Declaration &decl)
1978{
1979 decl.Clear();
1980 return false;
1981}
1982
Greg Clayton84db9102012-03-26 23:03:23 +00001983ConstString
1984ValueObject::GetTypeName()
1985{
Greg Clayton99558cc42015-08-24 23:46:31 +00001986 return GetCompilerType().GetConstTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00001987}
1988
1989ConstString
Enrico Granatae8daa2f2014-05-17 19:14:17 +00001990ValueObject::GetDisplayTypeName()
1991{
1992 return GetTypeName();
1993}
1994
1995ConstString
Greg Clayton84db9102012-03-26 23:03:23 +00001996ValueObject::GetQualifiedTypeName()
1997{
Greg Clayton99558cc42015-08-24 23:46:31 +00001998 return GetCompilerType().GetConstQualifiedTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00001999}
2000
2001
Greg Claytonafacd142011-09-02 01:15:17 +00002002LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00002003ValueObject::GetObjectRuntimeLanguage ()
2004{
Greg Clayton99558cc42015-08-24 23:46:31 +00002005 return GetCompilerType().GetMinimumLanguage ();
Jim Ingham5a369122010-09-28 01:25:32 +00002006}
2007
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002008void
Jim Ingham58b59f92011-04-22 23:53:53 +00002009ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002010{
Jim Ingham58b59f92011-04-22 23:53:53 +00002011 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002012}
2013
2014ValueObjectSP
2015ValueObject::GetSyntheticChild (const ConstString &key) const
2016{
2017 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00002018 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002019 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00002020 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002021 return synthetic_child_sp;
2022}
2023
Greg Clayton2452ab72013-02-08 22:02:02 +00002024uint32_t
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002025ValueObject::GetTypeInfo (CompilerType *pointee_or_element_compiler_type)
Greg Clayton2452ab72013-02-08 22:02:02 +00002026{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002027 return GetCompilerType().GetTypeInfo (pointee_or_element_compiler_type);
Greg Clayton2452ab72013-02-08 22:02:02 +00002028}
2029
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002030bool
2031ValueObject::IsPointerType ()
2032{
Greg Clayton99558cc42015-08-24 23:46:31 +00002033 return GetCompilerType().IsPointerType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002034}
2035
Jim Inghamb7603bb2011-03-18 00:05:18 +00002036bool
Greg Claytondaf515f2011-07-09 20:12:33 +00002037ValueObject::IsArrayType ()
2038{
Greg Clayton99558cc42015-08-24 23:46:31 +00002039 return GetCompilerType().IsArrayType (NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00002040}
2041
2042bool
Enrico Granata9fc19442011-07-06 02:13:41 +00002043ValueObject::IsScalarType ()
2044{
Greg Clayton99558cc42015-08-24 23:46:31 +00002045 return GetCompilerType().IsScalarType ();
Enrico Granata9fc19442011-07-06 02:13:41 +00002046}
2047
2048bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00002049ValueObject::IsIntegerType (bool &is_signed)
2050{
Greg Clayton99558cc42015-08-24 23:46:31 +00002051 return GetCompilerType().IsIntegerType (is_signed);
Jim Inghamb7603bb2011-03-18 00:05:18 +00002052}
Greg Clayton73b472d2010-10-27 03:32:59 +00002053
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002054bool
2055ValueObject::IsPointerOrReferenceType ()
2056{
Greg Clayton99558cc42015-08-24 23:46:31 +00002057 return GetCompilerType().IsPointerOrReferenceType ();
Greg Clayton007d5be2011-05-30 00:49:24 +00002058}
2059
2060bool
Greg Claytondea8cb42011-06-29 22:09:02 +00002061ValueObject::IsPossibleDynamicType ()
2062{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002063 ExecutionContext exe_ctx (GetExecutionContextRef());
2064 Process *process = exe_ctx.GetProcessPtr();
2065 if (process)
2066 return process->IsPossibleDynamicValue(*this);
2067 else
Greg Clayton99558cc42015-08-24 23:46:31 +00002068 return GetCompilerType().IsPossibleDynamicType (NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00002069}
2070
Enrico Granata9e7b3882012-12-13 23:50:33 +00002071bool
Enrico Granata560558e2015-02-11 02:35:39 +00002072ValueObject::IsRuntimeSupportValue ()
2073{
2074 Process *process(GetProcessSP().get());
2075 if (process)
2076 {
2077 LanguageRuntime *runtime = process->GetLanguageRuntime(GetObjectRuntimeLanguage());
2078 if (!runtime)
2079 runtime = process->GetObjCLanguageRuntime();
2080 if (runtime)
2081 return runtime->IsRuntimeSupportValue(*this);
2082 }
2083 return false;
2084}
2085
2086bool
Enrico Granata9e7b3882012-12-13 23:50:33 +00002087ValueObject::IsObjCNil ()
2088{
Enrico Granata622be232014-10-21 20:52:14 +00002089 const uint32_t mask = eTypeIsObjC | eTypeIsPointer;
Greg Clayton99558cc42015-08-24 23:46:31 +00002090 bool isObjCpointer = (((GetCompilerType().GetTypeInfo(NULL)) & mask) == mask);
Enrico Granata7277d202013-03-15 23:33:15 +00002091 if (!isObjCpointer)
2092 return false;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002093 bool canReadValue = true;
2094 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
Enrico Granata7277d202013-03-15 23:33:15 +00002095 return canReadValue && isZero;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002096}
2097
Greg Claytondaf515f2011-07-09 20:12:33 +00002098// This allows you to create an array member using and index
2099// that doesn't not fall in the normal bounds of the array.
2100// Many times structure can be defined as:
2101// struct Collection
2102// {
2103// uint32_t item_count;
2104// Item item_array[0];
2105// };
2106// The size of the "item_array" is 1, but many times in practice
2107// there are more items in "item_array".
2108
2109ValueObjectSP
Bruce Mitchener11d86362015-02-26 23:55:39 +00002110ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00002111{
2112 ValueObjectSP synthetic_child_sp;
Bruce Mitchener11d86362015-02-26 23:55:39 +00002113 if (IsPointerType () || IsArrayType())
Greg Claytondaf515f2011-07-09 20:12:33 +00002114 {
2115 char index_str[64];
Deepak Panickal99fbc072014-03-03 15:39:47 +00002116 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
Greg Claytondaf515f2011-07-09 20:12:33 +00002117 ConstString index_const_str(index_str);
2118 // Check if we have already created a synthetic array member in this
2119 // valid object. If we have we will re-use it.
2120 synthetic_child_sp = GetSyntheticChild (index_const_str);
2121 if (!synthetic_child_sp)
2122 {
2123 ValueObject *synthetic_child;
2124 // We haven't made a synthetic array member for INDEX yet, so
2125 // lets make one and cache it for any future reference.
2126 synthetic_child = CreateChildAtIndex(0, true, index);
Bruce Mitchener11d86362015-02-26 23:55:39 +00002127
Greg Claytondaf515f2011-07-09 20:12:33 +00002128 // Cache the value if we got one back...
2129 if (synthetic_child)
2130 {
2131 AddSyntheticChild(index_const_str, synthetic_child);
2132 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002133 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00002134 synthetic_child_sp->m_is_array_item_for_pointer = true;
2135 }
2136 }
2137 }
2138 return synthetic_child_sp;
2139}
2140
Enrico Granata9fc19442011-07-06 02:13:41 +00002141ValueObjectSP
2142ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2143{
2144 ValueObjectSP synthetic_child_sp;
2145 if (IsScalarType ())
2146 {
2147 char index_str[64];
2148 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2149 ConstString index_const_str(index_str);
2150 // Check if we have already created a synthetic array member in this
2151 // valid object. If we have we will re-use it.
2152 synthetic_child_sp = GetSyntheticChild (index_const_str);
2153 if (!synthetic_child_sp)
2154 {
Enrico Granata9fc19442011-07-06 02:13:41 +00002155 // We haven't made a synthetic array member for INDEX yet, so
2156 // lets make one and cache it for any future reference.
Greg Clayton57ee3062013-07-11 22:46:58 +00002157 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
Greg Clayton99558cc42015-08-24 23:46:31 +00002158 GetCompilerType(),
Greg Clayton57ee3062013-07-11 22:46:58 +00002159 index_const_str,
2160 GetByteSize(),
2161 0,
2162 to-from+1,
2163 from,
2164 false,
2165 false,
2166 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002167
2168 // Cache the value if we got one back...
2169 if (synthetic_child)
2170 {
2171 AddSyntheticChild(index_const_str, synthetic_child);
2172 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002173 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002174 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2175 }
2176 }
2177 }
2178 return synthetic_child_sp;
2179}
2180
Greg Claytonafacd142011-09-02 01:15:17 +00002181ValueObjectSP
Greg Claytona1e5dc82015-08-11 22:53:00 +00002182ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const CompilerType& type, bool can_create)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002183{
2184
2185 ValueObjectSP synthetic_child_sp;
2186
2187 char name_str[64];
2188 snprintf(name_str, sizeof(name_str), "@%i", offset);
2189 ConstString name_const_str(name_str);
2190
2191 // Check if we have already created a synthetic array member in this
2192 // valid object. If we have we will re-use it.
2193 synthetic_child_sp = GetSyntheticChild (name_const_str);
2194
2195 if (synthetic_child_sp.get())
2196 return synthetic_child_sp;
2197
2198 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002199 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002200
Enrico Granata951bdd52015-01-28 01:09:45 +00002201 ExecutionContext exe_ctx (GetExecutionContextRef());
2202
Enrico Granata6f3533f2011-07-29 19:53:35 +00002203 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
Greg Clayton57ee3062013-07-11 22:46:58 +00002204 type,
Enrico Granata6f3533f2011-07-29 19:53:35 +00002205 name_const_str,
Greg Clayton526ae042015-02-12 00:34:25 +00002206 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
Enrico Granata6f3533f2011-07-29 19:53:35 +00002207 offset,
2208 0,
2209 0,
2210 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002211 false,
2212 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002213 if (synthetic_child)
2214 {
2215 AddSyntheticChild(name_const_str, synthetic_child);
2216 synthetic_child_sp = synthetic_child->GetSP();
2217 synthetic_child_sp->SetName(name_const_str);
2218 synthetic_child_sp->m_is_child_at_offset = true;
2219 }
2220 return synthetic_child_sp;
2221}
2222
Enrico Granata32556cd2014-08-26 20:54:04 +00002223ValueObjectSP
Greg Claytona1e5dc82015-08-11 22:53:00 +00002224ValueObject::GetSyntheticBase (uint32_t offset, const CompilerType& type, bool can_create)
Enrico Granata32556cd2014-08-26 20:54:04 +00002225{
2226 ValueObjectSP synthetic_child_sp;
2227
2228 char name_str[64];
2229 snprintf(name_str, sizeof(name_str), "%s", type.GetTypeName().AsCString("<unknown>"));
2230 ConstString name_const_str(name_str);
2231
2232 // Check if we have already created a synthetic array member in this
2233 // valid object. If we have we will re-use it.
2234 synthetic_child_sp = GetSyntheticChild (name_const_str);
2235
2236 if (synthetic_child_sp.get())
2237 return synthetic_child_sp;
2238
2239 if (!can_create)
2240 return ValueObjectSP();
2241
Enrico Granata32556cd2014-08-26 20:54:04 +00002242 const bool is_base_class = true;
2243
Enrico Granata951bdd52015-01-28 01:09:45 +00002244 ExecutionContext exe_ctx (GetExecutionContextRef());
2245
Enrico Granata32556cd2014-08-26 20:54:04 +00002246 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2247 type,
2248 name_const_str,
Greg Clayton526ae042015-02-12 00:34:25 +00002249 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
Enrico Granata32556cd2014-08-26 20:54:04 +00002250 offset,
2251 0,
2252 0,
2253 is_base_class,
2254 false,
2255 eAddressTypeInvalid);
2256 if (synthetic_child)
2257 {
2258 AddSyntheticChild(name_const_str, synthetic_child);
2259 synthetic_child_sp = synthetic_child->GetSP();
2260 synthetic_child_sp->SetName(name_const_str);
2261 }
2262 return synthetic_child_sp;
2263}
2264
2265
Enrico Granatad55546b2011-07-22 00:16:08 +00002266// your expression path needs to have a leading . or ->
2267// (unless it somehow "looks like" an array, in which case it has
2268// a leading [ symbol). while the [ is meaningful and should be shown
2269// to the user, . and -> are just parser design, but by no means
2270// added information for the user.. strip them off
2271static const char*
2272SkipLeadingExpressionPathSeparators(const char* expression)
2273{
2274 if (!expression || !expression[0])
2275 return expression;
2276 if (expression[0] == '.')
2277 return expression+1;
2278 if (expression[0] == '-' && expression[1] == '>')
2279 return expression+2;
2280 return expression;
2281}
2282
Greg Claytonafacd142011-09-02 01:15:17 +00002283ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002284ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2285{
2286 ValueObjectSP synthetic_child_sp;
2287 ConstString name_const_string(expression);
2288 // Check if we have already created a synthetic array member in this
2289 // valid object. If we have we will re-use it.
2290 synthetic_child_sp = GetSyntheticChild (name_const_string);
2291 if (!synthetic_child_sp)
2292 {
2293 // We haven't made a synthetic array member for expression yet, so
2294 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002295 synthetic_child_sp = GetValueForExpressionPath(expression,
2296 NULL, NULL, NULL,
Enrico Granataef238c12015-03-12 22:30:58 +00002297 GetValueForExpressionPathOptions().SetSyntheticChildrenTraversal(GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None));
Enrico Granatad55546b2011-07-22 00:16:08 +00002298
2299 // Cache the value if we got one back...
2300 if (synthetic_child_sp.get())
2301 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002302 // 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 +00002303 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002304 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002305 }
2306 }
2307 return synthetic_child_sp;
2308}
2309
2310void
Enrico Granata86cc9822012-03-19 22:58:49 +00002311ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002312{
Enrico Granata86cc9822012-03-19 22:58:49 +00002313 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002314 return;
2315
Enrico Granatac5bc4122012-03-27 02:35:13 +00002316 TargetSP target_sp(GetTargetSP());
Enrico Granata5d5f60c2013-09-24 22:58:37 +00002317 if (target_sp && target_sp->GetEnableSyntheticValue() == false)
Enrico Granatac5bc4122012-03-27 02:35:13 +00002318 {
2319 m_synthetic_value = NULL;
2320 return;
2321 }
2322
Enrico Granatae3e91512012-10-22 18:18:36 +00002323 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2324
Enrico Granata5548cb52013-01-28 23:47:25 +00002325 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002326 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002327
Enrico Granata0c489f52012-03-01 04:24:26 +00002328 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002329 return;
2330
Enrico Granatae3e91512012-10-22 18:18:36 +00002331 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2332 return;
2333
Enrico Granata86cc9822012-03-19 22:58:49 +00002334 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002335}
2336
Jim Ingham78a685a2011-04-16 00:01:13 +00002337void
Greg Claytonafacd142011-09-02 01:15:17 +00002338ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002339{
Greg Claytonafacd142011-09-02 01:15:17 +00002340 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002341 return;
2342
Jim Ingham58b59f92011-04-22 23:53:53 +00002343 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002344 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002345 ExecutionContext exe_ctx (GetExecutionContextRef());
2346 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002347 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002348 {
2349 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002350 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002351 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002352 }
2353}
2354
Jim Ingham58b59f92011-04-22 23:53:53 +00002355ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002356ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002357{
Greg Claytonafacd142011-09-02 01:15:17 +00002358 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002359 return ValueObjectSP();
2360
2361 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002362 {
Jim Ingham2837b762011-05-04 03:43:18 +00002363 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002364 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002365 if (m_dynamic_value)
2366 return m_dynamic_value->GetSP();
2367 else
2368 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002369}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002370
Jim Ingham60dbabb2011-12-08 19:44:08 +00002371ValueObjectSP
2372ValueObject::GetStaticValue()
2373{
2374 return GetSP();
2375}
2376
Enrico Granata886147f2012-05-08 18:47:08 +00002377lldb::ValueObjectSP
2378ValueObject::GetNonSyntheticValue ()
2379{
2380 return GetSP();
2381}
2382
Enrico Granatad55546b2011-07-22 00:16:08 +00002383ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002384ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002385{
Enrico Granata86cc9822012-03-19 22:58:49 +00002386 if (use_synthetic == false)
2387 return ValueObjectSP();
2388
Enrico Granatad55546b2011-07-22 00:16:08 +00002389 CalculateSyntheticValue(use_synthetic);
2390
2391 if (m_synthetic_value)
2392 return m_synthetic_value->GetSP();
2393 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002394 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002395}
2396
Greg Claytone221f822011-01-21 01:59:00 +00002397bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002398ValueObject::HasSyntheticValue()
2399{
Enrico Granata5548cb52013-01-28 23:47:25 +00002400 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002401
Enrico Granata0c489f52012-03-01 04:24:26 +00002402 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002403 return false;
2404
Enrico Granata86cc9822012-03-19 22:58:49 +00002405 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002406
2407 if (m_synthetic_value)
2408 return true;
2409 else
2410 return false;
2411}
2412
2413bool
Greg Claytone221f822011-01-21 01:59:00 +00002414ValueObject::GetBaseClassPath (Stream &s)
2415{
2416 if (IsBaseClass())
2417 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002418 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002419 CompilerType compiler_type = GetCompilerType();
Greg Claytone221f822011-01-21 01:59:00 +00002420 std::string cxx_class_name;
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002421 bool this_had_base_class = ClangASTContext::GetCXXClassName (compiler_type, cxx_class_name);
Greg Claytone221f822011-01-21 01:59:00 +00002422 if (this_had_base_class)
2423 {
2424 if (parent_had_base_class)
2425 s.PutCString("::");
2426 s.PutCString(cxx_class_name.c_str());
2427 }
2428 return parent_had_base_class || this_had_base_class;
2429 }
2430 return false;
2431}
2432
2433
2434ValueObject *
2435ValueObject::GetNonBaseClassParent()
2436{
Jim Ingham78a685a2011-04-16 00:01:13 +00002437 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002438 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002439 if (GetParent()->IsBaseClass())
2440 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002441 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002442 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002443 }
2444 return NULL;
2445}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002446
Enrico Granataa3c8f042014-08-19 22:29:08 +00002447
2448bool
2449ValueObject::IsBaseClass (uint32_t& depth)
2450{
2451 if (!IsBaseClass())
2452 {
2453 depth = 0;
2454 return false;
2455 }
2456 if (GetParent())
2457 {
2458 GetParent()->IsBaseClass(depth);
2459 depth = depth + 1;
2460 return true;
2461 }
2462 // TODO: a base of no parent? weird..
2463 depth = 1;
2464 return true;
2465}
2466
Greg Clayton1d3afba2010-10-05 00:00:42 +00002467void
Enrico Granata4becb372011-06-29 22:27:15 +00002468ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002469{
Enrico Granata986fa5f2014-12-09 21:41:16 +00002470 // synthetic children do not actually "exist" as part of the hierarchy, and sometimes they are consed up in ways
2471 // that don't make sense from an underlying language/API standpoint. So, use a special code path here to return
2472 // something that can hopefully be used in expression
2473 if (m_is_synthetic_children_generated)
2474 {
2475 UpdateValueIfNeeded();
2476
2477 if (m_value.GetValueType() == Value::eValueTypeLoadAddress)
2478 {
2479 if (IsPointerOrReferenceType())
2480 {
2481 s.Printf("((%s)0x%" PRIx64 ")",
2482 GetTypeName().AsCString("void"),
2483 GetValueAsUnsigned(0));
2484 return;
2485 }
2486 else
2487 {
2488 uint64_t load_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
2489 if (load_addr != LLDB_INVALID_ADDRESS)
2490 {
2491 s.Printf("(*( (%s *)0x%" PRIx64 "))",
2492 GetTypeName().AsCString("void"),
2493 load_addr);
2494 return;
2495 }
2496 }
2497 }
2498
2499 if (CanProvideValue())
2500 {
2501 s.Printf("((%s)%s)",
2502 GetTypeName().AsCString("void"),
2503 GetValueAsCString());
2504 return;
2505 }
2506
2507 return;
2508 }
2509
Greg Claytone221f822011-01-21 01:59:00 +00002510 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002511
Enrico Granata86cc9822012-03-19 22:58:49 +00002512 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002513 {
Enrico Granata4becb372011-06-29 22:27:15 +00002514 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2515 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2516 // the eHonorPointers mode is meant to produce strings in this latter format
2517 s.PutCString("*(");
2518 }
Greg Claytone221f822011-01-21 01:59:00 +00002519
Enrico Granata4becb372011-06-29 22:27:15 +00002520 ValueObject* parent = GetParent();
2521
2522 if (parent)
2523 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002524
2525 // if we are a deref_of_parent just because we are synthetic array
2526 // members made up to allow ptr[%d] syntax to work in variable
2527 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002528 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002529 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002530
Greg Claytone221f822011-01-21 01:59:00 +00002531 if (!IsBaseClass())
2532 {
2533 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002534 {
Greg Claytone221f822011-01-21 01:59:00 +00002535 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2536 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002537 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002538 CompilerType non_base_class_parent_compiler_type = non_base_class_parent->GetCompilerType();
2539 if (non_base_class_parent_compiler_type)
Greg Claytone221f822011-01-21 01:59:00 +00002540 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002541 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002542 {
2543 s.PutCString("->");
2544 }
Enrico Granata4becb372011-06-29 22:27:15 +00002545 else
2546 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002547 const uint32_t non_base_class_parent_type_info = non_base_class_parent_compiler_type.GetTypeInfo();
Greg Clayton57ee3062013-07-11 22:46:58 +00002548
Enrico Granata622be232014-10-21 20:52:14 +00002549 if (non_base_class_parent_type_info & eTypeIsPointer)
Enrico Granata4becb372011-06-29 22:27:15 +00002550 {
2551 s.PutCString("->");
2552 }
Enrico Granata622be232014-10-21 20:52:14 +00002553 else if ((non_base_class_parent_type_info & eTypeHasChildren) &&
2554 !(non_base_class_parent_type_info & eTypeIsArray))
Enrico Granata4becb372011-06-29 22:27:15 +00002555 {
2556 s.PutChar('.');
2557 }
Greg Claytone221f822011-01-21 01:59:00 +00002558 }
2559 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002560 }
Greg Claytone221f822011-01-21 01:59:00 +00002561
2562 const char *name = GetName().GetCString();
2563 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002564 {
Greg Claytone221f822011-01-21 01:59:00 +00002565 if (qualify_cxx_base_classes)
2566 {
2567 if (GetBaseClassPath (s))
2568 s.PutCString("::");
2569 }
2570 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002571 }
2572 }
2573 }
2574
Enrico Granata86cc9822012-03-19 22:58:49 +00002575 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002576 {
Greg Claytone221f822011-01-21 01:59:00 +00002577 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002578 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002579}
2580
Greg Claytonafacd142011-09-02 01:15:17 +00002581ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002582ValueObject::GetValueForExpressionPath(const char* expression,
2583 const char** first_unparsed,
2584 ExpressionPathScanEndReason* reason_to_stop,
2585 ExpressionPathEndResultType* final_value_type,
2586 const GetValueForExpressionPathOptions& options,
2587 ExpressionPathAftermath* final_task_on_target)
2588{
2589
2590 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002591 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2592 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002593 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002594
2595 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2596 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2597 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2598 final_value_type ? final_value_type : &dummy_final_value_type,
2599 options,
2600 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2601
Enrico Granata86cc9822012-03-19 22:58:49 +00002602 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002603 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002604
Enrico Granata86cc9822012-03-19 22:58:49 +00002605 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 +00002606 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002607 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002608 {
2609 Error error;
2610 ValueObjectSP final_value = ret_val->Dereference(error);
2611 if (error.Fail() || !final_value.get())
2612 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002613 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002614 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002615 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002616 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002617 return ValueObjectSP();
2618 }
2619 else
2620 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002621 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002622 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002623 return final_value;
2624 }
2625 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002626 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002627 {
2628 Error error;
2629 ValueObjectSP final_value = ret_val->AddressOf(error);
2630 if (error.Fail() || !final_value.get())
2631 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002632 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002633 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002634 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002635 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002636 return ValueObjectSP();
2637 }
2638 else
2639 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002640 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002641 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002642 return final_value;
2643 }
2644 }
2645 }
2646 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2647}
2648
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002649int
2650ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002651 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002652 const char** first_unparsed,
2653 ExpressionPathScanEndReason* reason_to_stop,
2654 ExpressionPathEndResultType* final_value_type,
2655 const GetValueForExpressionPathOptions& options,
2656 ExpressionPathAftermath* final_task_on_target)
2657{
2658 const char* dummy_first_unparsed;
2659 ExpressionPathScanEndReason dummy_reason_to_stop;
2660 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002661 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002662
2663 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2664 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2665 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2666 final_value_type ? final_value_type : &dummy_final_value_type,
2667 options,
2668 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2669
2670 if (!ret_val.get()) // if there are errors, I add nothing to the list
2671 return 0;
2672
Enrico Granata86ea8d82012-03-29 01:34:34 +00002673 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002674 {
2675 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002676 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002677 {
2678 list->Append(ret_val);
2679 return 1;
2680 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002681 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 +00002682 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002683 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002684 {
2685 Error error;
2686 ValueObjectSP final_value = ret_val->Dereference(error);
2687 if (error.Fail() || !final_value.get())
2688 {
Greg Clayton23f59502012-07-17 03:23:13 +00002689 if (reason_to_stop)
2690 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2691 if (final_value_type)
2692 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002693 return 0;
2694 }
2695 else
2696 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002697 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002698 list->Append(final_value);
2699 return 1;
2700 }
2701 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002702 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002703 {
2704 Error error;
2705 ValueObjectSP final_value = ret_val->AddressOf(error);
2706 if (error.Fail() || !final_value.get())
2707 {
Greg Clayton23f59502012-07-17 03:23:13 +00002708 if (reason_to_stop)
2709 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2710 if (final_value_type)
2711 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002712 return 0;
2713 }
2714 else
2715 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002716 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002717 list->Append(final_value);
2718 return 1;
2719 }
2720 }
2721 }
2722 }
2723 else
2724 {
2725 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2726 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2727 ret_val,
2728 list,
2729 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2730 final_value_type ? final_value_type : &dummy_final_value_type,
2731 options,
2732 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2733 }
2734 // in any non-covered case, just do the obviously right thing
2735 list->Append(ret_val);
2736 return 1;
2737}
2738
Greg Claytonafacd142011-09-02 01:15:17 +00002739ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002740ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2741 const char** first_unparsed,
2742 ExpressionPathScanEndReason* reason_to_stop,
2743 ExpressionPathEndResultType* final_result,
2744 const GetValueForExpressionPathOptions& options,
2745 ExpressionPathAftermath* what_next)
2746{
2747 ValueObjectSP root = GetSP();
2748
2749 if (!root.get())
2750 return ValueObjectSP();
2751
2752 *first_unparsed = expression_cstr;
2753
2754 while (true)
2755 {
2756
2757 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2758
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002759 CompilerType root_compiler_type = root->GetCompilerType();
2760 CompilerType pointee_compiler_type;
2761 Flags pointee_compiler_type_info;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002762
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002763 Flags root_compiler_type_info(root_compiler_type.GetTypeInfo(&pointee_compiler_type));
2764 if (pointee_compiler_type)
2765 pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002766
2767 if (!expression_cstr || *expression_cstr == '\0')
2768 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002769 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002770 return root;
2771 }
2772
2773 switch (*expression_cstr)
2774 {
2775 case '-':
2776 {
2777 if (options.m_check_dot_vs_arrow_syntax &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002778 root_compiler_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 +00002779 {
2780 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002781 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2782 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002783 return ValueObjectSP();
2784 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002785 if (root_compiler_type_info.Test(eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2786 root_compiler_type_info.Test(eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002787 options.m_no_fragile_ivar)
2788 {
2789 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002790 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2791 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002792 return ValueObjectSP();
2793 }
2794 if (expression_cstr[1] != '>')
2795 {
2796 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002797 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2798 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002799 return ValueObjectSP();
2800 }
2801 expression_cstr++; // skip the -
2802 }
2803 case '.': // or fallthrough from ->
2804 {
2805 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002806 root_compiler_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 +00002807 {
2808 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002809 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2810 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002811 return ValueObjectSP();
2812 }
2813 expression_cstr++; // skip .
2814 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2815 ConstString child_name;
2816 if (!next_separator) // if no other separator just expand this last layer
2817 {
2818 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002819 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2820
2821 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002822 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002823 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002824 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2825 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002826 return child_valobj_sp;
2827 }
Enrico Granataef238c12015-03-12 22:30:58 +00002828 else
Enrico Granata8c9d3562011-08-11 17:08:01 +00002829 {
Enrico Granataef238c12015-03-12 22:30:58 +00002830 switch (options.m_synthetic_children_traversal)
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002831 {
Enrico Granataef238c12015-03-12 22:30:58 +00002832 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None:
2833 break;
2834 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic:
2835 if (root->IsSynthetic())
2836 {
2837 child_valobj_sp = root->GetNonSyntheticValue();
2838 if (child_valobj_sp.get())
2839 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2840 }
2841 break;
2842 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic:
2843 if (!root->IsSynthetic())
2844 {
2845 child_valobj_sp = root->GetSyntheticValue();
2846 if (child_valobj_sp.get())
2847 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2848 }
2849 break;
2850 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both:
2851 if (root->IsSynthetic())
2852 {
2853 child_valobj_sp = root->GetNonSyntheticValue();
2854 if (child_valobj_sp.get())
2855 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2856 }
2857 else
2858 {
2859 child_valobj_sp = root->GetSyntheticValue();
2860 if (child_valobj_sp.get())
2861 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2862 }
2863 break;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002864 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002865 }
2866
2867 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2868 // so we hit the "else" branch, and return an error
2869 if(child_valobj_sp.get()) // if it worked, just return
2870 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002871 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002872 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2873 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002874 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002875 }
2876 else
2877 {
2878 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002879 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2880 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002881 return ValueObjectSP();
2882 }
2883 }
2884 else // other layers do expand
2885 {
2886 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002887 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2888 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002889 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002890 root = child_valobj_sp;
2891 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002892 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002893 continue;
2894 }
Enrico Granataef238c12015-03-12 22:30:58 +00002895 else
Enrico Granata8c9d3562011-08-11 17:08:01 +00002896 {
Enrico Granataef238c12015-03-12 22:30:58 +00002897 switch (options.m_synthetic_children_traversal)
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002898 {
Enrico Granataef238c12015-03-12 22:30:58 +00002899 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None:
2900 break;
2901 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic:
2902 if (root->IsSynthetic())
2903 {
2904 child_valobj_sp = root->GetNonSyntheticValue();
2905 if (child_valobj_sp.get())
2906 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2907 }
2908 break;
2909 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic:
2910 if (!root->IsSynthetic())
2911 {
2912 child_valobj_sp = root->GetSyntheticValue();
2913 if (child_valobj_sp.get())
2914 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2915 }
2916 break;
2917 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both:
2918 if (root->IsSynthetic())
2919 {
2920 child_valobj_sp = root->GetNonSyntheticValue();
2921 if (child_valobj_sp.get())
2922 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2923 }
2924 else
2925 {
2926 child_valobj_sp = root->GetSyntheticValue();
2927 if (child_valobj_sp.get())
2928 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2929 }
2930 break;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002931 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002932 }
2933
2934 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2935 // so we hit the "else" branch, and return an error
2936 if(child_valobj_sp.get()) // if it worked, move on
2937 {
2938 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002939 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002940 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002941 continue;
2942 }
2943 else
2944 {
2945 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002946 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2947 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002948 return ValueObjectSP();
2949 }
2950 }
2951 break;
2952 }
2953 case '[':
2954 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002955 if (!root_compiler_type_info.Test(eTypeIsArray) && !root_compiler_type_info.Test(eTypeIsPointer) && !root_compiler_type_info.Test(eTypeIsVector)) // if this is not a T[] nor a T*
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002956 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002957 if (!root_compiler_type_info.Test(eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002958 {
Enrico Granataef238c12015-03-12 22:30:58 +00002959 if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None) // ...only chance left is synthetic
Enrico Granata27b625e2011-08-09 01:04:56 +00002960 {
2961 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002962 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2963 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002964 return ValueObjectSP();
2965 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002966 }
2967 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2968 {
2969 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002970 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2971 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002972 return ValueObjectSP();
2973 }
2974 }
2975 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2976 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002977 if (!root_compiler_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002978 {
2979 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002980 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2981 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002982 return ValueObjectSP();
2983 }
2984 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2985 {
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 }
2992 const char *separator_position = ::strchr(expression_cstr+1,'-');
2993 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2994 if (!close_bracket_position) // if there is no ], this is a syntax error
2995 {
2996 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002997 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2998 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002999 return ValueObjectSP();
3000 }
3001 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3002 {
3003 char *end = NULL;
3004 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3005 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3006 {
3007 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003008 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3009 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003010 return ValueObjectSP();
3011 }
3012 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3013 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003014 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003015 {
3016 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003017 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3018 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003019 return root;
3020 }
3021 else
3022 {
3023 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003024 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3025 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003026 return ValueObjectSP();
3027 }
3028 }
3029 // from here on we do have a valid index
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003030 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003031 {
Greg Claytondaf515f2011-07-09 20:12:33 +00003032 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
3033 if (!child_valobj_sp)
Bruce Mitchener11d86362015-02-26 23:55:39 +00003034 child_valobj_sp = root->GetSyntheticArrayMember(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003035 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00003036 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
3037 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00003038 if (child_valobj_sp)
3039 {
3040 root = child_valobj_sp;
3041 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003042 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00003043 continue;
3044 }
3045 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003046 {
3047 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003048 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3049 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003050 return ValueObjectSP();
3051 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003052 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003053 else if (root_compiler_type_info.Test(eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003054 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003055 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
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003056 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003057 {
3058 Error error;
3059 root = root->Dereference(error);
3060 if (error.Fail() || !root.get())
3061 {
3062 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003063 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3064 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003065 return ValueObjectSP();
3066 }
3067 else
3068 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003069 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003070 continue;
3071 }
3072 }
3073 else
3074 {
Greg Clayton99558cc42015-08-24 23:46:31 +00003075 if (root->GetCompilerType().GetMinimumLanguage() == eLanguageTypeObjC
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003076 && pointee_compiler_type_info.AllClear(eTypeIsPointer)
Greg Clayton84db9102012-03-26 23:03:23 +00003077 && root->HasSyntheticValue()
Enrico Granataef238c12015-03-12 22:30:58 +00003078 && (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic ||
3079 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both))
Enrico Granata27b625e2011-08-09 01:04:56 +00003080 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003081 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003082 }
3083 else
Bruce Mitchener11d86362015-02-26 23:55:39 +00003084 root = root->GetSyntheticArrayMember(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003085 if (!root.get())
3086 {
3087 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003088 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3089 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003090 return ValueObjectSP();
3091 }
3092 else
3093 {
3094 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003095 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003096 continue;
3097 }
3098 }
3099 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003100 else if (root_compiler_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003101 {
3102 root = root->GetSyntheticBitFieldChild(index, index, true);
3103 if (!root.get())
3104 {
3105 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003106 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3107 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003108 return ValueObjectSP();
3109 }
3110 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3111 {
3112 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003113 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3114 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003115 return root;
3116 }
3117 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003118 else if (root_compiler_type_info.Test(eTypeIsVector))
Enrico Granata08a1bb82013-06-19 00:00:45 +00003119 {
3120 root = root->GetChildAtIndex(index, true);
3121 if (!root.get())
3122 {
3123 *first_unparsed = expression_cstr;
3124 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3125 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3126 return ValueObjectSP();
3127 }
3128 else
3129 {
3130 *first_unparsed = end+1; // skip ]
3131 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3132 continue;
3133 }
3134 }
Enrico Granataef238c12015-03-12 22:30:58 +00003135 else if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic ||
3136 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both)
Enrico Granata27b625e2011-08-09 01:04:56 +00003137 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003138 if (root->HasSyntheticValue())
3139 root = root->GetSyntheticValue();
3140 else if (!root->IsSynthetic())
3141 {
3142 *first_unparsed = expression_cstr;
3143 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3144 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3145 return ValueObjectSP();
3146 }
3147 // if we are here, then root itself is a synthetic VO.. should be good to go
3148
Enrico Granata27b625e2011-08-09 01:04:56 +00003149 if (!root.get())
3150 {
3151 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003152 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3153 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3154 return ValueObjectSP();
3155 }
3156 root = root->GetChildAtIndex(index, true);
3157 if (!root.get())
3158 {
3159 *first_unparsed = expression_cstr;
3160 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3161 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003162 return ValueObjectSP();
3163 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00003164 else
3165 {
3166 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003167 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00003168 continue;
3169 }
Enrico Granata27b625e2011-08-09 01:04:56 +00003170 }
3171 else
3172 {
3173 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003174 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3175 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003176 return ValueObjectSP();
3177 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003178 }
3179 else // we have a low and a high index
3180 {
3181 char *end = NULL;
3182 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3183 if (!end || end != separator_position) // if something weird is in our way return an error
3184 {
3185 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003186 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3187 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003188 return ValueObjectSP();
3189 }
3190 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3191 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3192 {
3193 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003194 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3195 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003196 return ValueObjectSP();
3197 }
3198 if (index_lower > index_higher) // swap indices if required
3199 {
3200 unsigned long temp = index_lower;
3201 index_lower = index_higher;
3202 index_higher = temp;
3203 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003204 if (root_compiler_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003205 {
3206 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3207 if (!root.get())
3208 {
3209 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003210 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3211 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003212 return ValueObjectSP();
3213 }
3214 else
3215 {
3216 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003217 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3218 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003219 return root;
3220 }
3221 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003222 else if (root_compiler_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 +00003223 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003224 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003225 {
3226 Error error;
3227 root = root->Dereference(error);
3228 if (error.Fail() || !root.get())
3229 {
3230 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003231 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3232 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003233 return ValueObjectSP();
3234 }
3235 else
3236 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003237 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003238 continue;
3239 }
3240 }
3241 else
3242 {
3243 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003244 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3245 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003246 return root;
3247 }
3248 }
3249 break;
3250 }
3251 default: // some non-separator is in the way
3252 {
3253 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003254 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3255 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003256 return ValueObjectSP();
3257 break;
3258 }
3259 }
3260 }
3261}
3262
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003263int
3264ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3265 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00003266 ValueObjectSP root,
3267 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003268 ExpressionPathScanEndReason* reason_to_stop,
3269 ExpressionPathEndResultType* final_result,
3270 const GetValueForExpressionPathOptions& options,
3271 ExpressionPathAftermath* what_next)
3272{
3273 if (!root.get())
3274 return 0;
3275
3276 *first_unparsed = expression_cstr;
3277
3278 while (true)
3279 {
3280
3281 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3282
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003283 CompilerType root_compiler_type = root->GetCompilerType();
3284 CompilerType pointee_compiler_type;
3285 Flags pointee_compiler_type_info;
3286 Flags root_compiler_type_info(root_compiler_type.GetTypeInfo(&pointee_compiler_type));
3287 if (pointee_compiler_type)
3288 pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003289
3290 if (!expression_cstr || *expression_cstr == '\0')
3291 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003292 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003293 list->Append(root);
3294 return 1;
3295 }
3296
3297 switch (*expression_cstr)
3298 {
3299 case '[':
3300 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003301 if (!root_compiler_type_info.Test(eTypeIsArray) && !root_compiler_type_info.Test(eTypeIsPointer)) // if this is not a T[] nor a T*
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003302 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003303 if (!root_compiler_type_info.Test(eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003304 {
3305 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003306 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3307 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003308 return 0;
3309 }
3310 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3311 {
3312 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003313 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3314 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003315 return 0;
3316 }
3317 }
3318 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3319 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003320 if (!root_compiler_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003321 {
3322 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003323 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3324 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003325 return 0;
3326 }
3327 else // expand this into list
3328 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003329 const size_t max_index = root->GetNumChildren() - 1;
3330 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003331 {
3332 ValueObjectSP child =
3333 root->GetChildAtIndex(index, true);
3334 list->Append(child);
3335 }
3336 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003337 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3338 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003339 return max_index; // tell me number of items I added to the VOList
3340 }
3341 }
3342 const char *separator_position = ::strchr(expression_cstr+1,'-');
3343 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3344 if (!close_bracket_position) // if there is no ], this is a syntax error
3345 {
3346 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003347 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3348 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003349 return 0;
3350 }
3351 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3352 {
3353 char *end = NULL;
3354 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3355 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3356 {
3357 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003358 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3359 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003360 return 0;
3361 }
3362 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3363 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003364 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003365 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003366 const size_t max_index = root->GetNumChildren() - 1;
3367 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003368 {
3369 ValueObjectSP child =
3370 root->GetChildAtIndex(index, true);
3371 list->Append(child);
3372 }
3373 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003374 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3375 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003376 return max_index; // tell me number of items I added to the VOList
3377 }
3378 else
3379 {
3380 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003381 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3382 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003383 return 0;
3384 }
3385 }
3386 // from here on we do have a valid index
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003387 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003388 {
3389 root = root->GetChildAtIndex(index, true);
3390 if (!root.get())
3391 {
3392 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003393 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3394 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003395 return 0;
3396 }
3397 else
3398 {
3399 list->Append(root);
3400 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003401 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3402 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003403 return 1;
3404 }
3405 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003406 else if (root_compiler_type_info.Test(eTypeIsPointer))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003407 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003408 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
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003409 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003410 {
3411 Error error;
3412 root = root->Dereference(error);
3413 if (error.Fail() || !root.get())
3414 {
3415 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003416 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3417 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003418 return 0;
3419 }
3420 else
3421 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003422 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003423 continue;
3424 }
3425 }
3426 else
3427 {
Bruce Mitchener11d86362015-02-26 23:55:39 +00003428 root = root->GetSyntheticArrayMember(index, true);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003429 if (!root.get())
3430 {
3431 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003432 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3433 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003434 return 0;
3435 }
3436 else
3437 {
3438 list->Append(root);
3439 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003440 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3441 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003442 return 1;
3443 }
3444 }
3445 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003446 else /*if (ClangASTContext::IsScalarType(root_compiler_type))*/
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003447 {
3448 root = root->GetSyntheticBitFieldChild(index, index, true);
3449 if (!root.get())
3450 {
3451 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003452 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3453 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003454 return 0;
3455 }
3456 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3457 {
3458 list->Append(root);
3459 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003460 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3461 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003462 return 1;
3463 }
3464 }
3465 }
3466 else // we have a low and a high index
3467 {
3468 char *end = NULL;
3469 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3470 if (!end || end != separator_position) // if something weird is in our way return an error
3471 {
3472 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003473 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3474 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003475 return 0;
3476 }
3477 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3478 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3479 {
3480 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003481 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3482 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003483 return 0;
3484 }
3485 if (index_lower > index_higher) // swap indices if required
3486 {
3487 unsigned long temp = index_lower;
3488 index_lower = index_higher;
3489 index_higher = temp;
3490 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003491 if (root_compiler_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003492 {
3493 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3494 if (!root.get())
3495 {
3496 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003497 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3498 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003499 return 0;
3500 }
3501 else
3502 {
3503 list->Append(root);
3504 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003505 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3506 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003507 return 1;
3508 }
3509 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003510 else if (root_compiler_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 +00003511 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003512 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003513 {
3514 Error error;
3515 root = root->Dereference(error);
3516 if (error.Fail() || !root.get())
3517 {
3518 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003519 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3520 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003521 return 0;
3522 }
3523 else
3524 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003525 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003526 continue;
3527 }
3528 }
3529 else
3530 {
Johnny Chen44805302011-07-19 19:48:13 +00003531 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003532 index <= index_higher; index++)
3533 {
3534 ValueObjectSP child =
3535 root->GetChildAtIndex(index, true);
3536 list->Append(child);
3537 }
3538 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003539 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3540 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003541 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3542 }
3543 }
3544 break;
3545 }
3546 default: // some non-[ separator, or something entirely wrong, is in the way
3547 {
3548 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003549 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3550 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003551 return 0;
3552 break;
3553 }
3554 }
3555 }
3556}
3557
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003558void
3559ValueObject::LogValueObject (Log *log)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003560{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003561 if (log)
Enrico Granatad5957332015-06-03 20:43:54 +00003562 return LogValueObject (log, DumpValueObjectOptions(*this));
Greg Clayton1d3afba2010-10-05 00:00:42 +00003563}
3564
Enrico Granata0c489f52012-03-01 04:24:26 +00003565void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003566ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003567{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003568 if (log)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003569 {
3570 StreamString s;
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003571 Dump (s, options);
Greg Claytonf830dbb2012-03-22 18:15:37 +00003572 if (s.GetSize())
3573 log->PutCString(s.GetData());
3574 }
3575}
3576
3577void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003578ValueObject::Dump (Stream &s)
Enrico Granata0c489f52012-03-01 04:24:26 +00003579{
Enrico Granatad5957332015-06-03 20:43:54 +00003580 Dump (s, DumpValueObjectOptions(*this));
Enrico Granata0c489f52012-03-01 04:24:26 +00003581}
3582
3583void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003584ValueObject::Dump (Stream &s,
3585 const DumpValueObjectOptions& options)
Enrico Granata0c489f52012-03-01 04:24:26 +00003586{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003587 ValueObjectPrinter printer(this,&s,options);
3588 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003589}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003590
3591ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003592ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003593{
3594 ValueObjectSP valobj_sp;
3595
Enrico Granatac3e320a2011-08-02 17:27:39 +00003596 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003597 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003598 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003599
3600 DataExtractor data;
3601 data.SetByteOrder (m_data.GetByteOrder());
3602 data.SetAddressByteSize(m_data.GetAddressByteSize());
3603
Enrico Granata9f1e2042012-04-24 22:15:37 +00003604 if (IsBitfield())
3605 {
3606 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
Greg Clayton57ee3062013-07-11 22:46:58 +00003607 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Enrico Granata9f1e2042012-04-24 22:15:37 +00003608 }
3609 else
Greg Clayton57ee3062013-07-11 22:46:58 +00003610 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003611
3612 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton99558cc42015-08-24 23:46:31 +00003613 GetCompilerType(),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003614 name,
3615 data,
3616 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003617 }
Jim Ingham6035b672011-03-31 00:19:25 +00003618
3619 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003620 {
Greg Claytoneeb15652013-12-10 23:16:40 +00003621 ExecutionContext exe_ctx (GetExecutionContextRef());
3622 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003623 }
3624 return valobj_sp;
3625}
3626
Enrico Granata538a88a2014-10-09 18:24:30 +00003627ValueObjectSP
3628ValueObject::GetQualifiedRepresentationIfAvailable (lldb::DynamicValueType dynValue,
3629 bool synthValue)
3630{
3631 ValueObjectSP result_sp(GetSP());
3632
3633 switch (dynValue)
3634 {
3635 case lldb::eDynamicCanRunTarget:
3636 case lldb::eDynamicDontRunTarget:
3637 {
3638 if (!result_sp->IsDynamic())
3639 {
3640 if (result_sp->GetDynamicValue(dynValue))
3641 result_sp = result_sp->GetDynamicValue(dynValue);
3642 }
3643 }
3644 break;
3645 case lldb::eNoDynamicValues:
Enrico Granata538a88a2014-10-09 18:24:30 +00003646 {
3647 if (result_sp->IsDynamic())
3648 {
3649 if (result_sp->GetStaticValue())
3650 result_sp = result_sp->GetStaticValue();
3651 }
3652 }
3653 break;
3654 }
3655
3656 if (synthValue)
3657 {
3658 if (!result_sp->IsSynthetic())
3659 {
3660 if (result_sp->GetSyntheticValue())
3661 result_sp = result_sp->GetSyntheticValue();
3662 }
3663 }
3664 else
3665 {
3666 if (result_sp->IsSynthetic())
3667 {
3668 if (result_sp->GetNonSyntheticValue())
3669 result_sp = result_sp->GetNonSyntheticValue();
3670 }
3671 }
3672
3673 return result_sp;
3674}
3675
Greg Clayton759e7442014-07-19 00:12:57 +00003676lldb::addr_t
3677ValueObject::GetCPPVTableAddress (AddressType &address_type)
3678{
Greg Claytona1e5dc82015-08-11 22:53:00 +00003679 CompilerType pointee_type;
Greg Clayton99558cc42015-08-24 23:46:31 +00003680 CompilerType this_type(GetCompilerType());
Greg Clayton759e7442014-07-19 00:12:57 +00003681 uint32_t type_info = this_type.GetTypeInfo(&pointee_type);
3682 if (type_info)
3683 {
3684 bool ptr_or_ref = false;
Enrico Granata622be232014-10-21 20:52:14 +00003685 if (type_info & (eTypeIsPointer | eTypeIsReference))
Greg Clayton759e7442014-07-19 00:12:57 +00003686 {
3687 ptr_or_ref = true;
3688 type_info = pointee_type.GetTypeInfo();
3689 }
3690
Enrico Granata622be232014-10-21 20:52:14 +00003691 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus;
Greg Clayton759e7442014-07-19 00:12:57 +00003692 if ((type_info & cpp_class) == cpp_class)
3693 {
3694 if (ptr_or_ref)
3695 {
3696 address_type = GetAddressTypeOfChildren();
3697 return GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
3698 }
3699 else
3700 return GetAddressOf (false, &address_type);
3701 }
3702 }
3703
3704 address_type = eAddressTypeInvalid;
3705 return LLDB_INVALID_ADDRESS;
3706}
3707
Greg Claytonafacd142011-09-02 01:15:17 +00003708ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003709ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003710{
Jim Ingham58b59f92011-04-22 23:53:53 +00003711 if (m_deref_valobj)
3712 return m_deref_valobj->GetSP();
Chaoren Lind7bdc272015-07-31 00:35:40 +00003713
3714 const bool is_pointer_or_reference_type = IsPointerOrReferenceType();
3715 if (is_pointer_or_reference_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003716 {
3717 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003718 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003719
3720 std::string child_name_str;
3721 uint32_t child_byte_size = 0;
3722 int32_t child_byte_offset = 0;
3723 uint32_t child_bitfield_bit_size = 0;
3724 uint32_t child_bitfield_bit_offset = 0;
3725 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003726 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003727 const bool transparent_pointers = false;
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003728 CompilerType compiler_type = GetCompilerType();
3729 CompilerType child_compiler_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003730
Greg Claytoncc4d0142012-02-17 07:49:44 +00003731 ExecutionContext exe_ctx (GetExecutionContextRef());
Chaoren Lind7bdc272015-07-31 00:35:40 +00003732
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003733 child_compiler_type = compiler_type.GetChildCompilerTypeAtIndex (&exe_ctx,
3734 0,
3735 transparent_pointers,
3736 omit_empty_base_classes,
3737 ignore_array_bounds,
3738 child_name_str,
3739 child_byte_size,
3740 child_byte_offset,
3741 child_bitfield_bit_size,
3742 child_bitfield_bit_offset,
3743 child_is_base_class,
3744 child_is_deref_of_parent,
3745 this);
3746 if (child_compiler_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003747 {
3748 ConstString child_name;
3749 if (!child_name_str.empty())
3750 child_name.SetCString (child_name_str.c_str());
3751
Jim Ingham58b59f92011-04-22 23:53:53 +00003752 m_deref_valobj = new ValueObjectChild (*this,
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003753 child_compiler_type,
Jim Ingham58b59f92011-04-22 23:53:53 +00003754 child_name,
3755 child_byte_size,
3756 child_byte_offset,
3757 child_bitfield_bit_size,
3758 child_bitfield_bit_offset,
3759 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003760 child_is_deref_of_parent,
3761 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003762 }
3763 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003764
Jim Ingham58b59f92011-04-22 23:53:53 +00003765 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003766 {
3767 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003768 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003769 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003770 else
3771 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003772 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003773 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003774
Chaoren Lind7bdc272015-07-31 00:35:40 +00003775 if (is_pointer_or_reference_type)
Greg Clayton54979cd2010-12-15 05:08:08 +00003776 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3777 else
Chaoren Lind7bdc272015-07-31 00:35:40 +00003778 error.SetErrorStringWithFormat("not a pointer or reference type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003779 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003780 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003781}
3782
Greg Claytonafacd142011-09-02 01:15:17 +00003783ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003784ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003785{
Jim Ingham78a685a2011-04-16 00:01:13 +00003786 if (m_addr_of_valobj_sp)
3787 return m_addr_of_valobj_sp;
3788
Greg Claytone0d378b2011-03-24 21:19:54 +00003789 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003790 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003791 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003792 error.Clear();
Siva Chandraa3747a92015-05-04 19:43:34 +00003793 if (addr != LLDB_INVALID_ADDRESS && address_type != eAddressTypeHost)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003794 {
3795 switch (address_type)
3796 {
3797 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003798 {
3799 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003800 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003801 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3802 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003803 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003804
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003805 case eAddressTypeFile:
3806 case eAddressTypeLoad:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003807 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003808 CompilerType compiler_type = GetCompilerType();
3809 if (compiler_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003810 {
3811 std::string name (1, '&');
3812 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003813 ExecutionContext exe_ctx (GetExecutionContextRef());
3814 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003815 compiler_type.GetPointerType(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003816 ConstString (name.c_str()),
3817 addr,
3818 eAddressTypeInvalid,
3819 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003820 }
3821 }
3822 break;
Siva Chandraa3747a92015-05-04 19:43:34 +00003823 default:
3824 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003825 }
3826 }
Sean Callananed185ab2013-04-19 19:47:32 +00003827 else
3828 {
3829 StreamString expr_path_strm;
3830 GetExpressionPath(expr_path_strm, true);
3831 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3832 }
3833
Jim Ingham78a685a2011-04-16 00:01:13 +00003834 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003835}
3836
Greg Clayton9a142cf2012-02-03 05:34:10 +00003837ValueObjectSP
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003838ValueObject::Cast (const CompilerType &compiler_type)
Greg Clayton9a142cf2012-02-03 05:34:10 +00003839{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003840 return ValueObjectCast::Create (*this, GetName(), compiler_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003841}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003842
Greg Claytonafacd142011-09-02 01:15:17 +00003843ValueObjectSP
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003844ValueObject::CastPointerType (const char *name, CompilerType &compiler_type)
Greg Claytonb2dcc362011-05-05 23:32:56 +00003845{
Greg Claytonafacd142011-09-02 01:15:17 +00003846 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003847 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003848 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003849
3850 if (ptr_value != LLDB_INVALID_ADDRESS)
3851 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003852 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003853 ExecutionContext exe_ctx (GetExecutionContextRef());
3854 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003855 name,
3856 ptr_addr,
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003857 compiler_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003858 }
3859 return valobj_sp;
3860}
3861
Greg Claytonafacd142011-09-02 01:15:17 +00003862ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003863ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3864{
Greg Claytonafacd142011-09-02 01:15:17 +00003865 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003866 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003867 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003868
3869 if (ptr_value != LLDB_INVALID_ADDRESS)
3870 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003871 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003872 ExecutionContext exe_ctx (GetExecutionContextRef());
3873 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003874 name,
3875 ptr_addr,
3876 type_sp);
3877 }
3878 return valobj_sp;
3879}
3880
Jim Ingham6035b672011-03-31 00:19:25 +00003881ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003882 m_mod_id(),
3883 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003884 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003885{
3886}
3887
3888ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003889 m_mod_id(),
3890 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003891 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003892{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003893 ExecutionContext exe_ctx(exe_scope);
3894 TargetSP target_sp (exe_ctx.GetTargetSP());
3895 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003896 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003897 m_exe_ctx_ref.SetTargetSP (target_sp);
3898 ProcessSP process_sp (exe_ctx.GetProcessSP());
3899 if (!process_sp)
3900 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003901
Greg Claytoncc4d0142012-02-17 07:49:44 +00003902 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003903 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003904 m_mod_id = process_sp->GetModID();
3905 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003906
Greg Claytoncc4d0142012-02-17 07:49:44 +00003907 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003908
Greg Claytoncc4d0142012-02-17 07:49:44 +00003909 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003910 {
3911 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003912 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003913 }
Jim Ingham6035b672011-03-31 00:19:25 +00003914
Greg Claytoncc4d0142012-02-17 07:49:44 +00003915 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003916 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003917 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003918
Jason Molendab57e4a12013-11-04 09:33:30 +00003919 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003920 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003921 {
3922 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003923 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003924 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003925 if (frame_sp)
3926 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003927 }
3928 }
3929 }
Jim Ingham6035b672011-03-31 00:19:25 +00003930}
3931
3932ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003933 m_mod_id(),
3934 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003935 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003936{
3937}
3938
3939ValueObject::EvaluationPoint::~EvaluationPoint ()
3940{
3941}
3942
Jim Ingham6035b672011-03-31 00:19:25 +00003943// This function checks the EvaluationPoint against the current process state. If the current
3944// state matches the evaluation point, or the evaluation point is already invalid, then we return
3945// false, meaning "no change". If the current state is different, we update our state, and return
3946// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3947// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003948// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003949
3950bool
Enrico Granatabb642e52015-05-16 01:27:00 +00003951ValueObject::EvaluationPoint::SyncWithProcessState(bool accept_invalid_exe_ctx)
Jim Ingham6035b672011-03-31 00:19:25 +00003952{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003953 // 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 +00003954 const bool thread_and_frame_only_if_stopped = true;
3955 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
Jim Ingham73ca05a2011-12-17 01:35:57 +00003956
Greg Claytoncc4d0142012-02-17 07:49:44 +00003957 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003958 return false;
3959
Jim Ingham6035b672011-03-31 00:19:25 +00003960 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003961 Process *process = exe_ctx.GetProcessPtr();
3962 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003963 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003964
Jim Ingham6035b672011-03-31 00:19:25 +00003965 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003966 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003967
Jim Ingham78a685a2011-04-16 00:01:13 +00003968 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3969 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003970 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003971 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003972
Greg Clayton23f59502012-07-17 03:23:13 +00003973 bool changed = false;
3974 const bool was_valid = m_mod_id.IsValid();
3975 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003976 {
3977 if (m_mod_id == current_mod_id)
3978 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003979 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003980 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003981 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003982 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003983 else
3984 {
3985 m_mod_id = current_mod_id;
3986 m_needs_update = true;
3987 changed = true;
3988 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003989 }
Jim Ingham6035b672011-03-31 00:19:25 +00003990
Jim Ingham73ca05a2011-12-17 01:35:57 +00003991 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3992 // That way we'll be sure to return a valid exe_scope.
3993 // 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 +00003994
Enrico Granatabb642e52015-05-16 01:27:00 +00003995 if (!accept_invalid_exe_ctx)
Jim Ingham6035b672011-03-31 00:19:25 +00003996 {
Enrico Granatabb642e52015-05-16 01:27:00 +00003997 if (m_exe_ctx_ref.HasThreadRef())
Greg Clayton262f80d2011-07-06 16:49:27 +00003998 {
Enrico Granatabb642e52015-05-16 01:27:00 +00003999 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
4000 if (thread_sp)
Greg Claytoncc4d0142012-02-17 07:49:44 +00004001 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004002 if (m_exe_ctx_ref.HasFrameRef())
Greg Claytoncc4d0142012-02-17 07:49:44 +00004003 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004004 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
4005 if (!frame_sp)
4006 {
4007 // We used to have a frame, but now it is gone
4008 SetInvalid();
4009 changed = was_valid;
4010 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00004011 }
4012 }
Enrico Granatabb642e52015-05-16 01:27:00 +00004013 else
4014 {
4015 // We used to have a thread, but now it is gone
4016 SetInvalid();
4017 changed = was_valid;
4018 }
Greg Clayton262f80d2011-07-06 16:49:27 +00004019 }
Jim Ingham6035b672011-03-31 00:19:25 +00004020 }
Enrico Granatabb642e52015-05-16 01:27:00 +00004021
Jim Ingham9ee01152011-12-10 01:49:43 +00004022 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00004023}
4024
Jim Ingham61be0902011-05-02 18:13:59 +00004025void
4026ValueObject::EvaluationPoint::SetUpdated ()
4027{
Greg Claytoncc4d0142012-02-17 07:49:44 +00004028 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
4029 if (process_sp)
4030 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00004031 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00004032}
4033
4034
Enrico Granataf2bbf712011-07-15 02:26:42 +00004035
4036void
Enrico Granata86cc9822012-03-19 22:58:49 +00004037ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004038{
Enrico Granata86cc9822012-03-19 22:58:49 +00004039 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4040 m_value_str.clear();
4041
4042 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4043 m_location_str.clear();
4044
4045 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
Enrico Granata86cc9822012-03-19 22:58:49 +00004046 m_summary_str.clear();
Enrico Granata86cc9822012-03-19 22:58:49 +00004047
4048 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4049 m_object_desc_str.clear();
4050
4051 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4052 {
4053 if (m_synthetic_value)
4054 m_synthetic_value = NULL;
4055 }
Enrico Granata744794a2014-09-05 21:46:22 +00004056
4057 if ((clear_mask & eClearUserVisibleDataItemsValidator) == eClearUserVisibleDataItemsValidator)
4058 m_validation_result.reset();
Johnny Chen44805302011-07-19 19:48:13 +00004059}
Enrico Granata9128ee22011-09-06 19:20:51 +00004060
4061SymbolContextScope *
4062ValueObject::GetSymbolContextScope()
4063{
4064 if (m_parent)
4065 {
4066 if (!m_parent->IsPointerOrReferenceType())
4067 return m_parent->GetSymbolContextScope();
4068 }
4069 return NULL;
4070}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004071
4072lldb::ValueObjectSP
4073ValueObject::CreateValueObjectFromExpression (const char* name,
4074 const char* expression,
4075 const ExecutionContext& exe_ctx)
4076{
Enrico Granata972be532014-12-17 21:18:43 +00004077 return CreateValueObjectFromExpression(name, expression, exe_ctx, EvaluateExpressionOptions());
4078}
4079
4080
4081lldb::ValueObjectSP
4082ValueObject::CreateValueObjectFromExpression (const char* name,
4083 const char* expression,
4084 const ExecutionContext& exe_ctx,
4085 const EvaluateExpressionOptions& options)
4086{
Enrico Granatab2698cd2012-09-13 18:27:09 +00004087 lldb::ValueObjectSP retval_sp;
4088 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4089 if (!target_sp)
4090 return retval_sp;
4091 if (!expression || !*expression)
4092 return retval_sp;
4093 target_sp->EvaluateExpression (expression,
4094 exe_ctx.GetFrameSP().get(),
Enrico Granata972be532014-12-17 21:18:43 +00004095 retval_sp,
4096 options);
Enrico Granatab2698cd2012-09-13 18:27:09 +00004097 if (retval_sp && name && *name)
4098 retval_sp->SetName(ConstString(name));
4099 return retval_sp;
4100}
4101
4102lldb::ValueObjectSP
4103ValueObject::CreateValueObjectFromAddress (const char* name,
4104 uint64_t address,
4105 const ExecutionContext& exe_ctx,
Greg Claytona1e5dc82015-08-11 22:53:00 +00004106 CompilerType type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004107{
Greg Clayton57ee3062013-07-11 22:46:58 +00004108 if (type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004109 {
Greg Claytona1e5dc82015-08-11 22:53:00 +00004110 CompilerType pointer_type(type.GetPointerType());
Greg Clayton57ee3062013-07-11 22:46:58 +00004111 if (pointer_type)
4112 {
4113 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4114 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4115 pointer_type,
4116 ConstString(name),
4117 buffer,
Enrico Granata972be532014-12-17 21:18:43 +00004118 exe_ctx.GetByteOrder(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004119 exe_ctx.GetAddressByteSize()));
4120 if (ptr_result_valobj_sp)
4121 {
4122 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4123 Error err;
4124 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4125 if (ptr_result_valobj_sp && name && *name)
4126 ptr_result_valobj_sp->SetName(ConstString(name));
4127 }
4128 return ptr_result_valobj_sp;
4129 }
Enrico Granatab2698cd2012-09-13 18:27:09 +00004130 }
Greg Clayton57ee3062013-07-11 22:46:58 +00004131 return lldb::ValueObjectSP();
Enrico Granatab2698cd2012-09-13 18:27:09 +00004132}
4133
4134lldb::ValueObjectSP
4135ValueObject::CreateValueObjectFromData (const char* name,
Enrico Granata7ca1c762014-03-31 23:02:25 +00004136 const DataExtractor& data,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004137 const ExecutionContext& exe_ctx,
Greg Claytona1e5dc82015-08-11 22:53:00 +00004138 CompilerType type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004139{
4140 lldb::ValueObjectSP new_value_sp;
4141 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004142 type,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004143 ConstString(name),
4144 data,
4145 LLDB_INVALID_ADDRESS);
4146 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4147 if (new_value_sp && name && *name)
4148 new_value_sp->SetName(ConstString(name));
4149 return new_value_sp;
4150}
Enrico Granata4873e522013-04-11 22:48:58 +00004151
4152ModuleSP
4153ValueObject::GetModule ()
4154{
4155 ValueObject* root(GetRoot());
4156 if (root != this)
4157 return root->GetModule();
4158 return lldb::ModuleSP();
4159}
4160
4161ValueObject*
4162ValueObject::GetRoot ()
4163{
4164 if (m_root)
4165 return m_root;
Enrico Granatade61eba2015-01-22 03:07:34 +00004166 return (m_root = FollowParentChain( [] (ValueObject* vo) -> bool {
4167 return (vo->m_parent != nullptr);
4168 }));
4169}
4170
4171ValueObject*
4172ValueObject::FollowParentChain (std::function<bool(ValueObject*)> f)
4173{
4174 ValueObject* vo = this;
4175 while (vo)
Enrico Granata4873e522013-04-11 22:48:58 +00004176 {
Enrico Granatade61eba2015-01-22 03:07:34 +00004177 if (f(vo) == false)
4178 break;
4179 vo = vo->m_parent;
Enrico Granata4873e522013-04-11 22:48:58 +00004180 }
Enrico Granatade61eba2015-01-22 03:07:34 +00004181 return vo;
Enrico Granata4873e522013-04-11 22:48:58 +00004182}
4183
4184AddressType
4185ValueObject::GetAddressTypeOfChildren()
4186{
4187 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
4188 {
4189 ValueObject* root(GetRoot());
4190 if (root != this)
4191 return root->GetAddressTypeOfChildren();
4192 }
4193 return m_address_type_of_ptr_or_ref_children;
4194}
4195
4196lldb::DynamicValueType
4197ValueObject::GetDynamicValueType ()
4198{
4199 ValueObject* with_dv_info = this;
4200 while (with_dv_info)
4201 {
4202 if (with_dv_info->HasDynamicValueTypeInfo())
4203 return with_dv_info->GetDynamicValueTypeImpl();
4204 with_dv_info = with_dv_info->m_parent;
4205 }
4206 return lldb::eNoDynamicValues;
4207}
Enrico Granata39d51412013-05-31 17:43:40 +00004208
Enrico Granata4873e522013-04-11 22:48:58 +00004209lldb::Format
4210ValueObject::GetFormat () const
4211{
4212 const ValueObject* with_fmt_info = this;
4213 while (with_fmt_info)
4214 {
4215 if (with_fmt_info->m_format != lldb::eFormatDefault)
4216 return with_fmt_info->m_format;
4217 with_fmt_info = with_fmt_info->m_parent;
4218 }
4219 return m_format;
4220}
Enrico Granatad07cfd32014-10-08 18:27:36 +00004221
Enrico Granatac1247f52014-11-06 21:23:20 +00004222lldb::LanguageType
4223ValueObject::GetPreferredDisplayLanguage ()
4224{
Enrico Granataed3228a2015-01-21 01:47:13 +00004225 lldb::LanguageType type = m_preferred_display_language;
4226 if (m_preferred_display_language == lldb::eLanguageTypeUnknown)
Enrico Granatac1247f52014-11-06 21:23:20 +00004227 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004228 if (GetRoot())
Enrico Granatac1247f52014-11-06 21:23:20 +00004229 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004230 if (GetRoot() == this)
Enrico Granatac1247f52014-11-06 21:23:20 +00004231 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004232 if (StackFrameSP frame_sp = GetFrameSP())
4233 {
4234 const SymbolContext& sc(frame_sp->GetSymbolContext(eSymbolContextCompUnit));
4235 if (CompileUnit* cu = sc.comp_unit)
4236 type = cu->GetLanguage();
4237 }
4238 }
4239 else
4240 {
4241 type = GetRoot()->GetPreferredDisplayLanguage();
Enrico Granatac1247f52014-11-06 21:23:20 +00004242 }
4243 }
Enrico Granatac1247f52014-11-06 21:23:20 +00004244 }
Enrico Granataed3228a2015-01-21 01:47:13 +00004245 return (m_preferred_display_language = type); // only compute it once
4246}
4247
4248void
4249ValueObject::SetPreferredDisplayLanguage (lldb::LanguageType lt)
4250{
4251 m_preferred_display_language = lt;
Enrico Granatac1247f52014-11-06 21:23:20 +00004252}
4253
Enrico Granatad07cfd32014-10-08 18:27:36 +00004254bool
4255ValueObject::CanProvideValue ()
4256{
Sean Callanan7375f3e2014-12-09 21:18:59 +00004257 // we need to support invalid types as providers of values because some bare-board
4258 // debugging scenarios have no notion of types, but still manage to have raw numeric
4259 // values for things like registers. sigh.
Greg Clayton99558cc42015-08-24 23:46:31 +00004260 const CompilerType &type(GetCompilerType());
Sean Callanan7375f3e2014-12-09 21:18:59 +00004261 return (false == type.IsValid()) || (0 != (type.GetTypeInfo() & eTypeHasValue));
4262}
4263
4264bool
4265ValueObject::IsChecksumEmpty ()
4266{
4267 return m_value_checksum.empty();
Enrico Granatad07cfd32014-10-08 18:27:36 +00004268}
Enrico Granata0c10a852014-12-08 23:13:56 +00004269
4270ValueObjectSP
4271ValueObject::Persist ()
4272{
4273 if (!UpdateValueIfNeeded())
4274 return nullptr;
4275
4276 TargetSP target_sp(GetTargetSP());
4277 if (!target_sp)
4278 return nullptr;
4279
Sean Callananb92bd752015-10-01 16:28:02 +00004280 PersistentExpressionState *persistent_state = target_sp->GetPersistentExpressionStateForLanguage(GetPreferredDisplayLanguage());
Sean Callanan8f1f9a12015-09-30 19:57:57 +00004281
4282 if (!persistent_state)
4283 return nullptr;
4284
4285 ConstString name(persistent_state->GetNextPersistentVariableName());
Enrico Granata0c10a852014-12-08 23:13:56 +00004286
Sean Callanan9301ec12015-10-01 23:07:06 +00004287 ValueObjectSP const_result_sp = ValueObjectConstResult::Create (target_sp.get(), GetValue(), name);
4288
4289 ExpressionVariableSP clang_var_sp = persistent_state->CreatePersistentVariable(const_result_sp);
4290 clang_var_sp->m_live_sp = clang_var_sp->m_frozen_sp;
4291 clang_var_sp->m_flags |= ExpressionVariable::EVIsProgramReference;
Enrico Granata0c10a852014-12-08 23:13:56 +00004292
4293 return clang_var_sp->GetValueObject();
4294}
Enrico Granatae29df232014-12-09 19:51:20 +00004295
4296bool
4297ValueObject::IsSyntheticChildrenGenerated ()
4298{
4299 return m_is_synthetic_children_generated;
4300}
4301
4302void
4303ValueObject::SetSyntheticChildrenGenerated (bool b)
4304{
4305 m_is_synthetic_children_generated = b;
4306}