blob: a784f49b7ffafa954dd6e9a2d512b89c83aeaa8b [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
Greg Clayton288bdf92010-09-02 02:59:18 +0000516ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000517{
Greg Clayton288bdf92010-09-02 02:59:18 +0000518 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000519}
520
521
522void
523ValueObject::SetValueIsValid (bool b)
524{
Greg Clayton288bdf92010-09-02 02:59:18 +0000525 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000526}
527
528bool
Jim Ingham6035b672011-03-31 00:19:25 +0000529ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000530{
Greg Clayton288bdf92010-09-02 02:59:18 +0000531 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000532}
533
534void
535ValueObject::SetValueDidChange (bool value_changed)
536{
Greg Clayton288bdf92010-09-02 02:59:18 +0000537 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000538}
539
540ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000541ValueObject::GetChildAtIndex (size_t idx, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000542{
543 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000544 // We may need to update our value if we are dynamic
545 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000546 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000547 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000548 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000549 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000550 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000551 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000552 // No we haven't created the child at this index, so lets have our
553 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000554 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000555 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000556
Enrico Granata9d60f602012-03-09 03:09:58 +0000557 ValueObject* child = m_children.GetChildAtIndex(idx);
558 if (child != NULL)
559 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000560 }
561 return child_sp;
562}
563
Enrico Granata3309d882013-01-12 01:00:22 +0000564ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000565ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
566 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000567{
568 if (idxs.size() == 0)
569 return GetSP();
570 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000571 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000572 {
573 root = root->GetChildAtIndex(idx, true);
574 if (!root)
575 {
576 if (index_of_error)
577 *index_of_error = idx;
578 return root;
579 }
580 }
581 return root;
582}
583
584ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000585ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
586 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000587{
588 if (idxs.size() == 0)
589 return GetSP();
590 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000591 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000592 {
593 root = root->GetChildAtIndex(idx.first, idx.second);
594 if (!root)
595 {
596 if (index_of_error)
597 *index_of_error = idx.first;
598 return root;
599 }
600 }
601 return root;
602}
603
604lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000605ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
606 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000607{
608 if (idxs.size() == 0)
609 return GetSP();
610 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000611 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000612 {
613 root = root->GetChildAtIndex(idx, true);
614 if (!root)
615 {
616 if (index_of_error)
617 *index_of_error = idx;
618 return root;
619 }
620 }
621 return root;
622}
623
624lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000625ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
626 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000627{
628 if (idxs.size() == 0)
629 return GetSP();
630 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000631 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000632 {
633 root = root->GetChildAtIndex(idx.first, idx.second);
634 if (!root)
635 {
636 if (index_of_error)
637 *index_of_error = idx.first;
638 return root;
639 }
640 }
641 return root;
642}
643
Enrico Granatae2e220a2013-09-12 00:48:47 +0000644lldb::ValueObjectSP
645ValueObject::GetChildAtNamePath (const std::initializer_list<ConstString> &names,
646 ConstString* name_of_error)
647{
648 if (names.size() == 0)
649 return GetSP();
650 ValueObjectSP root(GetSP());
651 for (ConstString name : names)
652 {
653 root = root->GetChildMemberWithName(name, true);
654 if (!root)
655 {
656 if (name_of_error)
657 *name_of_error = name;
658 return root;
659 }
660 }
661 return root;
662}
663
664lldb::ValueObjectSP
665ValueObject::GetChildAtNamePath (const std::vector<ConstString> &names,
666 ConstString* name_of_error)
667{
668 if (names.size() == 0)
669 return GetSP();
670 ValueObjectSP root(GetSP());
671 for (ConstString name : names)
672 {
673 root = root->GetChildMemberWithName(name, true);
674 if (!root)
675 {
676 if (name_of_error)
677 *name_of_error = name;
678 return root;
679 }
680 }
681 return root;
682}
683
684lldb::ValueObjectSP
685ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names,
686 ConstString* name_of_error)
687{
688 if (names.size() == 0)
689 return GetSP();
690 ValueObjectSP root(GetSP());
691 for (std::pair<ConstString, bool> name : names)
692 {
693 root = root->GetChildMemberWithName(name.first, name.second);
694 if (!root)
695 {
696 if (name_of_error)
697 *name_of_error = name.first;
698 return root;
699 }
700 }
701 return root;
702}
703
704lldb::ValueObjectSP
705ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names,
706 ConstString* name_of_error)
707{
708 if (names.size() == 0)
709 return GetSP();
710 ValueObjectSP root(GetSP());
711 for (std::pair<ConstString, bool> name : names)
712 {
713 root = root->GetChildMemberWithName(name.first, name.second);
714 if (!root)
715 {
716 if (name_of_error)
717 *name_of_error = name.first;
718 return root;
719 }
720 }
721 return root;
722}
723
Greg Claytonc7bece562013-01-25 18:06:21 +0000724size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000725ValueObject::GetIndexOfChildWithName (const ConstString &name)
726{
727 bool omit_empty_base_classes = true;
Greg Clayton99558cc42015-08-24 23:46:31 +0000728 return GetCompilerType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000729}
730
731ValueObjectSP
732ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
733{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000734 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000735 // classes (which really aren't part of the expression path), so we
736 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000737 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000738
Greg Claytondea8cb42011-06-29 22:09:02 +0000739 // We may need to update our value if we are dynamic
740 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000741 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000742
743 std::vector<uint32_t> child_indexes;
Greg Claytondea8cb42011-06-29 22:09:02 +0000744 bool omit_empty_base_classes = true;
Greg Clayton99558cc42015-08-24 23:46:31 +0000745 const size_t num_child_indexes = GetCompilerType().GetIndexOfChildMemberWithName (name.GetCString(),
Greg Clayton57ee3062013-07-11 22:46:58 +0000746 omit_empty_base_classes,
747 child_indexes);
Greg Claytondea8cb42011-06-29 22:09:02 +0000748 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000749 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000750 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
751 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
752
753 child_sp = GetChildAtIndex(*pos, can_create);
754 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000755 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000756 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000757 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000758 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
759 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000760 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000761 else
762 {
763 child_sp.reset();
764 }
765
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000766 }
767 }
768 return child_sp;
769}
770
771
Greg Claytonc7bece562013-01-25 18:06:21 +0000772size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000773ValueObject::GetNumChildren ()
774{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000775 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000776 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000777 {
778 SetNumChildren (CalculateNumChildren());
779 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000780 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000781}
Greg Clayton4a792072012-10-23 01:50:10 +0000782
783bool
784ValueObject::MightHaveChildren()
785{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000786 bool has_children = false;
Greg Clayton2452ab72013-02-08 22:02:02 +0000787 const uint32_t type_info = GetTypeInfo();
788 if (type_info)
Greg Clayton4a792072012-10-23 01:50:10 +0000789 {
Enrico Granata622be232014-10-21 20:52:14 +0000790 if (type_info & (eTypeHasChildren |
791 eTypeIsPointer |
792 eTypeIsReference))
Greg Clayton4a792072012-10-23 01:50:10 +0000793 has_children = true;
794 }
795 else
796 {
797 has_children = GetNumChildren () > 0;
798 }
799 return has_children;
800}
801
802// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000803void
Greg Claytonc7bece562013-01-25 18:06:21 +0000804ValueObject::SetNumChildren (size_t num_children)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000805{
Greg Clayton288bdf92010-09-02 02:59:18 +0000806 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000807 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000808}
809
810void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000811ValueObject::SetName (const ConstString &name)
812{
813 m_name = name;
814}
815
Jim Ingham58b59f92011-04-22 23:53:53 +0000816ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000817ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000818{
Jim Ingham2eec4872011-05-07 00:10:58 +0000819 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000820
Greg Claytondea8cb42011-06-29 22:09:02 +0000821 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000822 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000823 std::string child_name_str;
824 uint32_t child_byte_size = 0;
825 int32_t child_byte_offset = 0;
826 uint32_t child_bitfield_bit_size = 0;
827 uint32_t child_bitfield_bit_offset = 0;
828 bool child_is_base_class = false;
829 bool child_is_deref_of_parent = false;
830
831 const bool transparent_pointers = synthetic_array_member == false;
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000832 CompilerType child_compiler_type;
Greg Claytondea8cb42011-06-29 22:09:02 +0000833
Greg Claytoncc4d0142012-02-17 07:49:44 +0000834 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000835
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000836 child_compiler_type = GetCompilerType().GetChildCompilerTypeAtIndex (&exe_ctx,
837 idx,
838 transparent_pointers,
839 omit_empty_base_classes,
840 ignore_array_bounds,
841 child_name_str,
842 child_byte_size,
843 child_byte_offset,
844 child_bitfield_bit_size,
845 child_bitfield_bit_offset,
846 child_is_base_class,
847 child_is_deref_of_parent,
848 this);
849 if (child_compiler_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000850 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000851 if (synthetic_index)
852 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000853
Greg Claytondea8cb42011-06-29 22:09:02 +0000854 ConstString child_name;
855 if (!child_name_str.empty())
856 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000857
Greg Claytondea8cb42011-06-29 22:09:02 +0000858 valobj = new ValueObjectChild (*this,
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000859 child_compiler_type,
Greg Claytondea8cb42011-06-29 22:09:02 +0000860 child_name,
861 child_byte_size,
862 child_byte_offset,
863 child_bitfield_bit_size,
864 child_bitfield_bit_offset,
865 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000866 child_is_deref_of_parent,
867 eAddressTypeInvalid);
868 //if (valobj)
869 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
870 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000871
Jim Ingham58b59f92011-04-22 23:53:53 +0000872 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000873}
874
Enrico Granata0c489f52012-03-01 04:24:26 +0000875bool
876ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
Enrico Granata31fda932015-10-07 01:41:23 +0000877 std::string& destination,
878 lldb::LanguageType lang)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000879{
Enrico Granata31fda932015-10-07 01:41:23 +0000880 return GetSummaryAsCString(summary_ptr, destination, TypeSummaryOptions().SetLanguage(lang));
Enrico Granatac1247f52014-11-06 21:23:20 +0000881}
882
883bool
884ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
885 std::string& destination,
886 const TypeSummaryOptions& options)
887{
Enrico Granata0c489f52012-03-01 04:24:26 +0000888 destination.clear();
Enrico Granata31fda932015-10-07 01:41:23 +0000889
Enrico Granata0c489f52012-03-01 04:24:26 +0000890 // ideally we would like to bail out if passing NULL, but if we do so
891 // we end up not providing the summary for function pointers anymore
892 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
893 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000894
895 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000896
Enrico Granata31fda932015-10-07 01:41:23 +0000897 TypeSummaryOptions actual_options(options);
898
899 if (actual_options.GetLanguage() == lldb::eLanguageTypeUnknown)
900 actual_options.SetLanguage(GetPreferredDisplayLanguage());
901
Enrico Granataf18c03e2012-04-04 17:34:10 +0000902 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
903 // information that we might care to see in a crash log. might be useful in very specific situations though.
904 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
Enrico Granata31fda932015-10-07 01:41:23 +0000905 GetTypeName().GetCString(),
906 GetName().GetCString(),
907 summary_ptr->GetDescription().c_str());*/
Enrico Granataf18c03e2012-04-04 17:34:10 +0000908
Enrico Granataff0f23d2014-12-10 02:00:45 +0000909 if (UpdateValueIfNeeded (false) && summary_ptr)
Enrico Granata0c489f52012-03-01 04:24:26 +0000910 {
Enrico Granataff0f23d2014-12-10 02:00:45 +0000911 if (HasSyntheticValue())
912 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 +0000913 summary_ptr->FormatObject(this, destination, actual_options);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000914 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000915 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000916 return !destination.empty();
917}
918
919const char *
Enrico Granata31fda932015-10-07 01:41:23 +0000920ValueObject::GetSummaryAsCString (lldb::LanguageType lang)
Enrico Granata0c489f52012-03-01 04:24:26 +0000921{
922 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
923 {
Enrico Granata31fda932015-10-07 01:41:23 +0000924 TypeSummaryOptions summary_options;
925 summary_options.SetLanguage(lang);
Enrico Granata0c489f52012-03-01 04:24:26 +0000926 GetSummaryAsCString(GetSummaryFormat().get(),
Enrico Granatac1247f52014-11-06 21:23:20 +0000927 m_summary_str,
Enrico Granata31fda932015-10-07 01:41:23 +0000928 summary_options);
Enrico Granata0c489f52012-03-01 04:24:26 +0000929 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000930 if (m_summary_str.empty())
931 return NULL;
932 return m_summary_str.c_str();
933}
934
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000935bool
Enrico Granata49bfafb2014-11-18 23:36:25 +0000936ValueObject::GetSummaryAsCString (std::string& destination,
937 const TypeSummaryOptions& options)
938{
939 return GetSummaryAsCString(GetSummaryFormat().get(),
Enrico Granata31fda932015-10-07 01:41:23 +0000940 destination,
941 options);
Enrico Granata49bfafb2014-11-18 23:36:25 +0000942}
943
944bool
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000945ValueObject::IsCStringContainer(bool check_pointer)
946{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000947 CompilerType pointee_or_element_compiler_type;
948 const Flags type_flags (GetTypeInfo (&pointee_or_element_compiler_type));
Enrico Granata622be232014-10-21 20:52:14 +0000949 bool is_char_arr_ptr (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000950 pointee_or_element_compiler_type.IsCharType ());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000951 if (!is_char_arr_ptr)
952 return false;
953 if (!check_pointer)
954 return true;
Enrico Granata622be232014-10-21 20:52:14 +0000955 if (type_flags.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000956 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000957 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000958 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000959 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000960 return (cstr_address != LLDB_INVALID_ADDRESS);
961}
962
Enrico Granata9128ee22011-09-06 19:20:51 +0000963size_t
964ValueObject::GetPointeeData (DataExtractor& data,
965 uint32_t item_idx,
966 uint32_t item_count)
967{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000968 CompilerType pointee_or_element_compiler_type;
969 const uint32_t type_info = GetTypeInfo (&pointee_or_element_compiler_type);
Enrico Granata622be232014-10-21 20:52:14 +0000970 const bool is_pointer_type = type_info & eTypeIsPointer;
971 const bool is_array_type = type_info & eTypeIsArray;
Greg Clayton2452ab72013-02-08 22:02:02 +0000972 if (!(is_pointer_type || is_array_type))
Enrico Granata9128ee22011-09-06 19:20:51 +0000973 return 0;
974
975 if (item_count == 0)
976 return 0;
977
Enrico Granata951bdd52015-01-28 01:09:45 +0000978 ExecutionContext exe_ctx (GetExecutionContextRef());
979
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000980 const uint64_t item_type_size = pointee_or_element_compiler_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
Enrico Granata9128ee22011-09-06 19:20:51 +0000981 const uint64_t bytes = item_count * item_type_size;
Enrico Granata9128ee22011-09-06 19:20:51 +0000982 const uint64_t offset = item_idx * item_type_size;
983
984 if (item_idx == 0 && item_count == 1) // simply a deref
985 {
Greg Clayton2452ab72013-02-08 22:02:02 +0000986 if (is_pointer_type)
Enrico Granata9128ee22011-09-06 19:20:51 +0000987 {
988 Error error;
989 ValueObjectSP pointee_sp = Dereference(error);
990 if (error.Fail() || pointee_sp.get() == NULL)
991 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +0000992 return pointee_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +0000993 }
994 else
995 {
996 ValueObjectSP child_sp = GetChildAtIndex(0, true);
997 if (child_sp.get() == NULL)
998 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +0000999 Error error;
1000 return child_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +00001001 }
1002 return true;
1003 }
1004 else /* (items > 1) */
1005 {
1006 Error error;
1007 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
1008 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
1009
1010 AddressType addr_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001011 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001012
Enrico Granata9128ee22011-09-06 19:20:51 +00001013 switch (addr_type)
1014 {
1015 case eAddressTypeFile:
1016 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001017 ModuleSP module_sp (GetModule());
1018 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001019 {
Enrico Granata9c2efe32012-08-07 01:49:34 +00001020 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +00001021 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001022 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001023 ExecutionContext exe_ctx (GetExecutionContextRef());
1024 Target* target = exe_ctx.GetTargetPtr();
1025 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +00001026 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001027 heap_buf_ptr->SetByteSize(bytes);
1028 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
1029 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +00001030 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001031 data.SetData(data_sp);
1032 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +00001033 }
1034 }
1035 }
1036 }
1037 break;
1038 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +00001039 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001040 ExecutionContext exe_ctx (GetExecutionContextRef());
1041 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +00001042 if (process)
1043 {
1044 heap_buf_ptr->SetByteSize(bytes);
1045 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
Enrico Granata5e1480c2013-10-30 17:52:44 +00001046 if (error.Success() || bytes_read > 0)
Enrico Granata9128ee22011-09-06 19:20:51 +00001047 {
1048 data.SetData(data_sp);
1049 return bytes_read;
1050 }
1051 }
1052 }
1053 break;
1054 case eAddressTypeHost:
1055 {
Greg Clayton99558cc42015-08-24 23:46:31 +00001056 const uint64_t max_bytes = GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope());
Greg Clayton2452ab72013-02-08 22:02:02 +00001057 if (max_bytes > offset)
1058 {
1059 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
Siva Chandrae32f2b52015-05-05 00:41:35 +00001060 addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1061 if (addr == LLDB_INVALID_ADDRESS)
1062 break;
Greg Clayton2452ab72013-02-08 22:02:02 +00001063 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
1064 data.SetData(data_sp);
1065 return bytes_read;
1066 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001067 }
1068 break;
1069 case eAddressTypeInvalid:
Enrico Granata9128ee22011-09-06 19:20:51 +00001070 break;
1071 }
1072 }
1073 return 0;
1074}
1075
Greg Claytonfaac1112013-03-14 18:31:44 +00001076uint64_t
Sean Callanan866e91c2014-02-28 22:27:53 +00001077ValueObject::GetData (DataExtractor& data, Error &error)
Enrico Granata9128ee22011-09-06 19:20:51 +00001078{
1079 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001080 ExecutionContext exe_ctx (GetExecutionContextRef());
Sean Callanan866e91c2014-02-28 22:27:53 +00001081 error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001082 if (error.Fail())
Sean Callananed185ab2013-04-19 19:47:32 +00001083 {
1084 if (m_data.GetByteSize())
1085 {
1086 data = m_data;
1087 return data.GetByteSize();
1088 }
1089 else
1090 {
1091 return 0;
1092 }
1093 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001094 data.SetAddressByteSize(m_data.GetAddressByteSize());
1095 data.SetByteOrder(m_data.GetByteOrder());
1096 return data.GetByteSize();
1097}
1098
Sean Callanan389823e2013-04-13 01:21:23 +00001099bool
1100ValueObject::SetData (DataExtractor &data, Error &error)
1101{
1102 error.Clear();
1103 // Make sure our value is up to date first so that our location and location
1104 // type is valid.
1105 if (!UpdateValueIfNeeded(false))
1106 {
1107 error.SetErrorString("unable to read value");
1108 return false;
1109 }
1110
1111 uint64_t count = 0;
Greg Clayton99558cc42015-08-24 23:46:31 +00001112 const Encoding encoding = GetCompilerType().GetEncoding(count);
Sean Callanan389823e2013-04-13 01:21:23 +00001113
1114 const size_t byte_size = GetByteSize();
1115
1116 Value::ValueType value_type = m_value.GetValueType();
1117
1118 switch (value_type)
1119 {
1120 case Value::eValueTypeScalar:
1121 {
1122 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1123
1124 if (!set_error.Success())
1125 {
1126 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1127 return false;
1128 }
1129 }
1130 break;
1131 case Value::eValueTypeLoadAddress:
1132 {
1133 // If it is a load address, then the scalar value is the storage location
1134 // of the data, and we have to shove this value down to that load location.
1135 ExecutionContext exe_ctx (GetExecutionContextRef());
1136 Process *process = exe_ctx.GetProcessPtr();
1137 if (process)
1138 {
1139 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1140 size_t bytes_written = process->WriteMemory(target_addr,
1141 data.GetDataStart(),
1142 byte_size,
1143 error);
1144 if (!error.Success())
1145 return false;
1146 if (bytes_written != byte_size)
1147 {
1148 error.SetErrorString("unable to write value to memory");
1149 return false;
1150 }
1151 }
1152 }
1153 break;
1154 case Value::eValueTypeHostAddress:
1155 {
1156 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1157 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1158 m_data.SetData(buffer_sp, 0);
1159 data.CopyByteOrderedData (0,
1160 byte_size,
1161 const_cast<uint8_t *>(m_data.GetDataStart()),
1162 byte_size,
1163 m_data.GetByteOrder());
1164 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1165 }
1166 break;
1167 case Value::eValueTypeFileAddress:
1168 case Value::eValueTypeVector:
1169 break;
1170 }
1171
1172 // If we have reached this point, then we have successfully changed the value.
1173 SetNeedsUpdate();
1174 return true;
1175}
1176
Enrico Granata9128ee22011-09-06 19:20:51 +00001177// will compute strlen(str), but without consuming more than
1178// maxlen bytes out of str (this serves the purpose of reading
1179// chunks of a string without having to worry about
1180// missing NULL terminators in the chunk)
1181// of course, if strlen(str) > maxlen, the function will return
1182// maxlen_value (which should be != maxlen, because that allows you
1183// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1184static uint32_t
1185strlen_or_inf (const char* str,
1186 uint32_t maxlen,
1187 uint32_t maxlen_value)
1188{
1189 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +00001190 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +00001191 {
Greg Clayton8dd5c172011-10-05 22:19:51 +00001192 while(*str)
1193 {
1194 len++;str++;
Greg Clayton2452ab72013-02-08 22:02:02 +00001195 if (len >= maxlen)
Greg Clayton8dd5c172011-10-05 22:19:51 +00001196 return maxlen_value;
1197 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001198 }
1199 return len;
1200}
1201
Enrico Granata2206b482014-10-30 18:27:31 +00001202static bool
1203CopyStringDataToBufferSP(const StreamString& source,
1204 lldb::DataBufferSP& destination)
1205{
1206 destination.reset(new DataBufferHeap(source.GetSize()+1,0));
1207 memcpy(destination->GetBytes(), source.GetString().c_str(), source.GetSize());
1208 return true;
1209}
1210
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001211size_t
Enrico Granata2206b482014-10-30 18:27:31 +00001212ValueObject::ReadPointedString (lldb::DataBufferSP& buffer_sp,
Greg Claytoncc4d0142012-02-17 07:49:44 +00001213 Error& error,
1214 uint32_t max_length,
1215 bool honor_array,
1216 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001217{
Enrico Granata2206b482014-10-30 18:27:31 +00001218 StreamString s;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001219 ExecutionContext exe_ctx (GetExecutionContextRef());
1220 Target* target = exe_ctx.GetTargetPtr();
Enrico Granata2206b482014-10-30 18:27:31 +00001221
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001222 if (!target)
1223 {
1224 s << "<no target to read from>";
1225 error.SetErrorString("no target to read from");
Enrico Granata2206b482014-10-30 18:27:31 +00001226 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001227 return 0;
1228 }
1229
1230 if (max_length == 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001231 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001232
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001233 size_t bytes_read = 0;
1234 size_t total_bytes_read = 0;
1235
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001236 CompilerType compiler_type = GetCompilerType();
1237 CompilerType elem_or_pointee_compiler_type;
1238 const Flags type_flags (GetTypeInfo (&elem_or_pointee_compiler_type));
Enrico Granata622be232014-10-21 20:52:14 +00001239 if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001240 elem_or_pointee_compiler_type.IsCharType ())
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001241 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001242 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1243 AddressType cstr_address_type = eAddressTypeInvalid;
1244
1245 size_t cstr_len = 0;
1246 bool capped_data = false;
Enrico Granata622be232014-10-21 20:52:14 +00001247 if (type_flags.Test (eTypeIsArray))
Greg Claytoncc4d0142012-02-17 07:49:44 +00001248 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001249 // We have an array
Greg Clayton57ee3062013-07-11 22:46:58 +00001250 uint64_t array_size = 0;
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001251 if (compiler_type.IsArrayType(NULL, &array_size, NULL))
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001252 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001253 cstr_len = array_size;
1254 if (cstr_len > max_length)
1255 {
1256 capped_data = true;
1257 cstr_len = max_length;
1258 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001259 }
1260 cstr_address = GetAddressOf (true, &cstr_address_type);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001261 }
1262 else
1263 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001264 // We have a pointer
1265 cstr_address = GetPointerValue (&cstr_address_type);
1266 }
1267
1268 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1269 {
1270 s << "<invalid address>";
1271 error.SetErrorString("invalid address");
Enrico Granata2206b482014-10-30 18:27:31 +00001272 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001273 return 0;
1274 }
Enrico Granata2206b482014-10-30 18:27:31 +00001275
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001276 Address cstr_so_addr (cstr_address);
1277 DataExtractor data;
1278 if (cstr_len > 0 && honor_array)
1279 {
1280 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1281 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1282 GetPointeeData(data, 0, cstr_len);
Enrico Granata2206b482014-10-30 18:27:31 +00001283
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001284 if ((bytes_read = data.GetByteSize()) > 0)
1285 {
1286 total_bytes_read = bytes_read;
Enrico Granata2206b482014-10-30 18:27:31 +00001287 for (size_t offset = 0; offset < bytes_read; offset++)
1288 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001289 if (capped_data)
1290 s << "...";
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001291 }
1292 }
1293 else
1294 {
1295 cstr_len = max_length;
1296 const size_t k_max_buf_size = 64;
Enrico Granata2206b482014-10-30 18:27:31 +00001297
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001298 size_t offset = 0;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001299
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001300 int cstr_len_displayed = -1;
1301 bool capped_cstr = false;
1302 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1303 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1304 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001305 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001306 total_bytes_read += bytes_read;
1307 const char *cstr = data.PeekCStr(0);
1308 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1309 if (len > k_max_buf_size)
1310 len = k_max_buf_size;
Enrico Granata2206b482014-10-30 18:27:31 +00001311
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001312 if (cstr_len_displayed < 0)
1313 cstr_len_displayed = len;
Enrico Granata2206b482014-10-30 18:27:31 +00001314
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001315 if (len == 0)
1316 break;
1317 cstr_len_displayed += len;
1318 if (len > bytes_read)
1319 len = bytes_read;
1320 if (len > cstr_len)
1321 len = cstr_len;
1322
Enrico Granata2206b482014-10-30 18:27:31 +00001323 for (size_t offset = 0; offset < bytes_read; offset++)
1324 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001325
1326 if (len < k_max_buf_size)
1327 break;
1328
1329 if (len >= cstr_len)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001330 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001331 capped_cstr = true;
1332 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001333 }
Enrico Granata2206b482014-10-30 18:27:31 +00001334
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001335 cstr_len -= len;
1336 offset += len;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001337 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001338
1339 if (cstr_len_displayed >= 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001340 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001341 if (capped_cstr)
1342 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001343 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001344 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001345 }
1346 else
1347 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001348 error.SetErrorString("not a string object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001349 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001350 }
Enrico Granata2206b482014-10-30 18:27:31 +00001351 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001352 return total_bytes_read;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001353}
1354
Enrico Granata744794a2014-09-05 21:46:22 +00001355std::pair<TypeValidatorResult, std::string>
1356ValueObject::GetValidationStatus ()
1357{
1358 if (!UpdateValueIfNeeded(true))
1359 return {TypeValidatorResult::Success,""}; // not the validator's job to discuss update problems
1360
1361 if (m_validation_result.hasValue())
1362 return m_validation_result.getValue();
1363
1364 if (!m_type_validator_sp)
1365 return {TypeValidatorResult::Success,""}; // no validator no failure
1366
1367 auto outcome = m_type_validator_sp->FormatObject(this);
1368
1369 return (m_validation_result = {outcome.m_result,outcome.m_message}).getValue();
1370}
1371
Jim Ingham53c47f12010-09-10 23:12:17 +00001372const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001373ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001374{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001375
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001376 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001377 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001378
1379 if (!m_object_desc_str.empty())
1380 return m_object_desc_str.c_str();
1381
Greg Claytoncc4d0142012-02-17 07:49:44 +00001382 ExecutionContext exe_ctx (GetExecutionContextRef());
1383 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001384 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001385 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001386
Jim Ingham53c47f12010-09-10 23:12:17 +00001387 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001388
Greg Claytonafacd142011-09-02 01:15:17 +00001389 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001390 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1391
Jim Inghama2cf2632010-12-23 02:29:54 +00001392 if (runtime == NULL)
1393 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001394 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001395 CompilerType compiler_type = GetCompilerType();
1396 if (compiler_type)
Jim Inghama2cf2632010-12-23 02:29:54 +00001397 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001398 bool is_signed;
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001399 if (compiler_type.IsIntegerType (is_signed) || compiler_type.IsPointerType ())
Jim Inghamb7603bb2011-03-18 00:05:18 +00001400 {
Greg Claytonafacd142011-09-02 01:15:17 +00001401 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001402 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001403 }
1404 }
1405
Jim Ingham8d543de2011-03-31 23:01:21 +00001406 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001407 {
1408 m_object_desc_str.append (s.GetData());
1409 }
Sean Callanan672ad942010-10-23 00:18:49 +00001410
1411 if (m_object_desc_str.empty())
1412 return NULL;
1413 else
1414 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001415}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001416
Enrico Granata0c489f52012-03-01 04:24:26 +00001417bool
Enrico Granata4939b982013-12-22 09:24:22 +00001418ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format,
1419 std::string& destination)
1420{
1421 if (UpdateValueIfNeeded(false))
1422 return format.FormatObject(this,destination);
1423 else
1424 return false;
1425}
1426
1427bool
Enrico Granata0c489f52012-03-01 04:24:26 +00001428ValueObject::GetValueAsCString (lldb::Format format,
1429 std::string& destination)
1430{
Enrico Granata30f287f2013-12-28 08:44:02 +00001431 return GetValueAsCString(TypeFormatImpl_Format(format),destination);
Enrico Granata0c489f52012-03-01 04:24:26 +00001432}
1433
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001434const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001435ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001436{
Enrico Granatab294fd22013-05-31 19:18:19 +00001437 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001438 {
Enrico Granata4939b982013-12-22 09:24:22 +00001439 lldb::TypeFormatImplSP format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001440 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001441 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001442 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001443 if (m_type_format_sp)
Enrico Granata4939b982013-12-22 09:24:22 +00001444 format_sp = m_type_format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001445 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001446 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001447 if (m_is_bitfield_for_scalar)
1448 my_format = eFormatUnsigned;
1449 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001450 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001451 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001452 {
1453 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1454 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001455 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001456 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001457 else
1458 {
Greg Clayton99558cc42015-08-24 23:46:31 +00001459 my_format = GetValue().GetCompilerType().GetFormat();
Enrico Granata0c489f52012-03-01 04:24:26 +00001460 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001461 }
1462 }
1463 }
Enrico Granatab294fd22013-05-31 19:18:19 +00001464 if (my_format != m_last_format || m_value_str.empty())
Enrico Granata297e69f2012-03-06 23:21:16 +00001465 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001466 m_last_format = my_format;
Enrico Granata4939b982013-12-22 09:24:22 +00001467 if (!format_sp)
Enrico Granata30f287f2013-12-28 08:44:02 +00001468 format_sp.reset(new TypeFormatImpl_Format(my_format));
Enrico Granata4939b982013-12-22 09:24:22 +00001469 if (GetValueAsCString(*format_sp.get(), m_value_str))
Enrico Granata297e69f2012-03-06 23:21:16 +00001470 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001471 if (!m_value_did_change && m_old_value_valid)
1472 {
1473 // The value was gotten successfully, so we consider the
1474 // value as changed if the value string differs
1475 SetValueDidChange (m_old_value_str != m_value_str);
1476 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001477 }
1478 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001479 }
1480 if (m_value_str.empty())
1481 return NULL;
1482 return m_value_str.c_str();
1483}
1484
Enrico Granatac3e320a2011-08-02 17:27:39 +00001485// if > 8bytes, 0 is returned. this method should mostly be used
1486// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001487uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001488ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001489{
1490 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001491 if (CanProvideValue())
Enrico Granatac3e320a2011-08-02 17:27:39 +00001492 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001493 Scalar scalar;
1494 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001495 {
1496 if (success)
1497 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001498 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001499 }
1500 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001501 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001502
1503 if (success)
1504 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001505 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001506}
1507
Enrico Granatad7373f62013-10-31 18:57:50 +00001508int64_t
1509ValueObject::GetValueAsSigned (int64_t fail_value, bool *success)
1510{
1511 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001512 if (CanProvideValue())
Enrico Granatad7373f62013-10-31 18:57:50 +00001513 {
1514 Scalar scalar;
1515 if (ResolveValue (scalar))
1516 {
1517 if (success)
1518 *success = true;
Tamas Berghammer5a9919f2015-01-23 10:54:21 +00001519 return scalar.SLongLong(fail_value);
Enrico Granatad7373f62013-10-31 18:57:50 +00001520 }
1521 // fallthrough, otherwise...
1522 }
1523
1524 if (success)
1525 *success = false;
Tamas Berghammer5a9919f2015-01-23 10:54:21 +00001526 return fail_value;
Enrico Granatad7373f62013-10-31 18:57:50 +00001527}
1528
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001529// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1530// this call up to date by returning true for your new special cases. We will eventually move
1531// to checking this call result before trying to display special cases
1532bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001533ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1534 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001535{
Greg Clayton57ee3062013-07-11 22:46:58 +00001536 Flags flags(GetTypeInfo());
Enrico Granata622be232014-10-21 20:52:14 +00001537 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001538 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001539 {
1540 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001541 (custom_format == eFormatCString ||
1542 custom_format == eFormatCharArray ||
1543 custom_format == eFormatChar ||
1544 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001545 return true;
1546
Enrico Granata622be232014-10-21 20:52:14 +00001547 if (flags.Test(eTypeIsArray))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001548 {
Greg Claytonafacd142011-09-02 01:15:17 +00001549 if ((custom_format == eFormatBytes) ||
1550 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001551 return true;
1552
Greg Claytonafacd142011-09-02 01:15:17 +00001553 if ((custom_format == eFormatVectorOfChar) ||
1554 (custom_format == eFormatVectorOfFloat32) ||
1555 (custom_format == eFormatVectorOfFloat64) ||
1556 (custom_format == eFormatVectorOfSInt16) ||
1557 (custom_format == eFormatVectorOfSInt32) ||
1558 (custom_format == eFormatVectorOfSInt64) ||
1559 (custom_format == eFormatVectorOfSInt8) ||
1560 (custom_format == eFormatVectorOfUInt128) ||
1561 (custom_format == eFormatVectorOfUInt16) ||
1562 (custom_format == eFormatVectorOfUInt32) ||
1563 (custom_format == eFormatVectorOfUInt64) ||
1564 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001565 return true;
1566 }
1567 }
1568 return false;
1569}
1570
Enrico Granata9fc19442011-07-06 02:13:41 +00001571bool
1572ValueObject::DumpPrintableRepresentation(Stream& s,
1573 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001574 Format custom_format,
Enrico Granata0dba9b32014-01-08 01:36:59 +00001575 PrintableRepresentationSpecialCases special,
1576 bool do_dump_error)
Enrico Granata9fc19442011-07-06 02:13:41 +00001577{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001578
Greg Clayton57ee3062013-07-11 22:46:58 +00001579 Flags flags(GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001580
Enrico Granata86cc9822012-03-19 22:58:49 +00001581 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1582 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1583
1584 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001585 {
Enrico Granata622be232014-10-21 20:52:14 +00001586 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001587 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001588 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001589 // when being asked to get a printable display an array or pointer type directly,
1590 // try to "do the right thing"
1591
1592 if (IsCStringContainer(true) &&
1593 (custom_format == eFormatCString ||
1594 custom_format == eFormatCharArray ||
1595 custom_format == eFormatChar ||
1596 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001597 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001598 Error error;
Enrico Granata2206b482014-10-30 18:27:31 +00001599 lldb::DataBufferSP buffer_sp;
1600 ReadPointedString(buffer_sp,
Enrico Granata86cc9822012-03-19 22:58:49 +00001601 error,
1602 0,
1603 (custom_format == eFormatVectorOfChar) ||
1604 (custom_format == eFormatCharArray));
Enrico Granataac494532015-09-09 22:30:24 +00001605 lldb_private::formatters::StringPrinter::ReadBufferAndDumpToStreamOptions options(*this);
Enrico Granata2206b482014-10-30 18:27:31 +00001606 options.SetData(DataExtractor(buffer_sp, lldb::eByteOrderInvalid, 8)); // none of this matters for a string - pass some defaults
1607 options.SetStream(&s);
1608 options.SetPrefixToken(0);
1609 options.SetQuote('"');
1610 options.SetSourceSize(buffer_sp->GetByteSize());
Enrico Granataac494532015-09-09 22:30:24 +00001611 formatters::StringPrinter::ReadBufferAndDumpToStream<lldb_private::formatters::StringPrinter::StringElementType::ASCII>(options);
Enrico Granata86cc9822012-03-19 22:58:49 +00001612 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001613 }
1614
Enrico Granata86cc9822012-03-19 22:58:49 +00001615 if (custom_format == eFormatEnum)
1616 return false;
1617
1618 // this only works for arrays, because I have no way to know when
1619 // the pointed memory ends, and no special \0 end of data marker
Enrico Granata622be232014-10-21 20:52:14 +00001620 if (flags.Test(eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001621 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001622 if ((custom_format == eFormatBytes) ||
1623 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001624 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001625 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001626
1627 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001628 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001629 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001630
1631 if (low)
1632 s << ',';
1633
1634 ValueObjectSP child = GetChildAtIndex(low,true);
1635 if (!child.get())
1636 {
1637 s << "<invalid child>";
1638 continue;
1639 }
1640 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1641 }
1642
1643 s << ']';
1644
1645 return true;
1646 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001647
Enrico Granata86cc9822012-03-19 22:58:49 +00001648 if ((custom_format == eFormatVectorOfChar) ||
1649 (custom_format == eFormatVectorOfFloat32) ||
1650 (custom_format == eFormatVectorOfFloat64) ||
1651 (custom_format == eFormatVectorOfSInt16) ||
1652 (custom_format == eFormatVectorOfSInt32) ||
1653 (custom_format == eFormatVectorOfSInt64) ||
1654 (custom_format == eFormatVectorOfSInt8) ||
1655 (custom_format == eFormatVectorOfUInt128) ||
1656 (custom_format == eFormatVectorOfUInt16) ||
1657 (custom_format == eFormatVectorOfUInt32) ||
1658 (custom_format == eFormatVectorOfUInt64) ||
1659 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1660 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001661 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001662
1663 Format format = FormatManager::GetSingleItemFormat(custom_format);
1664
1665 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001666 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001667 {
1668
1669 if (low)
1670 s << ',';
1671
1672 ValueObjectSP child = GetChildAtIndex(low,true);
1673 if (!child.get())
1674 {
1675 s << "<invalid child>";
1676 continue;
1677 }
1678 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1679 }
1680
1681 s << ']';
1682
1683 return true;
1684 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001685 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001686
1687 if ((custom_format == eFormatBoolean) ||
1688 (custom_format == eFormatBinary) ||
1689 (custom_format == eFormatChar) ||
1690 (custom_format == eFormatCharPrintable) ||
1691 (custom_format == eFormatComplexFloat) ||
1692 (custom_format == eFormatDecimal) ||
1693 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001694 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001695 (custom_format == eFormatFloat) ||
1696 (custom_format == eFormatOctal) ||
1697 (custom_format == eFormatOSType) ||
1698 (custom_format == eFormatUnicode16) ||
1699 (custom_format == eFormatUnicode32) ||
1700 (custom_format == eFormatUnsigned) ||
1701 (custom_format == eFormatPointer) ||
1702 (custom_format == eFormatComplexInteger) ||
1703 (custom_format == eFormatComplex) ||
1704 (custom_format == eFormatDefault)) // use the [] operator
1705 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001706 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001707 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001708
1709 if (only_special)
1710 return false;
1711
Enrico Granata86cc9822012-03-19 22:58:49 +00001712 bool var_success = false;
1713
1714 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001715 const char *cstr = NULL;
Enrico Granata2c75f112013-06-21 00:04:51 +00001716
1717 // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1718 // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1719 // area for cases where our desired output is not backed by some other longer-term storage
Greg Claytonc7bece562013-01-25 18:06:21 +00001720 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001721
Enrico Granata465f4bc2014-02-15 01:24:44 +00001722 if (custom_format != eFormatInvalid)
Enrico Granata86cc9822012-03-19 22:58:49 +00001723 SetFormat(custom_format);
1724
1725 switch(val_obj_display)
1726 {
1727 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001728 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001729 break;
1730
1731 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001732 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001733 break;
1734
1735 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001736 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001737 break;
1738
1739 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001740 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001741 break;
1742
1743 case eValueObjectRepresentationStyleChildrenCount:
Deepak Panickal99fbc072014-03-03 15:39:47 +00001744 strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren());
Greg Claytonc7bece562013-01-25 18:06:21 +00001745 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001746 break;
1747
1748 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001749 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001750 break;
Enrico Granata2c75f112013-06-21 00:04:51 +00001751
1752 case eValueObjectRepresentationStyleName:
1753 cstr = GetName().AsCString();
1754 break;
1755
1756 case eValueObjectRepresentationStyleExpressionPath:
1757 GetExpressionPath(strm, false);
1758 cstr = strm.GetString().c_str();
1759 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001760 }
1761
Greg Claytonc7bece562013-01-25 18:06:21 +00001762 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001763 {
1764 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001765 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001766 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1767 {
Enrico Granatad07cfd32014-10-08 18:27:36 +00001768 if (!CanProvideValue())
Enrico Granata86cc9822012-03-19 22:58:49 +00001769 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001770 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1771 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001772 }
1773 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001774 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001775 }
1776 }
1777
Greg Claytonc7bece562013-01-25 18:06:21 +00001778 if (cstr)
1779 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001780 else
1781 {
1782 if (m_error.Fail())
Enrico Granata0dba9b32014-01-08 01:36:59 +00001783 {
1784 if (do_dump_error)
1785 s.Printf("<%s>", m_error.AsCString());
1786 else
1787 return false;
1788 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001789 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1790 s.PutCString("<no summary available>");
1791 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1792 s.PutCString("<no value available>");
1793 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1794 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1795 else
1796 s.PutCString("<no printable representation>");
1797 }
1798
1799 // we should only return false here if we could not do *anything*
1800 // even if we have an error message as output, that's a success
1801 // from our callers' perspective, so return true
1802 var_success = true;
Enrico Granata465f4bc2014-02-15 01:24:44 +00001803
1804 if (custom_format != eFormatInvalid)
1805 SetFormat(eFormatDefault);
Enrico Granata86cc9822012-03-19 22:58:49 +00001806 }
1807
Enrico Granataf4efecd2011-07-12 22:56:10 +00001808 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001809}
1810
Greg Clayton737b9322010-09-13 03:32:57 +00001811addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001812ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001813{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001814 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001815 return LLDB_INVALID_ADDRESS;
1816
Greg Clayton73b472d2010-10-27 03:32:59 +00001817 switch (m_value.GetValueType())
1818 {
1819 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001820 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001821 if (scalar_is_load_address)
1822 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001823 if(address_type)
1824 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001825 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1826 }
1827 break;
1828
1829 case Value::eValueTypeLoadAddress:
1830 case Value::eValueTypeFileAddress:
Greg Clayton73b472d2010-10-27 03:32:59 +00001831 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001832 if(address_type)
1833 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001834 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1835 }
1836 break;
Siva Chandraa3747a92015-05-04 19:43:34 +00001837 case Value::eValueTypeHostAddress:
Siva Chandrae32f2b52015-05-05 00:41:35 +00001838 {
1839 if(address_type)
1840 *address_type = m_value.GetValueAddressType ();
1841 return LLDB_INVALID_ADDRESS;
1842 }
Siva Chandraa3747a92015-05-04 19:43:34 +00001843 break;
Greg Clayton73b472d2010-10-27 03:32:59 +00001844 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001845 if (address_type)
1846 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001847 return LLDB_INVALID_ADDRESS;
1848}
1849
1850addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001851ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001852{
Greg Claytonafacd142011-09-02 01:15:17 +00001853 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001854 if(address_type)
1855 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001856
Enrico Granatac3e320a2011-08-02 17:27:39 +00001857 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001858 return address;
1859
Greg Clayton73b472d2010-10-27 03:32:59 +00001860 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001861 {
1862 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001863 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001864 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001865 break;
1866
Enrico Granata9128ee22011-09-06 19:20:51 +00001867 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001868 case Value::eValueTypeLoadAddress:
1869 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001870 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001871 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001872 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001873 }
1874 break;
1875 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001876
Enrico Granata9128ee22011-09-06 19:20:51 +00001877 if (address_type)
1878 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001879
Greg Clayton737b9322010-09-13 03:32:57 +00001880 return address;
1881}
1882
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001883bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001884ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001885{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001886 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001887 // Make sure our value is up to date first so that our location and location
1888 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001889 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001890 {
1891 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001892 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001893 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001894
Greg Claytonfaac1112013-03-14 18:31:44 +00001895 uint64_t count = 0;
Greg Clayton99558cc42015-08-24 23:46:31 +00001896 const Encoding encoding = GetCompilerType().GetEncoding (count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001897
Greg Claytonb1320972010-07-14 00:18:15 +00001898 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001899
Jim Ingham16e0c682011-08-12 23:34:31 +00001900 Value::ValueType value_type = m_value.GetValueType();
1901
1902 if (value_type == Value::eValueTypeScalar)
1903 {
1904 // If the value is already a scalar, then let the scalar change itself:
1905 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1906 }
Sagar Thakur8536fd12015-08-20 09:12:46 +00001907 else if (byte_size <= 16)
Jim Ingham16e0c682011-08-12 23:34:31 +00001908 {
1909 // If the value fits in a scalar, then make a new scalar and again let the
1910 // scalar code do the conversion, then figure out where to put the new value.
1911 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001912 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1913 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001914 {
Jim Ingham4b536182011-08-09 02:12:22 +00001915 switch (value_type)
1916 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001917 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001918 {
1919 // If it is a load address, then the scalar value is the storage location
1920 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001921 ExecutionContext exe_ctx (GetExecutionContextRef());
1922 Process *process = exe_ctx.GetProcessPtr();
1923 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001924 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001925 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001926 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1927 new_scalar,
1928 byte_size,
1929 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001930 if (!error.Success())
1931 return false;
1932 if (bytes_written != byte_size)
1933 {
1934 error.SetErrorString("unable to write value to memory");
1935 return false;
1936 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001937 }
1938 }
Jim Ingham4b536182011-08-09 02:12:22 +00001939 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001940 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001941 {
1942 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1943 DataExtractor new_data;
1944 new_data.SetByteOrder (m_data.GetByteOrder());
1945
1946 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1947 m_data.SetData(buffer_sp, 0);
1948 bool success = new_scalar.GetData(new_data);
1949 if (success)
1950 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001951 new_data.CopyByteOrderedData (0,
1952 byte_size,
1953 const_cast<uint8_t *>(m_data.GetDataStart()),
1954 byte_size,
1955 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001956 }
1957 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1958
1959 }
Jim Ingham4b536182011-08-09 02:12:22 +00001960 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001961 case Value::eValueTypeFileAddress:
1962 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001963 case Value::eValueTypeVector:
1964 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001965 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001966 }
1967 else
1968 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001969 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001970 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001971 }
1972 else
1973 {
1974 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001975 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001976 return false;
1977 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001978
1979 // If we have reached this point, then we have successfully changed the value.
1980 SetNeedsUpdate();
1981 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001982}
1983
Greg Clayton81e871e2012-02-04 02:27:34 +00001984bool
1985ValueObject::GetDeclaration (Declaration &decl)
1986{
1987 decl.Clear();
1988 return false;
1989}
1990
Greg Clayton84db9102012-03-26 23:03:23 +00001991ConstString
1992ValueObject::GetTypeName()
1993{
Greg Clayton99558cc42015-08-24 23:46:31 +00001994 return GetCompilerType().GetConstTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00001995}
1996
1997ConstString
Enrico Granatae8daa2f2014-05-17 19:14:17 +00001998ValueObject::GetDisplayTypeName()
1999{
2000 return GetTypeName();
2001}
2002
2003ConstString
Greg Clayton84db9102012-03-26 23:03:23 +00002004ValueObject::GetQualifiedTypeName()
2005{
Greg Clayton99558cc42015-08-24 23:46:31 +00002006 return GetCompilerType().GetConstQualifiedTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00002007}
2008
2009
Greg Claytonafacd142011-09-02 01:15:17 +00002010LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00002011ValueObject::GetObjectRuntimeLanguage ()
2012{
Greg Clayton99558cc42015-08-24 23:46:31 +00002013 return GetCompilerType().GetMinimumLanguage ();
Jim Ingham5a369122010-09-28 01:25:32 +00002014}
2015
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002016void
Jim Ingham58b59f92011-04-22 23:53:53 +00002017ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002018{
Jim Ingham58b59f92011-04-22 23:53:53 +00002019 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002020}
2021
2022ValueObjectSP
2023ValueObject::GetSyntheticChild (const ConstString &key) const
2024{
2025 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00002026 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002027 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00002028 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002029 return synthetic_child_sp;
2030}
2031
Greg Clayton2452ab72013-02-08 22:02:02 +00002032uint32_t
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002033ValueObject::GetTypeInfo (CompilerType *pointee_or_element_compiler_type)
Greg Clayton2452ab72013-02-08 22:02:02 +00002034{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002035 return GetCompilerType().GetTypeInfo (pointee_or_element_compiler_type);
Greg Clayton2452ab72013-02-08 22:02:02 +00002036}
2037
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002038bool
2039ValueObject::IsPointerType ()
2040{
Greg Clayton99558cc42015-08-24 23:46:31 +00002041 return GetCompilerType().IsPointerType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002042}
2043
Jim Inghamb7603bb2011-03-18 00:05:18 +00002044bool
Greg Claytondaf515f2011-07-09 20:12:33 +00002045ValueObject::IsArrayType ()
2046{
Greg Clayton99558cc42015-08-24 23:46:31 +00002047 return GetCompilerType().IsArrayType (NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00002048}
2049
2050bool
Enrico Granata9fc19442011-07-06 02:13:41 +00002051ValueObject::IsScalarType ()
2052{
Greg Clayton99558cc42015-08-24 23:46:31 +00002053 return GetCompilerType().IsScalarType ();
Enrico Granata9fc19442011-07-06 02:13:41 +00002054}
2055
2056bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00002057ValueObject::IsIntegerType (bool &is_signed)
2058{
Greg Clayton99558cc42015-08-24 23:46:31 +00002059 return GetCompilerType().IsIntegerType (is_signed);
Jim Inghamb7603bb2011-03-18 00:05:18 +00002060}
Greg Clayton73b472d2010-10-27 03:32:59 +00002061
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002062bool
2063ValueObject::IsPointerOrReferenceType ()
2064{
Greg Clayton99558cc42015-08-24 23:46:31 +00002065 return GetCompilerType().IsPointerOrReferenceType ();
Greg Clayton007d5be2011-05-30 00:49:24 +00002066}
2067
2068bool
Greg Claytondea8cb42011-06-29 22:09:02 +00002069ValueObject::IsPossibleDynamicType ()
2070{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002071 ExecutionContext exe_ctx (GetExecutionContextRef());
2072 Process *process = exe_ctx.GetProcessPtr();
2073 if (process)
2074 return process->IsPossibleDynamicValue(*this);
2075 else
Greg Clayton99558cc42015-08-24 23:46:31 +00002076 return GetCompilerType().IsPossibleDynamicType (NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00002077}
2078
Enrico Granata9e7b3882012-12-13 23:50:33 +00002079bool
Enrico Granata560558e2015-02-11 02:35:39 +00002080ValueObject::IsRuntimeSupportValue ()
2081{
2082 Process *process(GetProcessSP().get());
2083 if (process)
2084 {
2085 LanguageRuntime *runtime = process->GetLanguageRuntime(GetObjectRuntimeLanguage());
2086 if (!runtime)
2087 runtime = process->GetObjCLanguageRuntime();
2088 if (runtime)
2089 return runtime->IsRuntimeSupportValue(*this);
2090 }
2091 return false;
2092}
2093
2094bool
Enrico Granata9e7b3882012-12-13 23:50:33 +00002095ValueObject::IsObjCNil ()
2096{
Enrico Granata622be232014-10-21 20:52:14 +00002097 const uint32_t mask = eTypeIsObjC | eTypeIsPointer;
Greg Clayton99558cc42015-08-24 23:46:31 +00002098 bool isObjCpointer = (((GetCompilerType().GetTypeInfo(NULL)) & mask) == mask);
Enrico Granata7277d202013-03-15 23:33:15 +00002099 if (!isObjCpointer)
2100 return false;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002101 bool canReadValue = true;
2102 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
Enrico Granata7277d202013-03-15 23:33:15 +00002103 return canReadValue && isZero;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002104}
2105
Greg Claytondaf515f2011-07-09 20:12:33 +00002106// This allows you to create an array member using and index
2107// that doesn't not fall in the normal bounds of the array.
2108// Many times structure can be defined as:
2109// struct Collection
2110// {
2111// uint32_t item_count;
2112// Item item_array[0];
2113// };
2114// The size of the "item_array" is 1, but many times in practice
2115// there are more items in "item_array".
2116
2117ValueObjectSP
Bruce Mitchener11d86362015-02-26 23:55:39 +00002118ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00002119{
2120 ValueObjectSP synthetic_child_sp;
Bruce Mitchener11d86362015-02-26 23:55:39 +00002121 if (IsPointerType () || IsArrayType())
Greg Claytondaf515f2011-07-09 20:12:33 +00002122 {
2123 char index_str[64];
Deepak Panickal99fbc072014-03-03 15:39:47 +00002124 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
Greg Claytondaf515f2011-07-09 20:12:33 +00002125 ConstString index_const_str(index_str);
2126 // Check if we have already created a synthetic array member in this
2127 // valid object. If we have we will re-use it.
2128 synthetic_child_sp = GetSyntheticChild (index_const_str);
2129 if (!synthetic_child_sp)
2130 {
2131 ValueObject *synthetic_child;
2132 // We haven't made a synthetic array member for INDEX yet, so
2133 // lets make one and cache it for any future reference.
2134 synthetic_child = CreateChildAtIndex(0, true, index);
Bruce Mitchener11d86362015-02-26 23:55:39 +00002135
Greg Claytondaf515f2011-07-09 20:12:33 +00002136 // Cache the value if we got one back...
2137 if (synthetic_child)
2138 {
2139 AddSyntheticChild(index_const_str, synthetic_child);
2140 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002141 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00002142 synthetic_child_sp->m_is_array_item_for_pointer = true;
2143 }
2144 }
2145 }
2146 return synthetic_child_sp;
2147}
2148
Enrico Granata9fc19442011-07-06 02:13:41 +00002149ValueObjectSP
2150ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2151{
2152 ValueObjectSP synthetic_child_sp;
2153 if (IsScalarType ())
2154 {
2155 char index_str[64];
2156 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2157 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 {
Enrico Granata9fc19442011-07-06 02:13:41 +00002163 // We haven't made a synthetic array member for INDEX yet, so
2164 // lets make one and cache it for any future reference.
Greg Clayton57ee3062013-07-11 22:46:58 +00002165 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
Greg Clayton99558cc42015-08-24 23:46:31 +00002166 GetCompilerType(),
Greg Clayton57ee3062013-07-11 22:46:58 +00002167 index_const_str,
2168 GetByteSize(),
2169 0,
2170 to-from+1,
2171 from,
2172 false,
2173 false,
2174 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002175
2176 // Cache the value if we got one back...
2177 if (synthetic_child)
2178 {
2179 AddSyntheticChild(index_const_str, synthetic_child);
2180 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002181 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002182 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2183 }
2184 }
2185 }
2186 return synthetic_child_sp;
2187}
2188
Greg Claytonafacd142011-09-02 01:15:17 +00002189ValueObjectSP
Greg Claytona1e5dc82015-08-11 22:53:00 +00002190ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const CompilerType& type, bool can_create)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002191{
2192
2193 ValueObjectSP synthetic_child_sp;
2194
2195 char name_str[64];
2196 snprintf(name_str, sizeof(name_str), "@%i", offset);
2197 ConstString name_const_str(name_str);
2198
2199 // Check if we have already created a synthetic array member in this
2200 // valid object. If we have we will re-use it.
2201 synthetic_child_sp = GetSyntheticChild (name_const_str);
2202
2203 if (synthetic_child_sp.get())
2204 return synthetic_child_sp;
2205
2206 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002207 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002208
Enrico Granata951bdd52015-01-28 01:09:45 +00002209 ExecutionContext exe_ctx (GetExecutionContextRef());
2210
Enrico Granata6f3533f2011-07-29 19:53:35 +00002211 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
Greg Clayton57ee3062013-07-11 22:46:58 +00002212 type,
Enrico Granata6f3533f2011-07-29 19:53:35 +00002213 name_const_str,
Greg Clayton526ae042015-02-12 00:34:25 +00002214 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
Enrico Granata6f3533f2011-07-29 19:53:35 +00002215 offset,
2216 0,
2217 0,
2218 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002219 false,
2220 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002221 if (synthetic_child)
2222 {
2223 AddSyntheticChild(name_const_str, synthetic_child);
2224 synthetic_child_sp = synthetic_child->GetSP();
2225 synthetic_child_sp->SetName(name_const_str);
2226 synthetic_child_sp->m_is_child_at_offset = true;
2227 }
2228 return synthetic_child_sp;
2229}
2230
Enrico Granata32556cd2014-08-26 20:54:04 +00002231ValueObjectSP
Greg Claytona1e5dc82015-08-11 22:53:00 +00002232ValueObject::GetSyntheticBase (uint32_t offset, const CompilerType& type, bool can_create)
Enrico Granata32556cd2014-08-26 20:54:04 +00002233{
2234 ValueObjectSP synthetic_child_sp;
2235
2236 char name_str[64];
2237 snprintf(name_str, sizeof(name_str), "%s", type.GetTypeName().AsCString("<unknown>"));
2238 ConstString name_const_str(name_str);
2239
2240 // Check if we have already created a synthetic array member in this
2241 // valid object. If we have we will re-use it.
2242 synthetic_child_sp = GetSyntheticChild (name_const_str);
2243
2244 if (synthetic_child_sp.get())
2245 return synthetic_child_sp;
2246
2247 if (!can_create)
2248 return ValueObjectSP();
2249
Enrico Granata32556cd2014-08-26 20:54:04 +00002250 const bool is_base_class = true;
2251
Enrico Granata951bdd52015-01-28 01:09:45 +00002252 ExecutionContext exe_ctx (GetExecutionContextRef());
2253
Enrico Granata32556cd2014-08-26 20:54:04 +00002254 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2255 type,
2256 name_const_str,
Greg Clayton526ae042015-02-12 00:34:25 +00002257 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
Enrico Granata32556cd2014-08-26 20:54:04 +00002258 offset,
2259 0,
2260 0,
2261 is_base_class,
2262 false,
2263 eAddressTypeInvalid);
2264 if (synthetic_child)
2265 {
2266 AddSyntheticChild(name_const_str, synthetic_child);
2267 synthetic_child_sp = synthetic_child->GetSP();
2268 synthetic_child_sp->SetName(name_const_str);
2269 }
2270 return synthetic_child_sp;
2271}
2272
2273
Enrico Granatad55546b2011-07-22 00:16:08 +00002274// your expression path needs to have a leading . or ->
2275// (unless it somehow "looks like" an array, in which case it has
2276// a leading [ symbol). while the [ is meaningful and should be shown
2277// to the user, . and -> are just parser design, but by no means
2278// added information for the user.. strip them off
2279static const char*
2280SkipLeadingExpressionPathSeparators(const char* expression)
2281{
2282 if (!expression || !expression[0])
2283 return expression;
2284 if (expression[0] == '.')
2285 return expression+1;
2286 if (expression[0] == '-' && expression[1] == '>')
2287 return expression+2;
2288 return expression;
2289}
2290
Greg Claytonafacd142011-09-02 01:15:17 +00002291ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002292ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2293{
2294 ValueObjectSP synthetic_child_sp;
2295 ConstString name_const_string(expression);
2296 // Check if we have already created a synthetic array member in this
2297 // valid object. If we have we will re-use it.
2298 synthetic_child_sp = GetSyntheticChild (name_const_string);
2299 if (!synthetic_child_sp)
2300 {
2301 // We haven't made a synthetic array member for expression yet, so
2302 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002303 synthetic_child_sp = GetValueForExpressionPath(expression,
2304 NULL, NULL, NULL,
Enrico Granataef238c12015-03-12 22:30:58 +00002305 GetValueForExpressionPathOptions().SetSyntheticChildrenTraversal(GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None));
Enrico Granatad55546b2011-07-22 00:16:08 +00002306
2307 // Cache the value if we got one back...
2308 if (synthetic_child_sp.get())
2309 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002310 // 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 +00002311 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002312 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002313 }
2314 }
2315 return synthetic_child_sp;
2316}
2317
2318void
Enrico Granata86cc9822012-03-19 22:58:49 +00002319ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002320{
Enrico Granata86cc9822012-03-19 22:58:49 +00002321 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002322 return;
2323
Enrico Granatac5bc4122012-03-27 02:35:13 +00002324 TargetSP target_sp(GetTargetSP());
Enrico Granata5d5f60c2013-09-24 22:58:37 +00002325 if (target_sp && target_sp->GetEnableSyntheticValue() == false)
Enrico Granatac5bc4122012-03-27 02:35:13 +00002326 {
2327 m_synthetic_value = NULL;
2328 return;
2329 }
2330
Enrico Granatae3e91512012-10-22 18:18:36 +00002331 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2332
Enrico Granata5548cb52013-01-28 23:47:25 +00002333 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002334 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002335
Enrico Granata0c489f52012-03-01 04:24:26 +00002336 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002337 return;
2338
Enrico Granatae3e91512012-10-22 18:18:36 +00002339 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2340 return;
2341
Enrico Granata86cc9822012-03-19 22:58:49 +00002342 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002343}
2344
Jim Ingham78a685a2011-04-16 00:01:13 +00002345void
Greg Claytonafacd142011-09-02 01:15:17 +00002346ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002347{
Greg Claytonafacd142011-09-02 01:15:17 +00002348 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002349 return;
2350
Jim Ingham58b59f92011-04-22 23:53:53 +00002351 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002352 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002353 ExecutionContext exe_ctx (GetExecutionContextRef());
2354 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002355 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002356 {
2357 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002358 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002359 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002360 }
2361}
2362
Jim Ingham58b59f92011-04-22 23:53:53 +00002363ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002364ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002365{
Greg Claytonafacd142011-09-02 01:15:17 +00002366 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002367 return ValueObjectSP();
2368
2369 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002370 {
Jim Ingham2837b762011-05-04 03:43:18 +00002371 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002372 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002373 if (m_dynamic_value)
2374 return m_dynamic_value->GetSP();
2375 else
2376 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002377}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002378
Jim Ingham60dbabb2011-12-08 19:44:08 +00002379ValueObjectSP
2380ValueObject::GetStaticValue()
2381{
2382 return GetSP();
2383}
2384
Enrico Granata886147f2012-05-08 18:47:08 +00002385lldb::ValueObjectSP
2386ValueObject::GetNonSyntheticValue ()
2387{
2388 return GetSP();
2389}
2390
Enrico Granatad55546b2011-07-22 00:16:08 +00002391ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002392ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002393{
Enrico Granata86cc9822012-03-19 22:58:49 +00002394 if (use_synthetic == false)
2395 return ValueObjectSP();
2396
Enrico Granatad55546b2011-07-22 00:16:08 +00002397 CalculateSyntheticValue(use_synthetic);
2398
2399 if (m_synthetic_value)
2400 return m_synthetic_value->GetSP();
2401 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002402 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002403}
2404
Greg Claytone221f822011-01-21 01:59:00 +00002405bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002406ValueObject::HasSyntheticValue()
2407{
Enrico Granata5548cb52013-01-28 23:47:25 +00002408 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002409
Enrico Granata0c489f52012-03-01 04:24:26 +00002410 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002411 return false;
2412
Enrico Granata86cc9822012-03-19 22:58:49 +00002413 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002414
2415 if (m_synthetic_value)
2416 return true;
2417 else
2418 return false;
2419}
2420
2421bool
Greg Claytone221f822011-01-21 01:59:00 +00002422ValueObject::GetBaseClassPath (Stream &s)
2423{
2424 if (IsBaseClass())
2425 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002426 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002427 CompilerType compiler_type = GetCompilerType();
Greg Claytone221f822011-01-21 01:59:00 +00002428 std::string cxx_class_name;
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002429 bool this_had_base_class = ClangASTContext::GetCXXClassName (compiler_type, cxx_class_name);
Greg Claytone221f822011-01-21 01:59:00 +00002430 if (this_had_base_class)
2431 {
2432 if (parent_had_base_class)
2433 s.PutCString("::");
2434 s.PutCString(cxx_class_name.c_str());
2435 }
2436 return parent_had_base_class || this_had_base_class;
2437 }
2438 return false;
2439}
2440
2441
2442ValueObject *
2443ValueObject::GetNonBaseClassParent()
2444{
Jim Ingham78a685a2011-04-16 00:01:13 +00002445 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002446 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002447 if (GetParent()->IsBaseClass())
2448 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002449 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002450 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002451 }
2452 return NULL;
2453}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002454
Enrico Granataa3c8f042014-08-19 22:29:08 +00002455
2456bool
2457ValueObject::IsBaseClass (uint32_t& depth)
2458{
2459 if (!IsBaseClass())
2460 {
2461 depth = 0;
2462 return false;
2463 }
2464 if (GetParent())
2465 {
2466 GetParent()->IsBaseClass(depth);
2467 depth = depth + 1;
2468 return true;
2469 }
2470 // TODO: a base of no parent? weird..
2471 depth = 1;
2472 return true;
2473}
2474
Greg Clayton1d3afba2010-10-05 00:00:42 +00002475void
Enrico Granata4becb372011-06-29 22:27:15 +00002476ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002477{
Enrico Granata986fa5f2014-12-09 21:41:16 +00002478 // synthetic children do not actually "exist" as part of the hierarchy, and sometimes they are consed up in ways
2479 // that don't make sense from an underlying language/API standpoint. So, use a special code path here to return
2480 // something that can hopefully be used in expression
2481 if (m_is_synthetic_children_generated)
2482 {
2483 UpdateValueIfNeeded();
2484
2485 if (m_value.GetValueType() == Value::eValueTypeLoadAddress)
2486 {
2487 if (IsPointerOrReferenceType())
2488 {
2489 s.Printf("((%s)0x%" PRIx64 ")",
2490 GetTypeName().AsCString("void"),
2491 GetValueAsUnsigned(0));
2492 return;
2493 }
2494 else
2495 {
2496 uint64_t load_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
2497 if (load_addr != LLDB_INVALID_ADDRESS)
2498 {
2499 s.Printf("(*( (%s *)0x%" PRIx64 "))",
2500 GetTypeName().AsCString("void"),
2501 load_addr);
2502 return;
2503 }
2504 }
2505 }
2506
2507 if (CanProvideValue())
2508 {
2509 s.Printf("((%s)%s)",
2510 GetTypeName().AsCString("void"),
2511 GetValueAsCString());
2512 return;
2513 }
2514
2515 return;
2516 }
2517
Greg Claytone221f822011-01-21 01:59:00 +00002518 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002519
Enrico Granata86cc9822012-03-19 22:58:49 +00002520 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002521 {
Enrico Granata4becb372011-06-29 22:27:15 +00002522 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2523 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2524 // the eHonorPointers mode is meant to produce strings in this latter format
2525 s.PutCString("*(");
2526 }
Greg Claytone221f822011-01-21 01:59:00 +00002527
Enrico Granata4becb372011-06-29 22:27:15 +00002528 ValueObject* parent = GetParent();
2529
2530 if (parent)
2531 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002532
2533 // if we are a deref_of_parent just because we are synthetic array
2534 // members made up to allow ptr[%d] syntax to work in variable
2535 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002536 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002537 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002538
Greg Claytone221f822011-01-21 01:59:00 +00002539 if (!IsBaseClass())
2540 {
2541 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002542 {
Greg Claytone221f822011-01-21 01:59:00 +00002543 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2544 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002545 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002546 CompilerType non_base_class_parent_compiler_type = non_base_class_parent->GetCompilerType();
2547 if (non_base_class_parent_compiler_type)
Greg Claytone221f822011-01-21 01:59:00 +00002548 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002549 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002550 {
2551 s.PutCString("->");
2552 }
Enrico Granata4becb372011-06-29 22:27:15 +00002553 else
2554 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002555 const uint32_t non_base_class_parent_type_info = non_base_class_parent_compiler_type.GetTypeInfo();
Greg Clayton57ee3062013-07-11 22:46:58 +00002556
Enrico Granata622be232014-10-21 20:52:14 +00002557 if (non_base_class_parent_type_info & eTypeIsPointer)
Enrico Granata4becb372011-06-29 22:27:15 +00002558 {
2559 s.PutCString("->");
2560 }
Enrico Granata622be232014-10-21 20:52:14 +00002561 else if ((non_base_class_parent_type_info & eTypeHasChildren) &&
2562 !(non_base_class_parent_type_info & eTypeIsArray))
Enrico Granata4becb372011-06-29 22:27:15 +00002563 {
2564 s.PutChar('.');
2565 }
Greg Claytone221f822011-01-21 01:59:00 +00002566 }
2567 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002568 }
Greg Claytone221f822011-01-21 01:59:00 +00002569
2570 const char *name = GetName().GetCString();
2571 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002572 {
Greg Claytone221f822011-01-21 01:59:00 +00002573 if (qualify_cxx_base_classes)
2574 {
2575 if (GetBaseClassPath (s))
2576 s.PutCString("::");
2577 }
2578 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002579 }
2580 }
2581 }
2582
Enrico Granata86cc9822012-03-19 22:58:49 +00002583 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002584 {
Greg Claytone221f822011-01-21 01:59:00 +00002585 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002586 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002587}
2588
Greg Claytonafacd142011-09-02 01:15:17 +00002589ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002590ValueObject::GetValueForExpressionPath(const char* expression,
2591 const char** first_unparsed,
2592 ExpressionPathScanEndReason* reason_to_stop,
2593 ExpressionPathEndResultType* final_value_type,
2594 const GetValueForExpressionPathOptions& options,
2595 ExpressionPathAftermath* final_task_on_target)
2596{
2597
2598 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002599 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2600 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002601 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002602
2603 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2604 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2605 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2606 final_value_type ? final_value_type : &dummy_final_value_type,
2607 options,
2608 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2609
Enrico Granata86cc9822012-03-19 22:58:49 +00002610 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002611 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002612
Enrico Granata86cc9822012-03-19 22:58:49 +00002613 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 +00002614 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002615 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002616 {
2617 Error error;
2618 ValueObjectSP final_value = ret_val->Dereference(error);
2619 if (error.Fail() || !final_value.get())
2620 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002621 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002622 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002623 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002624 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002625 return ValueObjectSP();
2626 }
2627 else
2628 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002629 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002630 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002631 return final_value;
2632 }
2633 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002634 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002635 {
2636 Error error;
2637 ValueObjectSP final_value = ret_val->AddressOf(error);
2638 if (error.Fail() || !final_value.get())
2639 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002640 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002641 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002642 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002643 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002644 return ValueObjectSP();
2645 }
2646 else
2647 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002648 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002649 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002650 return final_value;
2651 }
2652 }
2653 }
2654 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2655}
2656
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002657int
2658ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002659 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002660 const char** first_unparsed,
2661 ExpressionPathScanEndReason* reason_to_stop,
2662 ExpressionPathEndResultType* final_value_type,
2663 const GetValueForExpressionPathOptions& options,
2664 ExpressionPathAftermath* final_task_on_target)
2665{
2666 const char* dummy_first_unparsed;
2667 ExpressionPathScanEndReason dummy_reason_to_stop;
2668 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002669 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002670
2671 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2672 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2673 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2674 final_value_type ? final_value_type : &dummy_final_value_type,
2675 options,
2676 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2677
2678 if (!ret_val.get()) // if there are errors, I add nothing to the list
2679 return 0;
2680
Enrico Granata86ea8d82012-03-29 01:34:34 +00002681 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002682 {
2683 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002684 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002685 {
2686 list->Append(ret_val);
2687 return 1;
2688 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002689 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 +00002690 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002691 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002692 {
2693 Error error;
2694 ValueObjectSP final_value = ret_val->Dereference(error);
2695 if (error.Fail() || !final_value.get())
2696 {
Greg Clayton23f59502012-07-17 03:23:13 +00002697 if (reason_to_stop)
2698 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2699 if (final_value_type)
2700 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002701 return 0;
2702 }
2703 else
2704 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002705 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002706 list->Append(final_value);
2707 return 1;
2708 }
2709 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002710 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002711 {
2712 Error error;
2713 ValueObjectSP final_value = ret_val->AddressOf(error);
2714 if (error.Fail() || !final_value.get())
2715 {
Greg Clayton23f59502012-07-17 03:23:13 +00002716 if (reason_to_stop)
2717 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2718 if (final_value_type)
2719 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002720 return 0;
2721 }
2722 else
2723 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002724 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002725 list->Append(final_value);
2726 return 1;
2727 }
2728 }
2729 }
2730 }
2731 else
2732 {
2733 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2734 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2735 ret_val,
2736 list,
2737 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2738 final_value_type ? final_value_type : &dummy_final_value_type,
2739 options,
2740 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2741 }
2742 // in any non-covered case, just do the obviously right thing
2743 list->Append(ret_val);
2744 return 1;
2745}
2746
Greg Claytonafacd142011-09-02 01:15:17 +00002747ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002748ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2749 const char** first_unparsed,
2750 ExpressionPathScanEndReason* reason_to_stop,
2751 ExpressionPathEndResultType* final_result,
2752 const GetValueForExpressionPathOptions& options,
2753 ExpressionPathAftermath* what_next)
2754{
2755 ValueObjectSP root = GetSP();
2756
2757 if (!root.get())
2758 return ValueObjectSP();
2759
2760 *first_unparsed = expression_cstr;
2761
2762 while (true)
2763 {
2764
2765 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2766
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002767 CompilerType root_compiler_type = root->GetCompilerType();
2768 CompilerType pointee_compiler_type;
2769 Flags pointee_compiler_type_info;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002770
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002771 Flags root_compiler_type_info(root_compiler_type.GetTypeInfo(&pointee_compiler_type));
2772 if (pointee_compiler_type)
2773 pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002774
2775 if (!expression_cstr || *expression_cstr == '\0')
2776 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002777 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002778 return root;
2779 }
2780
2781 switch (*expression_cstr)
2782 {
2783 case '-':
2784 {
2785 if (options.m_check_dot_vs_arrow_syntax &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002786 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 +00002787 {
2788 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002789 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2790 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002791 return ValueObjectSP();
2792 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002793 if (root_compiler_type_info.Test(eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2794 root_compiler_type_info.Test(eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002795 options.m_no_fragile_ivar)
2796 {
2797 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002798 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2799 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002800 return ValueObjectSP();
2801 }
2802 if (expression_cstr[1] != '>')
2803 {
2804 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002805 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2806 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002807 return ValueObjectSP();
2808 }
2809 expression_cstr++; // skip the -
2810 }
2811 case '.': // or fallthrough from ->
2812 {
2813 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002814 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 +00002815 {
2816 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002817 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2818 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002819 return ValueObjectSP();
2820 }
2821 expression_cstr++; // skip .
2822 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2823 ConstString child_name;
2824 if (!next_separator) // if no other separator just expand this last layer
2825 {
2826 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002827 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2828
2829 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002830 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002831 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002832 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2833 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002834 return child_valobj_sp;
2835 }
Enrico Granataef238c12015-03-12 22:30:58 +00002836 else
Enrico Granata8c9d3562011-08-11 17:08:01 +00002837 {
Enrico Granataef238c12015-03-12 22:30:58 +00002838 switch (options.m_synthetic_children_traversal)
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002839 {
Enrico Granataef238c12015-03-12 22:30:58 +00002840 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None:
2841 break;
2842 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic:
2843 if (root->IsSynthetic())
2844 {
2845 child_valobj_sp = root->GetNonSyntheticValue();
2846 if (child_valobj_sp.get())
2847 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2848 }
2849 break;
2850 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic:
2851 if (!root->IsSynthetic())
2852 {
2853 child_valobj_sp = root->GetSyntheticValue();
2854 if (child_valobj_sp.get())
2855 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2856 }
2857 break;
2858 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both:
2859 if (root->IsSynthetic())
2860 {
2861 child_valobj_sp = root->GetNonSyntheticValue();
2862 if (child_valobj_sp.get())
2863 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2864 }
2865 else
2866 {
2867 child_valobj_sp = root->GetSyntheticValue();
2868 if (child_valobj_sp.get())
2869 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2870 }
2871 break;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002872 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002873 }
2874
2875 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2876 // so we hit the "else" branch, and return an error
2877 if(child_valobj_sp.get()) // if it worked, just return
2878 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002879 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002880 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2881 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002882 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002883 }
2884 else
2885 {
2886 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002887 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2888 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002889 return ValueObjectSP();
2890 }
2891 }
2892 else // other layers do expand
2893 {
2894 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002895 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2896 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002897 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002898 root = child_valobj_sp;
2899 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002900 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002901 continue;
2902 }
Enrico Granataef238c12015-03-12 22:30:58 +00002903 else
Enrico Granata8c9d3562011-08-11 17:08:01 +00002904 {
Enrico Granataef238c12015-03-12 22:30:58 +00002905 switch (options.m_synthetic_children_traversal)
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002906 {
Enrico Granataef238c12015-03-12 22:30:58 +00002907 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None:
2908 break;
2909 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic:
2910 if (root->IsSynthetic())
2911 {
2912 child_valobj_sp = root->GetNonSyntheticValue();
2913 if (child_valobj_sp.get())
2914 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2915 }
2916 break;
2917 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic:
2918 if (!root->IsSynthetic())
2919 {
2920 child_valobj_sp = root->GetSyntheticValue();
2921 if (child_valobj_sp.get())
2922 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2923 }
2924 break;
2925 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both:
2926 if (root->IsSynthetic())
2927 {
2928 child_valobj_sp = root->GetNonSyntheticValue();
2929 if (child_valobj_sp.get())
2930 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2931 }
2932 else
2933 {
2934 child_valobj_sp = root->GetSyntheticValue();
2935 if (child_valobj_sp.get())
2936 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2937 }
2938 break;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002939 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002940 }
2941
2942 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2943 // so we hit the "else" branch, and return an error
2944 if(child_valobj_sp.get()) // if it worked, move on
2945 {
2946 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002947 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002948 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002949 continue;
2950 }
2951 else
2952 {
2953 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002954 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2955 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002956 return ValueObjectSP();
2957 }
2958 }
2959 break;
2960 }
2961 case '[':
2962 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002963 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 +00002964 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002965 if (!root_compiler_type_info.Test(eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002966 {
Enrico Granataef238c12015-03-12 22:30:58 +00002967 if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None) // ...only chance left is synthetic
Enrico Granata27b625e2011-08-09 01:04:56 +00002968 {
2969 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002970 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2971 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002972 return ValueObjectSP();
2973 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002974 }
2975 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2976 {
2977 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002978 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2979 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002980 return ValueObjectSP();
2981 }
2982 }
2983 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2984 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002985 if (!root_compiler_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002986 {
2987 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002988 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2989 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002990 return ValueObjectSP();
2991 }
2992 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2993 {
2994 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002995 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2996 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002997 return root;
2998 }
2999 }
3000 const char *separator_position = ::strchr(expression_cstr+1,'-');
3001 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3002 if (!close_bracket_position) // if there is no ], this is a syntax error
3003 {
3004 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003005 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3006 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003007 return ValueObjectSP();
3008 }
3009 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3010 {
3011 char *end = NULL;
3012 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3013 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3014 {
3015 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003016 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3017 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003018 return ValueObjectSP();
3019 }
3020 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3021 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003022 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003023 {
3024 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003025 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3026 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003027 return root;
3028 }
3029 else
3030 {
3031 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003032 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3033 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003034 return ValueObjectSP();
3035 }
3036 }
3037 // from here on we do have a valid index
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003038 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003039 {
Greg Claytondaf515f2011-07-09 20:12:33 +00003040 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
3041 if (!child_valobj_sp)
Bruce Mitchener11d86362015-02-26 23:55:39 +00003042 child_valobj_sp = root->GetSyntheticArrayMember(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003043 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00003044 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
3045 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00003046 if (child_valobj_sp)
3047 {
3048 root = child_valobj_sp;
3049 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003050 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00003051 continue;
3052 }
3053 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003054 {
3055 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003056 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3057 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003058 return ValueObjectSP();
3059 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003060 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003061 else if (root_compiler_type_info.Test(eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003062 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003063 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 +00003064 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003065 {
3066 Error error;
3067 root = root->Dereference(error);
3068 if (error.Fail() || !root.get())
3069 {
3070 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003071 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3072 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003073 return ValueObjectSP();
3074 }
3075 else
3076 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003077 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003078 continue;
3079 }
3080 }
3081 else
3082 {
Greg Clayton99558cc42015-08-24 23:46:31 +00003083 if (root->GetCompilerType().GetMinimumLanguage() == eLanguageTypeObjC
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003084 && pointee_compiler_type_info.AllClear(eTypeIsPointer)
Greg Clayton84db9102012-03-26 23:03:23 +00003085 && root->HasSyntheticValue()
Enrico Granataef238c12015-03-12 22:30:58 +00003086 && (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic ||
3087 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both))
Enrico Granata27b625e2011-08-09 01:04:56 +00003088 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003089 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003090 }
3091 else
Bruce Mitchener11d86362015-02-26 23:55:39 +00003092 root = root->GetSyntheticArrayMember(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003093 if (!root.get())
3094 {
3095 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003096 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3097 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003098 return ValueObjectSP();
3099 }
3100 else
3101 {
3102 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003103 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003104 continue;
3105 }
3106 }
3107 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003108 else if (root_compiler_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003109 {
3110 root = root->GetSyntheticBitFieldChild(index, index, true);
3111 if (!root.get())
3112 {
3113 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003114 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3115 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003116 return ValueObjectSP();
3117 }
3118 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3119 {
3120 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003121 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3122 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003123 return root;
3124 }
3125 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003126 else if (root_compiler_type_info.Test(eTypeIsVector))
Enrico Granata08a1bb82013-06-19 00:00:45 +00003127 {
3128 root = root->GetChildAtIndex(index, true);
3129 if (!root.get())
3130 {
3131 *first_unparsed = expression_cstr;
3132 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3133 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3134 return ValueObjectSP();
3135 }
3136 else
3137 {
3138 *first_unparsed = end+1; // skip ]
3139 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3140 continue;
3141 }
3142 }
Enrico Granataef238c12015-03-12 22:30:58 +00003143 else if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic ||
3144 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both)
Enrico Granata27b625e2011-08-09 01:04:56 +00003145 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003146 if (root->HasSyntheticValue())
3147 root = root->GetSyntheticValue();
3148 else if (!root->IsSynthetic())
3149 {
3150 *first_unparsed = expression_cstr;
3151 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3152 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3153 return ValueObjectSP();
3154 }
3155 // if we are here, then root itself is a synthetic VO.. should be good to go
3156
Enrico Granata27b625e2011-08-09 01:04:56 +00003157 if (!root.get())
3158 {
3159 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003160 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3161 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3162 return ValueObjectSP();
3163 }
3164 root = root->GetChildAtIndex(index, true);
3165 if (!root.get())
3166 {
3167 *first_unparsed = expression_cstr;
3168 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3169 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003170 return ValueObjectSP();
3171 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00003172 else
3173 {
3174 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003175 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00003176 continue;
3177 }
Enrico Granata27b625e2011-08-09 01:04:56 +00003178 }
3179 else
3180 {
3181 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003182 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3183 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003184 return ValueObjectSP();
3185 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003186 }
3187 else // we have a low and a high index
3188 {
3189 char *end = NULL;
3190 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3191 if (!end || end != separator_position) // if something weird is in our way return an error
3192 {
3193 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003194 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3195 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003196 return ValueObjectSP();
3197 }
3198 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3199 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3200 {
3201 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003202 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3203 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003204 return ValueObjectSP();
3205 }
3206 if (index_lower > index_higher) // swap indices if required
3207 {
3208 unsigned long temp = index_lower;
3209 index_lower = index_higher;
3210 index_higher = temp;
3211 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003212 if (root_compiler_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003213 {
3214 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3215 if (!root.get())
3216 {
3217 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003218 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3219 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003220 return ValueObjectSP();
3221 }
3222 else
3223 {
3224 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003225 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3226 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003227 return root;
3228 }
3229 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003230 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 +00003231 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003232 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003233 {
3234 Error error;
3235 root = root->Dereference(error);
3236 if (error.Fail() || !root.get())
3237 {
3238 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003239 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3240 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003241 return ValueObjectSP();
3242 }
3243 else
3244 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003245 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003246 continue;
3247 }
3248 }
3249 else
3250 {
3251 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003252 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3253 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003254 return root;
3255 }
3256 }
3257 break;
3258 }
3259 default: // some non-separator is in the way
3260 {
3261 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003262 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3263 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003264 return ValueObjectSP();
3265 break;
3266 }
3267 }
3268 }
3269}
3270
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003271int
3272ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3273 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00003274 ValueObjectSP root,
3275 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003276 ExpressionPathScanEndReason* reason_to_stop,
3277 ExpressionPathEndResultType* final_result,
3278 const GetValueForExpressionPathOptions& options,
3279 ExpressionPathAftermath* what_next)
3280{
3281 if (!root.get())
3282 return 0;
3283
3284 *first_unparsed = expression_cstr;
3285
3286 while (true)
3287 {
3288
3289 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3290
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003291 CompilerType root_compiler_type = root->GetCompilerType();
3292 CompilerType pointee_compiler_type;
3293 Flags pointee_compiler_type_info;
3294 Flags root_compiler_type_info(root_compiler_type.GetTypeInfo(&pointee_compiler_type));
3295 if (pointee_compiler_type)
3296 pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003297
3298 if (!expression_cstr || *expression_cstr == '\0')
3299 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003300 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003301 list->Append(root);
3302 return 1;
3303 }
3304
3305 switch (*expression_cstr)
3306 {
3307 case '[':
3308 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003309 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 +00003310 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003311 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 +00003312 {
3313 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003314 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3315 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003316 return 0;
3317 }
3318 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3319 {
3320 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003321 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3322 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003323 return 0;
3324 }
3325 }
3326 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3327 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003328 if (!root_compiler_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003329 {
3330 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003331 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3332 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003333 return 0;
3334 }
3335 else // expand this into list
3336 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003337 const size_t max_index = root->GetNumChildren() - 1;
3338 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003339 {
3340 ValueObjectSP child =
3341 root->GetChildAtIndex(index, true);
3342 list->Append(child);
3343 }
3344 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003345 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3346 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003347 return max_index; // tell me number of items I added to the VOList
3348 }
3349 }
3350 const char *separator_position = ::strchr(expression_cstr+1,'-');
3351 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3352 if (!close_bracket_position) // if there is no ], this is a syntax error
3353 {
3354 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003355 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3356 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003357 return 0;
3358 }
3359 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3360 {
3361 char *end = NULL;
3362 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3363 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3364 {
3365 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003366 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3367 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003368 return 0;
3369 }
3370 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3371 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003372 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003373 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003374 const size_t max_index = root->GetNumChildren() - 1;
3375 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003376 {
3377 ValueObjectSP child =
3378 root->GetChildAtIndex(index, true);
3379 list->Append(child);
3380 }
3381 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003382 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3383 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003384 return max_index; // tell me number of items I added to the VOList
3385 }
3386 else
3387 {
3388 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003389 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3390 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003391 return 0;
3392 }
3393 }
3394 // from here on we do have a valid index
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003395 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003396 {
3397 root = root->GetChildAtIndex(index, true);
3398 if (!root.get())
3399 {
3400 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003401 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3402 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003403 return 0;
3404 }
3405 else
3406 {
3407 list->Append(root);
3408 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003409 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3410 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003411 return 1;
3412 }
3413 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003414 else if (root_compiler_type_info.Test(eTypeIsPointer))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003415 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003416 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 +00003417 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003418 {
3419 Error error;
3420 root = root->Dereference(error);
3421 if (error.Fail() || !root.get())
3422 {
3423 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003424 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3425 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003426 return 0;
3427 }
3428 else
3429 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003430 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003431 continue;
3432 }
3433 }
3434 else
3435 {
Bruce Mitchener11d86362015-02-26 23:55:39 +00003436 root = root->GetSyntheticArrayMember(index, true);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003437 if (!root.get())
3438 {
3439 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003440 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3441 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003442 return 0;
3443 }
3444 else
3445 {
3446 list->Append(root);
3447 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003448 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3449 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003450 return 1;
3451 }
3452 }
3453 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003454 else /*if (ClangASTContext::IsScalarType(root_compiler_type))*/
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003455 {
3456 root = root->GetSyntheticBitFieldChild(index, index, true);
3457 if (!root.get())
3458 {
3459 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003460 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3461 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003462 return 0;
3463 }
3464 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3465 {
3466 list->Append(root);
3467 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003468 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3469 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003470 return 1;
3471 }
3472 }
3473 }
3474 else // we have a low and a high index
3475 {
3476 char *end = NULL;
3477 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3478 if (!end || end != separator_position) // if something weird is in our way return an error
3479 {
3480 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003481 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3482 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003483 return 0;
3484 }
3485 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3486 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3487 {
3488 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003489 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3490 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003491 return 0;
3492 }
3493 if (index_lower > index_higher) // swap indices if required
3494 {
3495 unsigned long temp = index_lower;
3496 index_lower = index_higher;
3497 index_higher = temp;
3498 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003499 if (root_compiler_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003500 {
3501 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3502 if (!root.get())
3503 {
3504 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003505 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3506 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003507 return 0;
3508 }
3509 else
3510 {
3511 list->Append(root);
3512 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003513 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3514 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003515 return 1;
3516 }
3517 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003518 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 +00003519 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003520 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003521 {
3522 Error error;
3523 root = root->Dereference(error);
3524 if (error.Fail() || !root.get())
3525 {
3526 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003527 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3528 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003529 return 0;
3530 }
3531 else
3532 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003533 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003534 continue;
3535 }
3536 }
3537 else
3538 {
Johnny Chen44805302011-07-19 19:48:13 +00003539 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003540 index <= index_higher; index++)
3541 {
3542 ValueObjectSP child =
3543 root->GetChildAtIndex(index, true);
3544 list->Append(child);
3545 }
3546 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003547 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3548 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003549 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3550 }
3551 }
3552 break;
3553 }
3554 default: // some non-[ separator, or something entirely wrong, is in the way
3555 {
3556 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003557 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3558 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003559 return 0;
3560 break;
3561 }
3562 }
3563 }
3564}
3565
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003566void
3567ValueObject::LogValueObject (Log *log)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003568{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003569 if (log)
Enrico Granatad5957332015-06-03 20:43:54 +00003570 return LogValueObject (log, DumpValueObjectOptions(*this));
Greg Clayton1d3afba2010-10-05 00:00:42 +00003571}
3572
Enrico Granata0c489f52012-03-01 04:24:26 +00003573void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003574ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003575{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003576 if (log)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003577 {
3578 StreamString s;
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003579 Dump (s, options);
Greg Claytonf830dbb2012-03-22 18:15:37 +00003580 if (s.GetSize())
3581 log->PutCString(s.GetData());
3582 }
3583}
3584
3585void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003586ValueObject::Dump (Stream &s)
Enrico Granata0c489f52012-03-01 04:24:26 +00003587{
Enrico Granatad5957332015-06-03 20:43:54 +00003588 Dump (s, DumpValueObjectOptions(*this));
Enrico Granata0c489f52012-03-01 04:24:26 +00003589}
3590
3591void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003592ValueObject::Dump (Stream &s,
3593 const DumpValueObjectOptions& options)
Enrico Granata0c489f52012-03-01 04:24:26 +00003594{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003595 ValueObjectPrinter printer(this,&s,options);
3596 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003597}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003598
3599ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003600ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003601{
3602 ValueObjectSP valobj_sp;
3603
Enrico Granatac3e320a2011-08-02 17:27:39 +00003604 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003605 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003606 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003607
3608 DataExtractor data;
3609 data.SetByteOrder (m_data.GetByteOrder());
3610 data.SetAddressByteSize(m_data.GetAddressByteSize());
3611
Enrico Granata9f1e2042012-04-24 22:15:37 +00003612 if (IsBitfield())
3613 {
3614 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
Greg Clayton57ee3062013-07-11 22:46:58 +00003615 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Enrico Granata9f1e2042012-04-24 22:15:37 +00003616 }
3617 else
Greg Clayton57ee3062013-07-11 22:46:58 +00003618 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003619
3620 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton99558cc42015-08-24 23:46:31 +00003621 GetCompilerType(),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003622 name,
3623 data,
3624 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003625 }
Jim Ingham6035b672011-03-31 00:19:25 +00003626
3627 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003628 {
Greg Claytoneeb15652013-12-10 23:16:40 +00003629 ExecutionContext exe_ctx (GetExecutionContextRef());
3630 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003631 }
3632 return valobj_sp;
3633}
3634
Enrico Granata538a88a2014-10-09 18:24:30 +00003635ValueObjectSP
3636ValueObject::GetQualifiedRepresentationIfAvailable (lldb::DynamicValueType dynValue,
3637 bool synthValue)
3638{
3639 ValueObjectSP result_sp(GetSP());
3640
3641 switch (dynValue)
3642 {
3643 case lldb::eDynamicCanRunTarget:
3644 case lldb::eDynamicDontRunTarget:
3645 {
3646 if (!result_sp->IsDynamic())
3647 {
3648 if (result_sp->GetDynamicValue(dynValue))
3649 result_sp = result_sp->GetDynamicValue(dynValue);
3650 }
3651 }
3652 break;
3653 case lldb::eNoDynamicValues:
Enrico Granata538a88a2014-10-09 18:24:30 +00003654 {
3655 if (result_sp->IsDynamic())
3656 {
3657 if (result_sp->GetStaticValue())
3658 result_sp = result_sp->GetStaticValue();
3659 }
3660 }
3661 break;
3662 }
3663
3664 if (synthValue)
3665 {
3666 if (!result_sp->IsSynthetic())
3667 {
3668 if (result_sp->GetSyntheticValue())
3669 result_sp = result_sp->GetSyntheticValue();
3670 }
3671 }
3672 else
3673 {
3674 if (result_sp->IsSynthetic())
3675 {
3676 if (result_sp->GetNonSyntheticValue())
3677 result_sp = result_sp->GetNonSyntheticValue();
3678 }
3679 }
3680
3681 return result_sp;
3682}
3683
Greg Clayton759e7442014-07-19 00:12:57 +00003684lldb::addr_t
3685ValueObject::GetCPPVTableAddress (AddressType &address_type)
3686{
Greg Claytona1e5dc82015-08-11 22:53:00 +00003687 CompilerType pointee_type;
Greg Clayton99558cc42015-08-24 23:46:31 +00003688 CompilerType this_type(GetCompilerType());
Greg Clayton759e7442014-07-19 00:12:57 +00003689 uint32_t type_info = this_type.GetTypeInfo(&pointee_type);
3690 if (type_info)
3691 {
3692 bool ptr_or_ref = false;
Enrico Granata622be232014-10-21 20:52:14 +00003693 if (type_info & (eTypeIsPointer | eTypeIsReference))
Greg Clayton759e7442014-07-19 00:12:57 +00003694 {
3695 ptr_or_ref = true;
3696 type_info = pointee_type.GetTypeInfo();
3697 }
3698
Enrico Granata622be232014-10-21 20:52:14 +00003699 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus;
Greg Clayton759e7442014-07-19 00:12:57 +00003700 if ((type_info & cpp_class) == cpp_class)
3701 {
3702 if (ptr_or_ref)
3703 {
3704 address_type = GetAddressTypeOfChildren();
3705 return GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
3706 }
3707 else
3708 return GetAddressOf (false, &address_type);
3709 }
3710 }
3711
3712 address_type = eAddressTypeInvalid;
3713 return LLDB_INVALID_ADDRESS;
3714}
3715
Greg Claytonafacd142011-09-02 01:15:17 +00003716ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003717ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003718{
Jim Ingham58b59f92011-04-22 23:53:53 +00003719 if (m_deref_valobj)
3720 return m_deref_valobj->GetSP();
Chaoren Lind7bdc272015-07-31 00:35:40 +00003721
3722 const bool is_pointer_or_reference_type = IsPointerOrReferenceType();
3723 if (is_pointer_or_reference_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003724 {
3725 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003726 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003727
3728 std::string child_name_str;
3729 uint32_t child_byte_size = 0;
3730 int32_t child_byte_offset = 0;
3731 uint32_t child_bitfield_bit_size = 0;
3732 uint32_t child_bitfield_bit_offset = 0;
3733 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003734 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003735 const bool transparent_pointers = false;
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003736 CompilerType compiler_type = GetCompilerType();
3737 CompilerType child_compiler_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003738
Greg Claytoncc4d0142012-02-17 07:49:44 +00003739 ExecutionContext exe_ctx (GetExecutionContextRef());
Chaoren Lind7bdc272015-07-31 00:35:40 +00003740
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003741 child_compiler_type = compiler_type.GetChildCompilerTypeAtIndex (&exe_ctx,
3742 0,
3743 transparent_pointers,
3744 omit_empty_base_classes,
3745 ignore_array_bounds,
3746 child_name_str,
3747 child_byte_size,
3748 child_byte_offset,
3749 child_bitfield_bit_size,
3750 child_bitfield_bit_offset,
3751 child_is_base_class,
3752 child_is_deref_of_parent,
3753 this);
3754 if (child_compiler_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003755 {
3756 ConstString child_name;
3757 if (!child_name_str.empty())
3758 child_name.SetCString (child_name_str.c_str());
3759
Jim Ingham58b59f92011-04-22 23:53:53 +00003760 m_deref_valobj = new ValueObjectChild (*this,
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003761 child_compiler_type,
Jim Ingham58b59f92011-04-22 23:53:53 +00003762 child_name,
3763 child_byte_size,
3764 child_byte_offset,
3765 child_bitfield_bit_size,
3766 child_bitfield_bit_offset,
3767 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003768 child_is_deref_of_parent,
3769 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003770 }
3771 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003772
Jim Ingham58b59f92011-04-22 23:53:53 +00003773 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003774 {
3775 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003776 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003777 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003778 else
3779 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003780 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003781 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003782
Chaoren Lind7bdc272015-07-31 00:35:40 +00003783 if (is_pointer_or_reference_type)
Greg Clayton54979cd2010-12-15 05:08:08 +00003784 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3785 else
Chaoren Lind7bdc272015-07-31 00:35:40 +00003786 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 +00003787 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003788 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003789}
3790
Greg Claytonafacd142011-09-02 01:15:17 +00003791ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003792ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003793{
Jim Ingham78a685a2011-04-16 00:01:13 +00003794 if (m_addr_of_valobj_sp)
3795 return m_addr_of_valobj_sp;
3796
Greg Claytone0d378b2011-03-24 21:19:54 +00003797 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003798 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003799 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003800 error.Clear();
Siva Chandraa3747a92015-05-04 19:43:34 +00003801 if (addr != LLDB_INVALID_ADDRESS && address_type != eAddressTypeHost)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003802 {
3803 switch (address_type)
3804 {
3805 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003806 {
3807 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003808 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003809 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3810 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003811 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003812
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003813 case eAddressTypeFile:
3814 case eAddressTypeLoad:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003815 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003816 CompilerType compiler_type = GetCompilerType();
3817 if (compiler_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003818 {
3819 std::string name (1, '&');
3820 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003821 ExecutionContext exe_ctx (GetExecutionContextRef());
3822 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003823 compiler_type.GetPointerType(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003824 ConstString (name.c_str()),
3825 addr,
3826 eAddressTypeInvalid,
3827 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003828 }
3829 }
3830 break;
Siva Chandraa3747a92015-05-04 19:43:34 +00003831 default:
3832 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003833 }
3834 }
Sean Callananed185ab2013-04-19 19:47:32 +00003835 else
3836 {
3837 StreamString expr_path_strm;
3838 GetExpressionPath(expr_path_strm, true);
3839 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3840 }
3841
Jim Ingham78a685a2011-04-16 00:01:13 +00003842 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003843}
3844
Greg Clayton9a142cf2012-02-03 05:34:10 +00003845ValueObjectSP
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003846ValueObject::Cast (const CompilerType &compiler_type)
Greg Clayton9a142cf2012-02-03 05:34:10 +00003847{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003848 return ValueObjectCast::Create (*this, GetName(), compiler_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003849}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003850
Greg Claytonafacd142011-09-02 01:15:17 +00003851ValueObjectSP
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003852ValueObject::CastPointerType (const char *name, CompilerType &compiler_type)
Greg Claytonb2dcc362011-05-05 23:32:56 +00003853{
Greg Claytonafacd142011-09-02 01:15:17 +00003854 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003855 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003856 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003857
3858 if (ptr_value != LLDB_INVALID_ADDRESS)
3859 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003860 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003861 ExecutionContext exe_ctx (GetExecutionContextRef());
3862 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003863 name,
3864 ptr_addr,
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003865 compiler_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003866 }
3867 return valobj_sp;
3868}
3869
Greg Claytonafacd142011-09-02 01:15:17 +00003870ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003871ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3872{
Greg Claytonafacd142011-09-02 01:15:17 +00003873 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003874 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003875 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003876
3877 if (ptr_value != LLDB_INVALID_ADDRESS)
3878 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003879 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003880 ExecutionContext exe_ctx (GetExecutionContextRef());
3881 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003882 name,
3883 ptr_addr,
3884 type_sp);
3885 }
3886 return valobj_sp;
3887}
3888
Jim Ingham6035b672011-03-31 00:19:25 +00003889ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003890 m_mod_id(),
3891 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003892 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003893{
3894}
3895
3896ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003897 m_mod_id(),
3898 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003899 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003900{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003901 ExecutionContext exe_ctx(exe_scope);
3902 TargetSP target_sp (exe_ctx.GetTargetSP());
3903 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003904 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003905 m_exe_ctx_ref.SetTargetSP (target_sp);
3906 ProcessSP process_sp (exe_ctx.GetProcessSP());
3907 if (!process_sp)
3908 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003909
Greg Claytoncc4d0142012-02-17 07:49:44 +00003910 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003911 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003912 m_mod_id = process_sp->GetModID();
3913 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003914
Greg Claytoncc4d0142012-02-17 07:49:44 +00003915 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003916
Greg Claytoncc4d0142012-02-17 07:49:44 +00003917 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003918 {
3919 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003920 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003921 }
Jim Ingham6035b672011-03-31 00:19:25 +00003922
Greg Claytoncc4d0142012-02-17 07:49:44 +00003923 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003924 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003925 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003926
Jason Molendab57e4a12013-11-04 09:33:30 +00003927 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003928 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003929 {
3930 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003931 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003932 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003933 if (frame_sp)
3934 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003935 }
3936 }
3937 }
Jim Ingham6035b672011-03-31 00:19:25 +00003938}
3939
3940ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003941 m_mod_id(),
3942 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003943 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003944{
3945}
3946
3947ValueObject::EvaluationPoint::~EvaluationPoint ()
3948{
3949}
3950
Jim Ingham6035b672011-03-31 00:19:25 +00003951// This function checks the EvaluationPoint against the current process state. If the current
3952// state matches the evaluation point, or the evaluation point is already invalid, then we return
3953// false, meaning "no change". If the current state is different, we update our state, and return
3954// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3955// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003956// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003957
3958bool
Enrico Granatabb642e52015-05-16 01:27:00 +00003959ValueObject::EvaluationPoint::SyncWithProcessState(bool accept_invalid_exe_ctx)
Jim Ingham6035b672011-03-31 00:19:25 +00003960{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003961 // 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 +00003962 const bool thread_and_frame_only_if_stopped = true;
3963 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
Jim Ingham73ca05a2011-12-17 01:35:57 +00003964
Greg Claytoncc4d0142012-02-17 07:49:44 +00003965 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003966 return false;
3967
Jim Ingham6035b672011-03-31 00:19:25 +00003968 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003969 Process *process = exe_ctx.GetProcessPtr();
3970 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003971 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003972
Jim Ingham6035b672011-03-31 00:19:25 +00003973 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003974 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003975
Jim Ingham78a685a2011-04-16 00:01:13 +00003976 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3977 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003978 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003979 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003980
Greg Clayton23f59502012-07-17 03:23:13 +00003981 bool changed = false;
3982 const bool was_valid = m_mod_id.IsValid();
3983 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003984 {
3985 if (m_mod_id == current_mod_id)
3986 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003987 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003988 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003989 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003990 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003991 else
3992 {
3993 m_mod_id = current_mod_id;
3994 m_needs_update = true;
3995 changed = true;
3996 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003997 }
Jim Ingham6035b672011-03-31 00:19:25 +00003998
Jim Ingham73ca05a2011-12-17 01:35:57 +00003999 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
4000 // That way we'll be sure to return a valid exe_scope.
4001 // 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 +00004002
Enrico Granatabb642e52015-05-16 01:27:00 +00004003 if (!accept_invalid_exe_ctx)
Jim Ingham6035b672011-03-31 00:19:25 +00004004 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004005 if (m_exe_ctx_ref.HasThreadRef())
Greg Clayton262f80d2011-07-06 16:49:27 +00004006 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004007 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
4008 if (thread_sp)
Greg Claytoncc4d0142012-02-17 07:49:44 +00004009 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004010 if (m_exe_ctx_ref.HasFrameRef())
Greg Claytoncc4d0142012-02-17 07:49:44 +00004011 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004012 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
4013 if (!frame_sp)
4014 {
4015 // We used to have a frame, but now it is gone
4016 SetInvalid();
4017 changed = was_valid;
4018 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00004019 }
4020 }
Enrico Granatabb642e52015-05-16 01:27:00 +00004021 else
4022 {
4023 // We used to have a thread, but now it is gone
4024 SetInvalid();
4025 changed = was_valid;
4026 }
Greg Clayton262f80d2011-07-06 16:49:27 +00004027 }
Jim Ingham6035b672011-03-31 00:19:25 +00004028 }
Enrico Granatabb642e52015-05-16 01:27:00 +00004029
Jim Ingham9ee01152011-12-10 01:49:43 +00004030 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00004031}
4032
Jim Ingham61be0902011-05-02 18:13:59 +00004033void
4034ValueObject::EvaluationPoint::SetUpdated ()
4035{
Greg Claytoncc4d0142012-02-17 07:49:44 +00004036 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
4037 if (process_sp)
4038 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00004039 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00004040}
4041
4042
Enrico Granataf2bbf712011-07-15 02:26:42 +00004043
4044void
Enrico Granata86cc9822012-03-19 22:58:49 +00004045ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004046{
Enrico Granata86cc9822012-03-19 22:58:49 +00004047 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4048 m_value_str.clear();
4049
4050 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4051 m_location_str.clear();
4052
4053 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
Enrico Granata86cc9822012-03-19 22:58:49 +00004054 m_summary_str.clear();
Enrico Granata86cc9822012-03-19 22:58:49 +00004055
4056 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4057 m_object_desc_str.clear();
4058
4059 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4060 {
4061 if (m_synthetic_value)
4062 m_synthetic_value = NULL;
4063 }
Enrico Granata744794a2014-09-05 21:46:22 +00004064
4065 if ((clear_mask & eClearUserVisibleDataItemsValidator) == eClearUserVisibleDataItemsValidator)
4066 m_validation_result.reset();
Johnny Chen44805302011-07-19 19:48:13 +00004067}
Enrico Granata9128ee22011-09-06 19:20:51 +00004068
4069SymbolContextScope *
4070ValueObject::GetSymbolContextScope()
4071{
4072 if (m_parent)
4073 {
4074 if (!m_parent->IsPointerOrReferenceType())
4075 return m_parent->GetSymbolContextScope();
4076 }
4077 return NULL;
4078}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004079
4080lldb::ValueObjectSP
4081ValueObject::CreateValueObjectFromExpression (const char* name,
4082 const char* expression,
4083 const ExecutionContext& exe_ctx)
4084{
Enrico Granata972be532014-12-17 21:18:43 +00004085 return CreateValueObjectFromExpression(name, expression, exe_ctx, EvaluateExpressionOptions());
4086}
4087
4088
4089lldb::ValueObjectSP
4090ValueObject::CreateValueObjectFromExpression (const char* name,
4091 const char* expression,
4092 const ExecutionContext& exe_ctx,
4093 const EvaluateExpressionOptions& options)
4094{
Enrico Granatab2698cd2012-09-13 18:27:09 +00004095 lldb::ValueObjectSP retval_sp;
4096 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4097 if (!target_sp)
4098 return retval_sp;
4099 if (!expression || !*expression)
4100 return retval_sp;
4101 target_sp->EvaluateExpression (expression,
4102 exe_ctx.GetFrameSP().get(),
Enrico Granata972be532014-12-17 21:18:43 +00004103 retval_sp,
4104 options);
Enrico Granatab2698cd2012-09-13 18:27:09 +00004105 if (retval_sp && name && *name)
4106 retval_sp->SetName(ConstString(name));
4107 return retval_sp;
4108}
4109
4110lldb::ValueObjectSP
4111ValueObject::CreateValueObjectFromAddress (const char* name,
4112 uint64_t address,
4113 const ExecutionContext& exe_ctx,
Greg Claytona1e5dc82015-08-11 22:53:00 +00004114 CompilerType type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004115{
Greg Clayton57ee3062013-07-11 22:46:58 +00004116 if (type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004117 {
Greg Claytona1e5dc82015-08-11 22:53:00 +00004118 CompilerType pointer_type(type.GetPointerType());
Greg Clayton57ee3062013-07-11 22:46:58 +00004119 if (pointer_type)
4120 {
4121 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4122 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4123 pointer_type,
4124 ConstString(name),
4125 buffer,
Enrico Granata972be532014-12-17 21:18:43 +00004126 exe_ctx.GetByteOrder(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004127 exe_ctx.GetAddressByteSize()));
4128 if (ptr_result_valobj_sp)
4129 {
4130 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4131 Error err;
4132 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4133 if (ptr_result_valobj_sp && name && *name)
4134 ptr_result_valobj_sp->SetName(ConstString(name));
4135 }
4136 return ptr_result_valobj_sp;
4137 }
Enrico Granatab2698cd2012-09-13 18:27:09 +00004138 }
Greg Clayton57ee3062013-07-11 22:46:58 +00004139 return lldb::ValueObjectSP();
Enrico Granatab2698cd2012-09-13 18:27:09 +00004140}
4141
4142lldb::ValueObjectSP
4143ValueObject::CreateValueObjectFromData (const char* name,
Enrico Granata7ca1c762014-03-31 23:02:25 +00004144 const DataExtractor& data,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004145 const ExecutionContext& exe_ctx,
Greg Claytona1e5dc82015-08-11 22:53:00 +00004146 CompilerType type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004147{
4148 lldb::ValueObjectSP new_value_sp;
4149 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004150 type,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004151 ConstString(name),
4152 data,
4153 LLDB_INVALID_ADDRESS);
4154 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4155 if (new_value_sp && name && *name)
4156 new_value_sp->SetName(ConstString(name));
4157 return new_value_sp;
4158}
Enrico Granata4873e522013-04-11 22:48:58 +00004159
4160ModuleSP
4161ValueObject::GetModule ()
4162{
4163 ValueObject* root(GetRoot());
4164 if (root != this)
4165 return root->GetModule();
4166 return lldb::ModuleSP();
4167}
4168
4169ValueObject*
4170ValueObject::GetRoot ()
4171{
4172 if (m_root)
4173 return m_root;
Enrico Granatade61eba2015-01-22 03:07:34 +00004174 return (m_root = FollowParentChain( [] (ValueObject* vo) -> bool {
4175 return (vo->m_parent != nullptr);
4176 }));
4177}
4178
4179ValueObject*
4180ValueObject::FollowParentChain (std::function<bool(ValueObject*)> f)
4181{
4182 ValueObject* vo = this;
4183 while (vo)
Enrico Granata4873e522013-04-11 22:48:58 +00004184 {
Enrico Granatade61eba2015-01-22 03:07:34 +00004185 if (f(vo) == false)
4186 break;
4187 vo = vo->m_parent;
Enrico Granata4873e522013-04-11 22:48:58 +00004188 }
Enrico Granatade61eba2015-01-22 03:07:34 +00004189 return vo;
Enrico Granata4873e522013-04-11 22:48:58 +00004190}
4191
4192AddressType
4193ValueObject::GetAddressTypeOfChildren()
4194{
4195 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
4196 {
4197 ValueObject* root(GetRoot());
4198 if (root != this)
4199 return root->GetAddressTypeOfChildren();
4200 }
4201 return m_address_type_of_ptr_or_ref_children;
4202}
4203
4204lldb::DynamicValueType
4205ValueObject::GetDynamicValueType ()
4206{
4207 ValueObject* with_dv_info = this;
4208 while (with_dv_info)
4209 {
4210 if (with_dv_info->HasDynamicValueTypeInfo())
4211 return with_dv_info->GetDynamicValueTypeImpl();
4212 with_dv_info = with_dv_info->m_parent;
4213 }
4214 return lldb::eNoDynamicValues;
4215}
Enrico Granata39d51412013-05-31 17:43:40 +00004216
Enrico Granata4873e522013-04-11 22:48:58 +00004217lldb::Format
4218ValueObject::GetFormat () const
4219{
4220 const ValueObject* with_fmt_info = this;
4221 while (with_fmt_info)
4222 {
4223 if (with_fmt_info->m_format != lldb::eFormatDefault)
4224 return with_fmt_info->m_format;
4225 with_fmt_info = with_fmt_info->m_parent;
4226 }
4227 return m_format;
4228}
Enrico Granatad07cfd32014-10-08 18:27:36 +00004229
Enrico Granatac1247f52014-11-06 21:23:20 +00004230lldb::LanguageType
4231ValueObject::GetPreferredDisplayLanguage ()
4232{
Enrico Granataed3228a2015-01-21 01:47:13 +00004233 lldb::LanguageType type = m_preferred_display_language;
4234 if (m_preferred_display_language == lldb::eLanguageTypeUnknown)
Enrico Granatac1247f52014-11-06 21:23:20 +00004235 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004236 if (GetRoot())
Enrico Granatac1247f52014-11-06 21:23:20 +00004237 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004238 if (GetRoot() == this)
Enrico Granatac1247f52014-11-06 21:23:20 +00004239 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004240 if (StackFrameSP frame_sp = GetFrameSP())
4241 {
4242 const SymbolContext& sc(frame_sp->GetSymbolContext(eSymbolContextCompUnit));
4243 if (CompileUnit* cu = sc.comp_unit)
4244 type = cu->GetLanguage();
4245 }
4246 }
4247 else
4248 {
4249 type = GetRoot()->GetPreferredDisplayLanguage();
Enrico Granatac1247f52014-11-06 21:23:20 +00004250 }
4251 }
Enrico Granatac1247f52014-11-06 21:23:20 +00004252 }
Enrico Granataed3228a2015-01-21 01:47:13 +00004253 return (m_preferred_display_language = type); // only compute it once
4254}
4255
4256void
4257ValueObject::SetPreferredDisplayLanguage (lldb::LanguageType lt)
4258{
4259 m_preferred_display_language = lt;
Enrico Granatac1247f52014-11-06 21:23:20 +00004260}
4261
Enrico Granatad07cfd32014-10-08 18:27:36 +00004262bool
4263ValueObject::CanProvideValue ()
4264{
Sean Callanan7375f3e2014-12-09 21:18:59 +00004265 // we need to support invalid types as providers of values because some bare-board
4266 // debugging scenarios have no notion of types, but still manage to have raw numeric
4267 // values for things like registers. sigh.
Greg Clayton99558cc42015-08-24 23:46:31 +00004268 const CompilerType &type(GetCompilerType());
Sean Callanan7375f3e2014-12-09 21:18:59 +00004269 return (false == type.IsValid()) || (0 != (type.GetTypeInfo() & eTypeHasValue));
4270}
4271
4272bool
4273ValueObject::IsChecksumEmpty ()
4274{
4275 return m_value_checksum.empty();
Enrico Granatad07cfd32014-10-08 18:27:36 +00004276}
Enrico Granata0c10a852014-12-08 23:13:56 +00004277
4278ValueObjectSP
4279ValueObject::Persist ()
4280{
4281 if (!UpdateValueIfNeeded())
4282 return nullptr;
4283
4284 TargetSP target_sp(GetTargetSP());
4285 if (!target_sp)
4286 return nullptr;
4287
Sean Callananb92bd752015-10-01 16:28:02 +00004288 PersistentExpressionState *persistent_state = target_sp->GetPersistentExpressionStateForLanguage(GetPreferredDisplayLanguage());
Sean Callanan8f1f9a12015-09-30 19:57:57 +00004289
4290 if (!persistent_state)
4291 return nullptr;
4292
4293 ConstString name(persistent_state->GetNextPersistentVariableName());
Enrico Granata0c10a852014-12-08 23:13:56 +00004294
Sean Callanan9301ec12015-10-01 23:07:06 +00004295 ValueObjectSP const_result_sp = ValueObjectConstResult::Create (target_sp.get(), GetValue(), name);
4296
4297 ExpressionVariableSP clang_var_sp = persistent_state->CreatePersistentVariable(const_result_sp);
4298 clang_var_sp->m_live_sp = clang_var_sp->m_frozen_sp;
4299 clang_var_sp->m_flags |= ExpressionVariable::EVIsProgramReference;
Enrico Granata0c10a852014-12-08 23:13:56 +00004300
4301 return clang_var_sp->GetValueObject();
4302}
Enrico Granatae29df232014-12-09 19:51:20 +00004303
4304bool
4305ValueObject::IsSyntheticChildrenGenerated ()
4306{
4307 return m_is_synthetic_children_generated;
4308}
4309
4310void
4311ValueObject::SetSyntheticChildrenGenerated (bool b)
4312{
4313 m_is_synthetic_children_generated = b;
4314}