blob: 11ccd1bcfb6e0d8ea1296ce6b27457ad6ab78ce0 [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{
Enrico Granata4edfef42015-10-06 17:55:14 +0000278 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_DATAFORMATTERS));
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
Jim Ingham98e6daf2015-10-31 00:02:18 +0000516ValueObject::IsLogicalTrue (Error& error)
517{
518 Scalar scalar_value;
519
520 if (!ResolveValue (scalar_value))
521 {
522 error.SetErrorString("failed to get a scalar result");
523 return false;
524 }
525
526 bool ret;
527 if (scalar_value.ULongLong(1) == 0)
528 ret = false;
529 else
530 ret = true;
531 error.Clear();
532 return ret;
533}
534
535bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000536ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000537{
Greg Clayton288bdf92010-09-02 02:59:18 +0000538 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000539}
540
541
542void
543ValueObject::SetValueIsValid (bool b)
544{
Greg Clayton288bdf92010-09-02 02:59:18 +0000545 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000546}
547
548bool
Jim Ingham6035b672011-03-31 00:19:25 +0000549ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000550{
Greg Clayton288bdf92010-09-02 02:59:18 +0000551 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000552}
553
554void
555ValueObject::SetValueDidChange (bool value_changed)
556{
Greg Clayton288bdf92010-09-02 02:59:18 +0000557 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000558}
559
560ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000561ValueObject::GetChildAtIndex (size_t idx, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000562{
563 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000564 // We may need to update our value if we are dynamic
565 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000566 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000567 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000568 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000569 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000570 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000571 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000572 // No we haven't created the child at this index, so lets have our
573 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000574 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000575 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000576
Enrico Granata9d60f602012-03-09 03:09:58 +0000577 ValueObject* child = m_children.GetChildAtIndex(idx);
578 if (child != NULL)
579 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000580 }
581 return child_sp;
582}
583
Enrico Granata3309d882013-01-12 01:00:22 +0000584ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000585ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& 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 (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000592 {
593 root = root->GetChildAtIndex(idx, true);
594 if (!root)
595 {
596 if (index_of_error)
597 *index_of_error = idx;
598 return root;
599 }
600 }
601 return root;
602}
603
604ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000605ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& 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 (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000612 {
613 root = root->GetChildAtIndex(idx.first, idx.second);
614 if (!root)
615 {
616 if (index_of_error)
617 *index_of_error = idx.first;
618 return root;
619 }
620 }
621 return root;
622}
623
624lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000625ValueObject::GetChildAtIndexPath (const std::vector<size_t> &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 (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000632 {
633 root = root->GetChildAtIndex(idx, true);
634 if (!root)
635 {
636 if (index_of_error)
637 *index_of_error = idx;
638 return root;
639 }
640 }
641 return root;
642}
643
644lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000645ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
646 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000647{
648 if (idxs.size() == 0)
649 return GetSP();
650 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000651 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000652 {
653 root = root->GetChildAtIndex(idx.first, idx.second);
654 if (!root)
655 {
656 if (index_of_error)
657 *index_of_error = idx.first;
658 return root;
659 }
660 }
661 return root;
662}
663
Enrico Granatae2e220a2013-09-12 00:48:47 +0000664lldb::ValueObjectSP
665ValueObject::GetChildAtNamePath (const std::initializer_list<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::vector<ConstString> &names,
686 ConstString* name_of_error)
687{
688 if (names.size() == 0)
689 return GetSP();
690 ValueObjectSP root(GetSP());
691 for (ConstString name : names)
692 {
693 root = root->GetChildMemberWithName(name, true);
694 if (!root)
695 {
696 if (name_of_error)
697 *name_of_error = name;
698 return root;
699 }
700 }
701 return root;
702}
703
704lldb::ValueObjectSP
705ValueObject::GetChildAtNamePath (const std::initializer_list< 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
724lldb::ValueObjectSP
725ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names,
726 ConstString* name_of_error)
727{
728 if (names.size() == 0)
729 return GetSP();
730 ValueObjectSP root(GetSP());
731 for (std::pair<ConstString, bool> name : names)
732 {
733 root = root->GetChildMemberWithName(name.first, name.second);
734 if (!root)
735 {
736 if (name_of_error)
737 *name_of_error = name.first;
738 return root;
739 }
740 }
741 return root;
742}
743
Greg Claytonc7bece562013-01-25 18:06:21 +0000744size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000745ValueObject::GetIndexOfChildWithName (const ConstString &name)
746{
747 bool omit_empty_base_classes = true;
Greg Clayton99558cc42015-08-24 23:46:31 +0000748 return GetCompilerType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000749}
750
751ValueObjectSP
752ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
753{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000754 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000755 // classes (which really aren't part of the expression path), so we
756 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000757 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000758
Greg Claytondea8cb42011-06-29 22:09:02 +0000759 // We may need to update our value if we are dynamic
760 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000761 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000762
763 std::vector<uint32_t> child_indexes;
Greg Claytondea8cb42011-06-29 22:09:02 +0000764 bool omit_empty_base_classes = true;
Greg Clayton99558cc42015-08-24 23:46:31 +0000765 const size_t num_child_indexes = GetCompilerType().GetIndexOfChildMemberWithName (name.GetCString(),
Greg Clayton57ee3062013-07-11 22:46:58 +0000766 omit_empty_base_classes,
767 child_indexes);
Greg Claytondea8cb42011-06-29 22:09:02 +0000768 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000769 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000770 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
771 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
772
773 child_sp = GetChildAtIndex(*pos, can_create);
774 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000775 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000776 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000777 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000778 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
779 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000780 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000781 else
782 {
783 child_sp.reset();
784 }
785
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000786 }
787 }
788 return child_sp;
789}
790
791
Greg Claytonc7bece562013-01-25 18:06:21 +0000792size_t
Siva Chandra9ac7a6c2015-10-21 19:28:08 +0000793ValueObject::GetNumChildren (uint32_t max)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000794{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000795 UpdateValueIfNeeded();
Siva Chandra9ac7a6c2015-10-21 19:28:08 +0000796
797 if (max < UINT32_MAX)
798 {
799 if (m_children_count_valid)
800 {
801 size_t children_count = m_children.GetChildrenCount();
802 return children_count <= max ? children_count : max;
803 }
804 else
805 return CalculateNumChildren(max);
806 }
807
Greg Clayton288bdf92010-09-02 02:59:18 +0000808 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000809 {
810 SetNumChildren (CalculateNumChildren());
811 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000812 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000813}
Greg Clayton4a792072012-10-23 01:50:10 +0000814
815bool
816ValueObject::MightHaveChildren()
817{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000818 bool has_children = false;
Greg Clayton2452ab72013-02-08 22:02:02 +0000819 const uint32_t type_info = GetTypeInfo();
820 if (type_info)
Greg Clayton4a792072012-10-23 01:50:10 +0000821 {
Enrico Granata622be232014-10-21 20:52:14 +0000822 if (type_info & (eTypeHasChildren |
823 eTypeIsPointer |
824 eTypeIsReference))
Greg Clayton4a792072012-10-23 01:50:10 +0000825 has_children = true;
826 }
827 else
828 {
829 has_children = GetNumChildren () > 0;
830 }
831 return has_children;
832}
833
834// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000835void
Greg Claytonc7bece562013-01-25 18:06:21 +0000836ValueObject::SetNumChildren (size_t num_children)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000837{
Greg Clayton288bdf92010-09-02 02:59:18 +0000838 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000839 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000840}
841
842void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000843ValueObject::SetName (const ConstString &name)
844{
845 m_name = name;
846}
847
Jim Ingham58b59f92011-04-22 23:53:53 +0000848ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000849ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000850{
Jim Ingham2eec4872011-05-07 00:10:58 +0000851 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000852
Greg Claytondea8cb42011-06-29 22:09:02 +0000853 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000854 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000855 std::string child_name_str;
856 uint32_t child_byte_size = 0;
857 int32_t child_byte_offset = 0;
858 uint32_t child_bitfield_bit_size = 0;
859 uint32_t child_bitfield_bit_offset = 0;
860 bool child_is_base_class = false;
861 bool child_is_deref_of_parent = false;
862
863 const bool transparent_pointers = synthetic_array_member == false;
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000864 CompilerType child_compiler_type;
Greg Claytondea8cb42011-06-29 22:09:02 +0000865
Greg Claytoncc4d0142012-02-17 07:49:44 +0000866 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000867
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000868 child_compiler_type = GetCompilerType().GetChildCompilerTypeAtIndex (&exe_ctx,
869 idx,
870 transparent_pointers,
871 omit_empty_base_classes,
872 ignore_array_bounds,
873 child_name_str,
874 child_byte_size,
875 child_byte_offset,
876 child_bitfield_bit_size,
877 child_bitfield_bit_offset,
878 child_is_base_class,
879 child_is_deref_of_parent,
880 this);
881 if (child_compiler_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000882 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000883 if (synthetic_index)
884 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000885
Greg Claytondea8cb42011-06-29 22:09:02 +0000886 ConstString child_name;
887 if (!child_name_str.empty())
888 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000889
Greg Claytondea8cb42011-06-29 22:09:02 +0000890 valobj = new ValueObjectChild (*this,
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000891 child_compiler_type,
Greg Claytondea8cb42011-06-29 22:09:02 +0000892 child_name,
893 child_byte_size,
894 child_byte_offset,
895 child_bitfield_bit_size,
896 child_bitfield_bit_offset,
897 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000898 child_is_deref_of_parent,
899 eAddressTypeInvalid);
900 //if (valobj)
901 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
902 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000903
Jim Ingham58b59f92011-04-22 23:53:53 +0000904 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000905}
906
Enrico Granata0c489f52012-03-01 04:24:26 +0000907bool
908ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
Enrico Granata31fda932015-10-07 01:41:23 +0000909 std::string& destination,
910 lldb::LanguageType lang)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000911{
Enrico Granata31fda932015-10-07 01:41:23 +0000912 return GetSummaryAsCString(summary_ptr, destination, TypeSummaryOptions().SetLanguage(lang));
Enrico Granatac1247f52014-11-06 21:23:20 +0000913}
914
915bool
916ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
917 std::string& destination,
918 const TypeSummaryOptions& options)
919{
Enrico Granata0c489f52012-03-01 04:24:26 +0000920 destination.clear();
Enrico Granata31fda932015-10-07 01:41:23 +0000921
Enrico Granata0c489f52012-03-01 04:24:26 +0000922 // ideally we would like to bail out if passing NULL, but if we do so
923 // we end up not providing the summary for function pointers anymore
924 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
925 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000926
927 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000928
Enrico Granata31fda932015-10-07 01:41:23 +0000929 TypeSummaryOptions actual_options(options);
930
931 if (actual_options.GetLanguage() == lldb::eLanguageTypeUnknown)
932 actual_options.SetLanguage(GetPreferredDisplayLanguage());
933
Enrico Granataf18c03e2012-04-04 17:34:10 +0000934 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
935 // information that we might care to see in a crash log. might be useful in very specific situations though.
936 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
Enrico Granata31fda932015-10-07 01:41:23 +0000937 GetTypeName().GetCString(),
938 GetName().GetCString(),
939 summary_ptr->GetDescription().c_str());*/
Enrico Granataf18c03e2012-04-04 17:34:10 +0000940
Enrico Granataff0f23d2014-12-10 02:00:45 +0000941 if (UpdateValueIfNeeded (false) && summary_ptr)
Enrico Granata0c489f52012-03-01 04:24:26 +0000942 {
Enrico Granataff0f23d2014-12-10 02:00:45 +0000943 if (HasSyntheticValue())
944 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
Enrico Granata31fda932015-10-07 01:41:23 +0000945 summary_ptr->FormatObject(this, destination, actual_options);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000946 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000947 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000948 return !destination.empty();
949}
950
951const char *
Enrico Granata31fda932015-10-07 01:41:23 +0000952ValueObject::GetSummaryAsCString (lldb::LanguageType lang)
Enrico Granata0c489f52012-03-01 04:24:26 +0000953{
954 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
955 {
Enrico Granata31fda932015-10-07 01:41:23 +0000956 TypeSummaryOptions summary_options;
957 summary_options.SetLanguage(lang);
Enrico Granata0c489f52012-03-01 04:24:26 +0000958 GetSummaryAsCString(GetSummaryFormat().get(),
Enrico Granatac1247f52014-11-06 21:23:20 +0000959 m_summary_str,
Enrico Granata31fda932015-10-07 01:41:23 +0000960 summary_options);
Enrico Granata0c489f52012-03-01 04:24:26 +0000961 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000962 if (m_summary_str.empty())
963 return NULL;
964 return m_summary_str.c_str();
965}
966
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000967bool
Enrico Granata49bfafb2014-11-18 23:36:25 +0000968ValueObject::GetSummaryAsCString (std::string& destination,
969 const TypeSummaryOptions& options)
970{
971 return GetSummaryAsCString(GetSummaryFormat().get(),
Enrico Granata31fda932015-10-07 01:41:23 +0000972 destination,
973 options);
Enrico Granata49bfafb2014-11-18 23:36:25 +0000974}
975
976bool
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000977ValueObject::IsCStringContainer(bool check_pointer)
978{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000979 CompilerType pointee_or_element_compiler_type;
980 const Flags type_flags (GetTypeInfo (&pointee_or_element_compiler_type));
Enrico Granata622be232014-10-21 20:52:14 +0000981 bool is_char_arr_ptr (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000982 pointee_or_element_compiler_type.IsCharType ());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000983 if (!is_char_arr_ptr)
984 return false;
985 if (!check_pointer)
986 return true;
Enrico Granata622be232014-10-21 20:52:14 +0000987 if (type_flags.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000988 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000989 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000990 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000991 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000992 return (cstr_address != LLDB_INVALID_ADDRESS);
993}
994
Enrico Granata9128ee22011-09-06 19:20:51 +0000995size_t
996ValueObject::GetPointeeData (DataExtractor& data,
997 uint32_t item_idx,
998 uint32_t item_count)
999{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001000 CompilerType pointee_or_element_compiler_type;
1001 const uint32_t type_info = GetTypeInfo (&pointee_or_element_compiler_type);
Enrico Granata622be232014-10-21 20:52:14 +00001002 const bool is_pointer_type = type_info & eTypeIsPointer;
1003 const bool is_array_type = type_info & eTypeIsArray;
Greg Clayton2452ab72013-02-08 22:02:02 +00001004 if (!(is_pointer_type || is_array_type))
Enrico Granata9128ee22011-09-06 19:20:51 +00001005 return 0;
1006
1007 if (item_count == 0)
1008 return 0;
1009
Enrico Granata951bdd52015-01-28 01:09:45 +00001010 ExecutionContext exe_ctx (GetExecutionContextRef());
1011
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001012 const uint64_t item_type_size = pointee_or_element_compiler_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
Enrico Granata9128ee22011-09-06 19:20:51 +00001013 const uint64_t bytes = item_count * item_type_size;
Enrico Granata9128ee22011-09-06 19:20:51 +00001014 const uint64_t offset = item_idx * item_type_size;
1015
1016 if (item_idx == 0 && item_count == 1) // simply a deref
1017 {
Greg Clayton2452ab72013-02-08 22:02:02 +00001018 if (is_pointer_type)
Enrico Granata9128ee22011-09-06 19:20:51 +00001019 {
1020 Error error;
1021 ValueObjectSP pointee_sp = Dereference(error);
1022 if (error.Fail() || pointee_sp.get() == NULL)
1023 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +00001024 return pointee_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +00001025 }
1026 else
1027 {
1028 ValueObjectSP child_sp = GetChildAtIndex(0, true);
1029 if (child_sp.get() == NULL)
1030 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +00001031 Error error;
1032 return child_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +00001033 }
1034 return true;
1035 }
1036 else /* (items > 1) */
1037 {
1038 Error error;
1039 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
1040 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
1041
1042 AddressType addr_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001043 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001044
Enrico Granata9128ee22011-09-06 19:20:51 +00001045 switch (addr_type)
1046 {
1047 case eAddressTypeFile:
1048 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001049 ModuleSP module_sp (GetModule());
1050 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001051 {
Enrico Granata9c2efe32012-08-07 01:49:34 +00001052 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +00001053 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001054 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001055 ExecutionContext exe_ctx (GetExecutionContextRef());
1056 Target* target = exe_ctx.GetTargetPtr();
1057 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +00001058 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001059 heap_buf_ptr->SetByteSize(bytes);
1060 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
1061 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +00001062 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001063 data.SetData(data_sp);
1064 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +00001065 }
1066 }
1067 }
1068 }
1069 break;
1070 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +00001071 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001072 ExecutionContext exe_ctx (GetExecutionContextRef());
1073 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +00001074 if (process)
1075 {
1076 heap_buf_ptr->SetByteSize(bytes);
1077 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
Enrico Granata5e1480c2013-10-30 17:52:44 +00001078 if (error.Success() || bytes_read > 0)
Enrico Granata9128ee22011-09-06 19:20:51 +00001079 {
1080 data.SetData(data_sp);
1081 return bytes_read;
1082 }
1083 }
1084 }
1085 break;
1086 case eAddressTypeHost:
1087 {
Greg Clayton99558cc42015-08-24 23:46:31 +00001088 const uint64_t max_bytes = GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope());
Greg Clayton2452ab72013-02-08 22:02:02 +00001089 if (max_bytes > offset)
1090 {
1091 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
Siva Chandrae32f2b52015-05-05 00:41:35 +00001092 addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1093 if (addr == LLDB_INVALID_ADDRESS)
1094 break;
Greg Clayton2452ab72013-02-08 22:02:02 +00001095 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
1096 data.SetData(data_sp);
1097 return bytes_read;
1098 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001099 }
1100 break;
1101 case eAddressTypeInvalid:
Enrico Granata9128ee22011-09-06 19:20:51 +00001102 break;
1103 }
1104 }
1105 return 0;
1106}
1107
Greg Claytonfaac1112013-03-14 18:31:44 +00001108uint64_t
Sean Callanan866e91c2014-02-28 22:27:53 +00001109ValueObject::GetData (DataExtractor& data, Error &error)
Enrico Granata9128ee22011-09-06 19:20:51 +00001110{
1111 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001112 ExecutionContext exe_ctx (GetExecutionContextRef());
Sean Callanan866e91c2014-02-28 22:27:53 +00001113 error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001114 if (error.Fail())
Sean Callananed185ab2013-04-19 19:47:32 +00001115 {
1116 if (m_data.GetByteSize())
1117 {
1118 data = m_data;
1119 return data.GetByteSize();
1120 }
1121 else
1122 {
1123 return 0;
1124 }
1125 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001126 data.SetAddressByteSize(m_data.GetAddressByteSize());
1127 data.SetByteOrder(m_data.GetByteOrder());
1128 return data.GetByteSize();
1129}
1130
Sean Callanan389823e2013-04-13 01:21:23 +00001131bool
1132ValueObject::SetData (DataExtractor &data, Error &error)
1133{
1134 error.Clear();
1135 // Make sure our value is up to date first so that our location and location
1136 // type is valid.
1137 if (!UpdateValueIfNeeded(false))
1138 {
1139 error.SetErrorString("unable to read value");
1140 return false;
1141 }
1142
1143 uint64_t count = 0;
Greg Clayton99558cc42015-08-24 23:46:31 +00001144 const Encoding encoding = GetCompilerType().GetEncoding(count);
Sean Callanan389823e2013-04-13 01:21:23 +00001145
1146 const size_t byte_size = GetByteSize();
1147
1148 Value::ValueType value_type = m_value.GetValueType();
1149
1150 switch (value_type)
1151 {
1152 case Value::eValueTypeScalar:
1153 {
1154 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1155
1156 if (!set_error.Success())
1157 {
1158 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1159 return false;
1160 }
1161 }
1162 break;
1163 case Value::eValueTypeLoadAddress:
1164 {
1165 // If it is a load address, then the scalar value is the storage location
1166 // of the data, and we have to shove this value down to that load location.
1167 ExecutionContext exe_ctx (GetExecutionContextRef());
1168 Process *process = exe_ctx.GetProcessPtr();
1169 if (process)
1170 {
1171 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1172 size_t bytes_written = process->WriteMemory(target_addr,
1173 data.GetDataStart(),
1174 byte_size,
1175 error);
1176 if (!error.Success())
1177 return false;
1178 if (bytes_written != byte_size)
1179 {
1180 error.SetErrorString("unable to write value to memory");
1181 return false;
1182 }
1183 }
1184 }
1185 break;
1186 case Value::eValueTypeHostAddress:
1187 {
1188 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1189 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1190 m_data.SetData(buffer_sp, 0);
1191 data.CopyByteOrderedData (0,
1192 byte_size,
1193 const_cast<uint8_t *>(m_data.GetDataStart()),
1194 byte_size,
1195 m_data.GetByteOrder());
1196 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1197 }
1198 break;
1199 case Value::eValueTypeFileAddress:
1200 case Value::eValueTypeVector:
1201 break;
1202 }
1203
1204 // If we have reached this point, then we have successfully changed the value.
1205 SetNeedsUpdate();
1206 return true;
1207}
1208
Enrico Granata9128ee22011-09-06 19:20:51 +00001209// will compute strlen(str), but without consuming more than
1210// maxlen bytes out of str (this serves the purpose of reading
1211// chunks of a string without having to worry about
1212// missing NULL terminators in the chunk)
1213// of course, if strlen(str) > maxlen, the function will return
1214// maxlen_value (which should be != maxlen, because that allows you
1215// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1216static uint32_t
1217strlen_or_inf (const char* str,
1218 uint32_t maxlen,
1219 uint32_t maxlen_value)
1220{
1221 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +00001222 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +00001223 {
Greg Clayton8dd5c172011-10-05 22:19:51 +00001224 while(*str)
1225 {
1226 len++;str++;
Greg Clayton2452ab72013-02-08 22:02:02 +00001227 if (len >= maxlen)
Greg Clayton8dd5c172011-10-05 22:19:51 +00001228 return maxlen_value;
1229 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001230 }
1231 return len;
1232}
1233
Enrico Granata2206b482014-10-30 18:27:31 +00001234static bool
1235CopyStringDataToBufferSP(const StreamString& source,
1236 lldb::DataBufferSP& destination)
1237{
1238 destination.reset(new DataBufferHeap(source.GetSize()+1,0));
1239 memcpy(destination->GetBytes(), source.GetString().c_str(), source.GetSize());
1240 return true;
1241}
1242
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001243size_t
Enrico Granata2206b482014-10-30 18:27:31 +00001244ValueObject::ReadPointedString (lldb::DataBufferSP& buffer_sp,
Greg Claytoncc4d0142012-02-17 07:49:44 +00001245 Error& error,
1246 uint32_t max_length,
1247 bool honor_array,
1248 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001249{
Enrico Granata2206b482014-10-30 18:27:31 +00001250 StreamString s;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001251 ExecutionContext exe_ctx (GetExecutionContextRef());
1252 Target* target = exe_ctx.GetTargetPtr();
Enrico Granata2206b482014-10-30 18:27:31 +00001253
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001254 if (!target)
1255 {
1256 s << "<no target to read from>";
1257 error.SetErrorString("no target to read from");
Enrico Granata2206b482014-10-30 18:27:31 +00001258 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001259 return 0;
1260 }
1261
1262 if (max_length == 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001263 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001264
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001265 size_t bytes_read = 0;
1266 size_t total_bytes_read = 0;
1267
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001268 CompilerType compiler_type = GetCompilerType();
1269 CompilerType elem_or_pointee_compiler_type;
1270 const Flags type_flags (GetTypeInfo (&elem_or_pointee_compiler_type));
Enrico Granata622be232014-10-21 20:52:14 +00001271 if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001272 elem_or_pointee_compiler_type.IsCharType ())
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001273 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001274 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1275 AddressType cstr_address_type = eAddressTypeInvalid;
1276
1277 size_t cstr_len = 0;
1278 bool capped_data = false;
Enrico Granata622be232014-10-21 20:52:14 +00001279 if (type_flags.Test (eTypeIsArray))
Greg Claytoncc4d0142012-02-17 07:49:44 +00001280 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001281 // We have an array
Greg Clayton57ee3062013-07-11 22:46:58 +00001282 uint64_t array_size = 0;
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001283 if (compiler_type.IsArrayType(NULL, &array_size, NULL))
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001284 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001285 cstr_len = array_size;
1286 if (cstr_len > max_length)
1287 {
1288 capped_data = true;
1289 cstr_len = max_length;
1290 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001291 }
1292 cstr_address = GetAddressOf (true, &cstr_address_type);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001293 }
1294 else
1295 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001296 // We have a pointer
1297 cstr_address = GetPointerValue (&cstr_address_type);
1298 }
1299
1300 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1301 {
1302 s << "<invalid address>";
1303 error.SetErrorString("invalid address");
Enrico Granata2206b482014-10-30 18:27:31 +00001304 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001305 return 0;
1306 }
Enrico Granata2206b482014-10-30 18:27:31 +00001307
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001308 Address cstr_so_addr (cstr_address);
1309 DataExtractor data;
1310 if (cstr_len > 0 && honor_array)
1311 {
1312 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1313 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1314 GetPointeeData(data, 0, cstr_len);
Enrico Granata2206b482014-10-30 18:27:31 +00001315
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001316 if ((bytes_read = data.GetByteSize()) > 0)
1317 {
1318 total_bytes_read = bytes_read;
Enrico Granata2206b482014-10-30 18:27:31 +00001319 for (size_t offset = 0; offset < bytes_read; offset++)
1320 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001321 if (capped_data)
1322 s << "...";
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001323 }
1324 }
1325 else
1326 {
1327 cstr_len = max_length;
1328 const size_t k_max_buf_size = 64;
Enrico Granata2206b482014-10-30 18:27:31 +00001329
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001330 size_t offset = 0;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001331
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001332 int cstr_len_displayed = -1;
1333 bool capped_cstr = false;
1334 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1335 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1336 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001337 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001338 total_bytes_read += bytes_read;
1339 const char *cstr = data.PeekCStr(0);
1340 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1341 if (len > k_max_buf_size)
1342 len = k_max_buf_size;
Enrico Granata2206b482014-10-30 18:27:31 +00001343
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001344 if (cstr_len_displayed < 0)
1345 cstr_len_displayed = len;
Enrico Granata2206b482014-10-30 18:27:31 +00001346
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001347 if (len == 0)
1348 break;
1349 cstr_len_displayed += len;
1350 if (len > bytes_read)
1351 len = bytes_read;
1352 if (len > cstr_len)
1353 len = cstr_len;
1354
Enrico Granata2206b482014-10-30 18:27:31 +00001355 for (size_t offset = 0; offset < bytes_read; offset++)
1356 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001357
1358 if (len < k_max_buf_size)
1359 break;
1360
1361 if (len >= cstr_len)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001362 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001363 capped_cstr = true;
1364 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001365 }
Enrico Granata2206b482014-10-30 18:27:31 +00001366
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001367 cstr_len -= len;
1368 offset += len;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001369 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001370
1371 if (cstr_len_displayed >= 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001372 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001373 if (capped_cstr)
1374 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001375 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001376 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001377 }
1378 else
1379 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001380 error.SetErrorString("not a string object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001381 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001382 }
Enrico Granata2206b482014-10-30 18:27:31 +00001383 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001384 return total_bytes_read;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001385}
1386
Enrico Granata744794a2014-09-05 21:46:22 +00001387std::pair<TypeValidatorResult, std::string>
1388ValueObject::GetValidationStatus ()
1389{
1390 if (!UpdateValueIfNeeded(true))
1391 return {TypeValidatorResult::Success,""}; // not the validator's job to discuss update problems
1392
1393 if (m_validation_result.hasValue())
1394 return m_validation_result.getValue();
1395
1396 if (!m_type_validator_sp)
1397 return {TypeValidatorResult::Success,""}; // no validator no failure
1398
1399 auto outcome = m_type_validator_sp->FormatObject(this);
1400
1401 return (m_validation_result = {outcome.m_result,outcome.m_message}).getValue();
1402}
1403
Jim Ingham53c47f12010-09-10 23:12:17 +00001404const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001405ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001406{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001407
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001408 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001409 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001410
1411 if (!m_object_desc_str.empty())
1412 return m_object_desc_str.c_str();
1413
Greg Claytoncc4d0142012-02-17 07:49:44 +00001414 ExecutionContext exe_ctx (GetExecutionContextRef());
1415 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001416 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001417 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001418
Jim Ingham53c47f12010-09-10 23:12:17 +00001419 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001420
Greg Claytonafacd142011-09-02 01:15:17 +00001421 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001422 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1423
Jim Inghama2cf2632010-12-23 02:29:54 +00001424 if (runtime == NULL)
1425 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001426 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001427 CompilerType compiler_type = GetCompilerType();
1428 if (compiler_type)
Jim Inghama2cf2632010-12-23 02:29:54 +00001429 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001430 bool is_signed;
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001431 if (compiler_type.IsIntegerType (is_signed) || compiler_type.IsPointerType ())
Jim Inghamb7603bb2011-03-18 00:05:18 +00001432 {
Greg Claytonafacd142011-09-02 01:15:17 +00001433 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001434 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001435 }
1436 }
1437
Jim Ingham8d543de2011-03-31 23:01:21 +00001438 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001439 {
1440 m_object_desc_str.append (s.GetData());
1441 }
Sean Callanan672ad942010-10-23 00:18:49 +00001442
1443 if (m_object_desc_str.empty())
1444 return NULL;
1445 else
1446 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001447}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001448
Enrico Granata0c489f52012-03-01 04:24:26 +00001449bool
Enrico Granata4939b982013-12-22 09:24:22 +00001450ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format,
1451 std::string& destination)
1452{
1453 if (UpdateValueIfNeeded(false))
1454 return format.FormatObject(this,destination);
1455 else
1456 return false;
1457}
1458
1459bool
Enrico Granata0c489f52012-03-01 04:24:26 +00001460ValueObject::GetValueAsCString (lldb::Format format,
1461 std::string& destination)
1462{
Enrico Granata30f287f2013-12-28 08:44:02 +00001463 return GetValueAsCString(TypeFormatImpl_Format(format),destination);
Enrico Granata0c489f52012-03-01 04:24:26 +00001464}
1465
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001466const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001467ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001468{
Enrico Granatab294fd22013-05-31 19:18:19 +00001469 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001470 {
Enrico Granata4939b982013-12-22 09:24:22 +00001471 lldb::TypeFormatImplSP format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001472 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001473 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001474 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001475 if (m_type_format_sp)
Enrico Granata4939b982013-12-22 09:24:22 +00001476 format_sp = m_type_format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001477 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001478 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001479 if (m_is_bitfield_for_scalar)
1480 my_format = eFormatUnsigned;
1481 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001482 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001483 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001484 {
1485 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1486 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001487 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001488 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001489 else
1490 {
Greg Clayton99558cc42015-08-24 23:46:31 +00001491 my_format = GetValue().GetCompilerType().GetFormat();
Enrico Granata0c489f52012-03-01 04:24:26 +00001492 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001493 }
1494 }
1495 }
Enrico Granatab294fd22013-05-31 19:18:19 +00001496 if (my_format != m_last_format || m_value_str.empty())
Enrico Granata297e69f2012-03-06 23:21:16 +00001497 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001498 m_last_format = my_format;
Enrico Granata4939b982013-12-22 09:24:22 +00001499 if (!format_sp)
Enrico Granata30f287f2013-12-28 08:44:02 +00001500 format_sp.reset(new TypeFormatImpl_Format(my_format));
Enrico Granata4939b982013-12-22 09:24:22 +00001501 if (GetValueAsCString(*format_sp.get(), m_value_str))
Enrico Granata297e69f2012-03-06 23:21:16 +00001502 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001503 if (!m_value_did_change && m_old_value_valid)
1504 {
1505 // The value was gotten successfully, so we consider the
1506 // value as changed if the value string differs
1507 SetValueDidChange (m_old_value_str != m_value_str);
1508 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001509 }
1510 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001511 }
1512 if (m_value_str.empty())
1513 return NULL;
1514 return m_value_str.c_str();
1515}
1516
Enrico Granatac3e320a2011-08-02 17:27:39 +00001517// if > 8bytes, 0 is returned. this method should mostly be used
1518// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001519uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001520ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001521{
1522 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001523 if (CanProvideValue())
Enrico Granatac3e320a2011-08-02 17:27:39 +00001524 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001525 Scalar scalar;
1526 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001527 {
1528 if (success)
1529 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001530 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001531 }
1532 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001533 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001534
1535 if (success)
1536 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001537 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001538}
1539
Enrico Granatad7373f62013-10-31 18:57:50 +00001540int64_t
1541ValueObject::GetValueAsSigned (int64_t fail_value, bool *success)
1542{
1543 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001544 if (CanProvideValue())
Enrico Granatad7373f62013-10-31 18:57:50 +00001545 {
1546 Scalar scalar;
1547 if (ResolveValue (scalar))
1548 {
1549 if (success)
1550 *success = true;
Tamas Berghammer5a9919f2015-01-23 10:54:21 +00001551 return scalar.SLongLong(fail_value);
Enrico Granatad7373f62013-10-31 18:57:50 +00001552 }
1553 // fallthrough, otherwise...
1554 }
1555
1556 if (success)
1557 *success = false;
Tamas Berghammer5a9919f2015-01-23 10:54:21 +00001558 return fail_value;
Enrico Granatad7373f62013-10-31 18:57:50 +00001559}
1560
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001561// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1562// this call up to date by returning true for your new special cases. We will eventually move
1563// to checking this call result before trying to display special cases
1564bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001565ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1566 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001567{
Greg Clayton57ee3062013-07-11 22:46:58 +00001568 Flags flags(GetTypeInfo());
Enrico Granata622be232014-10-21 20:52:14 +00001569 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001570 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001571 {
1572 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001573 (custom_format == eFormatCString ||
1574 custom_format == eFormatCharArray ||
1575 custom_format == eFormatChar ||
1576 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001577 return true;
1578
Enrico Granata622be232014-10-21 20:52:14 +00001579 if (flags.Test(eTypeIsArray))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001580 {
Greg Claytonafacd142011-09-02 01:15:17 +00001581 if ((custom_format == eFormatBytes) ||
1582 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001583 return true;
1584
Greg Claytonafacd142011-09-02 01:15:17 +00001585 if ((custom_format == eFormatVectorOfChar) ||
1586 (custom_format == eFormatVectorOfFloat32) ||
1587 (custom_format == eFormatVectorOfFloat64) ||
1588 (custom_format == eFormatVectorOfSInt16) ||
1589 (custom_format == eFormatVectorOfSInt32) ||
1590 (custom_format == eFormatVectorOfSInt64) ||
1591 (custom_format == eFormatVectorOfSInt8) ||
1592 (custom_format == eFormatVectorOfUInt128) ||
1593 (custom_format == eFormatVectorOfUInt16) ||
1594 (custom_format == eFormatVectorOfUInt32) ||
1595 (custom_format == eFormatVectorOfUInt64) ||
1596 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001597 return true;
1598 }
1599 }
1600 return false;
1601}
1602
Enrico Granata9fc19442011-07-06 02:13:41 +00001603bool
1604ValueObject::DumpPrintableRepresentation(Stream& s,
1605 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001606 Format custom_format,
Enrico Granata0dba9b32014-01-08 01:36:59 +00001607 PrintableRepresentationSpecialCases special,
1608 bool do_dump_error)
Enrico Granata9fc19442011-07-06 02:13:41 +00001609{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001610
Greg Clayton57ee3062013-07-11 22:46:58 +00001611 Flags flags(GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001612
Enrico Granata86cc9822012-03-19 22:58:49 +00001613 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1614 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1615
1616 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001617 {
Enrico Granata622be232014-10-21 20:52:14 +00001618 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001619 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001620 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001621 // when being asked to get a printable display an array or pointer type directly,
1622 // try to "do the right thing"
1623
1624 if (IsCStringContainer(true) &&
1625 (custom_format == eFormatCString ||
1626 custom_format == eFormatCharArray ||
1627 custom_format == eFormatChar ||
1628 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001629 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001630 Error error;
Enrico Granata2206b482014-10-30 18:27:31 +00001631 lldb::DataBufferSP buffer_sp;
1632 ReadPointedString(buffer_sp,
Enrico Granata86cc9822012-03-19 22:58:49 +00001633 error,
1634 0,
1635 (custom_format == eFormatVectorOfChar) ||
1636 (custom_format == eFormatCharArray));
Enrico Granataac494532015-09-09 22:30:24 +00001637 lldb_private::formatters::StringPrinter::ReadBufferAndDumpToStreamOptions options(*this);
Enrico Granata2206b482014-10-30 18:27:31 +00001638 options.SetData(DataExtractor(buffer_sp, lldb::eByteOrderInvalid, 8)); // none of this matters for a string - pass some defaults
1639 options.SetStream(&s);
1640 options.SetPrefixToken(0);
1641 options.SetQuote('"');
1642 options.SetSourceSize(buffer_sp->GetByteSize());
Enrico Granataac494532015-09-09 22:30:24 +00001643 formatters::StringPrinter::ReadBufferAndDumpToStream<lldb_private::formatters::StringPrinter::StringElementType::ASCII>(options);
Enrico Granata86cc9822012-03-19 22:58:49 +00001644 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001645 }
1646
Enrico Granata86cc9822012-03-19 22:58:49 +00001647 if (custom_format == eFormatEnum)
1648 return false;
1649
1650 // this only works for arrays, because I have no way to know when
1651 // the pointed memory ends, and no special \0 end of data marker
Enrico Granata622be232014-10-21 20:52:14 +00001652 if (flags.Test(eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001653 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001654 if ((custom_format == eFormatBytes) ||
1655 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001656 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001657 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001658
1659 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001660 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001661 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001662
1663 if (low)
1664 s << ',';
1665
1666 ValueObjectSP child = GetChildAtIndex(low,true);
1667 if (!child.get())
1668 {
1669 s << "<invalid child>";
1670 continue;
1671 }
1672 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1673 }
1674
1675 s << ']';
1676
1677 return true;
1678 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001679
Enrico Granata86cc9822012-03-19 22:58:49 +00001680 if ((custom_format == eFormatVectorOfChar) ||
1681 (custom_format == eFormatVectorOfFloat32) ||
1682 (custom_format == eFormatVectorOfFloat64) ||
1683 (custom_format == eFormatVectorOfSInt16) ||
1684 (custom_format == eFormatVectorOfSInt32) ||
1685 (custom_format == eFormatVectorOfSInt64) ||
1686 (custom_format == eFormatVectorOfSInt8) ||
1687 (custom_format == eFormatVectorOfUInt128) ||
1688 (custom_format == eFormatVectorOfUInt16) ||
1689 (custom_format == eFormatVectorOfUInt32) ||
1690 (custom_format == eFormatVectorOfUInt64) ||
1691 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1692 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001693 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001694
1695 Format format = FormatManager::GetSingleItemFormat(custom_format);
1696
1697 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001698 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001699 {
1700
1701 if (low)
1702 s << ',';
1703
1704 ValueObjectSP child = GetChildAtIndex(low,true);
1705 if (!child.get())
1706 {
1707 s << "<invalid child>";
1708 continue;
1709 }
1710 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1711 }
1712
1713 s << ']';
1714
1715 return true;
1716 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001717 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001718
1719 if ((custom_format == eFormatBoolean) ||
1720 (custom_format == eFormatBinary) ||
1721 (custom_format == eFormatChar) ||
1722 (custom_format == eFormatCharPrintable) ||
1723 (custom_format == eFormatComplexFloat) ||
1724 (custom_format == eFormatDecimal) ||
1725 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001726 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001727 (custom_format == eFormatFloat) ||
1728 (custom_format == eFormatOctal) ||
1729 (custom_format == eFormatOSType) ||
1730 (custom_format == eFormatUnicode16) ||
1731 (custom_format == eFormatUnicode32) ||
1732 (custom_format == eFormatUnsigned) ||
1733 (custom_format == eFormatPointer) ||
1734 (custom_format == eFormatComplexInteger) ||
1735 (custom_format == eFormatComplex) ||
1736 (custom_format == eFormatDefault)) // use the [] operator
1737 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001738 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001739 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001740
1741 if (only_special)
1742 return false;
1743
Enrico Granata86cc9822012-03-19 22:58:49 +00001744 bool var_success = false;
1745
1746 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001747 const char *cstr = NULL;
Enrico Granata2c75f112013-06-21 00:04:51 +00001748
1749 // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1750 // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1751 // area for cases where our desired output is not backed by some other longer-term storage
Greg Claytonc7bece562013-01-25 18:06:21 +00001752 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001753
Enrico Granata465f4bc2014-02-15 01:24:44 +00001754 if (custom_format != eFormatInvalid)
Enrico Granata86cc9822012-03-19 22:58:49 +00001755 SetFormat(custom_format);
1756
1757 switch(val_obj_display)
1758 {
1759 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001760 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001761 break;
1762
1763 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001764 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001765 break;
1766
1767 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001768 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001769 break;
1770
1771 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001772 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001773 break;
1774
1775 case eValueObjectRepresentationStyleChildrenCount:
Deepak Panickal99fbc072014-03-03 15:39:47 +00001776 strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren());
Greg Claytonc7bece562013-01-25 18:06:21 +00001777 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001778 break;
1779
1780 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001781 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001782 break;
Enrico Granata2c75f112013-06-21 00:04:51 +00001783
1784 case eValueObjectRepresentationStyleName:
1785 cstr = GetName().AsCString();
1786 break;
1787
1788 case eValueObjectRepresentationStyleExpressionPath:
1789 GetExpressionPath(strm, false);
1790 cstr = strm.GetString().c_str();
1791 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001792 }
1793
Greg Claytonc7bece562013-01-25 18:06:21 +00001794 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001795 {
1796 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001797 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001798 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1799 {
Enrico Granatad07cfd32014-10-08 18:27:36 +00001800 if (!CanProvideValue())
Enrico Granata86cc9822012-03-19 22:58:49 +00001801 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001802 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1803 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001804 }
1805 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001806 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001807 }
1808 }
1809
Greg Claytonc7bece562013-01-25 18:06:21 +00001810 if (cstr)
1811 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001812 else
1813 {
1814 if (m_error.Fail())
Enrico Granata0dba9b32014-01-08 01:36:59 +00001815 {
1816 if (do_dump_error)
1817 s.Printf("<%s>", m_error.AsCString());
1818 else
1819 return false;
1820 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001821 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1822 s.PutCString("<no summary available>");
1823 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1824 s.PutCString("<no value available>");
1825 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1826 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1827 else
1828 s.PutCString("<no printable representation>");
1829 }
1830
1831 // we should only return false here if we could not do *anything*
1832 // even if we have an error message as output, that's a success
1833 // from our callers' perspective, so return true
1834 var_success = true;
Enrico Granata465f4bc2014-02-15 01:24:44 +00001835
1836 if (custom_format != eFormatInvalid)
1837 SetFormat(eFormatDefault);
Enrico Granata86cc9822012-03-19 22:58:49 +00001838 }
1839
Enrico Granataf4efecd2011-07-12 22:56:10 +00001840 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001841}
1842
Greg Clayton737b9322010-09-13 03:32:57 +00001843addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001844ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001845{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001846 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001847 return LLDB_INVALID_ADDRESS;
1848
Greg Clayton73b472d2010-10-27 03:32:59 +00001849 switch (m_value.GetValueType())
1850 {
1851 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001852 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001853 if (scalar_is_load_address)
1854 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001855 if(address_type)
1856 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001857 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1858 }
1859 break;
1860
1861 case Value::eValueTypeLoadAddress:
1862 case Value::eValueTypeFileAddress:
Greg Clayton73b472d2010-10-27 03:32:59 +00001863 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001864 if(address_type)
1865 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001866 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1867 }
1868 break;
Siva Chandraa3747a92015-05-04 19:43:34 +00001869 case Value::eValueTypeHostAddress:
Siva Chandrae32f2b52015-05-05 00:41:35 +00001870 {
1871 if(address_type)
1872 *address_type = m_value.GetValueAddressType ();
1873 return LLDB_INVALID_ADDRESS;
1874 }
Siva Chandraa3747a92015-05-04 19:43:34 +00001875 break;
Greg Clayton73b472d2010-10-27 03:32:59 +00001876 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001877 if (address_type)
1878 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001879 return LLDB_INVALID_ADDRESS;
1880}
1881
1882addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001883ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001884{
Greg Claytonafacd142011-09-02 01:15:17 +00001885 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001886 if(address_type)
1887 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001888
Enrico Granatac3e320a2011-08-02 17:27:39 +00001889 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001890 return address;
1891
Greg Clayton73b472d2010-10-27 03:32:59 +00001892 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001893 {
1894 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001895 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001896 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001897 break;
1898
Enrico Granata9128ee22011-09-06 19:20:51 +00001899 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001900 case Value::eValueTypeLoadAddress:
1901 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001902 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001903 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001904 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001905 }
1906 break;
1907 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001908
Enrico Granata9128ee22011-09-06 19:20:51 +00001909 if (address_type)
1910 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001911
Greg Clayton737b9322010-09-13 03:32:57 +00001912 return address;
1913}
1914
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001915bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001916ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001917{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001918 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001919 // Make sure our value is up to date first so that our location and location
1920 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001921 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001922 {
1923 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001924 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001925 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001926
Greg Claytonfaac1112013-03-14 18:31:44 +00001927 uint64_t count = 0;
Greg Clayton99558cc42015-08-24 23:46:31 +00001928 const Encoding encoding = GetCompilerType().GetEncoding (count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001929
Greg Claytonb1320972010-07-14 00:18:15 +00001930 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001931
Jim Ingham16e0c682011-08-12 23:34:31 +00001932 Value::ValueType value_type = m_value.GetValueType();
1933
1934 if (value_type == Value::eValueTypeScalar)
1935 {
1936 // If the value is already a scalar, then let the scalar change itself:
1937 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1938 }
Sagar Thakur8536fd12015-08-20 09:12:46 +00001939 else if (byte_size <= 16)
Jim Ingham16e0c682011-08-12 23:34:31 +00001940 {
1941 // If the value fits in a scalar, then make a new scalar and again let the
1942 // scalar code do the conversion, then figure out where to put the new value.
1943 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001944 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1945 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001946 {
Jim Ingham4b536182011-08-09 02:12:22 +00001947 switch (value_type)
1948 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001949 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001950 {
1951 // If it is a load address, then the scalar value is the storage location
1952 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001953 ExecutionContext exe_ctx (GetExecutionContextRef());
1954 Process *process = exe_ctx.GetProcessPtr();
1955 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001956 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001957 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001958 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1959 new_scalar,
1960 byte_size,
1961 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001962 if (!error.Success())
1963 return false;
1964 if (bytes_written != byte_size)
1965 {
1966 error.SetErrorString("unable to write value to memory");
1967 return false;
1968 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001969 }
1970 }
Jim Ingham4b536182011-08-09 02:12:22 +00001971 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001972 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001973 {
1974 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1975 DataExtractor new_data;
1976 new_data.SetByteOrder (m_data.GetByteOrder());
1977
1978 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1979 m_data.SetData(buffer_sp, 0);
1980 bool success = new_scalar.GetData(new_data);
1981 if (success)
1982 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001983 new_data.CopyByteOrderedData (0,
1984 byte_size,
1985 const_cast<uint8_t *>(m_data.GetDataStart()),
1986 byte_size,
1987 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001988 }
1989 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1990
1991 }
Jim Ingham4b536182011-08-09 02:12:22 +00001992 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001993 case Value::eValueTypeFileAddress:
1994 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001995 case Value::eValueTypeVector:
1996 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001997 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001998 }
1999 else
2000 {
Jim Ingham16e0c682011-08-12 23:34:31 +00002001 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002002 }
Jim Ingham16e0c682011-08-12 23:34:31 +00002003 }
2004 else
2005 {
2006 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00002007 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002008 return false;
2009 }
Jim Ingham16e0c682011-08-12 23:34:31 +00002010
2011 // If we have reached this point, then we have successfully changed the value.
2012 SetNeedsUpdate();
2013 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002014}
2015
Greg Clayton81e871e2012-02-04 02:27:34 +00002016bool
2017ValueObject::GetDeclaration (Declaration &decl)
2018{
2019 decl.Clear();
2020 return false;
2021}
2022
Greg Clayton84db9102012-03-26 23:03:23 +00002023ConstString
2024ValueObject::GetTypeName()
2025{
Greg Clayton99558cc42015-08-24 23:46:31 +00002026 return GetCompilerType().GetConstTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00002027}
2028
2029ConstString
Enrico Granatae8daa2f2014-05-17 19:14:17 +00002030ValueObject::GetDisplayTypeName()
2031{
2032 return GetTypeName();
2033}
2034
2035ConstString
Greg Clayton84db9102012-03-26 23:03:23 +00002036ValueObject::GetQualifiedTypeName()
2037{
Greg Clayton99558cc42015-08-24 23:46:31 +00002038 return GetCompilerType().GetConstQualifiedTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00002039}
2040
2041
Greg Claytonafacd142011-09-02 01:15:17 +00002042LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00002043ValueObject::GetObjectRuntimeLanguage ()
2044{
Greg Clayton99558cc42015-08-24 23:46:31 +00002045 return GetCompilerType().GetMinimumLanguage ();
Jim Ingham5a369122010-09-28 01:25:32 +00002046}
2047
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002048void
Jim Ingham58b59f92011-04-22 23:53:53 +00002049ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002050{
Jim Ingham58b59f92011-04-22 23:53:53 +00002051 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002052}
2053
2054ValueObjectSP
2055ValueObject::GetSyntheticChild (const ConstString &key) const
2056{
2057 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00002058 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002059 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00002060 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002061 return synthetic_child_sp;
2062}
2063
Greg Clayton2452ab72013-02-08 22:02:02 +00002064uint32_t
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002065ValueObject::GetTypeInfo (CompilerType *pointee_or_element_compiler_type)
Greg Clayton2452ab72013-02-08 22:02:02 +00002066{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002067 return GetCompilerType().GetTypeInfo (pointee_or_element_compiler_type);
Greg Clayton2452ab72013-02-08 22:02:02 +00002068}
2069
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002070bool
2071ValueObject::IsPointerType ()
2072{
Greg Clayton99558cc42015-08-24 23:46:31 +00002073 return GetCompilerType().IsPointerType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002074}
2075
Jim Inghamb7603bb2011-03-18 00:05:18 +00002076bool
Greg Claytondaf515f2011-07-09 20:12:33 +00002077ValueObject::IsArrayType ()
2078{
Greg Clayton99558cc42015-08-24 23:46:31 +00002079 return GetCompilerType().IsArrayType (NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00002080}
2081
2082bool
Enrico Granata9fc19442011-07-06 02:13:41 +00002083ValueObject::IsScalarType ()
2084{
Greg Clayton99558cc42015-08-24 23:46:31 +00002085 return GetCompilerType().IsScalarType ();
Enrico Granata9fc19442011-07-06 02:13:41 +00002086}
2087
2088bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00002089ValueObject::IsIntegerType (bool &is_signed)
2090{
Greg Clayton99558cc42015-08-24 23:46:31 +00002091 return GetCompilerType().IsIntegerType (is_signed);
Jim Inghamb7603bb2011-03-18 00:05:18 +00002092}
Greg Clayton73b472d2010-10-27 03:32:59 +00002093
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002094bool
2095ValueObject::IsPointerOrReferenceType ()
2096{
Greg Clayton99558cc42015-08-24 23:46:31 +00002097 return GetCompilerType().IsPointerOrReferenceType ();
Greg Clayton007d5be2011-05-30 00:49:24 +00002098}
2099
2100bool
Greg Claytondea8cb42011-06-29 22:09:02 +00002101ValueObject::IsPossibleDynamicType ()
2102{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002103 ExecutionContext exe_ctx (GetExecutionContextRef());
2104 Process *process = exe_ctx.GetProcessPtr();
2105 if (process)
2106 return process->IsPossibleDynamicValue(*this);
2107 else
Greg Clayton99558cc42015-08-24 23:46:31 +00002108 return GetCompilerType().IsPossibleDynamicType (NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00002109}
2110
Enrico Granata9e7b3882012-12-13 23:50:33 +00002111bool
Enrico Granata560558e2015-02-11 02:35:39 +00002112ValueObject::IsRuntimeSupportValue ()
2113{
2114 Process *process(GetProcessSP().get());
2115 if (process)
2116 {
2117 LanguageRuntime *runtime = process->GetLanguageRuntime(GetObjectRuntimeLanguage());
2118 if (!runtime)
2119 runtime = process->GetObjCLanguageRuntime();
2120 if (runtime)
2121 return runtime->IsRuntimeSupportValue(*this);
2122 }
2123 return false;
2124}
2125
2126bool
Enrico Granata9e7b3882012-12-13 23:50:33 +00002127ValueObject::IsObjCNil ()
2128{
Enrico Granata622be232014-10-21 20:52:14 +00002129 const uint32_t mask = eTypeIsObjC | eTypeIsPointer;
Greg Clayton99558cc42015-08-24 23:46:31 +00002130 bool isObjCpointer = (((GetCompilerType().GetTypeInfo(NULL)) & mask) == mask);
Enrico Granata7277d202013-03-15 23:33:15 +00002131 if (!isObjCpointer)
2132 return false;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002133 bool canReadValue = true;
2134 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
Enrico Granata7277d202013-03-15 23:33:15 +00002135 return canReadValue && isZero;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002136}
2137
Greg Claytondaf515f2011-07-09 20:12:33 +00002138// This allows you to create an array member using and index
2139// that doesn't not fall in the normal bounds of the array.
2140// Many times structure can be defined as:
2141// struct Collection
2142// {
2143// uint32_t item_count;
2144// Item item_array[0];
2145// };
2146// The size of the "item_array" is 1, but many times in practice
2147// there are more items in "item_array".
2148
2149ValueObjectSP
Bruce Mitchener11d86362015-02-26 23:55:39 +00002150ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00002151{
2152 ValueObjectSP synthetic_child_sp;
Bruce Mitchener11d86362015-02-26 23:55:39 +00002153 if (IsPointerType () || IsArrayType())
Greg Claytondaf515f2011-07-09 20:12:33 +00002154 {
2155 char index_str[64];
Deepak Panickal99fbc072014-03-03 15:39:47 +00002156 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
Greg Claytondaf515f2011-07-09 20:12:33 +00002157 ConstString index_const_str(index_str);
2158 // Check if we have already created a synthetic array member in this
2159 // valid object. If we have we will re-use it.
2160 synthetic_child_sp = GetSyntheticChild (index_const_str);
2161 if (!synthetic_child_sp)
2162 {
2163 ValueObject *synthetic_child;
2164 // We haven't made a synthetic array member for INDEX yet, so
2165 // lets make one and cache it for any future reference.
2166 synthetic_child = CreateChildAtIndex(0, true, index);
Bruce Mitchener11d86362015-02-26 23:55:39 +00002167
Greg Claytondaf515f2011-07-09 20:12:33 +00002168 // 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));
Greg Claytondaf515f2011-07-09 20:12:33 +00002174 synthetic_child_sp->m_is_array_item_for_pointer = true;
2175 }
2176 }
2177 }
2178 return synthetic_child_sp;
2179}
2180
Enrico Granata9fc19442011-07-06 02:13:41 +00002181ValueObjectSP
2182ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2183{
2184 ValueObjectSP synthetic_child_sp;
2185 if (IsScalarType ())
2186 {
2187 char index_str[64];
2188 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2189 ConstString index_const_str(index_str);
2190 // Check if we have already created a synthetic array member in this
2191 // valid object. If we have we will re-use it.
2192 synthetic_child_sp = GetSyntheticChild (index_const_str);
2193 if (!synthetic_child_sp)
2194 {
Enrico Granata9fc19442011-07-06 02:13:41 +00002195 // We haven't made a synthetic array member for INDEX yet, so
2196 // lets make one and cache it for any future reference.
Greg Clayton57ee3062013-07-11 22:46:58 +00002197 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
Greg Clayton99558cc42015-08-24 23:46:31 +00002198 GetCompilerType(),
Greg Clayton57ee3062013-07-11 22:46:58 +00002199 index_const_str,
2200 GetByteSize(),
2201 0,
2202 to-from+1,
2203 from,
2204 false,
2205 false,
2206 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002207
2208 // Cache the value if we got one back...
2209 if (synthetic_child)
2210 {
2211 AddSyntheticChild(index_const_str, synthetic_child);
2212 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002213 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002214 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2215 }
2216 }
2217 }
2218 return synthetic_child_sp;
2219}
2220
Greg Claytonafacd142011-09-02 01:15:17 +00002221ValueObjectSP
Greg Claytona1e5dc82015-08-11 22:53:00 +00002222ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const CompilerType& type, bool can_create)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002223{
2224
2225 ValueObjectSP synthetic_child_sp;
2226
2227 char name_str[64];
2228 snprintf(name_str, sizeof(name_str), "@%i", offset);
2229 ConstString name_const_str(name_str);
2230
2231 // Check if we have already created a synthetic array member in this
2232 // valid object. If we have we will re-use it.
2233 synthetic_child_sp = GetSyntheticChild (name_const_str);
2234
2235 if (synthetic_child_sp.get())
2236 return synthetic_child_sp;
2237
2238 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002239 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002240
Enrico Granata951bdd52015-01-28 01:09:45 +00002241 ExecutionContext exe_ctx (GetExecutionContextRef());
2242
Enrico Granata6f3533f2011-07-29 19:53:35 +00002243 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
Greg Clayton57ee3062013-07-11 22:46:58 +00002244 type,
Enrico Granata6f3533f2011-07-29 19:53:35 +00002245 name_const_str,
Greg Clayton526ae042015-02-12 00:34:25 +00002246 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
Enrico Granata6f3533f2011-07-29 19:53:35 +00002247 offset,
2248 0,
2249 0,
2250 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002251 false,
2252 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002253 if (synthetic_child)
2254 {
2255 AddSyntheticChild(name_const_str, synthetic_child);
2256 synthetic_child_sp = synthetic_child->GetSP();
2257 synthetic_child_sp->SetName(name_const_str);
2258 synthetic_child_sp->m_is_child_at_offset = true;
2259 }
2260 return synthetic_child_sp;
2261}
2262
Enrico Granata32556cd2014-08-26 20:54:04 +00002263ValueObjectSP
Greg Claytona1e5dc82015-08-11 22:53:00 +00002264ValueObject::GetSyntheticBase (uint32_t offset, const CompilerType& type, bool can_create)
Enrico Granata32556cd2014-08-26 20:54:04 +00002265{
2266 ValueObjectSP synthetic_child_sp;
2267
2268 char name_str[64];
2269 snprintf(name_str, sizeof(name_str), "%s", type.GetTypeName().AsCString("<unknown>"));
2270 ConstString name_const_str(name_str);
2271
2272 // Check if we have already created a synthetic array member in this
2273 // valid object. If we have we will re-use it.
2274 synthetic_child_sp = GetSyntheticChild (name_const_str);
2275
2276 if (synthetic_child_sp.get())
2277 return synthetic_child_sp;
2278
2279 if (!can_create)
2280 return ValueObjectSP();
2281
Enrico Granata32556cd2014-08-26 20:54:04 +00002282 const bool is_base_class = true;
2283
Enrico Granata951bdd52015-01-28 01:09:45 +00002284 ExecutionContext exe_ctx (GetExecutionContextRef());
2285
Enrico Granata32556cd2014-08-26 20:54:04 +00002286 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2287 type,
2288 name_const_str,
Greg Clayton526ae042015-02-12 00:34:25 +00002289 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
Enrico Granata32556cd2014-08-26 20:54:04 +00002290 offset,
2291 0,
2292 0,
2293 is_base_class,
2294 false,
2295 eAddressTypeInvalid);
2296 if (synthetic_child)
2297 {
2298 AddSyntheticChild(name_const_str, synthetic_child);
2299 synthetic_child_sp = synthetic_child->GetSP();
2300 synthetic_child_sp->SetName(name_const_str);
2301 }
2302 return synthetic_child_sp;
2303}
2304
2305
Enrico Granatad55546b2011-07-22 00:16:08 +00002306// your expression path needs to have a leading . or ->
2307// (unless it somehow "looks like" an array, in which case it has
2308// a leading [ symbol). while the [ is meaningful and should be shown
2309// to the user, . and -> are just parser design, but by no means
2310// added information for the user.. strip them off
2311static const char*
2312SkipLeadingExpressionPathSeparators(const char* expression)
2313{
2314 if (!expression || !expression[0])
2315 return expression;
2316 if (expression[0] == '.')
2317 return expression+1;
2318 if (expression[0] == '-' && expression[1] == '>')
2319 return expression+2;
2320 return expression;
2321}
2322
Greg Claytonafacd142011-09-02 01:15:17 +00002323ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002324ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2325{
2326 ValueObjectSP synthetic_child_sp;
2327 ConstString name_const_string(expression);
2328 // Check if we have already created a synthetic array member in this
2329 // valid object. If we have we will re-use it.
2330 synthetic_child_sp = GetSyntheticChild (name_const_string);
2331 if (!synthetic_child_sp)
2332 {
2333 // We haven't made a synthetic array member for expression yet, so
2334 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002335 synthetic_child_sp = GetValueForExpressionPath(expression,
2336 NULL, NULL, NULL,
Enrico Granataef238c12015-03-12 22:30:58 +00002337 GetValueForExpressionPathOptions().SetSyntheticChildrenTraversal(GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None));
Enrico Granatad55546b2011-07-22 00:16:08 +00002338
2339 // Cache the value if we got one back...
2340 if (synthetic_child_sp.get())
2341 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002342 // 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 +00002343 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002344 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002345 }
2346 }
2347 return synthetic_child_sp;
2348}
2349
2350void
Enrico Granata86cc9822012-03-19 22:58:49 +00002351ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002352{
Enrico Granata86cc9822012-03-19 22:58:49 +00002353 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002354 return;
2355
Enrico Granatac5bc4122012-03-27 02:35:13 +00002356 TargetSP target_sp(GetTargetSP());
Enrico Granata5d5f60c2013-09-24 22:58:37 +00002357 if (target_sp && target_sp->GetEnableSyntheticValue() == false)
Enrico Granatac5bc4122012-03-27 02:35:13 +00002358 {
2359 m_synthetic_value = NULL;
2360 return;
2361 }
2362
Enrico Granatae3e91512012-10-22 18:18:36 +00002363 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2364
Enrico Granata5548cb52013-01-28 23:47:25 +00002365 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002366 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002367
Enrico Granata0c489f52012-03-01 04:24:26 +00002368 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002369 return;
2370
Enrico Granatae3e91512012-10-22 18:18:36 +00002371 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2372 return;
2373
Enrico Granata86cc9822012-03-19 22:58:49 +00002374 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002375}
2376
Jim Ingham78a685a2011-04-16 00:01:13 +00002377void
Greg Claytonafacd142011-09-02 01:15:17 +00002378ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002379{
Greg Claytonafacd142011-09-02 01:15:17 +00002380 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002381 return;
2382
Jim Ingham58b59f92011-04-22 23:53:53 +00002383 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002384 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002385 ExecutionContext exe_ctx (GetExecutionContextRef());
2386 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002387 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002388 {
2389 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002390 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002391 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002392 }
2393}
2394
Jim Ingham58b59f92011-04-22 23:53:53 +00002395ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002396ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002397{
Greg Claytonafacd142011-09-02 01:15:17 +00002398 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002399 return ValueObjectSP();
2400
2401 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002402 {
Jim Ingham2837b762011-05-04 03:43:18 +00002403 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002404 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002405 if (m_dynamic_value)
2406 return m_dynamic_value->GetSP();
2407 else
2408 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002409}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002410
Jim Ingham60dbabb2011-12-08 19:44:08 +00002411ValueObjectSP
2412ValueObject::GetStaticValue()
2413{
2414 return GetSP();
2415}
2416
Enrico Granata886147f2012-05-08 18:47:08 +00002417lldb::ValueObjectSP
2418ValueObject::GetNonSyntheticValue ()
2419{
2420 return GetSP();
2421}
2422
Enrico Granatad55546b2011-07-22 00:16:08 +00002423ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002424ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002425{
Enrico Granata86cc9822012-03-19 22:58:49 +00002426 if (use_synthetic == false)
2427 return ValueObjectSP();
2428
Enrico Granatad55546b2011-07-22 00:16:08 +00002429 CalculateSyntheticValue(use_synthetic);
2430
2431 if (m_synthetic_value)
2432 return m_synthetic_value->GetSP();
2433 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002434 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002435}
2436
Greg Claytone221f822011-01-21 01:59:00 +00002437bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002438ValueObject::HasSyntheticValue()
2439{
Enrico Granata5548cb52013-01-28 23:47:25 +00002440 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002441
Enrico Granata0c489f52012-03-01 04:24:26 +00002442 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002443 return false;
2444
Enrico Granata86cc9822012-03-19 22:58:49 +00002445 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002446
2447 if (m_synthetic_value)
2448 return true;
2449 else
2450 return false;
2451}
2452
2453bool
Greg Claytone221f822011-01-21 01:59:00 +00002454ValueObject::GetBaseClassPath (Stream &s)
2455{
2456 if (IsBaseClass())
2457 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002458 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002459 CompilerType compiler_type = GetCompilerType();
Greg Claytone221f822011-01-21 01:59:00 +00002460 std::string cxx_class_name;
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002461 bool this_had_base_class = ClangASTContext::GetCXXClassName (compiler_type, cxx_class_name);
Greg Claytone221f822011-01-21 01:59:00 +00002462 if (this_had_base_class)
2463 {
2464 if (parent_had_base_class)
2465 s.PutCString("::");
2466 s.PutCString(cxx_class_name.c_str());
2467 }
2468 return parent_had_base_class || this_had_base_class;
2469 }
2470 return false;
2471}
2472
2473
2474ValueObject *
2475ValueObject::GetNonBaseClassParent()
2476{
Jim Ingham78a685a2011-04-16 00:01:13 +00002477 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002478 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002479 if (GetParent()->IsBaseClass())
2480 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002481 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002482 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002483 }
2484 return NULL;
2485}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002486
Enrico Granataa3c8f042014-08-19 22:29:08 +00002487
2488bool
2489ValueObject::IsBaseClass (uint32_t& depth)
2490{
2491 if (!IsBaseClass())
2492 {
2493 depth = 0;
2494 return false;
2495 }
2496 if (GetParent())
2497 {
2498 GetParent()->IsBaseClass(depth);
2499 depth = depth + 1;
2500 return true;
2501 }
2502 // TODO: a base of no parent? weird..
2503 depth = 1;
2504 return true;
2505}
2506
Greg Clayton1d3afba2010-10-05 00:00:42 +00002507void
Enrico Granata4becb372011-06-29 22:27:15 +00002508ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002509{
Enrico Granata986fa5f2014-12-09 21:41:16 +00002510 // synthetic children do not actually "exist" as part of the hierarchy, and sometimes they are consed up in ways
2511 // that don't make sense from an underlying language/API standpoint. So, use a special code path here to return
2512 // something that can hopefully be used in expression
2513 if (m_is_synthetic_children_generated)
2514 {
2515 UpdateValueIfNeeded();
2516
2517 if (m_value.GetValueType() == Value::eValueTypeLoadAddress)
2518 {
2519 if (IsPointerOrReferenceType())
2520 {
2521 s.Printf("((%s)0x%" PRIx64 ")",
2522 GetTypeName().AsCString("void"),
2523 GetValueAsUnsigned(0));
2524 return;
2525 }
2526 else
2527 {
2528 uint64_t load_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
2529 if (load_addr != LLDB_INVALID_ADDRESS)
2530 {
2531 s.Printf("(*( (%s *)0x%" PRIx64 "))",
2532 GetTypeName().AsCString("void"),
2533 load_addr);
2534 return;
2535 }
2536 }
2537 }
2538
2539 if (CanProvideValue())
2540 {
2541 s.Printf("((%s)%s)",
2542 GetTypeName().AsCString("void"),
2543 GetValueAsCString());
2544 return;
2545 }
2546
2547 return;
2548 }
2549
Greg Claytone221f822011-01-21 01:59:00 +00002550 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002551
Enrico Granata86cc9822012-03-19 22:58:49 +00002552 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002553 {
Enrico Granata4becb372011-06-29 22:27:15 +00002554 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2555 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2556 // the eHonorPointers mode is meant to produce strings in this latter format
2557 s.PutCString("*(");
2558 }
Greg Claytone221f822011-01-21 01:59:00 +00002559
Enrico Granata4becb372011-06-29 22:27:15 +00002560 ValueObject* parent = GetParent();
2561
2562 if (parent)
2563 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002564
2565 // if we are a deref_of_parent just because we are synthetic array
2566 // members made up to allow ptr[%d] syntax to work in variable
2567 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002568 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002569 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002570
Greg Claytone221f822011-01-21 01:59:00 +00002571 if (!IsBaseClass())
2572 {
2573 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002574 {
Greg Claytone221f822011-01-21 01:59:00 +00002575 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2576 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002577 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002578 CompilerType non_base_class_parent_compiler_type = non_base_class_parent->GetCompilerType();
2579 if (non_base_class_parent_compiler_type)
Greg Claytone221f822011-01-21 01:59:00 +00002580 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002581 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002582 {
2583 s.PutCString("->");
2584 }
Enrico Granata4becb372011-06-29 22:27:15 +00002585 else
2586 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002587 const uint32_t non_base_class_parent_type_info = non_base_class_parent_compiler_type.GetTypeInfo();
Greg Clayton57ee3062013-07-11 22:46:58 +00002588
Enrico Granata622be232014-10-21 20:52:14 +00002589 if (non_base_class_parent_type_info & eTypeIsPointer)
Enrico Granata4becb372011-06-29 22:27:15 +00002590 {
2591 s.PutCString("->");
2592 }
Enrico Granata622be232014-10-21 20:52:14 +00002593 else if ((non_base_class_parent_type_info & eTypeHasChildren) &&
2594 !(non_base_class_parent_type_info & eTypeIsArray))
Enrico Granata4becb372011-06-29 22:27:15 +00002595 {
2596 s.PutChar('.');
2597 }
Greg Claytone221f822011-01-21 01:59:00 +00002598 }
2599 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002600 }
Greg Claytone221f822011-01-21 01:59:00 +00002601
2602 const char *name = GetName().GetCString();
2603 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002604 {
Greg Claytone221f822011-01-21 01:59:00 +00002605 if (qualify_cxx_base_classes)
2606 {
2607 if (GetBaseClassPath (s))
2608 s.PutCString("::");
2609 }
2610 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002611 }
2612 }
2613 }
2614
Enrico Granata86cc9822012-03-19 22:58:49 +00002615 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002616 {
Greg Claytone221f822011-01-21 01:59:00 +00002617 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002618 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002619}
2620
Greg Claytonafacd142011-09-02 01:15:17 +00002621ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002622ValueObject::GetValueForExpressionPath(const char* expression,
2623 const char** first_unparsed,
2624 ExpressionPathScanEndReason* reason_to_stop,
2625 ExpressionPathEndResultType* final_value_type,
2626 const GetValueForExpressionPathOptions& options,
2627 ExpressionPathAftermath* final_task_on_target)
2628{
2629
2630 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002631 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2632 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002633 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002634
2635 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2636 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2637 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2638 final_value_type ? final_value_type : &dummy_final_value_type,
2639 options,
2640 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2641
Enrico Granata86cc9822012-03-19 22:58:49 +00002642 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002643 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002644
Enrico Granata86cc9822012-03-19 22:58:49 +00002645 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 +00002646 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002647 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002648 {
2649 Error error;
2650 ValueObjectSP final_value = ret_val->Dereference(error);
2651 if (error.Fail() || !final_value.get())
2652 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002653 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002654 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002655 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002656 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002657 return ValueObjectSP();
2658 }
2659 else
2660 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002661 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002662 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002663 return final_value;
2664 }
2665 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002666 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002667 {
2668 Error error;
2669 ValueObjectSP final_value = ret_val->AddressOf(error);
2670 if (error.Fail() || !final_value.get())
2671 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002672 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002673 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002674 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002675 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002676 return ValueObjectSP();
2677 }
2678 else
2679 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002680 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002681 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002682 return final_value;
2683 }
2684 }
2685 }
2686 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2687}
2688
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002689int
2690ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002691 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002692 const char** first_unparsed,
2693 ExpressionPathScanEndReason* reason_to_stop,
2694 ExpressionPathEndResultType* final_value_type,
2695 const GetValueForExpressionPathOptions& options,
2696 ExpressionPathAftermath* final_task_on_target)
2697{
2698 const char* dummy_first_unparsed;
2699 ExpressionPathScanEndReason dummy_reason_to_stop;
2700 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002701 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002702
2703 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2704 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2705 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2706 final_value_type ? final_value_type : &dummy_final_value_type,
2707 options,
2708 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2709
2710 if (!ret_val.get()) // if there are errors, I add nothing to the list
2711 return 0;
2712
Enrico Granata86ea8d82012-03-29 01:34:34 +00002713 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002714 {
2715 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002716 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002717 {
2718 list->Append(ret_val);
2719 return 1;
2720 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002721 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 +00002722 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002723 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002724 {
2725 Error error;
2726 ValueObjectSP final_value = ret_val->Dereference(error);
2727 if (error.Fail() || !final_value.get())
2728 {
Greg Clayton23f59502012-07-17 03:23:13 +00002729 if (reason_to_stop)
2730 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2731 if (final_value_type)
2732 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002733 return 0;
2734 }
2735 else
2736 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002737 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002738 list->Append(final_value);
2739 return 1;
2740 }
2741 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002742 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002743 {
2744 Error error;
2745 ValueObjectSP final_value = ret_val->AddressOf(error);
2746 if (error.Fail() || !final_value.get())
2747 {
Greg Clayton23f59502012-07-17 03:23:13 +00002748 if (reason_to_stop)
2749 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2750 if (final_value_type)
2751 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002752 return 0;
2753 }
2754 else
2755 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002756 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002757 list->Append(final_value);
2758 return 1;
2759 }
2760 }
2761 }
2762 }
2763 else
2764 {
2765 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2766 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2767 ret_val,
2768 list,
2769 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2770 final_value_type ? final_value_type : &dummy_final_value_type,
2771 options,
2772 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2773 }
2774 // in any non-covered case, just do the obviously right thing
2775 list->Append(ret_val);
2776 return 1;
2777}
2778
Greg Claytonafacd142011-09-02 01:15:17 +00002779ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002780ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2781 const char** first_unparsed,
2782 ExpressionPathScanEndReason* reason_to_stop,
2783 ExpressionPathEndResultType* final_result,
2784 const GetValueForExpressionPathOptions& options,
2785 ExpressionPathAftermath* what_next)
2786{
2787 ValueObjectSP root = GetSP();
2788
2789 if (!root.get())
2790 return ValueObjectSP();
2791
2792 *first_unparsed = expression_cstr;
2793
2794 while (true)
2795 {
2796
2797 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2798
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002799 CompilerType root_compiler_type = root->GetCompilerType();
2800 CompilerType pointee_compiler_type;
2801 Flags pointee_compiler_type_info;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002802
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002803 Flags root_compiler_type_info(root_compiler_type.GetTypeInfo(&pointee_compiler_type));
2804 if (pointee_compiler_type)
2805 pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002806
2807 if (!expression_cstr || *expression_cstr == '\0')
2808 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002809 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002810 return root;
2811 }
2812
2813 switch (*expression_cstr)
2814 {
2815 case '-':
2816 {
2817 if (options.m_check_dot_vs_arrow_syntax &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002818 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 +00002819 {
2820 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002821 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2822 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002823 return ValueObjectSP();
2824 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002825 if (root_compiler_type_info.Test(eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2826 root_compiler_type_info.Test(eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002827 options.m_no_fragile_ivar)
2828 {
2829 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002830 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2831 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002832 return ValueObjectSP();
2833 }
2834 if (expression_cstr[1] != '>')
2835 {
2836 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002837 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2838 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002839 return ValueObjectSP();
2840 }
2841 expression_cstr++; // skip the -
2842 }
2843 case '.': // or fallthrough from ->
2844 {
2845 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002846 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 +00002847 {
2848 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002849 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2850 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002851 return ValueObjectSP();
2852 }
2853 expression_cstr++; // skip .
2854 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2855 ConstString child_name;
2856 if (!next_separator) // if no other separator just expand this last layer
2857 {
2858 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002859 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2860
2861 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002862 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002863 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002864 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2865 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002866 return child_valobj_sp;
2867 }
Enrico Granataef238c12015-03-12 22:30:58 +00002868 else
Enrico Granata8c9d3562011-08-11 17:08:01 +00002869 {
Enrico Granataef238c12015-03-12 22:30:58 +00002870 switch (options.m_synthetic_children_traversal)
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002871 {
Enrico Granataef238c12015-03-12 22:30:58 +00002872 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None:
2873 break;
2874 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic:
2875 if (root->IsSynthetic())
2876 {
2877 child_valobj_sp = root->GetNonSyntheticValue();
2878 if (child_valobj_sp.get())
2879 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2880 }
2881 break;
2882 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic:
2883 if (!root->IsSynthetic())
2884 {
2885 child_valobj_sp = root->GetSyntheticValue();
2886 if (child_valobj_sp.get())
2887 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2888 }
2889 break;
2890 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both:
2891 if (root->IsSynthetic())
2892 {
2893 child_valobj_sp = root->GetNonSyntheticValue();
2894 if (child_valobj_sp.get())
2895 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2896 }
2897 else
2898 {
2899 child_valobj_sp = root->GetSyntheticValue();
2900 if (child_valobj_sp.get())
2901 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2902 }
2903 break;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002904 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002905 }
2906
2907 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2908 // so we hit the "else" branch, and return an error
2909 if(child_valobj_sp.get()) // if it worked, just return
2910 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002911 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002912 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2913 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002914 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002915 }
2916 else
2917 {
2918 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002919 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2920 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002921 return ValueObjectSP();
2922 }
2923 }
2924 else // other layers do expand
2925 {
2926 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002927 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2928 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002929 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002930 root = child_valobj_sp;
2931 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002932 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002933 continue;
2934 }
Enrico Granataef238c12015-03-12 22:30:58 +00002935 else
Enrico Granata8c9d3562011-08-11 17:08:01 +00002936 {
Enrico Granataef238c12015-03-12 22:30:58 +00002937 switch (options.m_synthetic_children_traversal)
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002938 {
Enrico Granataef238c12015-03-12 22:30:58 +00002939 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None:
2940 break;
2941 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic:
2942 if (root->IsSynthetic())
2943 {
2944 child_valobj_sp = root->GetNonSyntheticValue();
2945 if (child_valobj_sp.get())
2946 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2947 }
2948 break;
2949 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic:
2950 if (!root->IsSynthetic())
2951 {
2952 child_valobj_sp = root->GetSyntheticValue();
2953 if (child_valobj_sp.get())
2954 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2955 }
2956 break;
2957 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both:
2958 if (root->IsSynthetic())
2959 {
2960 child_valobj_sp = root->GetNonSyntheticValue();
2961 if (child_valobj_sp.get())
2962 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2963 }
2964 else
2965 {
2966 child_valobj_sp = root->GetSyntheticValue();
2967 if (child_valobj_sp.get())
2968 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2969 }
2970 break;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002971 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002972 }
2973
2974 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2975 // so we hit the "else" branch, and return an error
2976 if(child_valobj_sp.get()) // if it worked, move on
2977 {
2978 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002979 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002980 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002981 continue;
2982 }
2983 else
2984 {
2985 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002986 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2987 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002988 return ValueObjectSP();
2989 }
2990 }
2991 break;
2992 }
2993 case '[':
2994 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002995 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 +00002996 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002997 if (!root_compiler_type_info.Test(eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002998 {
Enrico Granataef238c12015-03-12 22:30:58 +00002999 if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None) // ...only chance left is synthetic
Enrico Granata27b625e2011-08-09 01:04:56 +00003000 {
3001 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003002 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3003 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003004 return ValueObjectSP();
3005 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003006 }
3007 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3008 {
3009 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003010 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3011 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003012 return ValueObjectSP();
3013 }
3014 }
3015 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3016 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003017 if (!root_compiler_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003018 {
3019 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003020 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3021 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003022 return ValueObjectSP();
3023 }
3024 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
3025 {
3026 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003027 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3028 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003029 return root;
3030 }
3031 }
3032 const char *separator_position = ::strchr(expression_cstr+1,'-');
3033 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3034 if (!close_bracket_position) // if there is no ], this is a syntax error
3035 {
3036 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003037 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3038 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003039 return ValueObjectSP();
3040 }
3041 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3042 {
3043 char *end = NULL;
3044 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3045 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3046 {
3047 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003048 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3049 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003050 return ValueObjectSP();
3051 }
3052 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3053 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003054 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003055 {
3056 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003057 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3058 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003059 return root;
3060 }
3061 else
3062 {
3063 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003064 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3065 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003066 return ValueObjectSP();
3067 }
3068 }
3069 // from here on we do have a valid index
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003070 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003071 {
Greg Claytondaf515f2011-07-09 20:12:33 +00003072 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
3073 if (!child_valobj_sp)
Bruce Mitchener11d86362015-02-26 23:55:39 +00003074 child_valobj_sp = root->GetSyntheticArrayMember(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003075 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00003076 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
3077 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00003078 if (child_valobj_sp)
3079 {
3080 root = child_valobj_sp;
3081 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003082 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00003083 continue;
3084 }
3085 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003086 {
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 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003092 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003093 else if (root_compiler_type_info.Test(eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003094 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003095 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 +00003096 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003097 {
3098 Error error;
3099 root = root->Dereference(error);
3100 if (error.Fail() || !root.get())
3101 {
3102 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003103 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3104 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003105 return ValueObjectSP();
3106 }
3107 else
3108 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003109 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003110 continue;
3111 }
3112 }
3113 else
3114 {
Greg Clayton99558cc42015-08-24 23:46:31 +00003115 if (root->GetCompilerType().GetMinimumLanguage() == eLanguageTypeObjC
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003116 && pointee_compiler_type_info.AllClear(eTypeIsPointer)
Greg Clayton84db9102012-03-26 23:03:23 +00003117 && root->HasSyntheticValue()
Enrico Granataef238c12015-03-12 22:30:58 +00003118 && (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic ||
3119 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both))
Enrico Granata27b625e2011-08-09 01:04:56 +00003120 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003121 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003122 }
3123 else
Bruce Mitchener11d86362015-02-26 23:55:39 +00003124 root = root->GetSyntheticArrayMember(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003125 if (!root.get())
3126 {
3127 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003128 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3129 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003130 return ValueObjectSP();
3131 }
3132 else
3133 {
3134 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003135 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003136 continue;
3137 }
3138 }
3139 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003140 else if (root_compiler_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003141 {
3142 root = root->GetSyntheticBitFieldChild(index, index, true);
3143 if (!root.get())
3144 {
3145 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003146 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3147 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003148 return ValueObjectSP();
3149 }
3150 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3151 {
3152 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003153 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3154 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003155 return root;
3156 }
3157 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003158 else if (root_compiler_type_info.Test(eTypeIsVector))
Enrico Granata08a1bb82013-06-19 00:00:45 +00003159 {
3160 root = root->GetChildAtIndex(index, true);
3161 if (!root.get())
3162 {
3163 *first_unparsed = expression_cstr;
3164 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3165 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3166 return ValueObjectSP();
3167 }
3168 else
3169 {
3170 *first_unparsed = end+1; // skip ]
3171 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3172 continue;
3173 }
3174 }
Enrico Granataef238c12015-03-12 22:30:58 +00003175 else if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic ||
3176 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both)
Enrico Granata27b625e2011-08-09 01:04:56 +00003177 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003178 if (root->HasSyntheticValue())
3179 root = root->GetSyntheticValue();
3180 else if (!root->IsSynthetic())
3181 {
3182 *first_unparsed = expression_cstr;
3183 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3184 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3185 return ValueObjectSP();
3186 }
3187 // if we are here, then root itself is a synthetic VO.. should be good to go
3188
Enrico Granata27b625e2011-08-09 01:04:56 +00003189 if (!root.get())
3190 {
3191 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003192 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3193 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3194 return ValueObjectSP();
3195 }
3196 root = root->GetChildAtIndex(index, true);
3197 if (!root.get())
3198 {
3199 *first_unparsed = expression_cstr;
3200 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3201 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003202 return ValueObjectSP();
3203 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00003204 else
3205 {
3206 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003207 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00003208 continue;
3209 }
Enrico Granata27b625e2011-08-09 01:04:56 +00003210 }
3211 else
3212 {
3213 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003214 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3215 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003216 return ValueObjectSP();
3217 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003218 }
3219 else // we have a low and a high index
3220 {
3221 char *end = NULL;
3222 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3223 if (!end || end != separator_position) // if something weird is in our way return an error
3224 {
3225 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003226 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3227 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003228 return ValueObjectSP();
3229 }
3230 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3231 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3232 {
3233 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003234 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3235 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003236 return ValueObjectSP();
3237 }
3238 if (index_lower > index_higher) // swap indices if required
3239 {
3240 unsigned long temp = index_lower;
3241 index_lower = index_higher;
3242 index_higher = temp;
3243 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003244 if (root_compiler_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003245 {
3246 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3247 if (!root.get())
3248 {
3249 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003250 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3251 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003252 return ValueObjectSP();
3253 }
3254 else
3255 {
3256 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003257 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3258 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003259 return root;
3260 }
3261 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003262 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 +00003263 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003264 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003265 {
3266 Error error;
3267 root = root->Dereference(error);
3268 if (error.Fail() || !root.get())
3269 {
3270 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003271 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3272 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003273 return ValueObjectSP();
3274 }
3275 else
3276 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003277 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003278 continue;
3279 }
3280 }
3281 else
3282 {
3283 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003284 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3285 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003286 return root;
3287 }
3288 }
3289 break;
3290 }
3291 default: // some non-separator is in the way
3292 {
3293 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003294 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3295 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003296 return ValueObjectSP();
3297 break;
3298 }
3299 }
3300 }
3301}
3302
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003303int
3304ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3305 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00003306 ValueObjectSP root,
3307 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003308 ExpressionPathScanEndReason* reason_to_stop,
3309 ExpressionPathEndResultType* final_result,
3310 const GetValueForExpressionPathOptions& options,
3311 ExpressionPathAftermath* what_next)
3312{
3313 if (!root.get())
3314 return 0;
3315
3316 *first_unparsed = expression_cstr;
3317
3318 while (true)
3319 {
3320
3321 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3322
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003323 CompilerType root_compiler_type = root->GetCompilerType();
3324 CompilerType pointee_compiler_type;
3325 Flags pointee_compiler_type_info;
3326 Flags root_compiler_type_info(root_compiler_type.GetTypeInfo(&pointee_compiler_type));
3327 if (pointee_compiler_type)
3328 pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003329
3330 if (!expression_cstr || *expression_cstr == '\0')
3331 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003332 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003333 list->Append(root);
3334 return 1;
3335 }
3336
3337 switch (*expression_cstr)
3338 {
3339 case '[':
3340 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003341 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 +00003342 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003343 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 +00003344 {
3345 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003346 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3347 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003348 return 0;
3349 }
3350 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3351 {
3352 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003353 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3354 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003355 return 0;
3356 }
3357 }
3358 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3359 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003360 if (!root_compiler_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003361 {
3362 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003363 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3364 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003365 return 0;
3366 }
3367 else // expand this into list
3368 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003369 const size_t max_index = root->GetNumChildren() - 1;
3370 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003371 {
3372 ValueObjectSP child =
3373 root->GetChildAtIndex(index, true);
3374 list->Append(child);
3375 }
3376 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003377 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3378 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003379 return max_index; // tell me number of items I added to the VOList
3380 }
3381 }
3382 const char *separator_position = ::strchr(expression_cstr+1,'-');
3383 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3384 if (!close_bracket_position) // if there is no ], this is a syntax error
3385 {
3386 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003387 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3388 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003389 return 0;
3390 }
3391 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3392 {
3393 char *end = NULL;
3394 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3395 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3396 {
3397 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003398 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3399 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003400 return 0;
3401 }
3402 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3403 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003404 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003405 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003406 const size_t max_index = root->GetNumChildren() - 1;
3407 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003408 {
3409 ValueObjectSP child =
3410 root->GetChildAtIndex(index, true);
3411 list->Append(child);
3412 }
3413 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003414 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3415 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003416 return max_index; // tell me number of items I added to the VOList
3417 }
3418 else
3419 {
3420 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003421 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3422 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003423 return 0;
3424 }
3425 }
3426 // from here on we do have a valid index
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003427 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003428 {
3429 root = root->GetChildAtIndex(index, true);
3430 if (!root.get())
3431 {
3432 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003433 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3434 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003435 return 0;
3436 }
3437 else
3438 {
3439 list->Append(root);
3440 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003441 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3442 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003443 return 1;
3444 }
3445 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003446 else if (root_compiler_type_info.Test(eTypeIsPointer))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003447 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003448 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 +00003449 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003450 {
3451 Error error;
3452 root = root->Dereference(error);
3453 if (error.Fail() || !root.get())
3454 {
3455 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003456 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3457 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003458 return 0;
3459 }
3460 else
3461 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003462 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003463 continue;
3464 }
3465 }
3466 else
3467 {
Bruce Mitchener11d86362015-02-26 23:55:39 +00003468 root = root->GetSyntheticArrayMember(index, true);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003469 if (!root.get())
3470 {
3471 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003472 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3473 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003474 return 0;
3475 }
3476 else
3477 {
3478 list->Append(root);
3479 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003480 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3481 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003482 return 1;
3483 }
3484 }
3485 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003486 else /*if (ClangASTContext::IsScalarType(root_compiler_type))*/
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003487 {
3488 root = root->GetSyntheticBitFieldChild(index, index, true);
3489 if (!root.get())
3490 {
3491 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003492 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3493 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003494 return 0;
3495 }
3496 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3497 {
3498 list->Append(root);
3499 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003500 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3501 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003502 return 1;
3503 }
3504 }
3505 }
3506 else // we have a low and a high index
3507 {
3508 char *end = NULL;
3509 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3510 if (!end || end != separator_position) // if something weird is in our way return an error
3511 {
3512 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003513 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3514 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003515 return 0;
3516 }
3517 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3518 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3519 {
3520 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003521 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3522 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003523 return 0;
3524 }
3525 if (index_lower > index_higher) // swap indices if required
3526 {
3527 unsigned long temp = index_lower;
3528 index_lower = index_higher;
3529 index_higher = temp;
3530 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003531 if (root_compiler_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003532 {
3533 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3534 if (!root.get())
3535 {
3536 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003537 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3538 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003539 return 0;
3540 }
3541 else
3542 {
3543 list->Append(root);
3544 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003545 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3546 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003547 return 1;
3548 }
3549 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003550 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 +00003551 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003552 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003553 {
3554 Error error;
3555 root = root->Dereference(error);
3556 if (error.Fail() || !root.get())
3557 {
3558 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003559 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3560 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003561 return 0;
3562 }
3563 else
3564 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003565 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003566 continue;
3567 }
3568 }
3569 else
3570 {
Johnny Chen44805302011-07-19 19:48:13 +00003571 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003572 index <= index_higher; index++)
3573 {
3574 ValueObjectSP child =
3575 root->GetChildAtIndex(index, true);
3576 list->Append(child);
3577 }
3578 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003579 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3580 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003581 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3582 }
3583 }
3584 break;
3585 }
3586 default: // some non-[ separator, or something entirely wrong, is in the way
3587 {
3588 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003589 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3590 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003591 return 0;
3592 break;
3593 }
3594 }
3595 }
3596}
3597
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003598void
3599ValueObject::LogValueObject (Log *log)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003600{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003601 if (log)
Enrico Granatad5957332015-06-03 20:43:54 +00003602 return LogValueObject (log, DumpValueObjectOptions(*this));
Greg Clayton1d3afba2010-10-05 00:00:42 +00003603}
3604
Enrico Granata0c489f52012-03-01 04:24:26 +00003605void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003606ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003607{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003608 if (log)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003609 {
3610 StreamString s;
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003611 Dump (s, options);
Greg Claytonf830dbb2012-03-22 18:15:37 +00003612 if (s.GetSize())
3613 log->PutCString(s.GetData());
3614 }
3615}
3616
3617void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003618ValueObject::Dump (Stream &s)
Enrico Granata0c489f52012-03-01 04:24:26 +00003619{
Enrico Granatad5957332015-06-03 20:43:54 +00003620 Dump (s, DumpValueObjectOptions(*this));
Enrico Granata0c489f52012-03-01 04:24:26 +00003621}
3622
3623void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003624ValueObject::Dump (Stream &s,
3625 const DumpValueObjectOptions& options)
Enrico Granata0c489f52012-03-01 04:24:26 +00003626{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003627 ValueObjectPrinter printer(this,&s,options);
3628 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003629}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003630
3631ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003632ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003633{
3634 ValueObjectSP valobj_sp;
3635
Enrico Granatac3e320a2011-08-02 17:27:39 +00003636 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003637 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003638 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003639
3640 DataExtractor data;
3641 data.SetByteOrder (m_data.GetByteOrder());
3642 data.SetAddressByteSize(m_data.GetAddressByteSize());
3643
Enrico Granata9f1e2042012-04-24 22:15:37 +00003644 if (IsBitfield())
3645 {
3646 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
Greg Clayton57ee3062013-07-11 22:46:58 +00003647 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Enrico Granata9f1e2042012-04-24 22:15:37 +00003648 }
3649 else
Greg Clayton57ee3062013-07-11 22:46:58 +00003650 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003651
3652 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton99558cc42015-08-24 23:46:31 +00003653 GetCompilerType(),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003654 name,
3655 data,
3656 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003657 }
Jim Ingham6035b672011-03-31 00:19:25 +00003658
3659 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003660 {
Greg Claytoneeb15652013-12-10 23:16:40 +00003661 ExecutionContext exe_ctx (GetExecutionContextRef());
3662 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003663 }
3664 return valobj_sp;
3665}
3666
Enrico Granata538a88a2014-10-09 18:24:30 +00003667ValueObjectSP
3668ValueObject::GetQualifiedRepresentationIfAvailable (lldb::DynamicValueType dynValue,
3669 bool synthValue)
3670{
3671 ValueObjectSP result_sp(GetSP());
3672
3673 switch (dynValue)
3674 {
3675 case lldb::eDynamicCanRunTarget:
3676 case lldb::eDynamicDontRunTarget:
3677 {
3678 if (!result_sp->IsDynamic())
3679 {
3680 if (result_sp->GetDynamicValue(dynValue))
3681 result_sp = result_sp->GetDynamicValue(dynValue);
3682 }
3683 }
3684 break;
3685 case lldb::eNoDynamicValues:
Enrico Granata538a88a2014-10-09 18:24:30 +00003686 {
3687 if (result_sp->IsDynamic())
3688 {
3689 if (result_sp->GetStaticValue())
3690 result_sp = result_sp->GetStaticValue();
3691 }
3692 }
3693 break;
3694 }
3695
3696 if (synthValue)
3697 {
3698 if (!result_sp->IsSynthetic())
3699 {
3700 if (result_sp->GetSyntheticValue())
3701 result_sp = result_sp->GetSyntheticValue();
3702 }
3703 }
3704 else
3705 {
3706 if (result_sp->IsSynthetic())
3707 {
3708 if (result_sp->GetNonSyntheticValue())
3709 result_sp = result_sp->GetNonSyntheticValue();
3710 }
3711 }
3712
3713 return result_sp;
3714}
3715
Greg Clayton759e7442014-07-19 00:12:57 +00003716lldb::addr_t
3717ValueObject::GetCPPVTableAddress (AddressType &address_type)
3718{
Greg Claytona1e5dc82015-08-11 22:53:00 +00003719 CompilerType pointee_type;
Greg Clayton99558cc42015-08-24 23:46:31 +00003720 CompilerType this_type(GetCompilerType());
Greg Clayton759e7442014-07-19 00:12:57 +00003721 uint32_t type_info = this_type.GetTypeInfo(&pointee_type);
3722 if (type_info)
3723 {
3724 bool ptr_or_ref = false;
Enrico Granata622be232014-10-21 20:52:14 +00003725 if (type_info & (eTypeIsPointer | eTypeIsReference))
Greg Clayton759e7442014-07-19 00:12:57 +00003726 {
3727 ptr_or_ref = true;
3728 type_info = pointee_type.GetTypeInfo();
3729 }
3730
Enrico Granata622be232014-10-21 20:52:14 +00003731 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus;
Greg Clayton759e7442014-07-19 00:12:57 +00003732 if ((type_info & cpp_class) == cpp_class)
3733 {
3734 if (ptr_or_ref)
3735 {
3736 address_type = GetAddressTypeOfChildren();
3737 return GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
3738 }
3739 else
3740 return GetAddressOf (false, &address_type);
3741 }
3742 }
3743
3744 address_type = eAddressTypeInvalid;
3745 return LLDB_INVALID_ADDRESS;
3746}
3747
Greg Claytonafacd142011-09-02 01:15:17 +00003748ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003749ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003750{
Jim Ingham58b59f92011-04-22 23:53:53 +00003751 if (m_deref_valobj)
3752 return m_deref_valobj->GetSP();
Chaoren Lind7bdc272015-07-31 00:35:40 +00003753
3754 const bool is_pointer_or_reference_type = IsPointerOrReferenceType();
3755 if (is_pointer_or_reference_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003756 {
3757 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003758 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003759
3760 std::string child_name_str;
3761 uint32_t child_byte_size = 0;
3762 int32_t child_byte_offset = 0;
3763 uint32_t child_bitfield_bit_size = 0;
3764 uint32_t child_bitfield_bit_offset = 0;
3765 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003766 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003767 const bool transparent_pointers = false;
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003768 CompilerType compiler_type = GetCompilerType();
3769 CompilerType child_compiler_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003770
Greg Claytoncc4d0142012-02-17 07:49:44 +00003771 ExecutionContext exe_ctx (GetExecutionContextRef());
Chaoren Lind7bdc272015-07-31 00:35:40 +00003772
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003773 child_compiler_type = compiler_type.GetChildCompilerTypeAtIndex (&exe_ctx,
3774 0,
3775 transparent_pointers,
3776 omit_empty_base_classes,
3777 ignore_array_bounds,
3778 child_name_str,
3779 child_byte_size,
3780 child_byte_offset,
3781 child_bitfield_bit_size,
3782 child_bitfield_bit_offset,
3783 child_is_base_class,
3784 child_is_deref_of_parent,
3785 this);
3786 if (child_compiler_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003787 {
3788 ConstString child_name;
3789 if (!child_name_str.empty())
3790 child_name.SetCString (child_name_str.c_str());
3791
Jim Ingham58b59f92011-04-22 23:53:53 +00003792 m_deref_valobj = new ValueObjectChild (*this,
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003793 child_compiler_type,
Jim Ingham58b59f92011-04-22 23:53:53 +00003794 child_name,
3795 child_byte_size,
3796 child_byte_offset,
3797 child_bitfield_bit_size,
3798 child_bitfield_bit_offset,
3799 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003800 child_is_deref_of_parent,
3801 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003802 }
3803 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003804
Jim Ingham58b59f92011-04-22 23:53:53 +00003805 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003806 {
3807 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003808 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003809 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003810 else
3811 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003812 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003813 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003814
Chaoren Lind7bdc272015-07-31 00:35:40 +00003815 if (is_pointer_or_reference_type)
Greg Clayton54979cd2010-12-15 05:08:08 +00003816 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3817 else
Chaoren Lind7bdc272015-07-31 00:35:40 +00003818 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 +00003819 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003820 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003821}
3822
Greg Claytonafacd142011-09-02 01:15:17 +00003823ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003824ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003825{
Jim Ingham78a685a2011-04-16 00:01:13 +00003826 if (m_addr_of_valobj_sp)
3827 return m_addr_of_valobj_sp;
3828
Greg Claytone0d378b2011-03-24 21:19:54 +00003829 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003830 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003831 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003832 error.Clear();
Siva Chandraa3747a92015-05-04 19:43:34 +00003833 if (addr != LLDB_INVALID_ADDRESS && address_type != eAddressTypeHost)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003834 {
3835 switch (address_type)
3836 {
3837 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003838 {
3839 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003840 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003841 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3842 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003843 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003844
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003845 case eAddressTypeFile:
3846 case eAddressTypeLoad:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003847 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003848 CompilerType compiler_type = GetCompilerType();
3849 if (compiler_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003850 {
3851 std::string name (1, '&');
3852 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003853 ExecutionContext exe_ctx (GetExecutionContextRef());
3854 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003855 compiler_type.GetPointerType(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003856 ConstString (name.c_str()),
3857 addr,
3858 eAddressTypeInvalid,
3859 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003860 }
3861 }
3862 break;
Siva Chandraa3747a92015-05-04 19:43:34 +00003863 default:
3864 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003865 }
3866 }
Sean Callananed185ab2013-04-19 19:47:32 +00003867 else
3868 {
3869 StreamString expr_path_strm;
3870 GetExpressionPath(expr_path_strm, true);
3871 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3872 }
3873
Jim Ingham78a685a2011-04-16 00:01:13 +00003874 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003875}
3876
Greg Clayton9a142cf2012-02-03 05:34:10 +00003877ValueObjectSP
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003878ValueObject::Cast (const CompilerType &compiler_type)
Greg Clayton9a142cf2012-02-03 05:34:10 +00003879{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003880 return ValueObjectCast::Create (*this, GetName(), compiler_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003881}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003882
Greg Claytonafacd142011-09-02 01:15:17 +00003883ValueObjectSP
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003884ValueObject::CastPointerType (const char *name, CompilerType &compiler_type)
Greg Claytonb2dcc362011-05-05 23:32:56 +00003885{
Greg Claytonafacd142011-09-02 01:15:17 +00003886 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003887 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003888 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003889
3890 if (ptr_value != LLDB_INVALID_ADDRESS)
3891 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003892 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003893 ExecutionContext exe_ctx (GetExecutionContextRef());
3894 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003895 name,
3896 ptr_addr,
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003897 compiler_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003898 }
3899 return valobj_sp;
3900}
3901
Greg Claytonafacd142011-09-02 01:15:17 +00003902ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003903ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3904{
Greg Claytonafacd142011-09-02 01:15:17 +00003905 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003906 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003907 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003908
3909 if (ptr_value != LLDB_INVALID_ADDRESS)
3910 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003911 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003912 ExecutionContext exe_ctx (GetExecutionContextRef());
3913 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003914 name,
3915 ptr_addr,
3916 type_sp);
3917 }
3918 return valobj_sp;
3919}
3920
Jim Ingham6035b672011-03-31 00:19:25 +00003921ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003922 m_mod_id(),
3923 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003924 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003925{
3926}
3927
3928ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003929 m_mod_id(),
3930 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003931 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003932{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003933 ExecutionContext exe_ctx(exe_scope);
3934 TargetSP target_sp (exe_ctx.GetTargetSP());
3935 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003936 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003937 m_exe_ctx_ref.SetTargetSP (target_sp);
3938 ProcessSP process_sp (exe_ctx.GetProcessSP());
3939 if (!process_sp)
3940 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003941
Greg Claytoncc4d0142012-02-17 07:49:44 +00003942 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003943 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003944 m_mod_id = process_sp->GetModID();
3945 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003946
Greg Claytoncc4d0142012-02-17 07:49:44 +00003947 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003948
Greg Claytoncc4d0142012-02-17 07:49:44 +00003949 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003950 {
3951 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003952 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003953 }
Jim Ingham6035b672011-03-31 00:19:25 +00003954
Greg Claytoncc4d0142012-02-17 07:49:44 +00003955 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003956 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003957 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003958
Jason Molendab57e4a12013-11-04 09:33:30 +00003959 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003960 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003961 {
3962 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003963 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003964 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003965 if (frame_sp)
3966 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003967 }
3968 }
3969 }
Jim Ingham6035b672011-03-31 00:19:25 +00003970}
3971
3972ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003973 m_mod_id(),
3974 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003975 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003976{
3977}
3978
3979ValueObject::EvaluationPoint::~EvaluationPoint ()
3980{
3981}
3982
Jim Ingham6035b672011-03-31 00:19:25 +00003983// This function checks the EvaluationPoint against the current process state. If the current
3984// state matches the evaluation point, or the evaluation point is already invalid, then we return
3985// false, meaning "no change". If the current state is different, we update our state, and return
3986// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3987// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003988// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003989
3990bool
Enrico Granatabb642e52015-05-16 01:27:00 +00003991ValueObject::EvaluationPoint::SyncWithProcessState(bool accept_invalid_exe_ctx)
Jim Ingham6035b672011-03-31 00:19:25 +00003992{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003993 // 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 +00003994 const bool thread_and_frame_only_if_stopped = true;
3995 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
Jim Ingham73ca05a2011-12-17 01:35:57 +00003996
Greg Claytoncc4d0142012-02-17 07:49:44 +00003997 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003998 return false;
3999
Jim Ingham6035b672011-03-31 00:19:25 +00004000 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00004001 Process *process = exe_ctx.GetProcessPtr();
4002 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00004003 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00004004
Jim Ingham6035b672011-03-31 00:19:25 +00004005 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00004006 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00004007
Jim Ingham78a685a2011-04-16 00:01:13 +00004008 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
4009 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00004010 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00004011 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00004012
Greg Clayton23f59502012-07-17 03:23:13 +00004013 bool changed = false;
4014 const bool was_valid = m_mod_id.IsValid();
4015 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004016 {
4017 if (m_mod_id == current_mod_id)
4018 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00004019 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004020 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00004021 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004022 }
Jim Ingham9ee01152011-12-10 01:49:43 +00004023 else
4024 {
4025 m_mod_id = current_mod_id;
4026 m_needs_update = true;
4027 changed = true;
4028 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004029 }
Jim Ingham6035b672011-03-31 00:19:25 +00004030
Jim Ingham73ca05a2011-12-17 01:35:57 +00004031 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
4032 // That way we'll be sure to return a valid exe_scope.
4033 // 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 +00004034
Enrico Granatabb642e52015-05-16 01:27:00 +00004035 if (!accept_invalid_exe_ctx)
Jim Ingham6035b672011-03-31 00:19:25 +00004036 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004037 if (m_exe_ctx_ref.HasThreadRef())
Greg Clayton262f80d2011-07-06 16:49:27 +00004038 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004039 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
4040 if (thread_sp)
Greg Claytoncc4d0142012-02-17 07:49:44 +00004041 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004042 if (m_exe_ctx_ref.HasFrameRef())
Greg Claytoncc4d0142012-02-17 07:49:44 +00004043 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004044 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
4045 if (!frame_sp)
4046 {
4047 // We used to have a frame, but now it is gone
4048 SetInvalid();
4049 changed = was_valid;
4050 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00004051 }
4052 }
Enrico Granatabb642e52015-05-16 01:27:00 +00004053 else
4054 {
4055 // We used to have a thread, but now it is gone
4056 SetInvalid();
4057 changed = was_valid;
4058 }
Greg Clayton262f80d2011-07-06 16:49:27 +00004059 }
Jim Ingham6035b672011-03-31 00:19:25 +00004060 }
Enrico Granatabb642e52015-05-16 01:27:00 +00004061
Jim Ingham9ee01152011-12-10 01:49:43 +00004062 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00004063}
4064
Jim Ingham61be0902011-05-02 18:13:59 +00004065void
4066ValueObject::EvaluationPoint::SetUpdated ()
4067{
Greg Claytoncc4d0142012-02-17 07:49:44 +00004068 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
4069 if (process_sp)
4070 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00004071 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00004072}
4073
4074
Enrico Granataf2bbf712011-07-15 02:26:42 +00004075
4076void
Enrico Granata86cc9822012-03-19 22:58:49 +00004077ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004078{
Enrico Granata86cc9822012-03-19 22:58:49 +00004079 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4080 m_value_str.clear();
4081
4082 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4083 m_location_str.clear();
4084
4085 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
Enrico Granata86cc9822012-03-19 22:58:49 +00004086 m_summary_str.clear();
Enrico Granata86cc9822012-03-19 22:58:49 +00004087
4088 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4089 m_object_desc_str.clear();
4090
4091 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4092 {
4093 if (m_synthetic_value)
4094 m_synthetic_value = NULL;
4095 }
Enrico Granata744794a2014-09-05 21:46:22 +00004096
4097 if ((clear_mask & eClearUserVisibleDataItemsValidator) == eClearUserVisibleDataItemsValidator)
4098 m_validation_result.reset();
Johnny Chen44805302011-07-19 19:48:13 +00004099}
Enrico Granata9128ee22011-09-06 19:20:51 +00004100
4101SymbolContextScope *
4102ValueObject::GetSymbolContextScope()
4103{
4104 if (m_parent)
4105 {
4106 if (!m_parent->IsPointerOrReferenceType())
4107 return m_parent->GetSymbolContextScope();
4108 }
4109 return NULL;
4110}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004111
4112lldb::ValueObjectSP
4113ValueObject::CreateValueObjectFromExpression (const char* name,
4114 const char* expression,
4115 const ExecutionContext& exe_ctx)
4116{
Enrico Granata972be532014-12-17 21:18:43 +00004117 return CreateValueObjectFromExpression(name, expression, exe_ctx, EvaluateExpressionOptions());
4118}
4119
4120
4121lldb::ValueObjectSP
4122ValueObject::CreateValueObjectFromExpression (const char* name,
4123 const char* expression,
4124 const ExecutionContext& exe_ctx,
4125 const EvaluateExpressionOptions& options)
4126{
Enrico Granatab2698cd2012-09-13 18:27:09 +00004127 lldb::ValueObjectSP retval_sp;
4128 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4129 if (!target_sp)
4130 return retval_sp;
4131 if (!expression || !*expression)
4132 return retval_sp;
4133 target_sp->EvaluateExpression (expression,
4134 exe_ctx.GetFrameSP().get(),
Enrico Granata972be532014-12-17 21:18:43 +00004135 retval_sp,
4136 options);
Enrico Granatab2698cd2012-09-13 18:27:09 +00004137 if (retval_sp && name && *name)
4138 retval_sp->SetName(ConstString(name));
4139 return retval_sp;
4140}
4141
4142lldb::ValueObjectSP
4143ValueObject::CreateValueObjectFromAddress (const char* name,
4144 uint64_t address,
4145 const ExecutionContext& exe_ctx,
Greg Claytona1e5dc82015-08-11 22:53:00 +00004146 CompilerType type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004147{
Greg Clayton57ee3062013-07-11 22:46:58 +00004148 if (type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004149 {
Greg Claytona1e5dc82015-08-11 22:53:00 +00004150 CompilerType pointer_type(type.GetPointerType());
Greg Clayton57ee3062013-07-11 22:46:58 +00004151 if (pointer_type)
4152 {
4153 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4154 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4155 pointer_type,
4156 ConstString(name),
4157 buffer,
Enrico Granata972be532014-12-17 21:18:43 +00004158 exe_ctx.GetByteOrder(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004159 exe_ctx.GetAddressByteSize()));
4160 if (ptr_result_valobj_sp)
4161 {
4162 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4163 Error err;
4164 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4165 if (ptr_result_valobj_sp && name && *name)
4166 ptr_result_valobj_sp->SetName(ConstString(name));
4167 }
4168 return ptr_result_valobj_sp;
4169 }
Enrico Granatab2698cd2012-09-13 18:27:09 +00004170 }
Greg Clayton57ee3062013-07-11 22:46:58 +00004171 return lldb::ValueObjectSP();
Enrico Granatab2698cd2012-09-13 18:27:09 +00004172}
4173
4174lldb::ValueObjectSP
4175ValueObject::CreateValueObjectFromData (const char* name,
Enrico Granata7ca1c762014-03-31 23:02:25 +00004176 const DataExtractor& data,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004177 const ExecutionContext& exe_ctx,
Greg Claytona1e5dc82015-08-11 22:53:00 +00004178 CompilerType type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004179{
4180 lldb::ValueObjectSP new_value_sp;
4181 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004182 type,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004183 ConstString(name),
4184 data,
4185 LLDB_INVALID_ADDRESS);
4186 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4187 if (new_value_sp && name && *name)
4188 new_value_sp->SetName(ConstString(name));
4189 return new_value_sp;
4190}
Enrico Granata4873e522013-04-11 22:48:58 +00004191
4192ModuleSP
4193ValueObject::GetModule ()
4194{
4195 ValueObject* root(GetRoot());
4196 if (root != this)
4197 return root->GetModule();
4198 return lldb::ModuleSP();
4199}
4200
4201ValueObject*
4202ValueObject::GetRoot ()
4203{
4204 if (m_root)
4205 return m_root;
Enrico Granatade61eba2015-01-22 03:07:34 +00004206 return (m_root = FollowParentChain( [] (ValueObject* vo) -> bool {
4207 return (vo->m_parent != nullptr);
4208 }));
4209}
4210
4211ValueObject*
4212ValueObject::FollowParentChain (std::function<bool(ValueObject*)> f)
4213{
4214 ValueObject* vo = this;
4215 while (vo)
Enrico Granata4873e522013-04-11 22:48:58 +00004216 {
Enrico Granatade61eba2015-01-22 03:07:34 +00004217 if (f(vo) == false)
4218 break;
4219 vo = vo->m_parent;
Enrico Granata4873e522013-04-11 22:48:58 +00004220 }
Enrico Granatade61eba2015-01-22 03:07:34 +00004221 return vo;
Enrico Granata4873e522013-04-11 22:48:58 +00004222}
4223
4224AddressType
4225ValueObject::GetAddressTypeOfChildren()
4226{
4227 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
4228 {
4229 ValueObject* root(GetRoot());
4230 if (root != this)
4231 return root->GetAddressTypeOfChildren();
4232 }
4233 return m_address_type_of_ptr_or_ref_children;
4234}
4235
4236lldb::DynamicValueType
4237ValueObject::GetDynamicValueType ()
4238{
4239 ValueObject* with_dv_info = this;
4240 while (with_dv_info)
4241 {
4242 if (with_dv_info->HasDynamicValueTypeInfo())
4243 return with_dv_info->GetDynamicValueTypeImpl();
4244 with_dv_info = with_dv_info->m_parent;
4245 }
4246 return lldb::eNoDynamicValues;
4247}
Enrico Granata39d51412013-05-31 17:43:40 +00004248
Enrico Granata4873e522013-04-11 22:48:58 +00004249lldb::Format
4250ValueObject::GetFormat () const
4251{
4252 const ValueObject* with_fmt_info = this;
4253 while (with_fmt_info)
4254 {
4255 if (with_fmt_info->m_format != lldb::eFormatDefault)
4256 return with_fmt_info->m_format;
4257 with_fmt_info = with_fmt_info->m_parent;
4258 }
4259 return m_format;
4260}
Enrico Granatad07cfd32014-10-08 18:27:36 +00004261
Enrico Granatac1247f52014-11-06 21:23:20 +00004262lldb::LanguageType
4263ValueObject::GetPreferredDisplayLanguage ()
4264{
Enrico Granataed3228a2015-01-21 01:47:13 +00004265 lldb::LanguageType type = m_preferred_display_language;
4266 if (m_preferred_display_language == lldb::eLanguageTypeUnknown)
Enrico Granatac1247f52014-11-06 21:23:20 +00004267 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004268 if (GetRoot())
Enrico Granatac1247f52014-11-06 21:23:20 +00004269 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004270 if (GetRoot() == this)
Enrico Granatac1247f52014-11-06 21:23:20 +00004271 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004272 if (StackFrameSP frame_sp = GetFrameSP())
4273 {
4274 const SymbolContext& sc(frame_sp->GetSymbolContext(eSymbolContextCompUnit));
4275 if (CompileUnit* cu = sc.comp_unit)
4276 type = cu->GetLanguage();
4277 }
4278 }
4279 else
4280 {
4281 type = GetRoot()->GetPreferredDisplayLanguage();
Enrico Granatac1247f52014-11-06 21:23:20 +00004282 }
4283 }
Enrico Granatac1247f52014-11-06 21:23:20 +00004284 }
Enrico Granataed3228a2015-01-21 01:47:13 +00004285 return (m_preferred_display_language = type); // only compute it once
4286}
4287
4288void
4289ValueObject::SetPreferredDisplayLanguage (lldb::LanguageType lt)
4290{
4291 m_preferred_display_language = lt;
Enrico Granatac1247f52014-11-06 21:23:20 +00004292}
4293
Enrico Granata73e8c4d2015-10-07 02:36:35 +00004294void
4295ValueObject::SetPreferredDisplayLanguageIfNeeded (lldb::LanguageType lt)
4296{
4297 if (m_preferred_display_language == lldb::eLanguageTypeUnknown)
4298 SetPreferredDisplayLanguage(lt);
4299}
4300
Enrico Granatad07cfd32014-10-08 18:27:36 +00004301bool
4302ValueObject::CanProvideValue ()
4303{
Sean Callanan7375f3e2014-12-09 21:18:59 +00004304 // we need to support invalid types as providers of values because some bare-board
4305 // debugging scenarios have no notion of types, but still manage to have raw numeric
4306 // values for things like registers. sigh.
Greg Clayton99558cc42015-08-24 23:46:31 +00004307 const CompilerType &type(GetCompilerType());
Sean Callanan7375f3e2014-12-09 21:18:59 +00004308 return (false == type.IsValid()) || (0 != (type.GetTypeInfo() & eTypeHasValue));
4309}
4310
4311bool
4312ValueObject::IsChecksumEmpty ()
4313{
4314 return m_value_checksum.empty();
Enrico Granatad07cfd32014-10-08 18:27:36 +00004315}
Enrico Granata0c10a852014-12-08 23:13:56 +00004316
4317ValueObjectSP
4318ValueObject::Persist ()
4319{
4320 if (!UpdateValueIfNeeded())
4321 return nullptr;
4322
4323 TargetSP target_sp(GetTargetSP());
4324 if (!target_sp)
4325 return nullptr;
4326
Sean Callananb92bd752015-10-01 16:28:02 +00004327 PersistentExpressionState *persistent_state = target_sp->GetPersistentExpressionStateForLanguage(GetPreferredDisplayLanguage());
Sean Callanan8f1f9a12015-09-30 19:57:57 +00004328
4329 if (!persistent_state)
4330 return nullptr;
4331
4332 ConstString name(persistent_state->GetNextPersistentVariableName());
Enrico Granata0c10a852014-12-08 23:13:56 +00004333
Sean Callanan9301ec12015-10-01 23:07:06 +00004334 ValueObjectSP const_result_sp = ValueObjectConstResult::Create (target_sp.get(), GetValue(), name);
4335
4336 ExpressionVariableSP clang_var_sp = persistent_state->CreatePersistentVariable(const_result_sp);
4337 clang_var_sp->m_live_sp = clang_var_sp->m_frozen_sp;
4338 clang_var_sp->m_flags |= ExpressionVariable::EVIsProgramReference;
Enrico Granata0c10a852014-12-08 23:13:56 +00004339
4340 return clang_var_sp->GetValueObject();
4341}
Enrico Granatae29df232014-12-09 19:51:20 +00004342
4343bool
4344ValueObject::IsSyntheticChildrenGenerated ()
4345{
4346 return m_is_synthetic_children_generated;
4347}
4348
4349void
4350ValueObject::SetSyntheticChildrenGenerated (bool b)
4351{
4352 m_is_synthetic_children_generated = b;
4353}