blob: ecafd202e4ca8e31e46a595a7a9dd82f81a28e17 [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
Siva Chandra9ac7a6c2015-10-21 19:28:08 +0000773ValueObject::GetNumChildren (uint32_t max)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000774{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000775 UpdateValueIfNeeded();
Siva Chandra9ac7a6c2015-10-21 19:28:08 +0000776
777 if (max < UINT32_MAX)
778 {
779 if (m_children_count_valid)
780 {
781 size_t children_count = m_children.GetChildrenCount();
782 return children_count <= max ? children_count : max;
783 }
784 else
785 return CalculateNumChildren(max);
786 }
787
Greg Clayton288bdf92010-09-02 02:59:18 +0000788 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000789 {
790 SetNumChildren (CalculateNumChildren());
791 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000792 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000793}
Greg Clayton4a792072012-10-23 01:50:10 +0000794
795bool
796ValueObject::MightHaveChildren()
797{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000798 bool has_children = false;
Greg Clayton2452ab72013-02-08 22:02:02 +0000799 const uint32_t type_info = GetTypeInfo();
800 if (type_info)
Greg Clayton4a792072012-10-23 01:50:10 +0000801 {
Enrico Granata622be232014-10-21 20:52:14 +0000802 if (type_info & (eTypeHasChildren |
803 eTypeIsPointer |
804 eTypeIsReference))
Greg Clayton4a792072012-10-23 01:50:10 +0000805 has_children = true;
806 }
807 else
808 {
809 has_children = GetNumChildren () > 0;
810 }
811 return has_children;
812}
813
814// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000815void
Greg Claytonc7bece562013-01-25 18:06:21 +0000816ValueObject::SetNumChildren (size_t num_children)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000817{
Greg Clayton288bdf92010-09-02 02:59:18 +0000818 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000819 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000820}
821
822void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000823ValueObject::SetName (const ConstString &name)
824{
825 m_name = name;
826}
827
Jim Ingham58b59f92011-04-22 23:53:53 +0000828ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000829ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000830{
Jim Ingham2eec4872011-05-07 00:10:58 +0000831 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000832
Greg Claytondea8cb42011-06-29 22:09:02 +0000833 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000834 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000835 std::string child_name_str;
836 uint32_t child_byte_size = 0;
837 int32_t child_byte_offset = 0;
838 uint32_t child_bitfield_bit_size = 0;
839 uint32_t child_bitfield_bit_offset = 0;
840 bool child_is_base_class = false;
841 bool child_is_deref_of_parent = false;
842
843 const bool transparent_pointers = synthetic_array_member == false;
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000844 CompilerType child_compiler_type;
Greg Claytondea8cb42011-06-29 22:09:02 +0000845
Greg Claytoncc4d0142012-02-17 07:49:44 +0000846 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000847
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000848 child_compiler_type = GetCompilerType().GetChildCompilerTypeAtIndex (&exe_ctx,
849 idx,
850 transparent_pointers,
851 omit_empty_base_classes,
852 ignore_array_bounds,
853 child_name_str,
854 child_byte_size,
855 child_byte_offset,
856 child_bitfield_bit_size,
857 child_bitfield_bit_offset,
858 child_is_base_class,
859 child_is_deref_of_parent,
860 this);
861 if (child_compiler_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000862 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000863 if (synthetic_index)
864 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000865
Greg Claytondea8cb42011-06-29 22:09:02 +0000866 ConstString child_name;
867 if (!child_name_str.empty())
868 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000869
Greg Claytondea8cb42011-06-29 22:09:02 +0000870 valobj = new ValueObjectChild (*this,
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000871 child_compiler_type,
Greg Claytondea8cb42011-06-29 22:09:02 +0000872 child_name,
873 child_byte_size,
874 child_byte_offset,
875 child_bitfield_bit_size,
876 child_bitfield_bit_offset,
877 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000878 child_is_deref_of_parent,
879 eAddressTypeInvalid);
880 //if (valobj)
881 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
882 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000883
Jim Ingham58b59f92011-04-22 23:53:53 +0000884 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000885}
886
Enrico Granata0c489f52012-03-01 04:24:26 +0000887bool
888ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
Enrico Granata31fda932015-10-07 01:41:23 +0000889 std::string& destination,
890 lldb::LanguageType lang)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000891{
Enrico Granata31fda932015-10-07 01:41:23 +0000892 return GetSummaryAsCString(summary_ptr, destination, TypeSummaryOptions().SetLanguage(lang));
Enrico Granatac1247f52014-11-06 21:23:20 +0000893}
894
895bool
896ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
897 std::string& destination,
898 const TypeSummaryOptions& options)
899{
Enrico Granata0c489f52012-03-01 04:24:26 +0000900 destination.clear();
Enrico Granata31fda932015-10-07 01:41:23 +0000901
Enrico Granata0c489f52012-03-01 04:24:26 +0000902 // ideally we would like to bail out if passing NULL, but if we do so
903 // we end up not providing the summary for function pointers anymore
904 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
905 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000906
907 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000908
Enrico Granata31fda932015-10-07 01:41:23 +0000909 TypeSummaryOptions actual_options(options);
910
911 if (actual_options.GetLanguage() == lldb::eLanguageTypeUnknown)
912 actual_options.SetLanguage(GetPreferredDisplayLanguage());
913
Enrico Granataf18c03e2012-04-04 17:34:10 +0000914 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
915 // information that we might care to see in a crash log. might be useful in very specific situations though.
916 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
Enrico Granata31fda932015-10-07 01:41:23 +0000917 GetTypeName().GetCString(),
918 GetName().GetCString(),
919 summary_ptr->GetDescription().c_str());*/
Enrico Granataf18c03e2012-04-04 17:34:10 +0000920
Enrico Granataff0f23d2014-12-10 02:00:45 +0000921 if (UpdateValueIfNeeded (false) && summary_ptr)
Enrico Granata0c489f52012-03-01 04:24:26 +0000922 {
Enrico Granataff0f23d2014-12-10 02:00:45 +0000923 if (HasSyntheticValue())
924 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 +0000925 summary_ptr->FormatObject(this, destination, actual_options);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000926 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000927 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000928 return !destination.empty();
929}
930
931const char *
Enrico Granata31fda932015-10-07 01:41:23 +0000932ValueObject::GetSummaryAsCString (lldb::LanguageType lang)
Enrico Granata0c489f52012-03-01 04:24:26 +0000933{
934 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
935 {
Enrico Granata31fda932015-10-07 01:41:23 +0000936 TypeSummaryOptions summary_options;
937 summary_options.SetLanguage(lang);
Enrico Granata0c489f52012-03-01 04:24:26 +0000938 GetSummaryAsCString(GetSummaryFormat().get(),
Enrico Granatac1247f52014-11-06 21:23:20 +0000939 m_summary_str,
Enrico Granata31fda932015-10-07 01:41:23 +0000940 summary_options);
Enrico Granata0c489f52012-03-01 04:24:26 +0000941 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000942 if (m_summary_str.empty())
943 return NULL;
944 return m_summary_str.c_str();
945}
946
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000947bool
Enrico Granata49bfafb2014-11-18 23:36:25 +0000948ValueObject::GetSummaryAsCString (std::string& destination,
949 const TypeSummaryOptions& options)
950{
951 return GetSummaryAsCString(GetSummaryFormat().get(),
Enrico Granata31fda932015-10-07 01:41:23 +0000952 destination,
953 options);
Enrico Granata49bfafb2014-11-18 23:36:25 +0000954}
955
956bool
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000957ValueObject::IsCStringContainer(bool check_pointer)
958{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000959 CompilerType pointee_or_element_compiler_type;
960 const Flags type_flags (GetTypeInfo (&pointee_or_element_compiler_type));
Enrico Granata622be232014-10-21 20:52:14 +0000961 bool is_char_arr_ptr (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000962 pointee_or_element_compiler_type.IsCharType ());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000963 if (!is_char_arr_ptr)
964 return false;
965 if (!check_pointer)
966 return true;
Enrico Granata622be232014-10-21 20:52:14 +0000967 if (type_flags.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000968 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000969 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000970 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000971 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000972 return (cstr_address != LLDB_INVALID_ADDRESS);
973}
974
Enrico Granata9128ee22011-09-06 19:20:51 +0000975size_t
976ValueObject::GetPointeeData (DataExtractor& data,
977 uint32_t item_idx,
978 uint32_t item_count)
979{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000980 CompilerType pointee_or_element_compiler_type;
981 const uint32_t type_info = GetTypeInfo (&pointee_or_element_compiler_type);
Enrico Granata622be232014-10-21 20:52:14 +0000982 const bool is_pointer_type = type_info & eTypeIsPointer;
983 const bool is_array_type = type_info & eTypeIsArray;
Greg Clayton2452ab72013-02-08 22:02:02 +0000984 if (!(is_pointer_type || is_array_type))
Enrico Granata9128ee22011-09-06 19:20:51 +0000985 return 0;
986
987 if (item_count == 0)
988 return 0;
989
Enrico Granata951bdd52015-01-28 01:09:45 +0000990 ExecutionContext exe_ctx (GetExecutionContextRef());
991
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000992 const uint64_t item_type_size = pointee_or_element_compiler_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
Enrico Granata9128ee22011-09-06 19:20:51 +0000993 const uint64_t bytes = item_count * item_type_size;
Enrico Granata9128ee22011-09-06 19:20:51 +0000994 const uint64_t offset = item_idx * item_type_size;
995
996 if (item_idx == 0 && item_count == 1) // simply a deref
997 {
Greg Clayton2452ab72013-02-08 22:02:02 +0000998 if (is_pointer_type)
Enrico Granata9128ee22011-09-06 19:20:51 +0000999 {
1000 Error error;
1001 ValueObjectSP pointee_sp = Dereference(error);
1002 if (error.Fail() || pointee_sp.get() == NULL)
1003 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +00001004 return pointee_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +00001005 }
1006 else
1007 {
1008 ValueObjectSP child_sp = GetChildAtIndex(0, true);
1009 if (child_sp.get() == NULL)
1010 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +00001011 Error error;
1012 return child_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +00001013 }
1014 return true;
1015 }
1016 else /* (items > 1) */
1017 {
1018 Error error;
1019 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
1020 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
1021
1022 AddressType addr_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001023 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001024
Enrico Granata9128ee22011-09-06 19:20:51 +00001025 switch (addr_type)
1026 {
1027 case eAddressTypeFile:
1028 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001029 ModuleSP module_sp (GetModule());
1030 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001031 {
Enrico Granata9c2efe32012-08-07 01:49:34 +00001032 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +00001033 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001034 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001035 ExecutionContext exe_ctx (GetExecutionContextRef());
1036 Target* target = exe_ctx.GetTargetPtr();
1037 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +00001038 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001039 heap_buf_ptr->SetByteSize(bytes);
1040 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
1041 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +00001042 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001043 data.SetData(data_sp);
1044 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +00001045 }
1046 }
1047 }
1048 }
1049 break;
1050 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +00001051 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001052 ExecutionContext exe_ctx (GetExecutionContextRef());
1053 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +00001054 if (process)
1055 {
1056 heap_buf_ptr->SetByteSize(bytes);
1057 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
Enrico Granata5e1480c2013-10-30 17:52:44 +00001058 if (error.Success() || bytes_read > 0)
Enrico Granata9128ee22011-09-06 19:20:51 +00001059 {
1060 data.SetData(data_sp);
1061 return bytes_read;
1062 }
1063 }
1064 }
1065 break;
1066 case eAddressTypeHost:
1067 {
Greg Clayton99558cc42015-08-24 23:46:31 +00001068 const uint64_t max_bytes = GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope());
Greg Clayton2452ab72013-02-08 22:02:02 +00001069 if (max_bytes > offset)
1070 {
1071 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
Siva Chandrae32f2b52015-05-05 00:41:35 +00001072 addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1073 if (addr == LLDB_INVALID_ADDRESS)
1074 break;
Greg Clayton2452ab72013-02-08 22:02:02 +00001075 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
1076 data.SetData(data_sp);
1077 return bytes_read;
1078 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001079 }
1080 break;
1081 case eAddressTypeInvalid:
Enrico Granata9128ee22011-09-06 19:20:51 +00001082 break;
1083 }
1084 }
1085 return 0;
1086}
1087
Greg Claytonfaac1112013-03-14 18:31:44 +00001088uint64_t
Sean Callanan866e91c2014-02-28 22:27:53 +00001089ValueObject::GetData (DataExtractor& data, Error &error)
Enrico Granata9128ee22011-09-06 19:20:51 +00001090{
1091 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001092 ExecutionContext exe_ctx (GetExecutionContextRef());
Sean Callanan866e91c2014-02-28 22:27:53 +00001093 error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001094 if (error.Fail())
Sean Callananed185ab2013-04-19 19:47:32 +00001095 {
1096 if (m_data.GetByteSize())
1097 {
1098 data = m_data;
1099 return data.GetByteSize();
1100 }
1101 else
1102 {
1103 return 0;
1104 }
1105 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001106 data.SetAddressByteSize(m_data.GetAddressByteSize());
1107 data.SetByteOrder(m_data.GetByteOrder());
1108 return data.GetByteSize();
1109}
1110
Sean Callanan389823e2013-04-13 01:21:23 +00001111bool
1112ValueObject::SetData (DataExtractor &data, Error &error)
1113{
1114 error.Clear();
1115 // Make sure our value is up to date first so that our location and location
1116 // type is valid.
1117 if (!UpdateValueIfNeeded(false))
1118 {
1119 error.SetErrorString("unable to read value");
1120 return false;
1121 }
1122
1123 uint64_t count = 0;
Greg Clayton99558cc42015-08-24 23:46:31 +00001124 const Encoding encoding = GetCompilerType().GetEncoding(count);
Sean Callanan389823e2013-04-13 01:21:23 +00001125
1126 const size_t byte_size = GetByteSize();
1127
1128 Value::ValueType value_type = m_value.GetValueType();
1129
1130 switch (value_type)
1131 {
1132 case Value::eValueTypeScalar:
1133 {
1134 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1135
1136 if (!set_error.Success())
1137 {
1138 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1139 return false;
1140 }
1141 }
1142 break;
1143 case Value::eValueTypeLoadAddress:
1144 {
1145 // If it is a load address, then the scalar value is the storage location
1146 // of the data, and we have to shove this value down to that load location.
1147 ExecutionContext exe_ctx (GetExecutionContextRef());
1148 Process *process = exe_ctx.GetProcessPtr();
1149 if (process)
1150 {
1151 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1152 size_t bytes_written = process->WriteMemory(target_addr,
1153 data.GetDataStart(),
1154 byte_size,
1155 error);
1156 if (!error.Success())
1157 return false;
1158 if (bytes_written != byte_size)
1159 {
1160 error.SetErrorString("unable to write value to memory");
1161 return false;
1162 }
1163 }
1164 }
1165 break;
1166 case Value::eValueTypeHostAddress:
1167 {
1168 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1169 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1170 m_data.SetData(buffer_sp, 0);
1171 data.CopyByteOrderedData (0,
1172 byte_size,
1173 const_cast<uint8_t *>(m_data.GetDataStart()),
1174 byte_size,
1175 m_data.GetByteOrder());
1176 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1177 }
1178 break;
1179 case Value::eValueTypeFileAddress:
1180 case Value::eValueTypeVector:
1181 break;
1182 }
1183
1184 // If we have reached this point, then we have successfully changed the value.
1185 SetNeedsUpdate();
1186 return true;
1187}
1188
Enrico Granata9128ee22011-09-06 19:20:51 +00001189// will compute strlen(str), but without consuming more than
1190// maxlen bytes out of str (this serves the purpose of reading
1191// chunks of a string without having to worry about
1192// missing NULL terminators in the chunk)
1193// of course, if strlen(str) > maxlen, the function will return
1194// maxlen_value (which should be != maxlen, because that allows you
1195// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1196static uint32_t
1197strlen_or_inf (const char* str,
1198 uint32_t maxlen,
1199 uint32_t maxlen_value)
1200{
1201 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +00001202 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +00001203 {
Greg Clayton8dd5c172011-10-05 22:19:51 +00001204 while(*str)
1205 {
1206 len++;str++;
Greg Clayton2452ab72013-02-08 22:02:02 +00001207 if (len >= maxlen)
Greg Clayton8dd5c172011-10-05 22:19:51 +00001208 return maxlen_value;
1209 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001210 }
1211 return len;
1212}
1213
Enrico Granata2206b482014-10-30 18:27:31 +00001214static bool
1215CopyStringDataToBufferSP(const StreamString& source,
1216 lldb::DataBufferSP& destination)
1217{
1218 destination.reset(new DataBufferHeap(source.GetSize()+1,0));
1219 memcpy(destination->GetBytes(), source.GetString().c_str(), source.GetSize());
1220 return true;
1221}
1222
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001223size_t
Enrico Granata2206b482014-10-30 18:27:31 +00001224ValueObject::ReadPointedString (lldb::DataBufferSP& buffer_sp,
Greg Claytoncc4d0142012-02-17 07:49:44 +00001225 Error& error,
1226 uint32_t max_length,
1227 bool honor_array,
1228 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001229{
Enrico Granata2206b482014-10-30 18:27:31 +00001230 StreamString s;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001231 ExecutionContext exe_ctx (GetExecutionContextRef());
1232 Target* target = exe_ctx.GetTargetPtr();
Enrico Granata2206b482014-10-30 18:27:31 +00001233
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001234 if (!target)
1235 {
1236 s << "<no target to read from>";
1237 error.SetErrorString("no target to read from");
Enrico Granata2206b482014-10-30 18:27:31 +00001238 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001239 return 0;
1240 }
1241
1242 if (max_length == 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001243 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001244
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001245 size_t bytes_read = 0;
1246 size_t total_bytes_read = 0;
1247
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001248 CompilerType compiler_type = GetCompilerType();
1249 CompilerType elem_or_pointee_compiler_type;
1250 const Flags type_flags (GetTypeInfo (&elem_or_pointee_compiler_type));
Enrico Granata622be232014-10-21 20:52:14 +00001251 if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001252 elem_or_pointee_compiler_type.IsCharType ())
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001253 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001254 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1255 AddressType cstr_address_type = eAddressTypeInvalid;
1256
1257 size_t cstr_len = 0;
1258 bool capped_data = false;
Enrico Granata622be232014-10-21 20:52:14 +00001259 if (type_flags.Test (eTypeIsArray))
Greg Claytoncc4d0142012-02-17 07:49:44 +00001260 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001261 // We have an array
Greg Clayton57ee3062013-07-11 22:46:58 +00001262 uint64_t array_size = 0;
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001263 if (compiler_type.IsArrayType(NULL, &array_size, NULL))
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001264 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001265 cstr_len = array_size;
1266 if (cstr_len > max_length)
1267 {
1268 capped_data = true;
1269 cstr_len = max_length;
1270 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001271 }
1272 cstr_address = GetAddressOf (true, &cstr_address_type);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001273 }
1274 else
1275 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001276 // We have a pointer
1277 cstr_address = GetPointerValue (&cstr_address_type);
1278 }
1279
1280 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1281 {
1282 s << "<invalid address>";
1283 error.SetErrorString("invalid address");
Enrico Granata2206b482014-10-30 18:27:31 +00001284 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001285 return 0;
1286 }
Enrico Granata2206b482014-10-30 18:27:31 +00001287
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001288 Address cstr_so_addr (cstr_address);
1289 DataExtractor data;
1290 if (cstr_len > 0 && honor_array)
1291 {
1292 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1293 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1294 GetPointeeData(data, 0, cstr_len);
Enrico Granata2206b482014-10-30 18:27:31 +00001295
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001296 if ((bytes_read = data.GetByteSize()) > 0)
1297 {
1298 total_bytes_read = bytes_read;
Enrico Granata2206b482014-10-30 18:27:31 +00001299 for (size_t offset = 0; offset < bytes_read; offset++)
1300 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001301 if (capped_data)
1302 s << "...";
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001303 }
1304 }
1305 else
1306 {
1307 cstr_len = max_length;
1308 const size_t k_max_buf_size = 64;
Enrico Granata2206b482014-10-30 18:27:31 +00001309
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001310 size_t offset = 0;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001311
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001312 int cstr_len_displayed = -1;
1313 bool capped_cstr = false;
1314 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1315 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1316 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001317 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001318 total_bytes_read += bytes_read;
1319 const char *cstr = data.PeekCStr(0);
1320 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1321 if (len > k_max_buf_size)
1322 len = k_max_buf_size;
Enrico Granata2206b482014-10-30 18:27:31 +00001323
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001324 if (cstr_len_displayed < 0)
1325 cstr_len_displayed = len;
Enrico Granata2206b482014-10-30 18:27:31 +00001326
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001327 if (len == 0)
1328 break;
1329 cstr_len_displayed += len;
1330 if (len > bytes_read)
1331 len = bytes_read;
1332 if (len > cstr_len)
1333 len = cstr_len;
1334
Enrico Granata2206b482014-10-30 18:27:31 +00001335 for (size_t offset = 0; offset < bytes_read; offset++)
1336 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001337
1338 if (len < k_max_buf_size)
1339 break;
1340
1341 if (len >= cstr_len)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001342 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001343 capped_cstr = true;
1344 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001345 }
Enrico Granata2206b482014-10-30 18:27:31 +00001346
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001347 cstr_len -= len;
1348 offset += len;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001349 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001350
1351 if (cstr_len_displayed >= 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001352 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001353 if (capped_cstr)
1354 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001355 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001356 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001357 }
1358 else
1359 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001360 error.SetErrorString("not a string object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001361 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001362 }
Enrico Granata2206b482014-10-30 18:27:31 +00001363 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001364 return total_bytes_read;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001365}
1366
Enrico Granata744794a2014-09-05 21:46:22 +00001367std::pair<TypeValidatorResult, std::string>
1368ValueObject::GetValidationStatus ()
1369{
1370 if (!UpdateValueIfNeeded(true))
1371 return {TypeValidatorResult::Success,""}; // not the validator's job to discuss update problems
1372
1373 if (m_validation_result.hasValue())
1374 return m_validation_result.getValue();
1375
1376 if (!m_type_validator_sp)
1377 return {TypeValidatorResult::Success,""}; // no validator no failure
1378
1379 auto outcome = m_type_validator_sp->FormatObject(this);
1380
1381 return (m_validation_result = {outcome.m_result,outcome.m_message}).getValue();
1382}
1383
Jim Ingham53c47f12010-09-10 23:12:17 +00001384const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001385ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001386{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001387
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001388 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001389 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001390
1391 if (!m_object_desc_str.empty())
1392 return m_object_desc_str.c_str();
1393
Greg Claytoncc4d0142012-02-17 07:49:44 +00001394 ExecutionContext exe_ctx (GetExecutionContextRef());
1395 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001396 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001397 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001398
Jim Ingham53c47f12010-09-10 23:12:17 +00001399 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001400
Greg Claytonafacd142011-09-02 01:15:17 +00001401 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001402 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1403
Jim Inghama2cf2632010-12-23 02:29:54 +00001404 if (runtime == NULL)
1405 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001406 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001407 CompilerType compiler_type = GetCompilerType();
1408 if (compiler_type)
Jim Inghama2cf2632010-12-23 02:29:54 +00001409 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001410 bool is_signed;
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001411 if (compiler_type.IsIntegerType (is_signed) || compiler_type.IsPointerType ())
Jim Inghamb7603bb2011-03-18 00:05:18 +00001412 {
Greg Claytonafacd142011-09-02 01:15:17 +00001413 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001414 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001415 }
1416 }
1417
Jim Ingham8d543de2011-03-31 23:01:21 +00001418 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001419 {
1420 m_object_desc_str.append (s.GetData());
1421 }
Sean Callanan672ad942010-10-23 00:18:49 +00001422
1423 if (m_object_desc_str.empty())
1424 return NULL;
1425 else
1426 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001427}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001428
Enrico Granata0c489f52012-03-01 04:24:26 +00001429bool
Enrico Granata4939b982013-12-22 09:24:22 +00001430ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format,
1431 std::string& destination)
1432{
1433 if (UpdateValueIfNeeded(false))
1434 return format.FormatObject(this,destination);
1435 else
1436 return false;
1437}
1438
1439bool
Enrico Granata0c489f52012-03-01 04:24:26 +00001440ValueObject::GetValueAsCString (lldb::Format format,
1441 std::string& destination)
1442{
Enrico Granata30f287f2013-12-28 08:44:02 +00001443 return GetValueAsCString(TypeFormatImpl_Format(format),destination);
Enrico Granata0c489f52012-03-01 04:24:26 +00001444}
1445
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001446const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001447ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001448{
Enrico Granatab294fd22013-05-31 19:18:19 +00001449 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001450 {
Enrico Granata4939b982013-12-22 09:24:22 +00001451 lldb::TypeFormatImplSP format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001452 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001453 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001454 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001455 if (m_type_format_sp)
Enrico Granata4939b982013-12-22 09:24:22 +00001456 format_sp = m_type_format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001457 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001458 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001459 if (m_is_bitfield_for_scalar)
1460 my_format = eFormatUnsigned;
1461 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001462 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001463 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001464 {
1465 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1466 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001467 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001468 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001469 else
1470 {
Greg Clayton99558cc42015-08-24 23:46:31 +00001471 my_format = GetValue().GetCompilerType().GetFormat();
Enrico Granata0c489f52012-03-01 04:24:26 +00001472 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001473 }
1474 }
1475 }
Enrico Granatab294fd22013-05-31 19:18:19 +00001476 if (my_format != m_last_format || m_value_str.empty())
Enrico Granata297e69f2012-03-06 23:21:16 +00001477 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001478 m_last_format = my_format;
Enrico Granata4939b982013-12-22 09:24:22 +00001479 if (!format_sp)
Enrico Granata30f287f2013-12-28 08:44:02 +00001480 format_sp.reset(new TypeFormatImpl_Format(my_format));
Enrico Granata4939b982013-12-22 09:24:22 +00001481 if (GetValueAsCString(*format_sp.get(), m_value_str))
Enrico Granata297e69f2012-03-06 23:21:16 +00001482 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001483 if (!m_value_did_change && m_old_value_valid)
1484 {
1485 // The value was gotten successfully, so we consider the
1486 // value as changed if the value string differs
1487 SetValueDidChange (m_old_value_str != m_value_str);
1488 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001489 }
1490 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001491 }
1492 if (m_value_str.empty())
1493 return NULL;
1494 return m_value_str.c_str();
1495}
1496
Enrico Granatac3e320a2011-08-02 17:27:39 +00001497// if > 8bytes, 0 is returned. this method should mostly be used
1498// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001499uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001500ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001501{
1502 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001503 if (CanProvideValue())
Enrico Granatac3e320a2011-08-02 17:27:39 +00001504 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001505 Scalar scalar;
1506 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001507 {
1508 if (success)
1509 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001510 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001511 }
1512 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001513 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001514
1515 if (success)
1516 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001517 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001518}
1519
Enrico Granatad7373f62013-10-31 18:57:50 +00001520int64_t
1521ValueObject::GetValueAsSigned (int64_t fail_value, bool *success)
1522{
1523 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001524 if (CanProvideValue())
Enrico Granatad7373f62013-10-31 18:57:50 +00001525 {
1526 Scalar scalar;
1527 if (ResolveValue (scalar))
1528 {
1529 if (success)
1530 *success = true;
Tamas Berghammer5a9919f2015-01-23 10:54:21 +00001531 return scalar.SLongLong(fail_value);
Enrico Granatad7373f62013-10-31 18:57:50 +00001532 }
1533 // fallthrough, otherwise...
1534 }
1535
1536 if (success)
1537 *success = false;
Tamas Berghammer5a9919f2015-01-23 10:54:21 +00001538 return fail_value;
Enrico Granatad7373f62013-10-31 18:57:50 +00001539}
1540
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001541// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1542// this call up to date by returning true for your new special cases. We will eventually move
1543// to checking this call result before trying to display special cases
1544bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001545ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1546 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001547{
Greg Clayton57ee3062013-07-11 22:46:58 +00001548 Flags flags(GetTypeInfo());
Enrico Granata622be232014-10-21 20:52:14 +00001549 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001550 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001551 {
1552 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001553 (custom_format == eFormatCString ||
1554 custom_format == eFormatCharArray ||
1555 custom_format == eFormatChar ||
1556 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001557 return true;
1558
Enrico Granata622be232014-10-21 20:52:14 +00001559 if (flags.Test(eTypeIsArray))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001560 {
Greg Claytonafacd142011-09-02 01:15:17 +00001561 if ((custom_format == eFormatBytes) ||
1562 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001563 return true;
1564
Greg Claytonafacd142011-09-02 01:15:17 +00001565 if ((custom_format == eFormatVectorOfChar) ||
1566 (custom_format == eFormatVectorOfFloat32) ||
1567 (custom_format == eFormatVectorOfFloat64) ||
1568 (custom_format == eFormatVectorOfSInt16) ||
1569 (custom_format == eFormatVectorOfSInt32) ||
1570 (custom_format == eFormatVectorOfSInt64) ||
1571 (custom_format == eFormatVectorOfSInt8) ||
1572 (custom_format == eFormatVectorOfUInt128) ||
1573 (custom_format == eFormatVectorOfUInt16) ||
1574 (custom_format == eFormatVectorOfUInt32) ||
1575 (custom_format == eFormatVectorOfUInt64) ||
1576 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001577 return true;
1578 }
1579 }
1580 return false;
1581}
1582
Enrico Granata9fc19442011-07-06 02:13:41 +00001583bool
1584ValueObject::DumpPrintableRepresentation(Stream& s,
1585 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001586 Format custom_format,
Enrico Granata0dba9b32014-01-08 01:36:59 +00001587 PrintableRepresentationSpecialCases special,
1588 bool do_dump_error)
Enrico Granata9fc19442011-07-06 02:13:41 +00001589{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001590
Greg Clayton57ee3062013-07-11 22:46:58 +00001591 Flags flags(GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001592
Enrico Granata86cc9822012-03-19 22:58:49 +00001593 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1594 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1595
1596 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001597 {
Enrico Granata622be232014-10-21 20:52:14 +00001598 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001599 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001600 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001601 // when being asked to get a printable display an array or pointer type directly,
1602 // try to "do the right thing"
1603
1604 if (IsCStringContainer(true) &&
1605 (custom_format == eFormatCString ||
1606 custom_format == eFormatCharArray ||
1607 custom_format == eFormatChar ||
1608 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001609 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001610 Error error;
Enrico Granata2206b482014-10-30 18:27:31 +00001611 lldb::DataBufferSP buffer_sp;
1612 ReadPointedString(buffer_sp,
Enrico Granata86cc9822012-03-19 22:58:49 +00001613 error,
1614 0,
1615 (custom_format == eFormatVectorOfChar) ||
1616 (custom_format == eFormatCharArray));
Enrico Granataac494532015-09-09 22:30:24 +00001617 lldb_private::formatters::StringPrinter::ReadBufferAndDumpToStreamOptions options(*this);
Enrico Granata2206b482014-10-30 18:27:31 +00001618 options.SetData(DataExtractor(buffer_sp, lldb::eByteOrderInvalid, 8)); // none of this matters for a string - pass some defaults
1619 options.SetStream(&s);
1620 options.SetPrefixToken(0);
1621 options.SetQuote('"');
1622 options.SetSourceSize(buffer_sp->GetByteSize());
Enrico Granataac494532015-09-09 22:30:24 +00001623 formatters::StringPrinter::ReadBufferAndDumpToStream<lldb_private::formatters::StringPrinter::StringElementType::ASCII>(options);
Enrico Granata86cc9822012-03-19 22:58:49 +00001624 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001625 }
1626
Enrico Granata86cc9822012-03-19 22:58:49 +00001627 if (custom_format == eFormatEnum)
1628 return false;
1629
1630 // this only works for arrays, because I have no way to know when
1631 // the pointed memory ends, and no special \0 end of data marker
Enrico Granata622be232014-10-21 20:52:14 +00001632 if (flags.Test(eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001633 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001634 if ((custom_format == eFormatBytes) ||
1635 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001636 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001637 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001638
1639 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001640 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001641 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001642
1643 if (low)
1644 s << ',';
1645
1646 ValueObjectSP child = GetChildAtIndex(low,true);
1647 if (!child.get())
1648 {
1649 s << "<invalid child>";
1650 continue;
1651 }
1652 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1653 }
1654
1655 s << ']';
1656
1657 return true;
1658 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001659
Enrico Granata86cc9822012-03-19 22:58:49 +00001660 if ((custom_format == eFormatVectorOfChar) ||
1661 (custom_format == eFormatVectorOfFloat32) ||
1662 (custom_format == eFormatVectorOfFloat64) ||
1663 (custom_format == eFormatVectorOfSInt16) ||
1664 (custom_format == eFormatVectorOfSInt32) ||
1665 (custom_format == eFormatVectorOfSInt64) ||
1666 (custom_format == eFormatVectorOfSInt8) ||
1667 (custom_format == eFormatVectorOfUInt128) ||
1668 (custom_format == eFormatVectorOfUInt16) ||
1669 (custom_format == eFormatVectorOfUInt32) ||
1670 (custom_format == eFormatVectorOfUInt64) ||
1671 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1672 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001673 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001674
1675 Format format = FormatManager::GetSingleItemFormat(custom_format);
1676
1677 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001678 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001679 {
1680
1681 if (low)
1682 s << ',';
1683
1684 ValueObjectSP child = GetChildAtIndex(low,true);
1685 if (!child.get())
1686 {
1687 s << "<invalid child>";
1688 continue;
1689 }
1690 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1691 }
1692
1693 s << ']';
1694
1695 return true;
1696 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001697 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001698
1699 if ((custom_format == eFormatBoolean) ||
1700 (custom_format == eFormatBinary) ||
1701 (custom_format == eFormatChar) ||
1702 (custom_format == eFormatCharPrintable) ||
1703 (custom_format == eFormatComplexFloat) ||
1704 (custom_format == eFormatDecimal) ||
1705 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001706 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001707 (custom_format == eFormatFloat) ||
1708 (custom_format == eFormatOctal) ||
1709 (custom_format == eFormatOSType) ||
1710 (custom_format == eFormatUnicode16) ||
1711 (custom_format == eFormatUnicode32) ||
1712 (custom_format == eFormatUnsigned) ||
1713 (custom_format == eFormatPointer) ||
1714 (custom_format == eFormatComplexInteger) ||
1715 (custom_format == eFormatComplex) ||
1716 (custom_format == eFormatDefault)) // use the [] operator
1717 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001718 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001719 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001720
1721 if (only_special)
1722 return false;
1723
Enrico Granata86cc9822012-03-19 22:58:49 +00001724 bool var_success = false;
1725
1726 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001727 const char *cstr = NULL;
Enrico Granata2c75f112013-06-21 00:04:51 +00001728
1729 // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1730 // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1731 // area for cases where our desired output is not backed by some other longer-term storage
Greg Claytonc7bece562013-01-25 18:06:21 +00001732 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001733
Enrico Granata465f4bc2014-02-15 01:24:44 +00001734 if (custom_format != eFormatInvalid)
Enrico Granata86cc9822012-03-19 22:58:49 +00001735 SetFormat(custom_format);
1736
1737 switch(val_obj_display)
1738 {
1739 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001740 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001741 break;
1742
1743 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001744 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001745 break;
1746
1747 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001748 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001749 break;
1750
1751 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001752 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001753 break;
1754
1755 case eValueObjectRepresentationStyleChildrenCount:
Deepak Panickal99fbc072014-03-03 15:39:47 +00001756 strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren());
Greg Claytonc7bece562013-01-25 18:06:21 +00001757 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001758 break;
1759
1760 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001761 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001762 break;
Enrico Granata2c75f112013-06-21 00:04:51 +00001763
1764 case eValueObjectRepresentationStyleName:
1765 cstr = GetName().AsCString();
1766 break;
1767
1768 case eValueObjectRepresentationStyleExpressionPath:
1769 GetExpressionPath(strm, false);
1770 cstr = strm.GetString().c_str();
1771 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001772 }
1773
Greg Claytonc7bece562013-01-25 18:06:21 +00001774 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001775 {
1776 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001777 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001778 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1779 {
Enrico Granatad07cfd32014-10-08 18:27:36 +00001780 if (!CanProvideValue())
Enrico Granata86cc9822012-03-19 22:58:49 +00001781 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001782 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1783 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001784 }
1785 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001786 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001787 }
1788 }
1789
Greg Claytonc7bece562013-01-25 18:06:21 +00001790 if (cstr)
1791 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001792 else
1793 {
1794 if (m_error.Fail())
Enrico Granata0dba9b32014-01-08 01:36:59 +00001795 {
1796 if (do_dump_error)
1797 s.Printf("<%s>", m_error.AsCString());
1798 else
1799 return false;
1800 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001801 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1802 s.PutCString("<no summary available>");
1803 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1804 s.PutCString("<no value available>");
1805 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1806 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1807 else
1808 s.PutCString("<no printable representation>");
1809 }
1810
1811 // we should only return false here if we could not do *anything*
1812 // even if we have an error message as output, that's a success
1813 // from our callers' perspective, so return true
1814 var_success = true;
Enrico Granata465f4bc2014-02-15 01:24:44 +00001815
1816 if (custom_format != eFormatInvalid)
1817 SetFormat(eFormatDefault);
Enrico Granata86cc9822012-03-19 22:58:49 +00001818 }
1819
Enrico Granataf4efecd2011-07-12 22:56:10 +00001820 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001821}
1822
Greg Clayton737b9322010-09-13 03:32:57 +00001823addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001824ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001825{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001826 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001827 return LLDB_INVALID_ADDRESS;
1828
Greg Clayton73b472d2010-10-27 03:32:59 +00001829 switch (m_value.GetValueType())
1830 {
1831 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001832 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001833 if (scalar_is_load_address)
1834 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001835 if(address_type)
1836 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001837 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1838 }
1839 break;
1840
1841 case Value::eValueTypeLoadAddress:
1842 case Value::eValueTypeFileAddress:
Greg Clayton73b472d2010-10-27 03:32:59 +00001843 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001844 if(address_type)
1845 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001846 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1847 }
1848 break;
Siva Chandraa3747a92015-05-04 19:43:34 +00001849 case Value::eValueTypeHostAddress:
Siva Chandrae32f2b52015-05-05 00:41:35 +00001850 {
1851 if(address_type)
1852 *address_type = m_value.GetValueAddressType ();
1853 return LLDB_INVALID_ADDRESS;
1854 }
Siva Chandraa3747a92015-05-04 19:43:34 +00001855 break;
Greg Clayton73b472d2010-10-27 03:32:59 +00001856 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001857 if (address_type)
1858 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001859 return LLDB_INVALID_ADDRESS;
1860}
1861
1862addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001863ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001864{
Greg Claytonafacd142011-09-02 01:15:17 +00001865 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001866 if(address_type)
1867 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001868
Enrico Granatac3e320a2011-08-02 17:27:39 +00001869 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001870 return address;
1871
Greg Clayton73b472d2010-10-27 03:32:59 +00001872 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001873 {
1874 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001875 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001876 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001877 break;
1878
Enrico Granata9128ee22011-09-06 19:20:51 +00001879 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001880 case Value::eValueTypeLoadAddress:
1881 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001882 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001883 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001884 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001885 }
1886 break;
1887 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001888
Enrico Granata9128ee22011-09-06 19:20:51 +00001889 if (address_type)
1890 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001891
Greg Clayton737b9322010-09-13 03:32:57 +00001892 return address;
1893}
1894
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001895bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001896ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001897{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001898 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001899 // Make sure our value is up to date first so that our location and location
1900 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001901 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001902 {
1903 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001904 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001905 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001906
Greg Claytonfaac1112013-03-14 18:31:44 +00001907 uint64_t count = 0;
Greg Clayton99558cc42015-08-24 23:46:31 +00001908 const Encoding encoding = GetCompilerType().GetEncoding (count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001909
Greg Claytonb1320972010-07-14 00:18:15 +00001910 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001911
Jim Ingham16e0c682011-08-12 23:34:31 +00001912 Value::ValueType value_type = m_value.GetValueType();
1913
1914 if (value_type == Value::eValueTypeScalar)
1915 {
1916 // If the value is already a scalar, then let the scalar change itself:
1917 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1918 }
Sagar Thakur8536fd12015-08-20 09:12:46 +00001919 else if (byte_size <= 16)
Jim Ingham16e0c682011-08-12 23:34:31 +00001920 {
1921 // If the value fits in a scalar, then make a new scalar and again let the
1922 // scalar code do the conversion, then figure out where to put the new value.
1923 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001924 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1925 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001926 {
Jim Ingham4b536182011-08-09 02:12:22 +00001927 switch (value_type)
1928 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001929 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001930 {
1931 // If it is a load address, then the scalar value is the storage location
1932 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001933 ExecutionContext exe_ctx (GetExecutionContextRef());
1934 Process *process = exe_ctx.GetProcessPtr();
1935 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001936 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001937 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001938 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1939 new_scalar,
1940 byte_size,
1941 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001942 if (!error.Success())
1943 return false;
1944 if (bytes_written != byte_size)
1945 {
1946 error.SetErrorString("unable to write value to memory");
1947 return false;
1948 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001949 }
1950 }
Jim Ingham4b536182011-08-09 02:12:22 +00001951 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001952 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001953 {
1954 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1955 DataExtractor new_data;
1956 new_data.SetByteOrder (m_data.GetByteOrder());
1957
1958 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1959 m_data.SetData(buffer_sp, 0);
1960 bool success = new_scalar.GetData(new_data);
1961 if (success)
1962 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001963 new_data.CopyByteOrderedData (0,
1964 byte_size,
1965 const_cast<uint8_t *>(m_data.GetDataStart()),
1966 byte_size,
1967 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001968 }
1969 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1970
1971 }
Jim Ingham4b536182011-08-09 02:12:22 +00001972 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001973 case Value::eValueTypeFileAddress:
1974 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001975 case Value::eValueTypeVector:
1976 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001977 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001978 }
1979 else
1980 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001981 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001982 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001983 }
1984 else
1985 {
1986 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001987 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001988 return false;
1989 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001990
1991 // If we have reached this point, then we have successfully changed the value.
1992 SetNeedsUpdate();
1993 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001994}
1995
Greg Clayton81e871e2012-02-04 02:27:34 +00001996bool
1997ValueObject::GetDeclaration (Declaration &decl)
1998{
1999 decl.Clear();
2000 return false;
2001}
2002
Greg Clayton84db9102012-03-26 23:03:23 +00002003ConstString
2004ValueObject::GetTypeName()
2005{
Greg Clayton99558cc42015-08-24 23:46:31 +00002006 return GetCompilerType().GetConstTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00002007}
2008
2009ConstString
Enrico Granatae8daa2f2014-05-17 19:14:17 +00002010ValueObject::GetDisplayTypeName()
2011{
2012 return GetTypeName();
2013}
2014
2015ConstString
Greg Clayton84db9102012-03-26 23:03:23 +00002016ValueObject::GetQualifiedTypeName()
2017{
Greg Clayton99558cc42015-08-24 23:46:31 +00002018 return GetCompilerType().GetConstQualifiedTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00002019}
2020
2021
Greg Claytonafacd142011-09-02 01:15:17 +00002022LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00002023ValueObject::GetObjectRuntimeLanguage ()
2024{
Greg Clayton99558cc42015-08-24 23:46:31 +00002025 return GetCompilerType().GetMinimumLanguage ();
Jim Ingham5a369122010-09-28 01:25:32 +00002026}
2027
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002028void
Jim Ingham58b59f92011-04-22 23:53:53 +00002029ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002030{
Jim Ingham58b59f92011-04-22 23:53:53 +00002031 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002032}
2033
2034ValueObjectSP
2035ValueObject::GetSyntheticChild (const ConstString &key) const
2036{
2037 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00002038 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002039 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00002040 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002041 return synthetic_child_sp;
2042}
2043
Greg Clayton2452ab72013-02-08 22:02:02 +00002044uint32_t
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002045ValueObject::GetTypeInfo (CompilerType *pointee_or_element_compiler_type)
Greg Clayton2452ab72013-02-08 22:02:02 +00002046{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002047 return GetCompilerType().GetTypeInfo (pointee_or_element_compiler_type);
Greg Clayton2452ab72013-02-08 22:02:02 +00002048}
2049
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002050bool
2051ValueObject::IsPointerType ()
2052{
Greg Clayton99558cc42015-08-24 23:46:31 +00002053 return GetCompilerType().IsPointerType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002054}
2055
Jim Inghamb7603bb2011-03-18 00:05:18 +00002056bool
Greg Claytondaf515f2011-07-09 20:12:33 +00002057ValueObject::IsArrayType ()
2058{
Greg Clayton99558cc42015-08-24 23:46:31 +00002059 return GetCompilerType().IsArrayType (NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00002060}
2061
2062bool
Enrico Granata9fc19442011-07-06 02:13:41 +00002063ValueObject::IsScalarType ()
2064{
Greg Clayton99558cc42015-08-24 23:46:31 +00002065 return GetCompilerType().IsScalarType ();
Enrico Granata9fc19442011-07-06 02:13:41 +00002066}
2067
2068bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00002069ValueObject::IsIntegerType (bool &is_signed)
2070{
Greg Clayton99558cc42015-08-24 23:46:31 +00002071 return GetCompilerType().IsIntegerType (is_signed);
Jim Inghamb7603bb2011-03-18 00:05:18 +00002072}
Greg Clayton73b472d2010-10-27 03:32:59 +00002073
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002074bool
2075ValueObject::IsPointerOrReferenceType ()
2076{
Greg Clayton99558cc42015-08-24 23:46:31 +00002077 return GetCompilerType().IsPointerOrReferenceType ();
Greg Clayton007d5be2011-05-30 00:49:24 +00002078}
2079
2080bool
Greg Claytondea8cb42011-06-29 22:09:02 +00002081ValueObject::IsPossibleDynamicType ()
2082{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002083 ExecutionContext exe_ctx (GetExecutionContextRef());
2084 Process *process = exe_ctx.GetProcessPtr();
2085 if (process)
2086 return process->IsPossibleDynamicValue(*this);
2087 else
Greg Clayton99558cc42015-08-24 23:46:31 +00002088 return GetCompilerType().IsPossibleDynamicType (NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00002089}
2090
Enrico Granata9e7b3882012-12-13 23:50:33 +00002091bool
Enrico Granata560558e2015-02-11 02:35:39 +00002092ValueObject::IsRuntimeSupportValue ()
2093{
2094 Process *process(GetProcessSP().get());
2095 if (process)
2096 {
2097 LanguageRuntime *runtime = process->GetLanguageRuntime(GetObjectRuntimeLanguage());
2098 if (!runtime)
2099 runtime = process->GetObjCLanguageRuntime();
2100 if (runtime)
2101 return runtime->IsRuntimeSupportValue(*this);
2102 }
2103 return false;
2104}
2105
2106bool
Enrico Granata9e7b3882012-12-13 23:50:33 +00002107ValueObject::IsObjCNil ()
2108{
Enrico Granata622be232014-10-21 20:52:14 +00002109 const uint32_t mask = eTypeIsObjC | eTypeIsPointer;
Greg Clayton99558cc42015-08-24 23:46:31 +00002110 bool isObjCpointer = (((GetCompilerType().GetTypeInfo(NULL)) & mask) == mask);
Enrico Granata7277d202013-03-15 23:33:15 +00002111 if (!isObjCpointer)
2112 return false;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002113 bool canReadValue = true;
2114 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
Enrico Granata7277d202013-03-15 23:33:15 +00002115 return canReadValue && isZero;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002116}
2117
Greg Claytondaf515f2011-07-09 20:12:33 +00002118// This allows you to create an array member using and index
2119// that doesn't not fall in the normal bounds of the array.
2120// Many times structure can be defined as:
2121// struct Collection
2122// {
2123// uint32_t item_count;
2124// Item item_array[0];
2125// };
2126// The size of the "item_array" is 1, but many times in practice
2127// there are more items in "item_array".
2128
2129ValueObjectSP
Bruce Mitchener11d86362015-02-26 23:55:39 +00002130ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00002131{
2132 ValueObjectSP synthetic_child_sp;
Bruce Mitchener11d86362015-02-26 23:55:39 +00002133 if (IsPointerType () || IsArrayType())
Greg Claytondaf515f2011-07-09 20:12:33 +00002134 {
2135 char index_str[64];
Deepak Panickal99fbc072014-03-03 15:39:47 +00002136 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
Greg Claytondaf515f2011-07-09 20:12:33 +00002137 ConstString index_const_str(index_str);
2138 // Check if we have already created a synthetic array member in this
2139 // valid object. If we have we will re-use it.
2140 synthetic_child_sp = GetSyntheticChild (index_const_str);
2141 if (!synthetic_child_sp)
2142 {
2143 ValueObject *synthetic_child;
2144 // We haven't made a synthetic array member for INDEX yet, so
2145 // lets make one and cache it for any future reference.
2146 synthetic_child = CreateChildAtIndex(0, true, index);
Bruce Mitchener11d86362015-02-26 23:55:39 +00002147
Greg Claytondaf515f2011-07-09 20:12:33 +00002148 // Cache the value if we got one back...
2149 if (synthetic_child)
2150 {
2151 AddSyntheticChild(index_const_str, synthetic_child);
2152 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002153 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00002154 synthetic_child_sp->m_is_array_item_for_pointer = true;
2155 }
2156 }
2157 }
2158 return synthetic_child_sp;
2159}
2160
Enrico Granata9fc19442011-07-06 02:13:41 +00002161ValueObjectSP
2162ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2163{
2164 ValueObjectSP synthetic_child_sp;
2165 if (IsScalarType ())
2166 {
2167 char index_str[64];
2168 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2169 ConstString index_const_str(index_str);
2170 // Check if we have already created a synthetic array member in this
2171 // valid object. If we have we will re-use it.
2172 synthetic_child_sp = GetSyntheticChild (index_const_str);
2173 if (!synthetic_child_sp)
2174 {
Enrico Granata9fc19442011-07-06 02:13:41 +00002175 // We haven't made a synthetic array member for INDEX yet, so
2176 // lets make one and cache it for any future reference.
Greg Clayton57ee3062013-07-11 22:46:58 +00002177 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
Greg Clayton99558cc42015-08-24 23:46:31 +00002178 GetCompilerType(),
Greg Clayton57ee3062013-07-11 22:46:58 +00002179 index_const_str,
2180 GetByteSize(),
2181 0,
2182 to-from+1,
2183 from,
2184 false,
2185 false,
2186 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002187
2188 // Cache the value if we got one back...
2189 if (synthetic_child)
2190 {
2191 AddSyntheticChild(index_const_str, synthetic_child);
2192 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002193 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002194 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2195 }
2196 }
2197 }
2198 return synthetic_child_sp;
2199}
2200
Greg Claytonafacd142011-09-02 01:15:17 +00002201ValueObjectSP
Greg Claytona1e5dc82015-08-11 22:53:00 +00002202ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const CompilerType& type, bool can_create)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002203{
2204
2205 ValueObjectSP synthetic_child_sp;
2206
2207 char name_str[64];
2208 snprintf(name_str, sizeof(name_str), "@%i", offset);
2209 ConstString name_const_str(name_str);
2210
2211 // Check if we have already created a synthetic array member in this
2212 // valid object. If we have we will re-use it.
2213 synthetic_child_sp = GetSyntheticChild (name_const_str);
2214
2215 if (synthetic_child_sp.get())
2216 return synthetic_child_sp;
2217
2218 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002219 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002220
Enrico Granata951bdd52015-01-28 01:09:45 +00002221 ExecutionContext exe_ctx (GetExecutionContextRef());
2222
Enrico Granata6f3533f2011-07-29 19:53:35 +00002223 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
Greg Clayton57ee3062013-07-11 22:46:58 +00002224 type,
Enrico Granata6f3533f2011-07-29 19:53:35 +00002225 name_const_str,
Greg Clayton526ae042015-02-12 00:34:25 +00002226 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
Enrico Granata6f3533f2011-07-29 19:53:35 +00002227 offset,
2228 0,
2229 0,
2230 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002231 false,
2232 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002233 if (synthetic_child)
2234 {
2235 AddSyntheticChild(name_const_str, synthetic_child);
2236 synthetic_child_sp = synthetic_child->GetSP();
2237 synthetic_child_sp->SetName(name_const_str);
2238 synthetic_child_sp->m_is_child_at_offset = true;
2239 }
2240 return synthetic_child_sp;
2241}
2242
Enrico Granata32556cd2014-08-26 20:54:04 +00002243ValueObjectSP
Greg Claytona1e5dc82015-08-11 22:53:00 +00002244ValueObject::GetSyntheticBase (uint32_t offset, const CompilerType& type, bool can_create)
Enrico Granata32556cd2014-08-26 20:54:04 +00002245{
2246 ValueObjectSP synthetic_child_sp;
2247
2248 char name_str[64];
2249 snprintf(name_str, sizeof(name_str), "%s", type.GetTypeName().AsCString("<unknown>"));
2250 ConstString name_const_str(name_str);
2251
2252 // Check if we have already created a synthetic array member in this
2253 // valid object. If we have we will re-use it.
2254 synthetic_child_sp = GetSyntheticChild (name_const_str);
2255
2256 if (synthetic_child_sp.get())
2257 return synthetic_child_sp;
2258
2259 if (!can_create)
2260 return ValueObjectSP();
2261
Enrico Granata32556cd2014-08-26 20:54:04 +00002262 const bool is_base_class = true;
2263
Enrico Granata951bdd52015-01-28 01:09:45 +00002264 ExecutionContext exe_ctx (GetExecutionContextRef());
2265
Enrico Granata32556cd2014-08-26 20:54:04 +00002266 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2267 type,
2268 name_const_str,
Greg Clayton526ae042015-02-12 00:34:25 +00002269 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
Enrico Granata32556cd2014-08-26 20:54:04 +00002270 offset,
2271 0,
2272 0,
2273 is_base_class,
2274 false,
2275 eAddressTypeInvalid);
2276 if (synthetic_child)
2277 {
2278 AddSyntheticChild(name_const_str, synthetic_child);
2279 synthetic_child_sp = synthetic_child->GetSP();
2280 synthetic_child_sp->SetName(name_const_str);
2281 }
2282 return synthetic_child_sp;
2283}
2284
2285
Enrico Granatad55546b2011-07-22 00:16:08 +00002286// your expression path needs to have a leading . or ->
2287// (unless it somehow "looks like" an array, in which case it has
2288// a leading [ symbol). while the [ is meaningful and should be shown
2289// to the user, . and -> are just parser design, but by no means
2290// added information for the user.. strip them off
2291static const char*
2292SkipLeadingExpressionPathSeparators(const char* expression)
2293{
2294 if (!expression || !expression[0])
2295 return expression;
2296 if (expression[0] == '.')
2297 return expression+1;
2298 if (expression[0] == '-' && expression[1] == '>')
2299 return expression+2;
2300 return expression;
2301}
2302
Greg Claytonafacd142011-09-02 01:15:17 +00002303ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002304ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2305{
2306 ValueObjectSP synthetic_child_sp;
2307 ConstString name_const_string(expression);
2308 // Check if we have already created a synthetic array member in this
2309 // valid object. If we have we will re-use it.
2310 synthetic_child_sp = GetSyntheticChild (name_const_string);
2311 if (!synthetic_child_sp)
2312 {
2313 // We haven't made a synthetic array member for expression yet, so
2314 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002315 synthetic_child_sp = GetValueForExpressionPath(expression,
2316 NULL, NULL, NULL,
Enrico Granataef238c12015-03-12 22:30:58 +00002317 GetValueForExpressionPathOptions().SetSyntheticChildrenTraversal(GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None));
Enrico Granatad55546b2011-07-22 00:16:08 +00002318
2319 // Cache the value if we got one back...
2320 if (synthetic_child_sp.get())
2321 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002322 // 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 +00002323 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002324 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002325 }
2326 }
2327 return synthetic_child_sp;
2328}
2329
2330void
Enrico Granata86cc9822012-03-19 22:58:49 +00002331ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002332{
Enrico Granata86cc9822012-03-19 22:58:49 +00002333 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002334 return;
2335
Enrico Granatac5bc4122012-03-27 02:35:13 +00002336 TargetSP target_sp(GetTargetSP());
Enrico Granata5d5f60c2013-09-24 22:58:37 +00002337 if (target_sp && target_sp->GetEnableSyntheticValue() == false)
Enrico Granatac5bc4122012-03-27 02:35:13 +00002338 {
2339 m_synthetic_value = NULL;
2340 return;
2341 }
2342
Enrico Granatae3e91512012-10-22 18:18:36 +00002343 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2344
Enrico Granata5548cb52013-01-28 23:47:25 +00002345 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002346 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002347
Enrico Granata0c489f52012-03-01 04:24:26 +00002348 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002349 return;
2350
Enrico Granatae3e91512012-10-22 18:18:36 +00002351 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2352 return;
2353
Enrico Granata86cc9822012-03-19 22:58:49 +00002354 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002355}
2356
Jim Ingham78a685a2011-04-16 00:01:13 +00002357void
Greg Claytonafacd142011-09-02 01:15:17 +00002358ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002359{
Greg Claytonafacd142011-09-02 01:15:17 +00002360 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002361 return;
2362
Jim Ingham58b59f92011-04-22 23:53:53 +00002363 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002364 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002365 ExecutionContext exe_ctx (GetExecutionContextRef());
2366 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002367 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002368 {
2369 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002370 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002371 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002372 }
2373}
2374
Jim Ingham58b59f92011-04-22 23:53:53 +00002375ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002376ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002377{
Greg Claytonafacd142011-09-02 01:15:17 +00002378 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002379 return ValueObjectSP();
2380
2381 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002382 {
Jim Ingham2837b762011-05-04 03:43:18 +00002383 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002384 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002385 if (m_dynamic_value)
2386 return m_dynamic_value->GetSP();
2387 else
2388 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002389}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002390
Jim Ingham60dbabb2011-12-08 19:44:08 +00002391ValueObjectSP
2392ValueObject::GetStaticValue()
2393{
2394 return GetSP();
2395}
2396
Enrico Granata886147f2012-05-08 18:47:08 +00002397lldb::ValueObjectSP
2398ValueObject::GetNonSyntheticValue ()
2399{
2400 return GetSP();
2401}
2402
Enrico Granatad55546b2011-07-22 00:16:08 +00002403ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002404ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002405{
Enrico Granata86cc9822012-03-19 22:58:49 +00002406 if (use_synthetic == false)
2407 return ValueObjectSP();
2408
Enrico Granatad55546b2011-07-22 00:16:08 +00002409 CalculateSyntheticValue(use_synthetic);
2410
2411 if (m_synthetic_value)
2412 return m_synthetic_value->GetSP();
2413 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002414 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002415}
2416
Greg Claytone221f822011-01-21 01:59:00 +00002417bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002418ValueObject::HasSyntheticValue()
2419{
Enrico Granata5548cb52013-01-28 23:47:25 +00002420 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002421
Enrico Granata0c489f52012-03-01 04:24:26 +00002422 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002423 return false;
2424
Enrico Granata86cc9822012-03-19 22:58:49 +00002425 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002426
2427 if (m_synthetic_value)
2428 return true;
2429 else
2430 return false;
2431}
2432
2433bool
Greg Claytone221f822011-01-21 01:59:00 +00002434ValueObject::GetBaseClassPath (Stream &s)
2435{
2436 if (IsBaseClass())
2437 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002438 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002439 CompilerType compiler_type = GetCompilerType();
Greg Claytone221f822011-01-21 01:59:00 +00002440 std::string cxx_class_name;
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002441 bool this_had_base_class = ClangASTContext::GetCXXClassName (compiler_type, cxx_class_name);
Greg Claytone221f822011-01-21 01:59:00 +00002442 if (this_had_base_class)
2443 {
2444 if (parent_had_base_class)
2445 s.PutCString("::");
2446 s.PutCString(cxx_class_name.c_str());
2447 }
2448 return parent_had_base_class || this_had_base_class;
2449 }
2450 return false;
2451}
2452
2453
2454ValueObject *
2455ValueObject::GetNonBaseClassParent()
2456{
Jim Ingham78a685a2011-04-16 00:01:13 +00002457 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002458 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002459 if (GetParent()->IsBaseClass())
2460 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002461 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002462 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002463 }
2464 return NULL;
2465}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002466
Enrico Granataa3c8f042014-08-19 22:29:08 +00002467
2468bool
2469ValueObject::IsBaseClass (uint32_t& depth)
2470{
2471 if (!IsBaseClass())
2472 {
2473 depth = 0;
2474 return false;
2475 }
2476 if (GetParent())
2477 {
2478 GetParent()->IsBaseClass(depth);
2479 depth = depth + 1;
2480 return true;
2481 }
2482 // TODO: a base of no parent? weird..
2483 depth = 1;
2484 return true;
2485}
2486
Greg Clayton1d3afba2010-10-05 00:00:42 +00002487void
Enrico Granata4becb372011-06-29 22:27:15 +00002488ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002489{
Enrico Granata986fa5f2014-12-09 21:41:16 +00002490 // synthetic children do not actually "exist" as part of the hierarchy, and sometimes they are consed up in ways
2491 // that don't make sense from an underlying language/API standpoint. So, use a special code path here to return
2492 // something that can hopefully be used in expression
2493 if (m_is_synthetic_children_generated)
2494 {
2495 UpdateValueIfNeeded();
2496
2497 if (m_value.GetValueType() == Value::eValueTypeLoadAddress)
2498 {
2499 if (IsPointerOrReferenceType())
2500 {
2501 s.Printf("((%s)0x%" PRIx64 ")",
2502 GetTypeName().AsCString("void"),
2503 GetValueAsUnsigned(0));
2504 return;
2505 }
2506 else
2507 {
2508 uint64_t load_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
2509 if (load_addr != LLDB_INVALID_ADDRESS)
2510 {
2511 s.Printf("(*( (%s *)0x%" PRIx64 "))",
2512 GetTypeName().AsCString("void"),
2513 load_addr);
2514 return;
2515 }
2516 }
2517 }
2518
2519 if (CanProvideValue())
2520 {
2521 s.Printf("((%s)%s)",
2522 GetTypeName().AsCString("void"),
2523 GetValueAsCString());
2524 return;
2525 }
2526
2527 return;
2528 }
2529
Greg Claytone221f822011-01-21 01:59:00 +00002530 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002531
Enrico Granata86cc9822012-03-19 22:58:49 +00002532 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002533 {
Enrico Granata4becb372011-06-29 22:27:15 +00002534 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2535 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2536 // the eHonorPointers mode is meant to produce strings in this latter format
2537 s.PutCString("*(");
2538 }
Greg Claytone221f822011-01-21 01:59:00 +00002539
Enrico Granata4becb372011-06-29 22:27:15 +00002540 ValueObject* parent = GetParent();
2541
2542 if (parent)
2543 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002544
2545 // if we are a deref_of_parent just because we are synthetic array
2546 // members made up to allow ptr[%d] syntax to work in variable
2547 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002548 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002549 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002550
Greg Claytone221f822011-01-21 01:59:00 +00002551 if (!IsBaseClass())
2552 {
2553 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002554 {
Greg Claytone221f822011-01-21 01:59:00 +00002555 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2556 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002557 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002558 CompilerType non_base_class_parent_compiler_type = non_base_class_parent->GetCompilerType();
2559 if (non_base_class_parent_compiler_type)
Greg Claytone221f822011-01-21 01:59:00 +00002560 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002561 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002562 {
2563 s.PutCString("->");
2564 }
Enrico Granata4becb372011-06-29 22:27:15 +00002565 else
2566 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002567 const uint32_t non_base_class_parent_type_info = non_base_class_parent_compiler_type.GetTypeInfo();
Greg Clayton57ee3062013-07-11 22:46:58 +00002568
Enrico Granata622be232014-10-21 20:52:14 +00002569 if (non_base_class_parent_type_info & eTypeIsPointer)
Enrico Granata4becb372011-06-29 22:27:15 +00002570 {
2571 s.PutCString("->");
2572 }
Enrico Granata622be232014-10-21 20:52:14 +00002573 else if ((non_base_class_parent_type_info & eTypeHasChildren) &&
2574 !(non_base_class_parent_type_info & eTypeIsArray))
Enrico Granata4becb372011-06-29 22:27:15 +00002575 {
2576 s.PutChar('.');
2577 }
Greg Claytone221f822011-01-21 01:59:00 +00002578 }
2579 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002580 }
Greg Claytone221f822011-01-21 01:59:00 +00002581
2582 const char *name = GetName().GetCString();
2583 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002584 {
Greg Claytone221f822011-01-21 01:59:00 +00002585 if (qualify_cxx_base_classes)
2586 {
2587 if (GetBaseClassPath (s))
2588 s.PutCString("::");
2589 }
2590 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002591 }
2592 }
2593 }
2594
Enrico Granata86cc9822012-03-19 22:58:49 +00002595 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002596 {
Greg Claytone221f822011-01-21 01:59:00 +00002597 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002598 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002599}
2600
Greg Claytonafacd142011-09-02 01:15:17 +00002601ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002602ValueObject::GetValueForExpressionPath(const char* expression,
2603 const char** first_unparsed,
2604 ExpressionPathScanEndReason* reason_to_stop,
2605 ExpressionPathEndResultType* final_value_type,
2606 const GetValueForExpressionPathOptions& options,
2607 ExpressionPathAftermath* final_task_on_target)
2608{
2609
2610 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002611 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2612 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002613 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002614
2615 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2616 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2617 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2618 final_value_type ? final_value_type : &dummy_final_value_type,
2619 options,
2620 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2621
Enrico Granata86cc9822012-03-19 22:58:49 +00002622 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002623 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002624
Enrico Granata86cc9822012-03-19 22:58:49 +00002625 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 +00002626 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002627 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002628 {
2629 Error error;
2630 ValueObjectSP final_value = ret_val->Dereference(error);
2631 if (error.Fail() || !final_value.get())
2632 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002633 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002634 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002635 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002636 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002637 return ValueObjectSP();
2638 }
2639 else
2640 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002641 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002642 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002643 return final_value;
2644 }
2645 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002646 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002647 {
2648 Error error;
2649 ValueObjectSP final_value = ret_val->AddressOf(error);
2650 if (error.Fail() || !final_value.get())
2651 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002652 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002653 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002654 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002655 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002656 return ValueObjectSP();
2657 }
2658 else
2659 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002660 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002661 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002662 return final_value;
2663 }
2664 }
2665 }
2666 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2667}
2668
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002669int
2670ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002671 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002672 const char** first_unparsed,
2673 ExpressionPathScanEndReason* reason_to_stop,
2674 ExpressionPathEndResultType* final_value_type,
2675 const GetValueForExpressionPathOptions& options,
2676 ExpressionPathAftermath* final_task_on_target)
2677{
2678 const char* dummy_first_unparsed;
2679 ExpressionPathScanEndReason dummy_reason_to_stop;
2680 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002681 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002682
2683 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2684 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2685 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2686 final_value_type ? final_value_type : &dummy_final_value_type,
2687 options,
2688 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2689
2690 if (!ret_val.get()) // if there are errors, I add nothing to the list
2691 return 0;
2692
Enrico Granata86ea8d82012-03-29 01:34:34 +00002693 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002694 {
2695 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002696 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002697 {
2698 list->Append(ret_val);
2699 return 1;
2700 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002701 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 +00002702 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002703 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002704 {
2705 Error error;
2706 ValueObjectSP final_value = ret_val->Dereference(error);
2707 if (error.Fail() || !final_value.get())
2708 {
Greg Clayton23f59502012-07-17 03:23:13 +00002709 if (reason_to_stop)
2710 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2711 if (final_value_type)
2712 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002713 return 0;
2714 }
2715 else
2716 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002717 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002718 list->Append(final_value);
2719 return 1;
2720 }
2721 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002722 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002723 {
2724 Error error;
2725 ValueObjectSP final_value = ret_val->AddressOf(error);
2726 if (error.Fail() || !final_value.get())
2727 {
Greg Clayton23f59502012-07-17 03:23:13 +00002728 if (reason_to_stop)
2729 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2730 if (final_value_type)
2731 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002732 return 0;
2733 }
2734 else
2735 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002736 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002737 list->Append(final_value);
2738 return 1;
2739 }
2740 }
2741 }
2742 }
2743 else
2744 {
2745 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2746 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2747 ret_val,
2748 list,
2749 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2750 final_value_type ? final_value_type : &dummy_final_value_type,
2751 options,
2752 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2753 }
2754 // in any non-covered case, just do the obviously right thing
2755 list->Append(ret_val);
2756 return 1;
2757}
2758
Greg Claytonafacd142011-09-02 01:15:17 +00002759ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002760ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2761 const char** first_unparsed,
2762 ExpressionPathScanEndReason* reason_to_stop,
2763 ExpressionPathEndResultType* final_result,
2764 const GetValueForExpressionPathOptions& options,
2765 ExpressionPathAftermath* what_next)
2766{
2767 ValueObjectSP root = GetSP();
2768
2769 if (!root.get())
2770 return ValueObjectSP();
2771
2772 *first_unparsed = expression_cstr;
2773
2774 while (true)
2775 {
2776
2777 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2778
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002779 CompilerType root_compiler_type = root->GetCompilerType();
2780 CompilerType pointee_compiler_type;
2781 Flags pointee_compiler_type_info;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002782
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002783 Flags root_compiler_type_info(root_compiler_type.GetTypeInfo(&pointee_compiler_type));
2784 if (pointee_compiler_type)
2785 pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002786
2787 if (!expression_cstr || *expression_cstr == '\0')
2788 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002789 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002790 return root;
2791 }
2792
2793 switch (*expression_cstr)
2794 {
2795 case '-':
2796 {
2797 if (options.m_check_dot_vs_arrow_syntax &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002798 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 +00002799 {
2800 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002801 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2802 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002803 return ValueObjectSP();
2804 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002805 if (root_compiler_type_info.Test(eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2806 root_compiler_type_info.Test(eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002807 options.m_no_fragile_ivar)
2808 {
2809 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002810 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2811 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002812 return ValueObjectSP();
2813 }
2814 if (expression_cstr[1] != '>')
2815 {
2816 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002817 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2818 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002819 return ValueObjectSP();
2820 }
2821 expression_cstr++; // skip the -
2822 }
2823 case '.': // or fallthrough from ->
2824 {
2825 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002826 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 +00002827 {
2828 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002829 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2830 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002831 return ValueObjectSP();
2832 }
2833 expression_cstr++; // skip .
2834 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2835 ConstString child_name;
2836 if (!next_separator) // if no other separator just expand this last layer
2837 {
2838 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002839 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2840
2841 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002842 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002843 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002844 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2845 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002846 return child_valobj_sp;
2847 }
Enrico Granataef238c12015-03-12 22:30:58 +00002848 else
Enrico Granata8c9d3562011-08-11 17:08:01 +00002849 {
Enrico Granataef238c12015-03-12 22:30:58 +00002850 switch (options.m_synthetic_children_traversal)
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002851 {
Enrico Granataef238c12015-03-12 22:30:58 +00002852 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None:
2853 break;
2854 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic:
2855 if (root->IsSynthetic())
2856 {
2857 child_valobj_sp = root->GetNonSyntheticValue();
2858 if (child_valobj_sp.get())
2859 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2860 }
2861 break;
2862 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic:
2863 if (!root->IsSynthetic())
2864 {
2865 child_valobj_sp = root->GetSyntheticValue();
2866 if (child_valobj_sp.get())
2867 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2868 }
2869 break;
2870 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both:
2871 if (root->IsSynthetic())
2872 {
2873 child_valobj_sp = root->GetNonSyntheticValue();
2874 if (child_valobj_sp.get())
2875 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2876 }
2877 else
2878 {
2879 child_valobj_sp = root->GetSyntheticValue();
2880 if (child_valobj_sp.get())
2881 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2882 }
2883 break;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002884 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002885 }
2886
2887 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2888 // so we hit the "else" branch, and return an error
2889 if(child_valobj_sp.get()) // if it worked, just return
2890 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002891 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002892 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2893 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002894 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002895 }
2896 else
2897 {
2898 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002899 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2900 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002901 return ValueObjectSP();
2902 }
2903 }
2904 else // other layers do expand
2905 {
2906 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002907 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2908 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002909 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002910 root = child_valobj_sp;
2911 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002912 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002913 continue;
2914 }
Enrico Granataef238c12015-03-12 22:30:58 +00002915 else
Enrico Granata8c9d3562011-08-11 17:08:01 +00002916 {
Enrico Granataef238c12015-03-12 22:30:58 +00002917 switch (options.m_synthetic_children_traversal)
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002918 {
Enrico Granataef238c12015-03-12 22:30:58 +00002919 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None:
2920 break;
2921 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic:
2922 if (root->IsSynthetic())
2923 {
2924 child_valobj_sp = root->GetNonSyntheticValue();
2925 if (child_valobj_sp.get())
2926 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2927 }
2928 break;
2929 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic:
2930 if (!root->IsSynthetic())
2931 {
2932 child_valobj_sp = root->GetSyntheticValue();
2933 if (child_valobj_sp.get())
2934 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2935 }
2936 break;
2937 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both:
2938 if (root->IsSynthetic())
2939 {
2940 child_valobj_sp = root->GetNonSyntheticValue();
2941 if (child_valobj_sp.get())
2942 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2943 }
2944 else
2945 {
2946 child_valobj_sp = root->GetSyntheticValue();
2947 if (child_valobj_sp.get())
2948 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2949 }
2950 break;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002951 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002952 }
2953
2954 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2955 // so we hit the "else" branch, and return an error
2956 if(child_valobj_sp.get()) // if it worked, move on
2957 {
2958 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002959 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002960 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002961 continue;
2962 }
2963 else
2964 {
2965 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002966 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2967 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002968 return ValueObjectSP();
2969 }
2970 }
2971 break;
2972 }
2973 case '[':
2974 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002975 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 +00002976 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002977 if (!root_compiler_type_info.Test(eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002978 {
Enrico Granataef238c12015-03-12 22:30:58 +00002979 if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None) // ...only chance left is synthetic
Enrico Granata27b625e2011-08-09 01:04:56 +00002980 {
2981 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002982 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2983 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002984 return ValueObjectSP();
2985 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002986 }
2987 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2988 {
2989 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002990 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2991 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002992 return ValueObjectSP();
2993 }
2994 }
2995 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2996 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002997 if (!root_compiler_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002998 {
2999 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003000 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3001 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003002 return ValueObjectSP();
3003 }
3004 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
3005 {
3006 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003007 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3008 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003009 return root;
3010 }
3011 }
3012 const char *separator_position = ::strchr(expression_cstr+1,'-');
3013 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3014 if (!close_bracket_position) // if there is no ], this is a syntax error
3015 {
3016 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003017 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3018 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003019 return ValueObjectSP();
3020 }
3021 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3022 {
3023 char *end = NULL;
3024 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3025 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3026 {
3027 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003028 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3029 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003030 return ValueObjectSP();
3031 }
3032 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3033 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003034 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003035 {
3036 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003037 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3038 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003039 return root;
3040 }
3041 else
3042 {
3043 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003044 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3045 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003046 return ValueObjectSP();
3047 }
3048 }
3049 // from here on we do have a valid index
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003050 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003051 {
Greg Claytondaf515f2011-07-09 20:12:33 +00003052 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
3053 if (!child_valobj_sp)
Bruce Mitchener11d86362015-02-26 23:55:39 +00003054 child_valobj_sp = root->GetSyntheticArrayMember(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003055 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00003056 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
3057 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00003058 if (child_valobj_sp)
3059 {
3060 root = child_valobj_sp;
3061 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003062 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00003063 continue;
3064 }
3065 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003066 {
3067 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003068 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3069 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003070 return ValueObjectSP();
3071 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003072 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003073 else if (root_compiler_type_info.Test(eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003074 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003075 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 +00003076 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003077 {
3078 Error error;
3079 root = root->Dereference(error);
3080 if (error.Fail() || !root.get())
3081 {
3082 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003083 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3084 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003085 return ValueObjectSP();
3086 }
3087 else
3088 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003089 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003090 continue;
3091 }
3092 }
3093 else
3094 {
Greg Clayton99558cc42015-08-24 23:46:31 +00003095 if (root->GetCompilerType().GetMinimumLanguage() == eLanguageTypeObjC
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003096 && pointee_compiler_type_info.AllClear(eTypeIsPointer)
Greg Clayton84db9102012-03-26 23:03:23 +00003097 && root->HasSyntheticValue()
Enrico Granataef238c12015-03-12 22:30:58 +00003098 && (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic ||
3099 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both))
Enrico Granata27b625e2011-08-09 01:04:56 +00003100 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003101 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003102 }
3103 else
Bruce Mitchener11d86362015-02-26 23:55:39 +00003104 root = root->GetSyntheticArrayMember(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003105 if (!root.get())
3106 {
3107 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003108 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3109 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003110 return ValueObjectSP();
3111 }
3112 else
3113 {
3114 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003115 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003116 continue;
3117 }
3118 }
3119 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003120 else if (root_compiler_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003121 {
3122 root = root->GetSyntheticBitFieldChild(index, index, true);
3123 if (!root.get())
3124 {
3125 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003126 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3127 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003128 return ValueObjectSP();
3129 }
3130 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3131 {
3132 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003133 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3134 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003135 return root;
3136 }
3137 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003138 else if (root_compiler_type_info.Test(eTypeIsVector))
Enrico Granata08a1bb82013-06-19 00:00:45 +00003139 {
3140 root = root->GetChildAtIndex(index, true);
3141 if (!root.get())
3142 {
3143 *first_unparsed = expression_cstr;
3144 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3145 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3146 return ValueObjectSP();
3147 }
3148 else
3149 {
3150 *first_unparsed = end+1; // skip ]
3151 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3152 continue;
3153 }
3154 }
Enrico Granataef238c12015-03-12 22:30:58 +00003155 else if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic ||
3156 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both)
Enrico Granata27b625e2011-08-09 01:04:56 +00003157 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003158 if (root->HasSyntheticValue())
3159 root = root->GetSyntheticValue();
3160 else if (!root->IsSynthetic())
3161 {
3162 *first_unparsed = expression_cstr;
3163 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3164 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3165 return ValueObjectSP();
3166 }
3167 // if we are here, then root itself is a synthetic VO.. should be good to go
3168
Enrico Granata27b625e2011-08-09 01:04:56 +00003169 if (!root.get())
3170 {
3171 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003172 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3173 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3174 return ValueObjectSP();
3175 }
3176 root = root->GetChildAtIndex(index, true);
3177 if (!root.get())
3178 {
3179 *first_unparsed = expression_cstr;
3180 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3181 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003182 return ValueObjectSP();
3183 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00003184 else
3185 {
3186 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003187 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00003188 continue;
3189 }
Enrico Granata27b625e2011-08-09 01:04:56 +00003190 }
3191 else
3192 {
3193 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003194 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3195 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003196 return ValueObjectSP();
3197 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003198 }
3199 else // we have a low and a high index
3200 {
3201 char *end = NULL;
3202 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3203 if (!end || end != separator_position) // if something weird is in our way return an error
3204 {
3205 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003206 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3207 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003208 return ValueObjectSP();
3209 }
3210 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3211 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3212 {
3213 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003214 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3215 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003216 return ValueObjectSP();
3217 }
3218 if (index_lower > index_higher) // swap indices if required
3219 {
3220 unsigned long temp = index_lower;
3221 index_lower = index_higher;
3222 index_higher = temp;
3223 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003224 if (root_compiler_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003225 {
3226 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3227 if (!root.get())
3228 {
3229 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003230 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3231 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003232 return ValueObjectSP();
3233 }
3234 else
3235 {
3236 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003237 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3238 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003239 return root;
3240 }
3241 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003242 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 +00003243 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003244 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003245 {
3246 Error error;
3247 root = root->Dereference(error);
3248 if (error.Fail() || !root.get())
3249 {
3250 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003251 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3252 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003253 return ValueObjectSP();
3254 }
3255 else
3256 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003257 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003258 continue;
3259 }
3260 }
3261 else
3262 {
3263 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003264 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3265 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003266 return root;
3267 }
3268 }
3269 break;
3270 }
3271 default: // some non-separator is in the way
3272 {
3273 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003274 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3275 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003276 return ValueObjectSP();
3277 break;
3278 }
3279 }
3280 }
3281}
3282
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003283int
3284ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3285 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00003286 ValueObjectSP root,
3287 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003288 ExpressionPathScanEndReason* reason_to_stop,
3289 ExpressionPathEndResultType* final_result,
3290 const GetValueForExpressionPathOptions& options,
3291 ExpressionPathAftermath* what_next)
3292{
3293 if (!root.get())
3294 return 0;
3295
3296 *first_unparsed = expression_cstr;
3297
3298 while (true)
3299 {
3300
3301 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3302
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003303 CompilerType root_compiler_type = root->GetCompilerType();
3304 CompilerType pointee_compiler_type;
3305 Flags pointee_compiler_type_info;
3306 Flags root_compiler_type_info(root_compiler_type.GetTypeInfo(&pointee_compiler_type));
3307 if (pointee_compiler_type)
3308 pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003309
3310 if (!expression_cstr || *expression_cstr == '\0')
3311 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003312 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003313 list->Append(root);
3314 return 1;
3315 }
3316
3317 switch (*expression_cstr)
3318 {
3319 case '[':
3320 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003321 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 +00003322 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003323 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 +00003324 {
3325 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003326 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3327 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003328 return 0;
3329 }
3330 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3331 {
3332 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003333 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3334 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003335 return 0;
3336 }
3337 }
3338 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3339 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003340 if (!root_compiler_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003341 {
3342 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003343 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3344 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003345 return 0;
3346 }
3347 else // expand this into list
3348 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003349 const size_t max_index = root->GetNumChildren() - 1;
3350 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003351 {
3352 ValueObjectSP child =
3353 root->GetChildAtIndex(index, true);
3354 list->Append(child);
3355 }
3356 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003357 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3358 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003359 return max_index; // tell me number of items I added to the VOList
3360 }
3361 }
3362 const char *separator_position = ::strchr(expression_cstr+1,'-');
3363 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3364 if (!close_bracket_position) // if there is no ], this is a syntax error
3365 {
3366 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003367 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3368 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003369 return 0;
3370 }
3371 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3372 {
3373 char *end = NULL;
3374 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3375 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3376 {
3377 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003378 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3379 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003380 return 0;
3381 }
3382 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3383 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003384 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003385 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003386 const size_t max_index = root->GetNumChildren() - 1;
3387 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003388 {
3389 ValueObjectSP child =
3390 root->GetChildAtIndex(index, true);
3391 list->Append(child);
3392 }
3393 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003394 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3395 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003396 return max_index; // tell me number of items I added to the VOList
3397 }
3398 else
3399 {
3400 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003401 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3402 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003403 return 0;
3404 }
3405 }
3406 // from here on we do have a valid index
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003407 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003408 {
3409 root = root->GetChildAtIndex(index, true);
3410 if (!root.get())
3411 {
3412 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003413 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3414 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003415 return 0;
3416 }
3417 else
3418 {
3419 list->Append(root);
3420 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003421 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3422 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003423 return 1;
3424 }
3425 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003426 else if (root_compiler_type_info.Test(eTypeIsPointer))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003427 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003428 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 +00003429 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003430 {
3431 Error error;
3432 root = root->Dereference(error);
3433 if (error.Fail() || !root.get())
3434 {
3435 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003436 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3437 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003438 return 0;
3439 }
3440 else
3441 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003442 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003443 continue;
3444 }
3445 }
3446 else
3447 {
Bruce Mitchener11d86362015-02-26 23:55:39 +00003448 root = root->GetSyntheticArrayMember(index, true);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003449 if (!root.get())
3450 {
3451 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003452 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3453 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003454 return 0;
3455 }
3456 else
3457 {
3458 list->Append(root);
3459 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003460 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3461 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003462 return 1;
3463 }
3464 }
3465 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003466 else /*if (ClangASTContext::IsScalarType(root_compiler_type))*/
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003467 {
3468 root = root->GetSyntheticBitFieldChild(index, index, true);
3469 if (!root.get())
3470 {
3471 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003472 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3473 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003474 return 0;
3475 }
3476 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3477 {
3478 list->Append(root);
3479 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003480 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3481 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003482 return 1;
3483 }
3484 }
3485 }
3486 else // we have a low and a high index
3487 {
3488 char *end = NULL;
3489 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3490 if (!end || end != separator_position) // if something weird is in our way return an error
3491 {
3492 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003493 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3494 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003495 return 0;
3496 }
3497 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3498 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3499 {
3500 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003501 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3502 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003503 return 0;
3504 }
3505 if (index_lower > index_higher) // swap indices if required
3506 {
3507 unsigned long temp = index_lower;
3508 index_lower = index_higher;
3509 index_higher = temp;
3510 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003511 if (root_compiler_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003512 {
3513 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3514 if (!root.get())
3515 {
3516 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003517 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3518 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003519 return 0;
3520 }
3521 else
3522 {
3523 list->Append(root);
3524 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003525 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3526 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003527 return 1;
3528 }
3529 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003530 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 +00003531 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003532 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003533 {
3534 Error error;
3535 root = root->Dereference(error);
3536 if (error.Fail() || !root.get())
3537 {
3538 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003539 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3540 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003541 return 0;
3542 }
3543 else
3544 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003545 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003546 continue;
3547 }
3548 }
3549 else
3550 {
Johnny Chen44805302011-07-19 19:48:13 +00003551 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003552 index <= index_higher; index++)
3553 {
3554 ValueObjectSP child =
3555 root->GetChildAtIndex(index, true);
3556 list->Append(child);
3557 }
3558 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003559 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3560 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003561 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3562 }
3563 }
3564 break;
3565 }
3566 default: // some non-[ separator, or something entirely wrong, is in the way
3567 {
3568 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003569 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3570 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003571 return 0;
3572 break;
3573 }
3574 }
3575 }
3576}
3577
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003578void
3579ValueObject::LogValueObject (Log *log)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003580{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003581 if (log)
Enrico Granatad5957332015-06-03 20:43:54 +00003582 return LogValueObject (log, DumpValueObjectOptions(*this));
Greg Clayton1d3afba2010-10-05 00:00:42 +00003583}
3584
Enrico Granata0c489f52012-03-01 04:24:26 +00003585void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003586ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003587{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003588 if (log)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003589 {
3590 StreamString s;
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003591 Dump (s, options);
Greg Claytonf830dbb2012-03-22 18:15:37 +00003592 if (s.GetSize())
3593 log->PutCString(s.GetData());
3594 }
3595}
3596
3597void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003598ValueObject::Dump (Stream &s)
Enrico Granata0c489f52012-03-01 04:24:26 +00003599{
Enrico Granatad5957332015-06-03 20:43:54 +00003600 Dump (s, DumpValueObjectOptions(*this));
Enrico Granata0c489f52012-03-01 04:24:26 +00003601}
3602
3603void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003604ValueObject::Dump (Stream &s,
3605 const DumpValueObjectOptions& options)
Enrico Granata0c489f52012-03-01 04:24:26 +00003606{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003607 ValueObjectPrinter printer(this,&s,options);
3608 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003609}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003610
3611ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003612ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003613{
3614 ValueObjectSP valobj_sp;
3615
Enrico Granatac3e320a2011-08-02 17:27:39 +00003616 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003617 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003618 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003619
3620 DataExtractor data;
3621 data.SetByteOrder (m_data.GetByteOrder());
3622 data.SetAddressByteSize(m_data.GetAddressByteSize());
3623
Enrico Granata9f1e2042012-04-24 22:15:37 +00003624 if (IsBitfield())
3625 {
3626 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
Greg Clayton57ee3062013-07-11 22:46:58 +00003627 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Enrico Granata9f1e2042012-04-24 22:15:37 +00003628 }
3629 else
Greg Clayton57ee3062013-07-11 22:46:58 +00003630 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003631
3632 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton99558cc42015-08-24 23:46:31 +00003633 GetCompilerType(),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003634 name,
3635 data,
3636 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003637 }
Jim Ingham6035b672011-03-31 00:19:25 +00003638
3639 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003640 {
Greg Claytoneeb15652013-12-10 23:16:40 +00003641 ExecutionContext exe_ctx (GetExecutionContextRef());
3642 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003643 }
3644 return valobj_sp;
3645}
3646
Enrico Granata538a88a2014-10-09 18:24:30 +00003647ValueObjectSP
3648ValueObject::GetQualifiedRepresentationIfAvailable (lldb::DynamicValueType dynValue,
3649 bool synthValue)
3650{
3651 ValueObjectSP result_sp(GetSP());
3652
3653 switch (dynValue)
3654 {
3655 case lldb::eDynamicCanRunTarget:
3656 case lldb::eDynamicDontRunTarget:
3657 {
3658 if (!result_sp->IsDynamic())
3659 {
3660 if (result_sp->GetDynamicValue(dynValue))
3661 result_sp = result_sp->GetDynamicValue(dynValue);
3662 }
3663 }
3664 break;
3665 case lldb::eNoDynamicValues:
Enrico Granata538a88a2014-10-09 18:24:30 +00003666 {
3667 if (result_sp->IsDynamic())
3668 {
3669 if (result_sp->GetStaticValue())
3670 result_sp = result_sp->GetStaticValue();
3671 }
3672 }
3673 break;
3674 }
3675
3676 if (synthValue)
3677 {
3678 if (!result_sp->IsSynthetic())
3679 {
3680 if (result_sp->GetSyntheticValue())
3681 result_sp = result_sp->GetSyntheticValue();
3682 }
3683 }
3684 else
3685 {
3686 if (result_sp->IsSynthetic())
3687 {
3688 if (result_sp->GetNonSyntheticValue())
3689 result_sp = result_sp->GetNonSyntheticValue();
3690 }
3691 }
3692
3693 return result_sp;
3694}
3695
Greg Clayton759e7442014-07-19 00:12:57 +00003696lldb::addr_t
3697ValueObject::GetCPPVTableAddress (AddressType &address_type)
3698{
Greg Claytona1e5dc82015-08-11 22:53:00 +00003699 CompilerType pointee_type;
Greg Clayton99558cc42015-08-24 23:46:31 +00003700 CompilerType this_type(GetCompilerType());
Greg Clayton759e7442014-07-19 00:12:57 +00003701 uint32_t type_info = this_type.GetTypeInfo(&pointee_type);
3702 if (type_info)
3703 {
3704 bool ptr_or_ref = false;
Enrico Granata622be232014-10-21 20:52:14 +00003705 if (type_info & (eTypeIsPointer | eTypeIsReference))
Greg Clayton759e7442014-07-19 00:12:57 +00003706 {
3707 ptr_or_ref = true;
3708 type_info = pointee_type.GetTypeInfo();
3709 }
3710
Enrico Granata622be232014-10-21 20:52:14 +00003711 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus;
Greg Clayton759e7442014-07-19 00:12:57 +00003712 if ((type_info & cpp_class) == cpp_class)
3713 {
3714 if (ptr_or_ref)
3715 {
3716 address_type = GetAddressTypeOfChildren();
3717 return GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
3718 }
3719 else
3720 return GetAddressOf (false, &address_type);
3721 }
3722 }
3723
3724 address_type = eAddressTypeInvalid;
3725 return LLDB_INVALID_ADDRESS;
3726}
3727
Greg Claytonafacd142011-09-02 01:15:17 +00003728ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003729ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003730{
Jim Ingham58b59f92011-04-22 23:53:53 +00003731 if (m_deref_valobj)
3732 return m_deref_valobj->GetSP();
Chaoren Lind7bdc272015-07-31 00:35:40 +00003733
3734 const bool is_pointer_or_reference_type = IsPointerOrReferenceType();
3735 if (is_pointer_or_reference_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003736 {
3737 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003738 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003739
3740 std::string child_name_str;
3741 uint32_t child_byte_size = 0;
3742 int32_t child_byte_offset = 0;
3743 uint32_t child_bitfield_bit_size = 0;
3744 uint32_t child_bitfield_bit_offset = 0;
3745 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003746 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003747 const bool transparent_pointers = false;
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003748 CompilerType compiler_type = GetCompilerType();
3749 CompilerType child_compiler_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003750
Greg Claytoncc4d0142012-02-17 07:49:44 +00003751 ExecutionContext exe_ctx (GetExecutionContextRef());
Chaoren Lind7bdc272015-07-31 00:35:40 +00003752
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003753 child_compiler_type = compiler_type.GetChildCompilerTypeAtIndex (&exe_ctx,
3754 0,
3755 transparent_pointers,
3756 omit_empty_base_classes,
3757 ignore_array_bounds,
3758 child_name_str,
3759 child_byte_size,
3760 child_byte_offset,
3761 child_bitfield_bit_size,
3762 child_bitfield_bit_offset,
3763 child_is_base_class,
3764 child_is_deref_of_parent,
3765 this);
3766 if (child_compiler_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003767 {
3768 ConstString child_name;
3769 if (!child_name_str.empty())
3770 child_name.SetCString (child_name_str.c_str());
3771
Jim Ingham58b59f92011-04-22 23:53:53 +00003772 m_deref_valobj = new ValueObjectChild (*this,
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003773 child_compiler_type,
Jim Ingham58b59f92011-04-22 23:53:53 +00003774 child_name,
3775 child_byte_size,
3776 child_byte_offset,
3777 child_bitfield_bit_size,
3778 child_bitfield_bit_offset,
3779 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003780 child_is_deref_of_parent,
3781 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003782 }
3783 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003784
Jim Ingham58b59f92011-04-22 23:53:53 +00003785 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003786 {
3787 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003788 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003789 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003790 else
3791 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003792 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003793 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003794
Chaoren Lind7bdc272015-07-31 00:35:40 +00003795 if (is_pointer_or_reference_type)
Greg Clayton54979cd2010-12-15 05:08:08 +00003796 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3797 else
Chaoren Lind7bdc272015-07-31 00:35:40 +00003798 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 +00003799 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003800 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003801}
3802
Greg Claytonafacd142011-09-02 01:15:17 +00003803ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003804ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003805{
Jim Ingham78a685a2011-04-16 00:01:13 +00003806 if (m_addr_of_valobj_sp)
3807 return m_addr_of_valobj_sp;
3808
Greg Claytone0d378b2011-03-24 21:19:54 +00003809 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003810 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003811 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003812 error.Clear();
Siva Chandraa3747a92015-05-04 19:43:34 +00003813 if (addr != LLDB_INVALID_ADDRESS && address_type != eAddressTypeHost)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003814 {
3815 switch (address_type)
3816 {
3817 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003818 {
3819 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003820 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003821 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3822 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003823 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003824
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003825 case eAddressTypeFile:
3826 case eAddressTypeLoad:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003827 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003828 CompilerType compiler_type = GetCompilerType();
3829 if (compiler_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003830 {
3831 std::string name (1, '&');
3832 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003833 ExecutionContext exe_ctx (GetExecutionContextRef());
3834 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003835 compiler_type.GetPointerType(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003836 ConstString (name.c_str()),
3837 addr,
3838 eAddressTypeInvalid,
3839 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003840 }
3841 }
3842 break;
Siva Chandraa3747a92015-05-04 19:43:34 +00003843 default:
3844 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003845 }
3846 }
Sean Callananed185ab2013-04-19 19:47:32 +00003847 else
3848 {
3849 StreamString expr_path_strm;
3850 GetExpressionPath(expr_path_strm, true);
3851 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3852 }
3853
Jim Ingham78a685a2011-04-16 00:01:13 +00003854 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003855}
3856
Greg Clayton9a142cf2012-02-03 05:34:10 +00003857ValueObjectSP
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003858ValueObject::Cast (const CompilerType &compiler_type)
Greg Clayton9a142cf2012-02-03 05:34:10 +00003859{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003860 return ValueObjectCast::Create (*this, GetName(), compiler_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003861}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003862
Greg Claytonafacd142011-09-02 01:15:17 +00003863ValueObjectSP
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003864ValueObject::CastPointerType (const char *name, CompilerType &compiler_type)
Greg Claytonb2dcc362011-05-05 23:32:56 +00003865{
Greg Claytonafacd142011-09-02 01:15:17 +00003866 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003867 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003868 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003869
3870 if (ptr_value != LLDB_INVALID_ADDRESS)
3871 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003872 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003873 ExecutionContext exe_ctx (GetExecutionContextRef());
3874 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003875 name,
3876 ptr_addr,
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003877 compiler_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003878 }
3879 return valobj_sp;
3880}
3881
Greg Claytonafacd142011-09-02 01:15:17 +00003882ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003883ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3884{
Greg Claytonafacd142011-09-02 01:15:17 +00003885 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003886 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003887 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003888
3889 if (ptr_value != LLDB_INVALID_ADDRESS)
3890 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003891 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003892 ExecutionContext exe_ctx (GetExecutionContextRef());
3893 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003894 name,
3895 ptr_addr,
3896 type_sp);
3897 }
3898 return valobj_sp;
3899}
3900
Jim Ingham6035b672011-03-31 00:19:25 +00003901ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003902 m_mod_id(),
3903 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003904 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003905{
3906}
3907
3908ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003909 m_mod_id(),
3910 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003911 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003912{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003913 ExecutionContext exe_ctx(exe_scope);
3914 TargetSP target_sp (exe_ctx.GetTargetSP());
3915 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003916 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003917 m_exe_ctx_ref.SetTargetSP (target_sp);
3918 ProcessSP process_sp (exe_ctx.GetProcessSP());
3919 if (!process_sp)
3920 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003921
Greg Claytoncc4d0142012-02-17 07:49:44 +00003922 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003923 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003924 m_mod_id = process_sp->GetModID();
3925 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003926
Greg Claytoncc4d0142012-02-17 07:49:44 +00003927 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003928
Greg Claytoncc4d0142012-02-17 07:49:44 +00003929 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003930 {
3931 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003932 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003933 }
Jim Ingham6035b672011-03-31 00:19:25 +00003934
Greg Claytoncc4d0142012-02-17 07:49:44 +00003935 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003936 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003937 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003938
Jason Molendab57e4a12013-11-04 09:33:30 +00003939 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003940 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003941 {
3942 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003943 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003944 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003945 if (frame_sp)
3946 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003947 }
3948 }
3949 }
Jim Ingham6035b672011-03-31 00:19:25 +00003950}
3951
3952ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003953 m_mod_id(),
3954 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003955 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003956{
3957}
3958
3959ValueObject::EvaluationPoint::~EvaluationPoint ()
3960{
3961}
3962
Jim Ingham6035b672011-03-31 00:19:25 +00003963// This function checks the EvaluationPoint against the current process state. If the current
3964// state matches the evaluation point, or the evaluation point is already invalid, then we return
3965// false, meaning "no change". If the current state is different, we update our state, and return
3966// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3967// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003968// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003969
3970bool
Enrico Granatabb642e52015-05-16 01:27:00 +00003971ValueObject::EvaluationPoint::SyncWithProcessState(bool accept_invalid_exe_ctx)
Jim Ingham6035b672011-03-31 00:19:25 +00003972{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003973 // 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 +00003974 const bool thread_and_frame_only_if_stopped = true;
3975 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
Jim Ingham73ca05a2011-12-17 01:35:57 +00003976
Greg Claytoncc4d0142012-02-17 07:49:44 +00003977 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003978 return false;
3979
Jim Ingham6035b672011-03-31 00:19:25 +00003980 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003981 Process *process = exe_ctx.GetProcessPtr();
3982 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003983 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003984
Jim Ingham6035b672011-03-31 00:19:25 +00003985 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003986 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003987
Jim Ingham78a685a2011-04-16 00:01:13 +00003988 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3989 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003990 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003991 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003992
Greg Clayton23f59502012-07-17 03:23:13 +00003993 bool changed = false;
3994 const bool was_valid = m_mod_id.IsValid();
3995 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003996 {
3997 if (m_mod_id == current_mod_id)
3998 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003999 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004000 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00004001 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004002 }
Jim Ingham9ee01152011-12-10 01:49:43 +00004003 else
4004 {
4005 m_mod_id = current_mod_id;
4006 m_needs_update = true;
4007 changed = true;
4008 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004009 }
Jim Ingham6035b672011-03-31 00:19:25 +00004010
Jim Ingham73ca05a2011-12-17 01:35:57 +00004011 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
4012 // That way we'll be sure to return a valid exe_scope.
4013 // 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 +00004014
Enrico Granatabb642e52015-05-16 01:27:00 +00004015 if (!accept_invalid_exe_ctx)
Jim Ingham6035b672011-03-31 00:19:25 +00004016 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004017 if (m_exe_ctx_ref.HasThreadRef())
Greg Clayton262f80d2011-07-06 16:49:27 +00004018 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004019 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
4020 if (thread_sp)
Greg Claytoncc4d0142012-02-17 07:49:44 +00004021 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004022 if (m_exe_ctx_ref.HasFrameRef())
Greg Claytoncc4d0142012-02-17 07:49:44 +00004023 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004024 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
4025 if (!frame_sp)
4026 {
4027 // We used to have a frame, but now it is gone
4028 SetInvalid();
4029 changed = was_valid;
4030 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00004031 }
4032 }
Enrico Granatabb642e52015-05-16 01:27:00 +00004033 else
4034 {
4035 // We used to have a thread, but now it is gone
4036 SetInvalid();
4037 changed = was_valid;
4038 }
Greg Clayton262f80d2011-07-06 16:49:27 +00004039 }
Jim Ingham6035b672011-03-31 00:19:25 +00004040 }
Enrico Granatabb642e52015-05-16 01:27:00 +00004041
Jim Ingham9ee01152011-12-10 01:49:43 +00004042 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00004043}
4044
Jim Ingham61be0902011-05-02 18:13:59 +00004045void
4046ValueObject::EvaluationPoint::SetUpdated ()
4047{
Greg Claytoncc4d0142012-02-17 07:49:44 +00004048 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
4049 if (process_sp)
4050 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00004051 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00004052}
4053
4054
Enrico Granataf2bbf712011-07-15 02:26:42 +00004055
4056void
Enrico Granata86cc9822012-03-19 22:58:49 +00004057ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004058{
Enrico Granata86cc9822012-03-19 22:58:49 +00004059 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4060 m_value_str.clear();
4061
4062 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4063 m_location_str.clear();
4064
4065 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
Enrico Granata86cc9822012-03-19 22:58:49 +00004066 m_summary_str.clear();
Enrico Granata86cc9822012-03-19 22:58:49 +00004067
4068 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4069 m_object_desc_str.clear();
4070
4071 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4072 {
4073 if (m_synthetic_value)
4074 m_synthetic_value = NULL;
4075 }
Enrico Granata744794a2014-09-05 21:46:22 +00004076
4077 if ((clear_mask & eClearUserVisibleDataItemsValidator) == eClearUserVisibleDataItemsValidator)
4078 m_validation_result.reset();
Johnny Chen44805302011-07-19 19:48:13 +00004079}
Enrico Granata9128ee22011-09-06 19:20:51 +00004080
4081SymbolContextScope *
4082ValueObject::GetSymbolContextScope()
4083{
4084 if (m_parent)
4085 {
4086 if (!m_parent->IsPointerOrReferenceType())
4087 return m_parent->GetSymbolContextScope();
4088 }
4089 return NULL;
4090}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004091
4092lldb::ValueObjectSP
4093ValueObject::CreateValueObjectFromExpression (const char* name,
4094 const char* expression,
4095 const ExecutionContext& exe_ctx)
4096{
Enrico Granata972be532014-12-17 21:18:43 +00004097 return CreateValueObjectFromExpression(name, expression, exe_ctx, EvaluateExpressionOptions());
4098}
4099
4100
4101lldb::ValueObjectSP
4102ValueObject::CreateValueObjectFromExpression (const char* name,
4103 const char* expression,
4104 const ExecutionContext& exe_ctx,
4105 const EvaluateExpressionOptions& options)
4106{
Enrico Granatab2698cd2012-09-13 18:27:09 +00004107 lldb::ValueObjectSP retval_sp;
4108 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4109 if (!target_sp)
4110 return retval_sp;
4111 if (!expression || !*expression)
4112 return retval_sp;
4113 target_sp->EvaluateExpression (expression,
4114 exe_ctx.GetFrameSP().get(),
Enrico Granata972be532014-12-17 21:18:43 +00004115 retval_sp,
4116 options);
Enrico Granatab2698cd2012-09-13 18:27:09 +00004117 if (retval_sp && name && *name)
4118 retval_sp->SetName(ConstString(name));
4119 return retval_sp;
4120}
4121
4122lldb::ValueObjectSP
4123ValueObject::CreateValueObjectFromAddress (const char* name,
4124 uint64_t address,
4125 const ExecutionContext& exe_ctx,
Greg Claytona1e5dc82015-08-11 22:53:00 +00004126 CompilerType type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004127{
Greg Clayton57ee3062013-07-11 22:46:58 +00004128 if (type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004129 {
Greg Claytona1e5dc82015-08-11 22:53:00 +00004130 CompilerType pointer_type(type.GetPointerType());
Greg Clayton57ee3062013-07-11 22:46:58 +00004131 if (pointer_type)
4132 {
4133 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4134 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4135 pointer_type,
4136 ConstString(name),
4137 buffer,
Enrico Granata972be532014-12-17 21:18:43 +00004138 exe_ctx.GetByteOrder(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004139 exe_ctx.GetAddressByteSize()));
4140 if (ptr_result_valobj_sp)
4141 {
4142 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4143 Error err;
4144 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4145 if (ptr_result_valobj_sp && name && *name)
4146 ptr_result_valobj_sp->SetName(ConstString(name));
4147 }
4148 return ptr_result_valobj_sp;
4149 }
Enrico Granatab2698cd2012-09-13 18:27:09 +00004150 }
Greg Clayton57ee3062013-07-11 22:46:58 +00004151 return lldb::ValueObjectSP();
Enrico Granatab2698cd2012-09-13 18:27:09 +00004152}
4153
4154lldb::ValueObjectSP
4155ValueObject::CreateValueObjectFromData (const char* name,
Enrico Granata7ca1c762014-03-31 23:02:25 +00004156 const DataExtractor& data,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004157 const ExecutionContext& exe_ctx,
Greg Claytona1e5dc82015-08-11 22:53:00 +00004158 CompilerType type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004159{
4160 lldb::ValueObjectSP new_value_sp;
4161 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004162 type,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004163 ConstString(name),
4164 data,
4165 LLDB_INVALID_ADDRESS);
4166 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4167 if (new_value_sp && name && *name)
4168 new_value_sp->SetName(ConstString(name));
4169 return new_value_sp;
4170}
Enrico Granata4873e522013-04-11 22:48:58 +00004171
4172ModuleSP
4173ValueObject::GetModule ()
4174{
4175 ValueObject* root(GetRoot());
4176 if (root != this)
4177 return root->GetModule();
4178 return lldb::ModuleSP();
4179}
4180
4181ValueObject*
4182ValueObject::GetRoot ()
4183{
4184 if (m_root)
4185 return m_root;
Enrico Granatade61eba2015-01-22 03:07:34 +00004186 return (m_root = FollowParentChain( [] (ValueObject* vo) -> bool {
4187 return (vo->m_parent != nullptr);
4188 }));
4189}
4190
4191ValueObject*
4192ValueObject::FollowParentChain (std::function<bool(ValueObject*)> f)
4193{
4194 ValueObject* vo = this;
4195 while (vo)
Enrico Granata4873e522013-04-11 22:48:58 +00004196 {
Enrico Granatade61eba2015-01-22 03:07:34 +00004197 if (f(vo) == false)
4198 break;
4199 vo = vo->m_parent;
Enrico Granata4873e522013-04-11 22:48:58 +00004200 }
Enrico Granatade61eba2015-01-22 03:07:34 +00004201 return vo;
Enrico Granata4873e522013-04-11 22:48:58 +00004202}
4203
4204AddressType
4205ValueObject::GetAddressTypeOfChildren()
4206{
4207 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
4208 {
4209 ValueObject* root(GetRoot());
4210 if (root != this)
4211 return root->GetAddressTypeOfChildren();
4212 }
4213 return m_address_type_of_ptr_or_ref_children;
4214}
4215
4216lldb::DynamicValueType
4217ValueObject::GetDynamicValueType ()
4218{
4219 ValueObject* with_dv_info = this;
4220 while (with_dv_info)
4221 {
4222 if (with_dv_info->HasDynamicValueTypeInfo())
4223 return with_dv_info->GetDynamicValueTypeImpl();
4224 with_dv_info = with_dv_info->m_parent;
4225 }
4226 return lldb::eNoDynamicValues;
4227}
Enrico Granata39d51412013-05-31 17:43:40 +00004228
Enrico Granata4873e522013-04-11 22:48:58 +00004229lldb::Format
4230ValueObject::GetFormat () const
4231{
4232 const ValueObject* with_fmt_info = this;
4233 while (with_fmt_info)
4234 {
4235 if (with_fmt_info->m_format != lldb::eFormatDefault)
4236 return with_fmt_info->m_format;
4237 with_fmt_info = with_fmt_info->m_parent;
4238 }
4239 return m_format;
4240}
Enrico Granatad07cfd32014-10-08 18:27:36 +00004241
Enrico Granatac1247f52014-11-06 21:23:20 +00004242lldb::LanguageType
4243ValueObject::GetPreferredDisplayLanguage ()
4244{
Enrico Granataed3228a2015-01-21 01:47:13 +00004245 lldb::LanguageType type = m_preferred_display_language;
4246 if (m_preferred_display_language == lldb::eLanguageTypeUnknown)
Enrico Granatac1247f52014-11-06 21:23:20 +00004247 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004248 if (GetRoot())
Enrico Granatac1247f52014-11-06 21:23:20 +00004249 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004250 if (GetRoot() == this)
Enrico Granatac1247f52014-11-06 21:23:20 +00004251 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004252 if (StackFrameSP frame_sp = GetFrameSP())
4253 {
4254 const SymbolContext& sc(frame_sp->GetSymbolContext(eSymbolContextCompUnit));
4255 if (CompileUnit* cu = sc.comp_unit)
4256 type = cu->GetLanguage();
4257 }
4258 }
4259 else
4260 {
4261 type = GetRoot()->GetPreferredDisplayLanguage();
Enrico Granatac1247f52014-11-06 21:23:20 +00004262 }
4263 }
Enrico Granatac1247f52014-11-06 21:23:20 +00004264 }
Enrico Granataed3228a2015-01-21 01:47:13 +00004265 return (m_preferred_display_language = type); // only compute it once
4266}
4267
4268void
4269ValueObject::SetPreferredDisplayLanguage (lldb::LanguageType lt)
4270{
4271 m_preferred_display_language = lt;
Enrico Granatac1247f52014-11-06 21:23:20 +00004272}
4273
Enrico Granata73e8c4d2015-10-07 02:36:35 +00004274void
4275ValueObject::SetPreferredDisplayLanguageIfNeeded (lldb::LanguageType lt)
4276{
4277 if (m_preferred_display_language == lldb::eLanguageTypeUnknown)
4278 SetPreferredDisplayLanguage(lt);
4279}
4280
Enrico Granatad07cfd32014-10-08 18:27:36 +00004281bool
4282ValueObject::CanProvideValue ()
4283{
Sean Callanan7375f3e2014-12-09 21:18:59 +00004284 // we need to support invalid types as providers of values because some bare-board
4285 // debugging scenarios have no notion of types, but still manage to have raw numeric
4286 // values for things like registers. sigh.
Greg Clayton99558cc42015-08-24 23:46:31 +00004287 const CompilerType &type(GetCompilerType());
Sean Callanan7375f3e2014-12-09 21:18:59 +00004288 return (false == type.IsValid()) || (0 != (type.GetTypeInfo() & eTypeHasValue));
4289}
4290
4291bool
4292ValueObject::IsChecksumEmpty ()
4293{
4294 return m_value_checksum.empty();
Enrico Granatad07cfd32014-10-08 18:27:36 +00004295}
Enrico Granata0c10a852014-12-08 23:13:56 +00004296
4297ValueObjectSP
4298ValueObject::Persist ()
4299{
4300 if (!UpdateValueIfNeeded())
4301 return nullptr;
4302
4303 TargetSP target_sp(GetTargetSP());
4304 if (!target_sp)
4305 return nullptr;
4306
Sean Callananb92bd752015-10-01 16:28:02 +00004307 PersistentExpressionState *persistent_state = target_sp->GetPersistentExpressionStateForLanguage(GetPreferredDisplayLanguage());
Sean Callanan8f1f9a12015-09-30 19:57:57 +00004308
4309 if (!persistent_state)
4310 return nullptr;
4311
4312 ConstString name(persistent_state->GetNextPersistentVariableName());
Enrico Granata0c10a852014-12-08 23:13:56 +00004313
Sean Callanan9301ec12015-10-01 23:07:06 +00004314 ValueObjectSP const_result_sp = ValueObjectConstResult::Create (target_sp.get(), GetValue(), name);
4315
4316 ExpressionVariableSP clang_var_sp = persistent_state->CreatePersistentVariable(const_result_sp);
4317 clang_var_sp->m_live_sp = clang_var_sp->m_frozen_sp;
4318 clang_var_sp->m_flags |= ExpressionVariable::EVIsProgramReference;
Enrico Granata0c10a852014-12-08 23:13:56 +00004319
4320 return clang_var_sp->GetValueObject();
4321}
Enrico Granatae29df232014-12-09 19:51:20 +00004322
4323bool
4324ValueObject::IsSyntheticChildrenGenerated ()
4325{
4326 return m_is_synthetic_children_generated;
4327}
4328
4329void
4330ValueObject::SetSyntheticChildrenGenerated (bool b)
4331{
4332 m_is_synthetic_children_generated = b;
4333}