blob: cf9dd776c6b1c6733f59b16e5bbbfc23957533ae [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"
Enrico Granata407b5c62015-11-02 21:52:05 +000050#include "lldb/Target/Language.h"
Jim Ingham5a369122010-09-28 01:25:32 +000051#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000052#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053#include "lldb/Target/Process.h"
54#include "lldb/Target/RegisterContext.h"
Greg Claytond5944cd2013-12-06 01:12:00 +000055#include "lldb/Target/SectionLoadList.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000056#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058
59using namespace lldb;
60using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000061using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062
Greg Claytonafacd142011-09-02 01:15:17 +000063static user_id_t g_value_obj_uid = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000064
65//----------------------------------------------------------------------
66// ValueObject constructor
67//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000068ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000069 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000070 m_parent (&parent),
Enrico Granata4873e522013-04-11 22:48:58 +000071 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +000072 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000073 m_name (),
74 m_data (),
75 m_value (),
76 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000077 m_value_str (),
78 m_old_value_str (),
79 m_location_str (),
80 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000081 m_object_desc_str (),
Enrico Granata744794a2014-09-05 21:46:22 +000082 m_validation_result(),
Jim Ingham58b59f92011-04-22 23:53:53 +000083 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000084 m_children (),
85 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000086 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000087 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000088 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000089 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +000090 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000091 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +000092 m_type_summary_sp(),
93 m_type_format_sp(),
94 m_synthetic_children_sp(),
Enrico Granata744794a2014-09-05 21:46:22 +000095 m_type_validator_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +000096 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +000097 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
Sean Callanan7375f3e2014-12-09 21:18:59 +000098 m_value_checksum(),
Enrico Granataed3228a2015-01-21 01:47:13 +000099 m_preferred_display_language(lldb::eLanguageTypeUnknown),
Greg Clayton288bdf92010-09-02 02:59:18 +0000100 m_value_is_valid (false),
101 m_value_did_change (false),
102 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000103 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000104 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000105 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000106 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000107 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000108 m_is_getting_summary(false),
Enrico Granatae29df232014-12-09 19:51:20 +0000109 m_did_calculate_complete_objc_class_type(false),
110 m_is_synthetic_children_generated(parent.m_is_synthetic_children_generated)
Jim Ingham6035b672011-03-31 00:19:25 +0000111{
Jim Ingham58b59f92011-04-22 23:53:53 +0000112 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000113}
114
115//----------------------------------------------------------------------
116// ValueObject constructor
117//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000118ValueObject::ValueObject (ExecutionContextScope *exe_scope,
119 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000120 UserID (++g_value_obj_uid), // Unique identifier for every value object
121 m_parent (NULL),
Enrico Granata4873e522013-04-11 22:48:58 +0000122 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000123 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000124 m_name (),
125 m_data (),
126 m_value (),
127 m_error (),
128 m_value_str (),
129 m_old_value_str (),
130 m_location_str (),
131 m_summary_str (),
132 m_object_desc_str (),
Enrico Granata744794a2014-09-05 21:46:22 +0000133 m_validation_result(),
Jim Ingham58b59f92011-04-22 23:53:53 +0000134 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000135 m_children (),
136 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000137 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000138 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000139 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000140 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +0000141 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000142 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +0000143 m_type_summary_sp(),
144 m_type_format_sp(),
145 m_synthetic_children_sp(),
Enrico Granata744794a2014-09-05 21:46:22 +0000146 m_type_validator_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000147 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000148 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Sean Callanan7375f3e2014-12-09 21:18:59 +0000149 m_value_checksum(),
Enrico Granataed3228a2015-01-21 01:47:13 +0000150 m_preferred_display_language(lldb::eLanguageTypeUnknown),
Jim Ingham6035b672011-03-31 00:19:25 +0000151 m_value_is_valid (false),
152 m_value_did_change (false),
153 m_children_count_valid (false),
154 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000155 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000156 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000157 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000158 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000159 m_is_getting_summary(false),
Enrico Granatae29df232014-12-09 19:51:20 +0000160 m_did_calculate_complete_objc_class_type(false),
161 m_is_synthetic_children_generated(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000162{
Jim Ingham58b59f92011-04-22 23:53:53 +0000163 m_manager = new ValueObjectManager();
164 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000165}
166
167//----------------------------------------------------------------------
168// Destructor
169//----------------------------------------------------------------------
170ValueObject::~ValueObject ()
171{
172}
173
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000174bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000175ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000176{
Enrico Granata4becb372011-06-29 22:27:15 +0000177
Enrico Granata9128ee22011-09-06 19:20:51 +0000178 bool did_change_formats = false;
179
Enrico Granata0a3958e2011-07-02 00:25:22 +0000180 if (update_format)
Enrico Granata5548cb52013-01-28 23:47:25 +0000181 did_change_formats = UpdateFormatsIfNeeded();
Enrico Granata4becb372011-06-29 22:27:15 +0000182
Greg Claytonb71f3842010-10-05 03:13:51 +0000183 // If this is a constant value, then our success is predicated on whether
184 // we have an error or not
185 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000186 {
Enrico Granatab1c6c482013-10-09 00:33:55 +0000187 // if you are constant, things might still have changed behind your back
188 // (e.g. you are a frozen object and things have changed deeper than you cared to freeze-dry yourself)
189 // in this case, your value has not changed, but "computed" entries might have, so you might now have
190 // a different summary, or a different object description. clear these so we will recompute them
Enrico Granata9128ee22011-09-06 19:20:51 +0000191 if (update_format && !did_change_formats)
Enrico Granatab1c6c482013-10-09 00:33:55 +0000192 ClearUserVisibleData(eClearUserVisibleDataItemsSummary | eClearUserVisibleDataItemsDescription);
Greg Claytonb71f3842010-10-05 03:13:51 +0000193 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000194 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000195
Sean Callanan7375f3e2014-12-09 21:18:59 +0000196 bool first_update = IsChecksumEmpty();
Jim Ingham6035b672011-03-31 00:19:25 +0000197
Enrico Granatabb642e52015-05-16 01:27:00 +0000198 if (NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000199 {
Jim Ingham6035b672011-03-31 00:19:25 +0000200 m_update_point.SetUpdated();
201
202 // Save the old value using swap to avoid a string copy which
203 // also will clear our m_value_str
204 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000205 {
Jim Ingham6035b672011-03-31 00:19:25 +0000206 m_old_value_valid = false;
207 }
208 else
209 {
210 m_old_value_valid = true;
211 m_old_value_str.swap (m_value_str);
Enrico Granata86cc9822012-03-19 22:58:49 +0000212 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham6035b672011-03-31 00:19:25 +0000213 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000214
Enrico Granataf2bbf712011-07-15 02:26:42 +0000215 ClearUserVisibleData();
216
Greg Claytonefbc7d22012-03-09 04:23:44 +0000217 if (IsInScope())
Jim Ingham6035b672011-03-31 00:19:25 +0000218 {
Greg Claytonefbc7d22012-03-09 04:23:44 +0000219 const bool value_was_valid = GetValueIsValid();
220 SetValueDidChange (false);
221
222 m_error.Clear();
223
224 // Call the pure virtual function to update the value
Sean Callanan7375f3e2014-12-09 21:18:59 +0000225
226 bool need_compare_checksums = false;
227 llvm::SmallVector<uint8_t, 16> old_checksum;
228
229 if (!first_update && CanProvideValue())
230 {
231 need_compare_checksums = true;
232 old_checksum.resize(m_value_checksum.size());
233 std::copy(m_value_checksum.begin(), m_value_checksum.end(), old_checksum.begin());
234 }
235
Greg Claytonefbc7d22012-03-09 04:23:44 +0000236 bool success = UpdateValue ();
237
238 SetValueIsValid (success);
239
Sean Callanan7375f3e2014-12-09 21:18:59 +0000240 if (success)
241 {
242 const uint64_t max_checksum_size = 128;
243 m_data.Checksum(m_value_checksum,
244 max_checksum_size);
245 }
246 else
247 {
248 need_compare_checksums = false;
249 m_value_checksum.clear();
250 }
251
Enrico Granata20c321c2015-01-08 19:11:43 +0000252 assert (!need_compare_checksums || (!old_checksum.empty() && !m_value_checksum.empty()));
253
Greg Claytonefbc7d22012-03-09 04:23:44 +0000254 if (first_update)
255 SetValueDidChange (false);
256 else if (!m_value_did_change && success == false)
257 {
258 // The value wasn't gotten successfully, so we mark this
259 // as changed if the value used to be valid and now isn't
260 SetValueDidChange (value_was_valid);
261 }
Sean Callanan7375f3e2014-12-09 21:18:59 +0000262 else if (need_compare_checksums)
263 {
264 SetValueDidChange(memcmp(&old_checksum[0], &m_value_checksum[0], m_value_checksum.size()));
265 }
266
Greg Claytonefbc7d22012-03-09 04:23:44 +0000267 }
268 else
269 {
270 m_error.SetErrorString("out of scope");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000271 }
272 }
273 return m_error.Success();
274}
275
Enrico Granata9128ee22011-09-06 19:20:51 +0000276bool
Enrico Granata5548cb52013-01-28 23:47:25 +0000277ValueObject::UpdateFormatsIfNeeded()
Enrico Granata4becb372011-06-29 22:27:15 +0000278{
Enrico Granata4edfef42015-10-06 17:55:14 +0000279 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_DATAFORMATTERS));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000280 if (log)
Enrico Granatad2284832012-10-17 22:23:56 +0000281 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000282 GetName().GetCString(), static_cast<void*>(this),
283 m_last_format_mgr_revision,
284 DataVisualization::GetCurrentRevision());
285
Enrico Granata9128ee22011-09-06 19:20:51 +0000286 bool any_change = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000287
Enrico Granata5548cb52013-01-28 23:47:25 +0000288 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()))
Enrico Granata4becb372011-06-29 22:27:15 +0000289 {
Enrico Granataa0db6ed2014-04-09 21:06:11 +0000290 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
291 any_change = true;
292
Enrico Granata852cc952013-10-08 19:03:22 +0000293 SetValueFormat(DataVisualization::GetFormat (*this, eNoDynamicValues));
Enrico Granata5548cb52013-01-28 23:47:25 +0000294 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000295#ifndef LLDB_DISABLE_PYTHON
Enrico Granata5548cb52013-01-28 23:47:25 +0000296 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000297#endif
Enrico Granata744794a2014-09-05 21:46:22 +0000298 SetValidator(DataVisualization::GetValidator(*this, GetDynamicValueType()));
Enrico Granata4becb372011-06-29 22:27:15 +0000299 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000300
Enrico Granata9128ee22011-09-06 19:20:51 +0000301 return any_change;
Enrico Granata4becb372011-06-29 22:27:15 +0000302}
303
Jim Ingham16e0c682011-08-12 23:34:31 +0000304void
305ValueObject::SetNeedsUpdate ()
306{
307 m_update_point.SetNeedsUpdate();
308 // We have to clear the value string here so ConstResult children will notice if their values are
309 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000310 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000311}
312
Enrico Granata13ac0e22012-10-17 19:03:34 +0000313void
Enrico Granatae3e91512012-10-22 18:18:36 +0000314ValueObject::ClearDynamicTypeInformation ()
Enrico Granata13ac0e22012-10-17 19:03:34 +0000315{
Enrico Granata38c54632013-10-30 00:04:29 +0000316 m_children_count_valid = false;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000317 m_did_calculate_complete_objc_class_type = false;
Enrico Granatae3e91512012-10-22 18:18:36 +0000318 m_last_format_mgr_revision = 0;
Greg Claytona1e5dc82015-08-11 22:53:00 +0000319 m_override_type = CompilerType();
Enrico Granatae3e91512012-10-22 18:18:36 +0000320 SetValueFormat(lldb::TypeFormatImplSP());
321 SetSummaryFormat(lldb::TypeSummaryImplSP());
322 SetSyntheticChildren(lldb::SyntheticChildrenSP());
Enrico Granata13ac0e22012-10-17 19:03:34 +0000323}
324
Greg Claytona1e5dc82015-08-11 22:53:00 +0000325CompilerType
Sean Callanan72772842012-02-22 23:57:45 +0000326ValueObject::MaybeCalculateCompleteType ()
327{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000328 CompilerType compiler_type(GetCompilerTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000329
Sean Callanan72772842012-02-22 23:57:45 +0000330 if (m_did_calculate_complete_objc_class_type)
331 {
332 if (m_override_type.IsValid())
333 return m_override_type;
334 else
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000335 return compiler_type;
Sean Callanan72772842012-02-22 23:57:45 +0000336 }
337
Greg Claytona1e5dc82015-08-11 22:53:00 +0000338 CompilerType class_type;
Greg Clayton57ee3062013-07-11 22:46:58 +0000339 bool is_pointer_type = false;
Sean Callanan72772842012-02-22 23:57:45 +0000340
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000341 if (ClangASTContext::IsObjCObjectPointerType(compiler_type, &class_type))
Sean Callanan72772842012-02-22 23:57:45 +0000342 {
343 is_pointer_type = true;
344 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000345 else if (ClangASTContext::IsObjCObjectOrInterfaceType(compiler_type))
Sean Callanan72772842012-02-22 23:57:45 +0000346 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000347 class_type = compiler_type;
Sean Callanan72772842012-02-22 23:57:45 +0000348 }
349 else
350 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000351 return compiler_type;
Sean Callanan72772842012-02-22 23:57:45 +0000352 }
353
354 m_did_calculate_complete_objc_class_type = true;
355
Greg Clayton57ee3062013-07-11 22:46:58 +0000356 if (class_type)
Sean Callanan72772842012-02-22 23:57:45 +0000357 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000358 ConstString class_name (class_type.GetConstTypeName());
Sean Callanan72772842012-02-22 23:57:45 +0000359
Greg Clayton57ee3062013-07-11 22:46:58 +0000360 if (class_name)
361 {
362 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
363
364 if (process_sp)
365 {
366 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
367
368 if (objc_language_runtime)
369 {
370 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name);
371
372 if (complete_objc_class_type_sp)
373 {
Greg Clayton99558cc42015-08-24 23:46:31 +0000374 CompilerType complete_class(complete_objc_class_type_sp->GetFullCompilerType ());
Greg Clayton57ee3062013-07-11 22:46:58 +0000375
376 if (complete_class.GetCompleteType())
377 {
378 if (is_pointer_type)
379 {
380 m_override_type = complete_class.GetPointerType();
381 }
382 else
383 {
384 m_override_type = complete_class;
385 }
386
387 if (m_override_type.IsValid())
388 return m_override_type;
389 }
390 }
391 }
392 }
393 }
Sean Callanan72772842012-02-22 23:57:45 +0000394 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000395 return compiler_type;
Sean Callanan72772842012-02-22 23:57:45 +0000396}
397
Greg Claytona1e5dc82015-08-11 22:53:00 +0000398CompilerType
Greg Clayton99558cc42015-08-24 23:46:31 +0000399ValueObject::GetCompilerType ()
Sean Callanan72772842012-02-22 23:57:45 +0000400{
Greg Clayton57ee3062013-07-11 22:46:58 +0000401 return MaybeCalculateCompleteType();
Sean Callanan72772842012-02-22 23:57:45 +0000402}
403
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000404TypeImpl
405ValueObject::GetTypeImpl ()
406{
Greg Clayton99558cc42015-08-24 23:46:31 +0000407 return TypeImpl(GetCompilerType());
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000408}
409
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000410DataExtractor &
411ValueObject::GetDataExtractor ()
412{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000413 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000414 return m_data;
415}
416
417const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000418ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000419{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000420 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000421 return m_error;
422}
423
424const ConstString &
425ValueObject::GetName() const
426{
427 return m_name;
428}
429
430const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000431ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000432{
Enrico Granata82fabf82013-04-30 20:45:04 +0000433 return GetLocationAsCStringImpl(m_value,
434 m_data);
435}
436
437const char *
438ValueObject::GetLocationAsCStringImpl (const Value& value,
439 const DataExtractor& data)
440{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000441 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000442 {
443 if (m_location_str.empty())
444 {
445 StreamString sstr;
Enrico Granata82fabf82013-04-30 20:45:04 +0000446
447 Value::ValueType value_type = value.GetValueType();
448
449 switch (value_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000450 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000451 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +0000452 case Value::eValueTypeVector:
Enrico Granata82fabf82013-04-30 20:45:04 +0000453 if (value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000454 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000455 RegisterInfo *reg_info = value.GetRegisterInfo();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000456 if (reg_info)
457 {
458 if (reg_info->name)
459 m_location_str = reg_info->name;
460 else if (reg_info->alt_name)
461 m_location_str = reg_info->alt_name;
Enrico Granata82fabf82013-04-30 20:45:04 +0000462 if (m_location_str.empty())
463 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000464 }
465 }
Enrico Granata82fabf82013-04-30 20:45:04 +0000466 if (m_location_str.empty())
467 m_location_str = (value_type == Value::eValueTypeVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000468 break;
469
470 case Value::eValueTypeLoadAddress:
471 case Value::eValueTypeFileAddress:
472 case Value::eValueTypeHostAddress:
473 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000474 uint32_t addr_nibble_size = data.GetAddressByteSize() * 2;
475 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000476 m_location_str.swap(sstr.GetString());
477 }
478 break;
479 }
480 }
481 }
482 return m_location_str.c_str();
483}
484
485Value &
486ValueObject::GetValue()
487{
488 return m_value;
489}
490
491const Value &
492ValueObject::GetValue() const
493{
494 return m_value;
495}
496
497bool
Jim Ingham6035b672011-03-31 00:19:25 +0000498ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000499{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000500 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
501 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000502 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000503 Value tmp_value(m_value);
Greg Clayton57ee3062013-07-11 22:46:58 +0000504 scalar = tmp_value.ResolveValue(&exe_ctx);
Greg Claytondcad5022011-12-29 01:26:56 +0000505 if (scalar.IsValid())
506 {
507 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
508 if (bitfield_bit_size)
509 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
510 return true;
511 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000512 }
Greg Claytondcad5022011-12-29 01:26:56 +0000513 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000514}
515
516bool
Jim Ingham98e6daf2015-10-31 00:02:18 +0000517ValueObject::IsLogicalTrue (Error& error)
518{
Enrico Granata407b5c62015-11-02 21:52:05 +0000519 if (Language *language = Language::FindPlugin(GetObjectRuntimeLanguage()))
520 {
521 LazyBool is_logical_true = language->IsLogicalTrue(*this, error);
522 switch (is_logical_true)
523 {
524 case eLazyBoolYes:
525 case eLazyBoolNo:
526 return (is_logical_true == true);
527 case eLazyBoolCalculate:
528 default:
529 break;
530 }
531 }
532
Jim Ingham98e6daf2015-10-31 00:02:18 +0000533 Scalar scalar_value;
534
535 if (!ResolveValue (scalar_value))
536 {
537 error.SetErrorString("failed to get a scalar result");
538 return false;
539 }
540
541 bool ret;
542 if (scalar_value.ULongLong(1) == 0)
543 ret = false;
544 else
545 ret = true;
546 error.Clear();
547 return ret;
548}
549
550bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000551ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000552{
Greg Clayton288bdf92010-09-02 02:59:18 +0000553 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000554}
555
556
557void
558ValueObject::SetValueIsValid (bool b)
559{
Greg Clayton288bdf92010-09-02 02:59:18 +0000560 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000561}
562
563bool
Jim Ingham6035b672011-03-31 00:19:25 +0000564ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000565{
Greg Clayton288bdf92010-09-02 02:59:18 +0000566 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000567}
568
569void
570ValueObject::SetValueDidChange (bool value_changed)
571{
Greg Clayton288bdf92010-09-02 02:59:18 +0000572 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000573}
574
575ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000576ValueObject::GetChildAtIndex (size_t idx, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000577{
578 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000579 // We may need to update our value if we are dynamic
580 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000581 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000582 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000583 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000584 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000585 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000586 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000587 // No we haven't created the child at this index, so lets have our
588 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000589 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000590 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000591
Enrico Granata9d60f602012-03-09 03:09:58 +0000592 ValueObject* child = m_children.GetChildAtIndex(idx);
593 if (child != NULL)
594 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000595 }
596 return child_sp;
597}
598
Enrico Granata3309d882013-01-12 01:00:22 +0000599ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000600ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
601 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000602{
603 if (idxs.size() == 0)
604 return GetSP();
605 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000606 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000607 {
608 root = root->GetChildAtIndex(idx, true);
609 if (!root)
610 {
611 if (index_of_error)
612 *index_of_error = idx;
613 return root;
614 }
615 }
616 return root;
617}
618
619ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000620ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
621 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000622{
623 if (idxs.size() == 0)
624 return GetSP();
625 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000626 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000627 {
628 root = root->GetChildAtIndex(idx.first, idx.second);
629 if (!root)
630 {
631 if (index_of_error)
632 *index_of_error = idx.first;
633 return root;
634 }
635 }
636 return root;
637}
638
639lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000640ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
641 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000642{
643 if (idxs.size() == 0)
644 return GetSP();
645 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000646 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000647 {
648 root = root->GetChildAtIndex(idx, true);
649 if (!root)
650 {
651 if (index_of_error)
652 *index_of_error = idx;
653 return root;
654 }
655 }
656 return root;
657}
658
659lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000660ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
661 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000662{
663 if (idxs.size() == 0)
664 return GetSP();
665 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000666 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000667 {
668 root = root->GetChildAtIndex(idx.first, idx.second);
669 if (!root)
670 {
671 if (index_of_error)
672 *index_of_error = idx.first;
673 return root;
674 }
675 }
676 return root;
677}
678
Enrico Granatae2e220a2013-09-12 00:48:47 +0000679lldb::ValueObjectSP
680ValueObject::GetChildAtNamePath (const std::initializer_list<ConstString> &names,
681 ConstString* name_of_error)
682{
683 if (names.size() == 0)
684 return GetSP();
685 ValueObjectSP root(GetSP());
686 for (ConstString name : names)
687 {
688 root = root->GetChildMemberWithName(name, true);
689 if (!root)
690 {
691 if (name_of_error)
692 *name_of_error = name;
693 return root;
694 }
695 }
696 return root;
697}
698
699lldb::ValueObjectSP
700ValueObject::GetChildAtNamePath (const std::vector<ConstString> &names,
701 ConstString* name_of_error)
702{
703 if (names.size() == 0)
704 return GetSP();
705 ValueObjectSP root(GetSP());
706 for (ConstString name : names)
707 {
708 root = root->GetChildMemberWithName(name, true);
709 if (!root)
710 {
711 if (name_of_error)
712 *name_of_error = name;
713 return root;
714 }
715 }
716 return root;
717}
718
719lldb::ValueObjectSP
720ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names,
721 ConstString* name_of_error)
722{
723 if (names.size() == 0)
724 return GetSP();
725 ValueObjectSP root(GetSP());
726 for (std::pair<ConstString, bool> name : names)
727 {
728 root = root->GetChildMemberWithName(name.first, name.second);
729 if (!root)
730 {
731 if (name_of_error)
732 *name_of_error = name.first;
733 return root;
734 }
735 }
736 return root;
737}
738
739lldb::ValueObjectSP
740ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names,
741 ConstString* name_of_error)
742{
743 if (names.size() == 0)
744 return GetSP();
745 ValueObjectSP root(GetSP());
746 for (std::pair<ConstString, bool> name : names)
747 {
748 root = root->GetChildMemberWithName(name.first, name.second);
749 if (!root)
750 {
751 if (name_of_error)
752 *name_of_error = name.first;
753 return root;
754 }
755 }
756 return root;
757}
758
Greg Claytonc7bece562013-01-25 18:06:21 +0000759size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000760ValueObject::GetIndexOfChildWithName (const ConstString &name)
761{
762 bool omit_empty_base_classes = true;
Greg Clayton99558cc42015-08-24 23:46:31 +0000763 return GetCompilerType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000764}
765
766ValueObjectSP
767ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
768{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000769 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000770 // classes (which really aren't part of the expression path), so we
771 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000772 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000773
Greg Claytondea8cb42011-06-29 22:09:02 +0000774 // We may need to update our value if we are dynamic
775 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000776 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000777
778 std::vector<uint32_t> child_indexes;
Greg Claytondea8cb42011-06-29 22:09:02 +0000779 bool omit_empty_base_classes = true;
Greg Clayton99558cc42015-08-24 23:46:31 +0000780 const size_t num_child_indexes = GetCompilerType().GetIndexOfChildMemberWithName (name.GetCString(),
Greg Clayton57ee3062013-07-11 22:46:58 +0000781 omit_empty_base_classes,
782 child_indexes);
Greg Claytondea8cb42011-06-29 22:09:02 +0000783 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000784 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000785 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
786 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
787
788 child_sp = GetChildAtIndex(*pos, can_create);
789 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000790 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000791 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000792 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000793 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
794 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000795 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000796 else
797 {
798 child_sp.reset();
799 }
800
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000801 }
802 }
803 return child_sp;
804}
805
806
Greg Claytonc7bece562013-01-25 18:06:21 +0000807size_t
Siva Chandra9ac7a6c2015-10-21 19:28:08 +0000808ValueObject::GetNumChildren (uint32_t max)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000809{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000810 UpdateValueIfNeeded();
Siva Chandra9ac7a6c2015-10-21 19:28:08 +0000811
812 if (max < UINT32_MAX)
813 {
814 if (m_children_count_valid)
815 {
816 size_t children_count = m_children.GetChildrenCount();
817 return children_count <= max ? children_count : max;
818 }
819 else
820 return CalculateNumChildren(max);
821 }
822
Greg Clayton288bdf92010-09-02 02:59:18 +0000823 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000824 {
825 SetNumChildren (CalculateNumChildren());
826 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000827 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000828}
Greg Clayton4a792072012-10-23 01:50:10 +0000829
830bool
831ValueObject::MightHaveChildren()
832{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000833 bool has_children = false;
Greg Clayton2452ab72013-02-08 22:02:02 +0000834 const uint32_t type_info = GetTypeInfo();
835 if (type_info)
Greg Clayton4a792072012-10-23 01:50:10 +0000836 {
Enrico Granata622be232014-10-21 20:52:14 +0000837 if (type_info & (eTypeHasChildren |
838 eTypeIsPointer |
839 eTypeIsReference))
Greg Clayton4a792072012-10-23 01:50:10 +0000840 has_children = true;
841 }
842 else
843 {
844 has_children = GetNumChildren () > 0;
845 }
846 return has_children;
847}
848
849// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000850void
Greg Claytonc7bece562013-01-25 18:06:21 +0000851ValueObject::SetNumChildren (size_t num_children)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000852{
Greg Clayton288bdf92010-09-02 02:59:18 +0000853 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000854 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000855}
856
857void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000858ValueObject::SetName (const ConstString &name)
859{
860 m_name = name;
861}
862
Jim Ingham58b59f92011-04-22 23:53:53 +0000863ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000864ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000865{
Jim Ingham2eec4872011-05-07 00:10:58 +0000866 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000867
Greg Claytondea8cb42011-06-29 22:09:02 +0000868 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000869 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000870 std::string child_name_str;
871 uint32_t child_byte_size = 0;
872 int32_t child_byte_offset = 0;
873 uint32_t child_bitfield_bit_size = 0;
874 uint32_t child_bitfield_bit_offset = 0;
875 bool child_is_base_class = false;
876 bool child_is_deref_of_parent = false;
877
878 const bool transparent_pointers = synthetic_array_member == false;
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000879 CompilerType child_compiler_type;
Greg Claytondea8cb42011-06-29 22:09:02 +0000880
Greg Claytoncc4d0142012-02-17 07:49:44 +0000881 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000882
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000883 child_compiler_type = GetCompilerType().GetChildCompilerTypeAtIndex (&exe_ctx,
884 idx,
885 transparent_pointers,
886 omit_empty_base_classes,
887 ignore_array_bounds,
888 child_name_str,
889 child_byte_size,
890 child_byte_offset,
891 child_bitfield_bit_size,
892 child_bitfield_bit_offset,
893 child_is_base_class,
894 child_is_deref_of_parent,
895 this);
896 if (child_compiler_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000897 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000898 if (synthetic_index)
899 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000900
Greg Claytondea8cb42011-06-29 22:09:02 +0000901 ConstString child_name;
902 if (!child_name_str.empty())
903 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000904
Greg Claytondea8cb42011-06-29 22:09:02 +0000905 valobj = new ValueObjectChild (*this,
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000906 child_compiler_type,
Greg Claytondea8cb42011-06-29 22:09:02 +0000907 child_name,
908 child_byte_size,
909 child_byte_offset,
910 child_bitfield_bit_size,
911 child_bitfield_bit_offset,
912 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000913 child_is_deref_of_parent,
914 eAddressTypeInvalid);
915 //if (valobj)
916 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
917 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000918
Jim Ingham58b59f92011-04-22 23:53:53 +0000919 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000920}
921
Enrico Granata0c489f52012-03-01 04:24:26 +0000922bool
923ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
Enrico Granata31fda932015-10-07 01:41:23 +0000924 std::string& destination,
925 lldb::LanguageType lang)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000926{
Enrico Granata31fda932015-10-07 01:41:23 +0000927 return GetSummaryAsCString(summary_ptr, destination, TypeSummaryOptions().SetLanguage(lang));
Enrico Granatac1247f52014-11-06 21:23:20 +0000928}
929
930bool
931ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
932 std::string& destination,
933 const TypeSummaryOptions& options)
934{
Enrico Granata0c489f52012-03-01 04:24:26 +0000935 destination.clear();
Enrico Granata31fda932015-10-07 01:41:23 +0000936
Enrico Granata0c489f52012-03-01 04:24:26 +0000937 // ideally we would like to bail out if passing NULL, but if we do so
938 // we end up not providing the summary for function pointers anymore
939 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
940 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000941
942 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000943
Enrico Granata31fda932015-10-07 01:41:23 +0000944 TypeSummaryOptions actual_options(options);
945
946 if (actual_options.GetLanguage() == lldb::eLanguageTypeUnknown)
947 actual_options.SetLanguage(GetPreferredDisplayLanguage());
948
Enrico Granataf18c03e2012-04-04 17:34:10 +0000949 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
950 // information that we might care to see in a crash log. might be useful in very specific situations though.
951 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
Enrico Granata31fda932015-10-07 01:41:23 +0000952 GetTypeName().GetCString(),
953 GetName().GetCString(),
954 summary_ptr->GetDescription().c_str());*/
Enrico Granataf18c03e2012-04-04 17:34:10 +0000955
Enrico Granataff0f23d2014-12-10 02:00:45 +0000956 if (UpdateValueIfNeeded (false) && summary_ptr)
Enrico Granata0c489f52012-03-01 04:24:26 +0000957 {
Enrico Granataff0f23d2014-12-10 02:00:45 +0000958 if (HasSyntheticValue())
959 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 +0000960 summary_ptr->FormatObject(this, destination, actual_options);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000961 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000962 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000963 return !destination.empty();
964}
965
966const char *
Enrico Granata31fda932015-10-07 01:41:23 +0000967ValueObject::GetSummaryAsCString (lldb::LanguageType lang)
Enrico Granata0c489f52012-03-01 04:24:26 +0000968{
969 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
970 {
Enrico Granata31fda932015-10-07 01:41:23 +0000971 TypeSummaryOptions summary_options;
972 summary_options.SetLanguage(lang);
Enrico Granata0c489f52012-03-01 04:24:26 +0000973 GetSummaryAsCString(GetSummaryFormat().get(),
Enrico Granatac1247f52014-11-06 21:23:20 +0000974 m_summary_str,
Enrico Granata31fda932015-10-07 01:41:23 +0000975 summary_options);
Enrico Granata0c489f52012-03-01 04:24:26 +0000976 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000977 if (m_summary_str.empty())
978 return NULL;
979 return m_summary_str.c_str();
980}
981
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000982bool
Enrico Granata49bfafb2014-11-18 23:36:25 +0000983ValueObject::GetSummaryAsCString (std::string& destination,
984 const TypeSummaryOptions& options)
985{
986 return GetSummaryAsCString(GetSummaryFormat().get(),
Enrico Granata31fda932015-10-07 01:41:23 +0000987 destination,
988 options);
Enrico Granata49bfafb2014-11-18 23:36:25 +0000989}
990
991bool
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000992ValueObject::IsCStringContainer(bool check_pointer)
993{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000994 CompilerType pointee_or_element_compiler_type;
995 const Flags type_flags (GetTypeInfo (&pointee_or_element_compiler_type));
Enrico Granata622be232014-10-21 20:52:14 +0000996 bool is_char_arr_ptr (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000997 pointee_or_element_compiler_type.IsCharType ());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000998 if (!is_char_arr_ptr)
999 return false;
1000 if (!check_pointer)
1001 return true;
Enrico Granata622be232014-10-21 20:52:14 +00001002 if (type_flags.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001003 return true;
Greg Claytonafacd142011-09-02 01:15:17 +00001004 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001005 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +00001006 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001007 return (cstr_address != LLDB_INVALID_ADDRESS);
1008}
1009
Enrico Granata9128ee22011-09-06 19:20:51 +00001010size_t
1011ValueObject::GetPointeeData (DataExtractor& data,
1012 uint32_t item_idx,
1013 uint32_t item_count)
1014{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001015 CompilerType pointee_or_element_compiler_type;
1016 const uint32_t type_info = GetTypeInfo (&pointee_or_element_compiler_type);
Enrico Granata622be232014-10-21 20:52:14 +00001017 const bool is_pointer_type = type_info & eTypeIsPointer;
1018 const bool is_array_type = type_info & eTypeIsArray;
Greg Clayton2452ab72013-02-08 22:02:02 +00001019 if (!(is_pointer_type || is_array_type))
Enrico Granata9128ee22011-09-06 19:20:51 +00001020 return 0;
1021
1022 if (item_count == 0)
1023 return 0;
1024
Enrico Granata951bdd52015-01-28 01:09:45 +00001025 ExecutionContext exe_ctx (GetExecutionContextRef());
1026
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001027 const uint64_t item_type_size = pointee_or_element_compiler_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
Enrico Granata9128ee22011-09-06 19:20:51 +00001028 const uint64_t bytes = item_count * item_type_size;
Enrico Granata9128ee22011-09-06 19:20:51 +00001029 const uint64_t offset = item_idx * item_type_size;
1030
1031 if (item_idx == 0 && item_count == 1) // simply a deref
1032 {
Greg Clayton2452ab72013-02-08 22:02:02 +00001033 if (is_pointer_type)
Enrico Granata9128ee22011-09-06 19:20:51 +00001034 {
1035 Error error;
1036 ValueObjectSP pointee_sp = Dereference(error);
1037 if (error.Fail() || pointee_sp.get() == NULL)
1038 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +00001039 return pointee_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +00001040 }
1041 else
1042 {
1043 ValueObjectSP child_sp = GetChildAtIndex(0, true);
1044 if (child_sp.get() == NULL)
1045 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +00001046 Error error;
1047 return child_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +00001048 }
1049 return true;
1050 }
1051 else /* (items > 1) */
1052 {
1053 Error error;
1054 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
1055 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
1056
1057 AddressType addr_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001058 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001059
Enrico Granata9128ee22011-09-06 19:20:51 +00001060 switch (addr_type)
1061 {
1062 case eAddressTypeFile:
1063 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001064 ModuleSP module_sp (GetModule());
1065 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001066 {
Enrico Granata9c2efe32012-08-07 01:49:34 +00001067 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +00001068 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001069 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001070 ExecutionContext exe_ctx (GetExecutionContextRef());
1071 Target* target = exe_ctx.GetTargetPtr();
1072 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +00001073 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001074 heap_buf_ptr->SetByteSize(bytes);
1075 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
1076 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +00001077 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001078 data.SetData(data_sp);
1079 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +00001080 }
1081 }
1082 }
1083 }
1084 break;
1085 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +00001086 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001087 ExecutionContext exe_ctx (GetExecutionContextRef());
1088 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +00001089 if (process)
1090 {
1091 heap_buf_ptr->SetByteSize(bytes);
1092 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
Enrico Granata5e1480c2013-10-30 17:52:44 +00001093 if (error.Success() || bytes_read > 0)
Enrico Granata9128ee22011-09-06 19:20:51 +00001094 {
1095 data.SetData(data_sp);
1096 return bytes_read;
1097 }
1098 }
1099 }
1100 break;
1101 case eAddressTypeHost:
1102 {
Greg Clayton99558cc42015-08-24 23:46:31 +00001103 const uint64_t max_bytes = GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope());
Greg Clayton2452ab72013-02-08 22:02:02 +00001104 if (max_bytes > offset)
1105 {
1106 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
Siva Chandrae32f2b52015-05-05 00:41:35 +00001107 addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Enrico Granata7339b9d2015-11-03 02:34:43 +00001108 if (addr == 0 || addr == LLDB_INVALID_ADDRESS)
Siva Chandrae32f2b52015-05-05 00:41:35 +00001109 break;
Greg Clayton2452ab72013-02-08 22:02:02 +00001110 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
1111 data.SetData(data_sp);
1112 return bytes_read;
1113 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001114 }
1115 break;
1116 case eAddressTypeInvalid:
Enrico Granata9128ee22011-09-06 19:20:51 +00001117 break;
1118 }
1119 }
1120 return 0;
1121}
1122
Greg Claytonfaac1112013-03-14 18:31:44 +00001123uint64_t
Sean Callanan866e91c2014-02-28 22:27:53 +00001124ValueObject::GetData (DataExtractor& data, Error &error)
Enrico Granata9128ee22011-09-06 19:20:51 +00001125{
1126 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001127 ExecutionContext exe_ctx (GetExecutionContextRef());
Sean Callanan866e91c2014-02-28 22:27:53 +00001128 error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001129 if (error.Fail())
Sean Callananed185ab2013-04-19 19:47:32 +00001130 {
1131 if (m_data.GetByteSize())
1132 {
1133 data = m_data;
1134 return data.GetByteSize();
1135 }
1136 else
1137 {
1138 return 0;
1139 }
1140 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001141 data.SetAddressByteSize(m_data.GetAddressByteSize());
1142 data.SetByteOrder(m_data.GetByteOrder());
1143 return data.GetByteSize();
1144}
1145
Sean Callanan389823e2013-04-13 01:21:23 +00001146bool
1147ValueObject::SetData (DataExtractor &data, Error &error)
1148{
1149 error.Clear();
1150 // Make sure our value is up to date first so that our location and location
1151 // type is valid.
1152 if (!UpdateValueIfNeeded(false))
1153 {
1154 error.SetErrorString("unable to read value");
1155 return false;
1156 }
1157
1158 uint64_t count = 0;
Greg Clayton99558cc42015-08-24 23:46:31 +00001159 const Encoding encoding = GetCompilerType().GetEncoding(count);
Sean Callanan389823e2013-04-13 01:21:23 +00001160
1161 const size_t byte_size = GetByteSize();
1162
1163 Value::ValueType value_type = m_value.GetValueType();
1164
1165 switch (value_type)
1166 {
1167 case Value::eValueTypeScalar:
1168 {
1169 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1170
1171 if (!set_error.Success())
1172 {
1173 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1174 return false;
1175 }
1176 }
1177 break;
1178 case Value::eValueTypeLoadAddress:
1179 {
1180 // If it is a load address, then the scalar value is the storage location
1181 // of the data, and we have to shove this value down to that load location.
1182 ExecutionContext exe_ctx (GetExecutionContextRef());
1183 Process *process = exe_ctx.GetProcessPtr();
1184 if (process)
1185 {
1186 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1187 size_t bytes_written = process->WriteMemory(target_addr,
1188 data.GetDataStart(),
1189 byte_size,
1190 error);
1191 if (!error.Success())
1192 return false;
1193 if (bytes_written != byte_size)
1194 {
1195 error.SetErrorString("unable to write value to memory");
1196 return false;
1197 }
1198 }
1199 }
1200 break;
1201 case Value::eValueTypeHostAddress:
1202 {
1203 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1204 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1205 m_data.SetData(buffer_sp, 0);
1206 data.CopyByteOrderedData (0,
1207 byte_size,
1208 const_cast<uint8_t *>(m_data.GetDataStart()),
1209 byte_size,
1210 m_data.GetByteOrder());
1211 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1212 }
1213 break;
1214 case Value::eValueTypeFileAddress:
1215 case Value::eValueTypeVector:
1216 break;
1217 }
1218
1219 // If we have reached this point, then we have successfully changed the value.
1220 SetNeedsUpdate();
1221 return true;
1222}
1223
Enrico Granata9128ee22011-09-06 19:20:51 +00001224// will compute strlen(str), but without consuming more than
1225// maxlen bytes out of str (this serves the purpose of reading
1226// chunks of a string without having to worry about
1227// missing NULL terminators in the chunk)
1228// of course, if strlen(str) > maxlen, the function will return
1229// maxlen_value (which should be != maxlen, because that allows you
1230// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1231static uint32_t
1232strlen_or_inf (const char* str,
1233 uint32_t maxlen,
1234 uint32_t maxlen_value)
1235{
1236 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +00001237 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +00001238 {
Greg Clayton8dd5c172011-10-05 22:19:51 +00001239 while(*str)
1240 {
1241 len++;str++;
Greg Clayton2452ab72013-02-08 22:02:02 +00001242 if (len >= maxlen)
Greg Clayton8dd5c172011-10-05 22:19:51 +00001243 return maxlen_value;
1244 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001245 }
1246 return len;
1247}
1248
Enrico Granata2206b482014-10-30 18:27:31 +00001249static bool
1250CopyStringDataToBufferSP(const StreamString& source,
1251 lldb::DataBufferSP& destination)
1252{
1253 destination.reset(new DataBufferHeap(source.GetSize()+1,0));
1254 memcpy(destination->GetBytes(), source.GetString().c_str(), source.GetSize());
1255 return true;
1256}
1257
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001258size_t
Enrico Granata2206b482014-10-30 18:27:31 +00001259ValueObject::ReadPointedString (lldb::DataBufferSP& buffer_sp,
Greg Claytoncc4d0142012-02-17 07:49:44 +00001260 Error& error,
1261 uint32_t max_length,
1262 bool honor_array,
1263 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001264{
Enrico Granata2206b482014-10-30 18:27:31 +00001265 StreamString s;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001266 ExecutionContext exe_ctx (GetExecutionContextRef());
1267 Target* target = exe_ctx.GetTargetPtr();
Enrico Granata2206b482014-10-30 18:27:31 +00001268
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001269 if (!target)
1270 {
1271 s << "<no target to read from>";
1272 error.SetErrorString("no target to read from");
Enrico Granata2206b482014-10-30 18:27:31 +00001273 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001274 return 0;
1275 }
1276
1277 if (max_length == 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001278 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001279
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001280 size_t bytes_read = 0;
1281 size_t total_bytes_read = 0;
1282
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001283 CompilerType compiler_type = GetCompilerType();
1284 CompilerType elem_or_pointee_compiler_type;
1285 const Flags type_flags (GetTypeInfo (&elem_or_pointee_compiler_type));
Enrico Granata622be232014-10-21 20:52:14 +00001286 if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001287 elem_or_pointee_compiler_type.IsCharType ())
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001288 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001289 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1290 AddressType cstr_address_type = eAddressTypeInvalid;
1291
1292 size_t cstr_len = 0;
1293 bool capped_data = false;
Enrico Granata622be232014-10-21 20:52:14 +00001294 if (type_flags.Test (eTypeIsArray))
Greg Claytoncc4d0142012-02-17 07:49:44 +00001295 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001296 // We have an array
Greg Clayton57ee3062013-07-11 22:46:58 +00001297 uint64_t array_size = 0;
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001298 if (compiler_type.IsArrayType(NULL, &array_size, NULL))
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001299 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001300 cstr_len = array_size;
1301 if (cstr_len > max_length)
1302 {
1303 capped_data = true;
1304 cstr_len = max_length;
1305 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001306 }
1307 cstr_address = GetAddressOf (true, &cstr_address_type);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001308 }
1309 else
1310 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001311 // We have a pointer
1312 cstr_address = GetPointerValue (&cstr_address_type);
1313 }
1314
1315 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1316 {
1317 s << "<invalid address>";
1318 error.SetErrorString("invalid address");
Enrico Granata2206b482014-10-30 18:27:31 +00001319 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001320 return 0;
1321 }
Enrico Granata2206b482014-10-30 18:27:31 +00001322
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001323 Address cstr_so_addr (cstr_address);
1324 DataExtractor data;
1325 if (cstr_len > 0 && honor_array)
1326 {
1327 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1328 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1329 GetPointeeData(data, 0, cstr_len);
Enrico Granata2206b482014-10-30 18:27:31 +00001330
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001331 if ((bytes_read = data.GetByteSize()) > 0)
1332 {
1333 total_bytes_read = bytes_read;
Enrico Granata2206b482014-10-30 18:27:31 +00001334 for (size_t offset = 0; offset < bytes_read; offset++)
1335 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001336 if (capped_data)
1337 s << "...";
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001338 }
1339 }
1340 else
1341 {
1342 cstr_len = max_length;
1343 const size_t k_max_buf_size = 64;
Enrico Granata2206b482014-10-30 18:27:31 +00001344
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001345 size_t offset = 0;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001346
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001347 int cstr_len_displayed = -1;
1348 bool capped_cstr = false;
1349 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1350 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1351 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001352 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001353 total_bytes_read += bytes_read;
1354 const char *cstr = data.PeekCStr(0);
1355 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1356 if (len > k_max_buf_size)
1357 len = k_max_buf_size;
Enrico Granata2206b482014-10-30 18:27:31 +00001358
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001359 if (cstr_len_displayed < 0)
1360 cstr_len_displayed = len;
Enrico Granata2206b482014-10-30 18:27:31 +00001361
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001362 if (len == 0)
1363 break;
1364 cstr_len_displayed += len;
1365 if (len > bytes_read)
1366 len = bytes_read;
1367 if (len > cstr_len)
1368 len = cstr_len;
1369
Enrico Granata2206b482014-10-30 18:27:31 +00001370 for (size_t offset = 0; offset < bytes_read; offset++)
1371 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001372
1373 if (len < k_max_buf_size)
1374 break;
1375
1376 if (len >= cstr_len)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001377 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001378 capped_cstr = true;
1379 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001380 }
Enrico Granata2206b482014-10-30 18:27:31 +00001381
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001382 cstr_len -= len;
1383 offset += len;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001384 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001385
1386 if (cstr_len_displayed >= 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001387 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001388 if (capped_cstr)
1389 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001390 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001391 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001392 }
1393 else
1394 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001395 error.SetErrorString("not a string object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001396 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001397 }
Enrico Granata2206b482014-10-30 18:27:31 +00001398 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001399 return total_bytes_read;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001400}
1401
Enrico Granata744794a2014-09-05 21:46:22 +00001402std::pair<TypeValidatorResult, std::string>
1403ValueObject::GetValidationStatus ()
1404{
1405 if (!UpdateValueIfNeeded(true))
1406 return {TypeValidatorResult::Success,""}; // not the validator's job to discuss update problems
1407
1408 if (m_validation_result.hasValue())
1409 return m_validation_result.getValue();
1410
1411 if (!m_type_validator_sp)
1412 return {TypeValidatorResult::Success,""}; // no validator no failure
1413
1414 auto outcome = m_type_validator_sp->FormatObject(this);
1415
1416 return (m_validation_result = {outcome.m_result,outcome.m_message}).getValue();
1417}
1418
Jim Ingham53c47f12010-09-10 23:12:17 +00001419const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001420ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001421{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001422
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001423 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001424 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001425
1426 if (!m_object_desc_str.empty())
1427 return m_object_desc_str.c_str();
1428
Greg Claytoncc4d0142012-02-17 07:49:44 +00001429 ExecutionContext exe_ctx (GetExecutionContextRef());
1430 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001431 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001432 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001433
Jim Ingham53c47f12010-09-10 23:12:17 +00001434 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001435
Greg Claytonafacd142011-09-02 01:15:17 +00001436 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001437 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1438
Jim Inghama2cf2632010-12-23 02:29:54 +00001439 if (runtime == NULL)
1440 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001441 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001442 CompilerType compiler_type = GetCompilerType();
1443 if (compiler_type)
Jim Inghama2cf2632010-12-23 02:29:54 +00001444 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001445 bool is_signed;
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001446 if (compiler_type.IsIntegerType (is_signed) || compiler_type.IsPointerType ())
Jim Inghamb7603bb2011-03-18 00:05:18 +00001447 {
Greg Claytonafacd142011-09-02 01:15:17 +00001448 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001449 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001450 }
1451 }
1452
Jim Ingham8d543de2011-03-31 23:01:21 +00001453 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001454 {
1455 m_object_desc_str.append (s.GetData());
1456 }
Sean Callanan672ad942010-10-23 00:18:49 +00001457
1458 if (m_object_desc_str.empty())
1459 return NULL;
1460 else
1461 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001462}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001463
Enrico Granata0c489f52012-03-01 04:24:26 +00001464bool
Enrico Granata4939b982013-12-22 09:24:22 +00001465ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format,
1466 std::string& destination)
1467{
1468 if (UpdateValueIfNeeded(false))
1469 return format.FormatObject(this,destination);
1470 else
1471 return false;
1472}
1473
1474bool
Enrico Granata0c489f52012-03-01 04:24:26 +00001475ValueObject::GetValueAsCString (lldb::Format format,
1476 std::string& destination)
1477{
Enrico Granata30f287f2013-12-28 08:44:02 +00001478 return GetValueAsCString(TypeFormatImpl_Format(format),destination);
Enrico Granata0c489f52012-03-01 04:24:26 +00001479}
1480
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001481const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001482ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001483{
Enrico Granatab294fd22013-05-31 19:18:19 +00001484 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001485 {
Enrico Granata4939b982013-12-22 09:24:22 +00001486 lldb::TypeFormatImplSP format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001487 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001488 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001489 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001490 if (m_type_format_sp)
Enrico Granata4939b982013-12-22 09:24:22 +00001491 format_sp = m_type_format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001492 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001493 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001494 if (m_is_bitfield_for_scalar)
1495 my_format = eFormatUnsigned;
1496 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001497 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001498 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001499 {
1500 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1501 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001502 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001503 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001504 else
1505 {
Greg Clayton99558cc42015-08-24 23:46:31 +00001506 my_format = GetValue().GetCompilerType().GetFormat();
Enrico Granata0c489f52012-03-01 04:24:26 +00001507 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001508 }
1509 }
1510 }
Enrico Granatab294fd22013-05-31 19:18:19 +00001511 if (my_format != m_last_format || m_value_str.empty())
Enrico Granata297e69f2012-03-06 23:21:16 +00001512 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001513 m_last_format = my_format;
Enrico Granata4939b982013-12-22 09:24:22 +00001514 if (!format_sp)
Enrico Granata30f287f2013-12-28 08:44:02 +00001515 format_sp.reset(new TypeFormatImpl_Format(my_format));
Enrico Granata4939b982013-12-22 09:24:22 +00001516 if (GetValueAsCString(*format_sp.get(), m_value_str))
Enrico Granata297e69f2012-03-06 23:21:16 +00001517 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001518 if (!m_value_did_change && m_old_value_valid)
1519 {
1520 // The value was gotten successfully, so we consider the
1521 // value as changed if the value string differs
1522 SetValueDidChange (m_old_value_str != m_value_str);
1523 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001524 }
1525 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001526 }
1527 if (m_value_str.empty())
1528 return NULL;
1529 return m_value_str.c_str();
1530}
1531
Enrico Granatac3e320a2011-08-02 17:27:39 +00001532// if > 8bytes, 0 is returned. this method should mostly be used
1533// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001534uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001535ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001536{
1537 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001538 if (CanProvideValue())
Enrico Granatac3e320a2011-08-02 17:27:39 +00001539 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001540 Scalar scalar;
1541 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001542 {
1543 if (success)
1544 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001545 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001546 }
1547 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001548 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001549
1550 if (success)
1551 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001552 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001553}
1554
Enrico Granatad7373f62013-10-31 18:57:50 +00001555int64_t
1556ValueObject::GetValueAsSigned (int64_t fail_value, bool *success)
1557{
1558 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001559 if (CanProvideValue())
Enrico Granatad7373f62013-10-31 18:57:50 +00001560 {
1561 Scalar scalar;
1562 if (ResolveValue (scalar))
1563 {
1564 if (success)
1565 *success = true;
Tamas Berghammer5a9919f2015-01-23 10:54:21 +00001566 return scalar.SLongLong(fail_value);
Enrico Granatad7373f62013-10-31 18:57:50 +00001567 }
1568 // fallthrough, otherwise...
1569 }
1570
1571 if (success)
1572 *success = false;
Tamas Berghammer5a9919f2015-01-23 10:54:21 +00001573 return fail_value;
Enrico Granatad7373f62013-10-31 18:57:50 +00001574}
1575
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001576// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1577// this call up to date by returning true for your new special cases. We will eventually move
1578// to checking this call result before trying to display special cases
1579bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001580ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1581 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001582{
Greg Clayton57ee3062013-07-11 22:46:58 +00001583 Flags flags(GetTypeInfo());
Enrico Granata622be232014-10-21 20:52:14 +00001584 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001585 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001586 {
1587 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001588 (custom_format == eFormatCString ||
1589 custom_format == eFormatCharArray ||
1590 custom_format == eFormatChar ||
1591 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001592 return true;
1593
Enrico Granata622be232014-10-21 20:52:14 +00001594 if (flags.Test(eTypeIsArray))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001595 {
Greg Claytonafacd142011-09-02 01:15:17 +00001596 if ((custom_format == eFormatBytes) ||
1597 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001598 return true;
1599
Greg Claytonafacd142011-09-02 01:15:17 +00001600 if ((custom_format == eFormatVectorOfChar) ||
1601 (custom_format == eFormatVectorOfFloat32) ||
1602 (custom_format == eFormatVectorOfFloat64) ||
1603 (custom_format == eFormatVectorOfSInt16) ||
1604 (custom_format == eFormatVectorOfSInt32) ||
1605 (custom_format == eFormatVectorOfSInt64) ||
1606 (custom_format == eFormatVectorOfSInt8) ||
1607 (custom_format == eFormatVectorOfUInt128) ||
1608 (custom_format == eFormatVectorOfUInt16) ||
1609 (custom_format == eFormatVectorOfUInt32) ||
1610 (custom_format == eFormatVectorOfUInt64) ||
1611 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001612 return true;
1613 }
1614 }
1615 return false;
1616}
1617
Enrico Granata9fc19442011-07-06 02:13:41 +00001618bool
1619ValueObject::DumpPrintableRepresentation(Stream& s,
1620 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001621 Format custom_format,
Enrico Granata0dba9b32014-01-08 01:36:59 +00001622 PrintableRepresentationSpecialCases special,
1623 bool do_dump_error)
Enrico Granata9fc19442011-07-06 02:13:41 +00001624{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001625
Greg Clayton57ee3062013-07-11 22:46:58 +00001626 Flags flags(GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001627
Enrico Granata86cc9822012-03-19 22:58:49 +00001628 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1629 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1630
1631 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001632 {
Enrico Granata622be232014-10-21 20:52:14 +00001633 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001634 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001635 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001636 // when being asked to get a printable display an array or pointer type directly,
1637 // try to "do the right thing"
1638
1639 if (IsCStringContainer(true) &&
1640 (custom_format == eFormatCString ||
1641 custom_format == eFormatCharArray ||
1642 custom_format == eFormatChar ||
1643 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001644 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001645 Error error;
Enrico Granata2206b482014-10-30 18:27:31 +00001646 lldb::DataBufferSP buffer_sp;
1647 ReadPointedString(buffer_sp,
Enrico Granata86cc9822012-03-19 22:58:49 +00001648 error,
1649 0,
1650 (custom_format == eFormatVectorOfChar) ||
1651 (custom_format == eFormatCharArray));
Enrico Granataac494532015-09-09 22:30:24 +00001652 lldb_private::formatters::StringPrinter::ReadBufferAndDumpToStreamOptions options(*this);
Enrico Granata2206b482014-10-30 18:27:31 +00001653 options.SetData(DataExtractor(buffer_sp, lldb::eByteOrderInvalid, 8)); // none of this matters for a string - pass some defaults
1654 options.SetStream(&s);
1655 options.SetPrefixToken(0);
1656 options.SetQuote('"');
1657 options.SetSourceSize(buffer_sp->GetByteSize());
Enrico Granataac494532015-09-09 22:30:24 +00001658 formatters::StringPrinter::ReadBufferAndDumpToStream<lldb_private::formatters::StringPrinter::StringElementType::ASCII>(options);
Enrico Granata86cc9822012-03-19 22:58:49 +00001659 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001660 }
1661
Enrico Granata86cc9822012-03-19 22:58:49 +00001662 if (custom_format == eFormatEnum)
1663 return false;
1664
1665 // this only works for arrays, because I have no way to know when
1666 // the pointed memory ends, and no special \0 end of data marker
Enrico Granata622be232014-10-21 20:52:14 +00001667 if (flags.Test(eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001668 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001669 if ((custom_format == eFormatBytes) ||
1670 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001671 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001672 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001673
1674 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001675 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001676 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001677
1678 if (low)
1679 s << ',';
1680
1681 ValueObjectSP child = GetChildAtIndex(low,true);
1682 if (!child.get())
1683 {
1684 s << "<invalid child>";
1685 continue;
1686 }
1687 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1688 }
1689
1690 s << ']';
1691
1692 return true;
1693 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001694
Enrico Granata86cc9822012-03-19 22:58:49 +00001695 if ((custom_format == eFormatVectorOfChar) ||
1696 (custom_format == eFormatVectorOfFloat32) ||
1697 (custom_format == eFormatVectorOfFloat64) ||
1698 (custom_format == eFormatVectorOfSInt16) ||
1699 (custom_format == eFormatVectorOfSInt32) ||
1700 (custom_format == eFormatVectorOfSInt64) ||
1701 (custom_format == eFormatVectorOfSInt8) ||
1702 (custom_format == eFormatVectorOfUInt128) ||
1703 (custom_format == eFormatVectorOfUInt16) ||
1704 (custom_format == eFormatVectorOfUInt32) ||
1705 (custom_format == eFormatVectorOfUInt64) ||
1706 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1707 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001708 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001709
1710 Format format = FormatManager::GetSingleItemFormat(custom_format);
1711
1712 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001713 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001714 {
1715
1716 if (low)
1717 s << ',';
1718
1719 ValueObjectSP child = GetChildAtIndex(low,true);
1720 if (!child.get())
1721 {
1722 s << "<invalid child>";
1723 continue;
1724 }
1725 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1726 }
1727
1728 s << ']';
1729
1730 return true;
1731 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001732 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001733
1734 if ((custom_format == eFormatBoolean) ||
1735 (custom_format == eFormatBinary) ||
1736 (custom_format == eFormatChar) ||
1737 (custom_format == eFormatCharPrintable) ||
1738 (custom_format == eFormatComplexFloat) ||
1739 (custom_format == eFormatDecimal) ||
1740 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001741 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001742 (custom_format == eFormatFloat) ||
1743 (custom_format == eFormatOctal) ||
1744 (custom_format == eFormatOSType) ||
1745 (custom_format == eFormatUnicode16) ||
1746 (custom_format == eFormatUnicode32) ||
1747 (custom_format == eFormatUnsigned) ||
1748 (custom_format == eFormatPointer) ||
1749 (custom_format == eFormatComplexInteger) ||
1750 (custom_format == eFormatComplex) ||
1751 (custom_format == eFormatDefault)) // use the [] operator
1752 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001753 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001754 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001755
1756 if (only_special)
1757 return false;
1758
Enrico Granata86cc9822012-03-19 22:58:49 +00001759 bool var_success = false;
1760
1761 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001762 const char *cstr = NULL;
Enrico Granata2c75f112013-06-21 00:04:51 +00001763
1764 // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1765 // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1766 // area for cases where our desired output is not backed by some other longer-term storage
Greg Claytonc7bece562013-01-25 18:06:21 +00001767 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001768
Enrico Granata465f4bc2014-02-15 01:24:44 +00001769 if (custom_format != eFormatInvalid)
Enrico Granata86cc9822012-03-19 22:58:49 +00001770 SetFormat(custom_format);
1771
1772 switch(val_obj_display)
1773 {
1774 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001775 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001776 break;
1777
1778 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001779 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001780 break;
1781
1782 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001783 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001784 break;
1785
1786 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001787 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001788 break;
1789
1790 case eValueObjectRepresentationStyleChildrenCount:
Deepak Panickal99fbc072014-03-03 15:39:47 +00001791 strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren());
Greg Claytonc7bece562013-01-25 18:06:21 +00001792 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001793 break;
1794
1795 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001796 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001797 break;
Enrico Granata2c75f112013-06-21 00:04:51 +00001798
1799 case eValueObjectRepresentationStyleName:
1800 cstr = GetName().AsCString();
1801 break;
1802
1803 case eValueObjectRepresentationStyleExpressionPath:
1804 GetExpressionPath(strm, false);
1805 cstr = strm.GetString().c_str();
1806 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001807 }
1808
Greg Claytonc7bece562013-01-25 18:06:21 +00001809 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001810 {
1811 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001812 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001813 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1814 {
Enrico Granatad07cfd32014-10-08 18:27:36 +00001815 if (!CanProvideValue())
Enrico Granata86cc9822012-03-19 22:58:49 +00001816 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001817 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1818 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001819 }
1820 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001821 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001822 }
1823 }
1824
Greg Claytonc7bece562013-01-25 18:06:21 +00001825 if (cstr)
1826 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001827 else
1828 {
1829 if (m_error.Fail())
Enrico Granata0dba9b32014-01-08 01:36:59 +00001830 {
1831 if (do_dump_error)
1832 s.Printf("<%s>", m_error.AsCString());
1833 else
1834 return false;
1835 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001836 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1837 s.PutCString("<no summary available>");
1838 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1839 s.PutCString("<no value available>");
1840 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1841 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1842 else
1843 s.PutCString("<no printable representation>");
1844 }
1845
1846 // we should only return false here if we could not do *anything*
1847 // even if we have an error message as output, that's a success
1848 // from our callers' perspective, so return true
1849 var_success = true;
Enrico Granata465f4bc2014-02-15 01:24:44 +00001850
1851 if (custom_format != eFormatInvalid)
1852 SetFormat(eFormatDefault);
Enrico Granata86cc9822012-03-19 22:58:49 +00001853 }
1854
Enrico Granataf4efecd2011-07-12 22:56:10 +00001855 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001856}
1857
Greg Clayton737b9322010-09-13 03:32:57 +00001858addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001859ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001860{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001861 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001862 return LLDB_INVALID_ADDRESS;
1863
Greg Clayton73b472d2010-10-27 03:32:59 +00001864 switch (m_value.GetValueType())
1865 {
1866 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001867 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001868 if (scalar_is_load_address)
1869 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001870 if(address_type)
1871 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001872 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1873 }
1874 break;
1875
1876 case Value::eValueTypeLoadAddress:
1877 case Value::eValueTypeFileAddress:
Greg Clayton73b472d2010-10-27 03:32:59 +00001878 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001879 if(address_type)
1880 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001881 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1882 }
1883 break;
Siva Chandraa3747a92015-05-04 19:43:34 +00001884 case Value::eValueTypeHostAddress:
Siva Chandrae32f2b52015-05-05 00:41:35 +00001885 {
1886 if(address_type)
1887 *address_type = m_value.GetValueAddressType ();
1888 return LLDB_INVALID_ADDRESS;
1889 }
Siva Chandraa3747a92015-05-04 19:43:34 +00001890 break;
Greg Clayton73b472d2010-10-27 03:32:59 +00001891 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001892 if (address_type)
1893 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001894 return LLDB_INVALID_ADDRESS;
1895}
1896
1897addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001898ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001899{
Greg Claytonafacd142011-09-02 01:15:17 +00001900 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001901 if(address_type)
1902 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001903
Enrico Granatac3e320a2011-08-02 17:27:39 +00001904 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001905 return address;
1906
Greg Clayton73b472d2010-10-27 03:32:59 +00001907 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001908 {
1909 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001910 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001911 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001912 break;
1913
Enrico Granata9128ee22011-09-06 19:20:51 +00001914 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001915 case Value::eValueTypeLoadAddress:
1916 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001917 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001918 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001919 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001920 }
1921 break;
1922 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001923
Enrico Granata9128ee22011-09-06 19:20:51 +00001924 if (address_type)
1925 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001926
Greg Clayton737b9322010-09-13 03:32:57 +00001927 return address;
1928}
1929
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001930bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001931ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001932{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001933 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001934 // Make sure our value is up to date first so that our location and location
1935 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001936 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001937 {
1938 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001939 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001940 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001941
Greg Claytonfaac1112013-03-14 18:31:44 +00001942 uint64_t count = 0;
Greg Clayton99558cc42015-08-24 23:46:31 +00001943 const Encoding encoding = GetCompilerType().GetEncoding (count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001944
Greg Claytonb1320972010-07-14 00:18:15 +00001945 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001946
Jim Ingham16e0c682011-08-12 23:34:31 +00001947 Value::ValueType value_type = m_value.GetValueType();
1948
1949 if (value_type == Value::eValueTypeScalar)
1950 {
1951 // If the value is already a scalar, then let the scalar change itself:
1952 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1953 }
Sagar Thakur8536fd12015-08-20 09:12:46 +00001954 else if (byte_size <= 16)
Jim Ingham16e0c682011-08-12 23:34:31 +00001955 {
1956 // If the value fits in a scalar, then make a new scalar and again let the
1957 // scalar code do the conversion, then figure out where to put the new value.
1958 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001959 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1960 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001961 {
Jim Ingham4b536182011-08-09 02:12:22 +00001962 switch (value_type)
1963 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001964 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001965 {
1966 // If it is a load address, then the scalar value is the storage location
1967 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001968 ExecutionContext exe_ctx (GetExecutionContextRef());
1969 Process *process = exe_ctx.GetProcessPtr();
1970 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001971 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001972 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001973 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1974 new_scalar,
1975 byte_size,
1976 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001977 if (!error.Success())
1978 return false;
1979 if (bytes_written != byte_size)
1980 {
1981 error.SetErrorString("unable to write value to memory");
1982 return false;
1983 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001984 }
1985 }
Jim Ingham4b536182011-08-09 02:12:22 +00001986 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001987 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001988 {
1989 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1990 DataExtractor new_data;
1991 new_data.SetByteOrder (m_data.GetByteOrder());
1992
1993 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1994 m_data.SetData(buffer_sp, 0);
1995 bool success = new_scalar.GetData(new_data);
1996 if (success)
1997 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001998 new_data.CopyByteOrderedData (0,
1999 byte_size,
2000 const_cast<uint8_t *>(m_data.GetDataStart()),
2001 byte_size,
2002 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00002003 }
2004 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
2005
2006 }
Jim Ingham4b536182011-08-09 02:12:22 +00002007 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00002008 case Value::eValueTypeFileAddress:
2009 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00002010 case Value::eValueTypeVector:
2011 break;
Jim Ingham4b536182011-08-09 02:12:22 +00002012 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002013 }
2014 else
2015 {
Jim Ingham16e0c682011-08-12 23:34:31 +00002016 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002017 }
Jim Ingham16e0c682011-08-12 23:34:31 +00002018 }
2019 else
2020 {
2021 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00002022 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002023 return false;
2024 }
Jim Ingham16e0c682011-08-12 23:34:31 +00002025
2026 // If we have reached this point, then we have successfully changed the value.
2027 SetNeedsUpdate();
2028 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002029}
2030
Greg Clayton81e871e2012-02-04 02:27:34 +00002031bool
2032ValueObject::GetDeclaration (Declaration &decl)
2033{
2034 decl.Clear();
2035 return false;
2036}
2037
Greg Clayton84db9102012-03-26 23:03:23 +00002038ConstString
2039ValueObject::GetTypeName()
2040{
Greg Clayton99558cc42015-08-24 23:46:31 +00002041 return GetCompilerType().GetConstTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00002042}
2043
2044ConstString
Enrico Granatae8daa2f2014-05-17 19:14:17 +00002045ValueObject::GetDisplayTypeName()
2046{
2047 return GetTypeName();
2048}
2049
2050ConstString
Greg Clayton84db9102012-03-26 23:03:23 +00002051ValueObject::GetQualifiedTypeName()
2052{
Greg Clayton99558cc42015-08-24 23:46:31 +00002053 return GetCompilerType().GetConstQualifiedTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00002054}
2055
2056
Greg Claytonafacd142011-09-02 01:15:17 +00002057LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00002058ValueObject::GetObjectRuntimeLanguage ()
2059{
Greg Clayton99558cc42015-08-24 23:46:31 +00002060 return GetCompilerType().GetMinimumLanguage ();
Jim Ingham5a369122010-09-28 01:25:32 +00002061}
2062
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002063void
Jim Ingham58b59f92011-04-22 23:53:53 +00002064ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002065{
Jim Ingham58b59f92011-04-22 23:53:53 +00002066 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002067}
2068
2069ValueObjectSP
2070ValueObject::GetSyntheticChild (const ConstString &key) const
2071{
2072 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00002073 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002074 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00002075 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002076 return synthetic_child_sp;
2077}
2078
Greg Clayton2452ab72013-02-08 22:02:02 +00002079uint32_t
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002080ValueObject::GetTypeInfo (CompilerType *pointee_or_element_compiler_type)
Greg Clayton2452ab72013-02-08 22:02:02 +00002081{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002082 return GetCompilerType().GetTypeInfo (pointee_or_element_compiler_type);
Greg Clayton2452ab72013-02-08 22:02:02 +00002083}
2084
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002085bool
2086ValueObject::IsPointerType ()
2087{
Greg Clayton99558cc42015-08-24 23:46:31 +00002088 return GetCompilerType().IsPointerType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002089}
2090
Jim Inghamb7603bb2011-03-18 00:05:18 +00002091bool
Greg Claytondaf515f2011-07-09 20:12:33 +00002092ValueObject::IsArrayType ()
2093{
Greg Clayton99558cc42015-08-24 23:46:31 +00002094 return GetCompilerType().IsArrayType (NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00002095}
2096
2097bool
Enrico Granata9fc19442011-07-06 02:13:41 +00002098ValueObject::IsScalarType ()
2099{
Greg Clayton99558cc42015-08-24 23:46:31 +00002100 return GetCompilerType().IsScalarType ();
Enrico Granata9fc19442011-07-06 02:13:41 +00002101}
2102
2103bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00002104ValueObject::IsIntegerType (bool &is_signed)
2105{
Greg Clayton99558cc42015-08-24 23:46:31 +00002106 return GetCompilerType().IsIntegerType (is_signed);
Jim Inghamb7603bb2011-03-18 00:05:18 +00002107}
Greg Clayton73b472d2010-10-27 03:32:59 +00002108
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002109bool
2110ValueObject::IsPointerOrReferenceType ()
2111{
Greg Clayton99558cc42015-08-24 23:46:31 +00002112 return GetCompilerType().IsPointerOrReferenceType ();
Greg Clayton007d5be2011-05-30 00:49:24 +00002113}
2114
2115bool
Greg Claytondea8cb42011-06-29 22:09:02 +00002116ValueObject::IsPossibleDynamicType ()
2117{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002118 ExecutionContext exe_ctx (GetExecutionContextRef());
2119 Process *process = exe_ctx.GetProcessPtr();
2120 if (process)
2121 return process->IsPossibleDynamicValue(*this);
2122 else
Greg Clayton99558cc42015-08-24 23:46:31 +00002123 return GetCompilerType().IsPossibleDynamicType (NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00002124}
2125
Enrico Granata9e7b3882012-12-13 23:50:33 +00002126bool
Enrico Granata560558e2015-02-11 02:35:39 +00002127ValueObject::IsRuntimeSupportValue ()
2128{
2129 Process *process(GetProcessSP().get());
2130 if (process)
2131 {
2132 LanguageRuntime *runtime = process->GetLanguageRuntime(GetObjectRuntimeLanguage());
2133 if (!runtime)
2134 runtime = process->GetObjCLanguageRuntime();
2135 if (runtime)
2136 return runtime->IsRuntimeSupportValue(*this);
2137 }
2138 return false;
2139}
2140
2141bool
Enrico Granata9e7b3882012-12-13 23:50:33 +00002142ValueObject::IsObjCNil ()
2143{
Enrico Granata622be232014-10-21 20:52:14 +00002144 const uint32_t mask = eTypeIsObjC | eTypeIsPointer;
Greg Clayton99558cc42015-08-24 23:46:31 +00002145 bool isObjCpointer = (((GetCompilerType().GetTypeInfo(NULL)) & mask) == mask);
Enrico Granata7277d202013-03-15 23:33:15 +00002146 if (!isObjCpointer)
2147 return false;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002148 bool canReadValue = true;
2149 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
Enrico Granata7277d202013-03-15 23:33:15 +00002150 return canReadValue && isZero;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002151}
2152
Greg Claytondaf515f2011-07-09 20:12:33 +00002153// This allows you to create an array member using and index
2154// that doesn't not fall in the normal bounds of the array.
2155// Many times structure can be defined as:
2156// struct Collection
2157// {
2158// uint32_t item_count;
2159// Item item_array[0];
2160// };
2161// The size of the "item_array" is 1, but many times in practice
2162// there are more items in "item_array".
2163
2164ValueObjectSP
Bruce Mitchener11d86362015-02-26 23:55:39 +00002165ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00002166{
2167 ValueObjectSP synthetic_child_sp;
Bruce Mitchener11d86362015-02-26 23:55:39 +00002168 if (IsPointerType () || IsArrayType())
Greg Claytondaf515f2011-07-09 20:12:33 +00002169 {
2170 char index_str[64];
Deepak Panickal99fbc072014-03-03 15:39:47 +00002171 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
Greg Claytondaf515f2011-07-09 20:12:33 +00002172 ConstString index_const_str(index_str);
2173 // Check if we have already created a synthetic array member in this
2174 // valid object. If we have we will re-use it.
2175 synthetic_child_sp = GetSyntheticChild (index_const_str);
2176 if (!synthetic_child_sp)
2177 {
2178 ValueObject *synthetic_child;
2179 // We haven't made a synthetic array member for INDEX yet, so
2180 // lets make one and cache it for any future reference.
2181 synthetic_child = CreateChildAtIndex(0, true, index);
Bruce Mitchener11d86362015-02-26 23:55:39 +00002182
Greg Claytondaf515f2011-07-09 20:12:33 +00002183 // Cache the value if we got one back...
2184 if (synthetic_child)
2185 {
2186 AddSyntheticChild(index_const_str, synthetic_child);
2187 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002188 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00002189 synthetic_child_sp->m_is_array_item_for_pointer = true;
2190 }
2191 }
2192 }
2193 return synthetic_child_sp;
2194}
2195
Enrico Granata9fc19442011-07-06 02:13:41 +00002196ValueObjectSP
2197ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2198{
2199 ValueObjectSP synthetic_child_sp;
2200 if (IsScalarType ())
2201 {
2202 char index_str[64];
2203 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2204 ConstString index_const_str(index_str);
2205 // Check if we have already created a synthetic array member in this
2206 // valid object. If we have we will re-use it.
2207 synthetic_child_sp = GetSyntheticChild (index_const_str);
2208 if (!synthetic_child_sp)
2209 {
Enrico Granata9fc19442011-07-06 02:13:41 +00002210 // We haven't made a synthetic array member for INDEX yet, so
2211 // lets make one and cache it for any future reference.
Greg Clayton57ee3062013-07-11 22:46:58 +00002212 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
Greg Clayton99558cc42015-08-24 23:46:31 +00002213 GetCompilerType(),
Greg Clayton57ee3062013-07-11 22:46:58 +00002214 index_const_str,
2215 GetByteSize(),
2216 0,
2217 to-from+1,
2218 from,
2219 false,
2220 false,
2221 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002222
2223 // Cache the value if we got one back...
2224 if (synthetic_child)
2225 {
2226 AddSyntheticChild(index_const_str, synthetic_child);
2227 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002228 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002229 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2230 }
2231 }
2232 }
2233 return synthetic_child_sp;
2234}
2235
Greg Claytonafacd142011-09-02 01:15:17 +00002236ValueObjectSP
Greg Claytona1e5dc82015-08-11 22:53:00 +00002237ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const CompilerType& type, bool can_create)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002238{
2239
2240 ValueObjectSP synthetic_child_sp;
2241
2242 char name_str[64];
2243 snprintf(name_str, sizeof(name_str), "@%i", offset);
2244 ConstString name_const_str(name_str);
2245
2246 // Check if we have already created a synthetic array member in this
2247 // valid object. If we have we will re-use it.
2248 synthetic_child_sp = GetSyntheticChild (name_const_str);
2249
2250 if (synthetic_child_sp.get())
2251 return synthetic_child_sp;
2252
2253 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002254 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002255
Enrico Granata951bdd52015-01-28 01:09:45 +00002256 ExecutionContext exe_ctx (GetExecutionContextRef());
2257
Enrico Granata6f3533f2011-07-29 19:53:35 +00002258 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
Greg Clayton57ee3062013-07-11 22:46:58 +00002259 type,
Enrico Granata6f3533f2011-07-29 19:53:35 +00002260 name_const_str,
Greg Clayton526ae042015-02-12 00:34:25 +00002261 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
Enrico Granata6f3533f2011-07-29 19:53:35 +00002262 offset,
2263 0,
2264 0,
2265 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002266 false,
2267 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002268 if (synthetic_child)
2269 {
2270 AddSyntheticChild(name_const_str, synthetic_child);
2271 synthetic_child_sp = synthetic_child->GetSP();
2272 synthetic_child_sp->SetName(name_const_str);
2273 synthetic_child_sp->m_is_child_at_offset = true;
2274 }
2275 return synthetic_child_sp;
2276}
2277
Enrico Granata32556cd2014-08-26 20:54:04 +00002278ValueObjectSP
Greg Claytona1e5dc82015-08-11 22:53:00 +00002279ValueObject::GetSyntheticBase (uint32_t offset, const CompilerType& type, bool can_create)
Enrico Granata32556cd2014-08-26 20:54:04 +00002280{
2281 ValueObjectSP synthetic_child_sp;
2282
2283 char name_str[64];
2284 snprintf(name_str, sizeof(name_str), "%s", type.GetTypeName().AsCString("<unknown>"));
2285 ConstString name_const_str(name_str);
2286
2287 // Check if we have already created a synthetic array member in this
2288 // valid object. If we have we will re-use it.
2289 synthetic_child_sp = GetSyntheticChild (name_const_str);
2290
2291 if (synthetic_child_sp.get())
2292 return synthetic_child_sp;
2293
2294 if (!can_create)
2295 return ValueObjectSP();
2296
Enrico Granata32556cd2014-08-26 20:54:04 +00002297 const bool is_base_class = true;
2298
Enrico Granata951bdd52015-01-28 01:09:45 +00002299 ExecutionContext exe_ctx (GetExecutionContextRef());
2300
Enrico Granata32556cd2014-08-26 20:54:04 +00002301 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2302 type,
2303 name_const_str,
Greg Clayton526ae042015-02-12 00:34:25 +00002304 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
Enrico Granata32556cd2014-08-26 20:54:04 +00002305 offset,
2306 0,
2307 0,
2308 is_base_class,
2309 false,
2310 eAddressTypeInvalid);
2311 if (synthetic_child)
2312 {
2313 AddSyntheticChild(name_const_str, synthetic_child);
2314 synthetic_child_sp = synthetic_child->GetSP();
2315 synthetic_child_sp->SetName(name_const_str);
2316 }
2317 return synthetic_child_sp;
2318}
2319
2320
Enrico Granatad55546b2011-07-22 00:16:08 +00002321// your expression path needs to have a leading . or ->
2322// (unless it somehow "looks like" an array, in which case it has
2323// a leading [ symbol). while the [ is meaningful and should be shown
2324// to the user, . and -> are just parser design, but by no means
2325// added information for the user.. strip them off
2326static const char*
2327SkipLeadingExpressionPathSeparators(const char* expression)
2328{
2329 if (!expression || !expression[0])
2330 return expression;
2331 if (expression[0] == '.')
2332 return expression+1;
2333 if (expression[0] == '-' && expression[1] == '>')
2334 return expression+2;
2335 return expression;
2336}
2337
Greg Claytonafacd142011-09-02 01:15:17 +00002338ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002339ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2340{
2341 ValueObjectSP synthetic_child_sp;
2342 ConstString name_const_string(expression);
2343 // Check if we have already created a synthetic array member in this
2344 // valid object. If we have we will re-use it.
2345 synthetic_child_sp = GetSyntheticChild (name_const_string);
2346 if (!synthetic_child_sp)
2347 {
2348 // We haven't made a synthetic array member for expression yet, so
2349 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002350 synthetic_child_sp = GetValueForExpressionPath(expression,
2351 NULL, NULL, NULL,
Enrico Granataef238c12015-03-12 22:30:58 +00002352 GetValueForExpressionPathOptions().SetSyntheticChildrenTraversal(GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None));
Enrico Granatad55546b2011-07-22 00:16:08 +00002353
2354 // Cache the value if we got one back...
2355 if (synthetic_child_sp.get())
2356 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002357 // 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 +00002358 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002359 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002360 }
2361 }
2362 return synthetic_child_sp;
2363}
2364
2365void
Enrico Granata86cc9822012-03-19 22:58:49 +00002366ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002367{
Enrico Granata86cc9822012-03-19 22:58:49 +00002368 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002369 return;
2370
Enrico Granatac5bc4122012-03-27 02:35:13 +00002371 TargetSP target_sp(GetTargetSP());
Enrico Granata5d5f60c2013-09-24 22:58:37 +00002372 if (target_sp && target_sp->GetEnableSyntheticValue() == false)
Enrico Granatac5bc4122012-03-27 02:35:13 +00002373 {
2374 m_synthetic_value = NULL;
2375 return;
2376 }
2377
Enrico Granatae3e91512012-10-22 18:18:36 +00002378 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2379
Enrico Granata5548cb52013-01-28 23:47:25 +00002380 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002381 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002382
Enrico Granata0c489f52012-03-01 04:24:26 +00002383 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002384 return;
2385
Enrico Granatae3e91512012-10-22 18:18:36 +00002386 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2387 return;
2388
Enrico Granata86cc9822012-03-19 22:58:49 +00002389 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002390}
2391
Jim Ingham78a685a2011-04-16 00:01:13 +00002392void
Greg Claytonafacd142011-09-02 01:15:17 +00002393ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002394{
Greg Claytonafacd142011-09-02 01:15:17 +00002395 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002396 return;
2397
Jim Ingham58b59f92011-04-22 23:53:53 +00002398 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002399 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002400 ExecutionContext exe_ctx (GetExecutionContextRef());
2401 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002402 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002403 {
2404 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002405 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002406 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002407 }
2408}
2409
Jim Ingham58b59f92011-04-22 23:53:53 +00002410ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002411ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002412{
Greg Claytonafacd142011-09-02 01:15:17 +00002413 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002414 return ValueObjectSP();
2415
2416 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002417 {
Jim Ingham2837b762011-05-04 03:43:18 +00002418 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002419 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002420 if (m_dynamic_value)
2421 return m_dynamic_value->GetSP();
2422 else
2423 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002424}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002425
Jim Ingham60dbabb2011-12-08 19:44:08 +00002426ValueObjectSP
2427ValueObject::GetStaticValue()
2428{
2429 return GetSP();
2430}
2431
Enrico Granata886147f2012-05-08 18:47:08 +00002432lldb::ValueObjectSP
2433ValueObject::GetNonSyntheticValue ()
2434{
2435 return GetSP();
2436}
2437
Enrico Granatad55546b2011-07-22 00:16:08 +00002438ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002439ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002440{
Enrico Granata86cc9822012-03-19 22:58:49 +00002441 if (use_synthetic == false)
2442 return ValueObjectSP();
2443
Enrico Granatad55546b2011-07-22 00:16:08 +00002444 CalculateSyntheticValue(use_synthetic);
2445
2446 if (m_synthetic_value)
2447 return m_synthetic_value->GetSP();
2448 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002449 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002450}
2451
Greg Claytone221f822011-01-21 01:59:00 +00002452bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002453ValueObject::HasSyntheticValue()
2454{
Enrico Granata5548cb52013-01-28 23:47:25 +00002455 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002456
Enrico Granata0c489f52012-03-01 04:24:26 +00002457 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002458 return false;
2459
Enrico Granata86cc9822012-03-19 22:58:49 +00002460 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002461
2462 if (m_synthetic_value)
2463 return true;
2464 else
2465 return false;
2466}
2467
2468bool
Greg Claytone221f822011-01-21 01:59:00 +00002469ValueObject::GetBaseClassPath (Stream &s)
2470{
2471 if (IsBaseClass())
2472 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002473 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002474 CompilerType compiler_type = GetCompilerType();
Greg Claytone221f822011-01-21 01:59:00 +00002475 std::string cxx_class_name;
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002476 bool this_had_base_class = ClangASTContext::GetCXXClassName (compiler_type, cxx_class_name);
Greg Claytone221f822011-01-21 01:59:00 +00002477 if (this_had_base_class)
2478 {
2479 if (parent_had_base_class)
2480 s.PutCString("::");
2481 s.PutCString(cxx_class_name.c_str());
2482 }
2483 return parent_had_base_class || this_had_base_class;
2484 }
2485 return false;
2486}
2487
2488
2489ValueObject *
2490ValueObject::GetNonBaseClassParent()
2491{
Jim Ingham78a685a2011-04-16 00:01:13 +00002492 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002493 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002494 if (GetParent()->IsBaseClass())
2495 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002496 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002497 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002498 }
2499 return NULL;
2500}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002501
Enrico Granataa3c8f042014-08-19 22:29:08 +00002502
2503bool
2504ValueObject::IsBaseClass (uint32_t& depth)
2505{
2506 if (!IsBaseClass())
2507 {
2508 depth = 0;
2509 return false;
2510 }
2511 if (GetParent())
2512 {
2513 GetParent()->IsBaseClass(depth);
2514 depth = depth + 1;
2515 return true;
2516 }
2517 // TODO: a base of no parent? weird..
2518 depth = 1;
2519 return true;
2520}
2521
Greg Clayton1d3afba2010-10-05 00:00:42 +00002522void
Enrico Granata4becb372011-06-29 22:27:15 +00002523ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002524{
Enrico Granata986fa5f2014-12-09 21:41:16 +00002525 // synthetic children do not actually "exist" as part of the hierarchy, and sometimes they are consed up in ways
2526 // that don't make sense from an underlying language/API standpoint. So, use a special code path here to return
2527 // something that can hopefully be used in expression
2528 if (m_is_synthetic_children_generated)
2529 {
2530 UpdateValueIfNeeded();
2531
2532 if (m_value.GetValueType() == Value::eValueTypeLoadAddress)
2533 {
2534 if (IsPointerOrReferenceType())
2535 {
2536 s.Printf("((%s)0x%" PRIx64 ")",
2537 GetTypeName().AsCString("void"),
2538 GetValueAsUnsigned(0));
2539 return;
2540 }
2541 else
2542 {
2543 uint64_t load_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
2544 if (load_addr != LLDB_INVALID_ADDRESS)
2545 {
2546 s.Printf("(*( (%s *)0x%" PRIx64 "))",
2547 GetTypeName().AsCString("void"),
2548 load_addr);
2549 return;
2550 }
2551 }
2552 }
2553
2554 if (CanProvideValue())
2555 {
2556 s.Printf("((%s)%s)",
2557 GetTypeName().AsCString("void"),
2558 GetValueAsCString());
2559 return;
2560 }
2561
2562 return;
2563 }
2564
Greg Claytone221f822011-01-21 01:59:00 +00002565 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002566
Enrico Granata86cc9822012-03-19 22:58:49 +00002567 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002568 {
Enrico Granata4becb372011-06-29 22:27:15 +00002569 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2570 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2571 // the eHonorPointers mode is meant to produce strings in this latter format
2572 s.PutCString("*(");
2573 }
Greg Claytone221f822011-01-21 01:59:00 +00002574
Enrico Granata4becb372011-06-29 22:27:15 +00002575 ValueObject* parent = GetParent();
2576
2577 if (parent)
2578 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002579
2580 // if we are a deref_of_parent just because we are synthetic array
2581 // members made up to allow ptr[%d] syntax to work in variable
2582 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002583 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002584 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002585
Greg Claytone221f822011-01-21 01:59:00 +00002586 if (!IsBaseClass())
2587 {
2588 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002589 {
Greg Claytone221f822011-01-21 01:59:00 +00002590 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2591 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002592 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002593 CompilerType non_base_class_parent_compiler_type = non_base_class_parent->GetCompilerType();
2594 if (non_base_class_parent_compiler_type)
Greg Claytone221f822011-01-21 01:59:00 +00002595 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002596 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002597 {
2598 s.PutCString("->");
2599 }
Enrico Granata4becb372011-06-29 22:27:15 +00002600 else
2601 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002602 const uint32_t non_base_class_parent_type_info = non_base_class_parent_compiler_type.GetTypeInfo();
Greg Clayton57ee3062013-07-11 22:46:58 +00002603
Enrico Granata622be232014-10-21 20:52:14 +00002604 if (non_base_class_parent_type_info & eTypeIsPointer)
Enrico Granata4becb372011-06-29 22:27:15 +00002605 {
2606 s.PutCString("->");
2607 }
Enrico Granata622be232014-10-21 20:52:14 +00002608 else if ((non_base_class_parent_type_info & eTypeHasChildren) &&
2609 !(non_base_class_parent_type_info & eTypeIsArray))
Enrico Granata4becb372011-06-29 22:27:15 +00002610 {
2611 s.PutChar('.');
2612 }
Greg Claytone221f822011-01-21 01:59:00 +00002613 }
2614 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002615 }
Greg Claytone221f822011-01-21 01:59:00 +00002616
2617 const char *name = GetName().GetCString();
2618 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002619 {
Greg Claytone221f822011-01-21 01:59:00 +00002620 if (qualify_cxx_base_classes)
2621 {
2622 if (GetBaseClassPath (s))
2623 s.PutCString("::");
2624 }
2625 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002626 }
2627 }
2628 }
2629
Enrico Granata86cc9822012-03-19 22:58:49 +00002630 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002631 {
Greg Claytone221f822011-01-21 01:59:00 +00002632 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002633 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002634}
2635
Greg Claytonafacd142011-09-02 01:15:17 +00002636ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002637ValueObject::GetValueForExpressionPath(const char* expression,
2638 const char** first_unparsed,
2639 ExpressionPathScanEndReason* reason_to_stop,
2640 ExpressionPathEndResultType* final_value_type,
2641 const GetValueForExpressionPathOptions& options,
2642 ExpressionPathAftermath* final_task_on_target)
2643{
2644
2645 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002646 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2647 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002648 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002649
2650 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2651 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2652 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2653 final_value_type ? final_value_type : &dummy_final_value_type,
2654 options,
2655 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2656
Enrico Granata86cc9822012-03-19 22:58:49 +00002657 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002658 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002659
Enrico Granata86cc9822012-03-19 22:58:49 +00002660 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 +00002661 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002662 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002663 {
2664 Error error;
2665 ValueObjectSP final_value = ret_val->Dereference(error);
2666 if (error.Fail() || !final_value.get())
2667 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002668 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002669 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002670 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002671 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002672 return ValueObjectSP();
2673 }
2674 else
2675 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002676 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002677 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002678 return final_value;
2679 }
2680 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002681 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002682 {
2683 Error error;
2684 ValueObjectSP final_value = ret_val->AddressOf(error);
2685 if (error.Fail() || !final_value.get())
2686 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002687 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002688 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002689 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002690 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002691 return ValueObjectSP();
2692 }
2693 else
2694 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002695 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002696 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002697 return final_value;
2698 }
2699 }
2700 }
2701 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2702}
2703
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002704int
2705ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002706 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002707 const char** first_unparsed,
2708 ExpressionPathScanEndReason* reason_to_stop,
2709 ExpressionPathEndResultType* final_value_type,
2710 const GetValueForExpressionPathOptions& options,
2711 ExpressionPathAftermath* final_task_on_target)
2712{
2713 const char* dummy_first_unparsed;
2714 ExpressionPathScanEndReason dummy_reason_to_stop;
2715 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002716 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002717
2718 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2719 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2720 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2721 final_value_type ? final_value_type : &dummy_final_value_type,
2722 options,
2723 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2724
2725 if (!ret_val.get()) // if there are errors, I add nothing to the list
2726 return 0;
2727
Enrico Granata86ea8d82012-03-29 01:34:34 +00002728 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002729 {
2730 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002731 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002732 {
2733 list->Append(ret_val);
2734 return 1;
2735 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002736 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 +00002737 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002738 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002739 {
2740 Error error;
2741 ValueObjectSP final_value = ret_val->Dereference(error);
2742 if (error.Fail() || !final_value.get())
2743 {
Greg Clayton23f59502012-07-17 03:23:13 +00002744 if (reason_to_stop)
2745 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2746 if (final_value_type)
2747 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002748 return 0;
2749 }
2750 else
2751 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002752 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002753 list->Append(final_value);
2754 return 1;
2755 }
2756 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002757 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002758 {
2759 Error error;
2760 ValueObjectSP final_value = ret_val->AddressOf(error);
2761 if (error.Fail() || !final_value.get())
2762 {
Greg Clayton23f59502012-07-17 03:23:13 +00002763 if (reason_to_stop)
2764 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2765 if (final_value_type)
2766 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002767 return 0;
2768 }
2769 else
2770 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002771 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002772 list->Append(final_value);
2773 return 1;
2774 }
2775 }
2776 }
2777 }
2778 else
2779 {
2780 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2781 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2782 ret_val,
2783 list,
2784 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2785 final_value_type ? final_value_type : &dummy_final_value_type,
2786 options,
2787 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2788 }
2789 // in any non-covered case, just do the obviously right thing
2790 list->Append(ret_val);
2791 return 1;
2792}
2793
Greg Claytonafacd142011-09-02 01:15:17 +00002794ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002795ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2796 const char** first_unparsed,
2797 ExpressionPathScanEndReason* reason_to_stop,
2798 ExpressionPathEndResultType* final_result,
2799 const GetValueForExpressionPathOptions& options,
2800 ExpressionPathAftermath* what_next)
2801{
2802 ValueObjectSP root = GetSP();
2803
2804 if (!root.get())
2805 return ValueObjectSP();
2806
2807 *first_unparsed = expression_cstr;
2808
2809 while (true)
2810 {
2811
2812 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2813
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002814 CompilerType root_compiler_type = root->GetCompilerType();
2815 CompilerType pointee_compiler_type;
2816 Flags pointee_compiler_type_info;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002817
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002818 Flags root_compiler_type_info(root_compiler_type.GetTypeInfo(&pointee_compiler_type));
2819 if (pointee_compiler_type)
2820 pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002821
2822 if (!expression_cstr || *expression_cstr == '\0')
2823 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002824 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002825 return root;
2826 }
2827
2828 switch (*expression_cstr)
2829 {
2830 case '-':
2831 {
2832 if (options.m_check_dot_vs_arrow_syntax &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002833 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 +00002834 {
2835 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002836 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2837 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002838 return ValueObjectSP();
2839 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002840 if (root_compiler_type_info.Test(eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2841 root_compiler_type_info.Test(eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002842 options.m_no_fragile_ivar)
2843 {
2844 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002845 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2846 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002847 return ValueObjectSP();
2848 }
2849 if (expression_cstr[1] != '>')
2850 {
2851 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002852 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2853 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002854 return ValueObjectSP();
2855 }
2856 expression_cstr++; // skip the -
2857 }
2858 case '.': // or fallthrough from ->
2859 {
2860 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002861 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 +00002862 {
2863 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002864 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2865 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002866 return ValueObjectSP();
2867 }
2868 expression_cstr++; // skip .
2869 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2870 ConstString child_name;
2871 if (!next_separator) // if no other separator just expand this last layer
2872 {
2873 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002874 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2875
2876 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002877 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002878 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002879 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2880 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002881 return child_valobj_sp;
2882 }
Enrico Granataef238c12015-03-12 22:30:58 +00002883 else
Enrico Granata8c9d3562011-08-11 17:08:01 +00002884 {
Enrico Granataef238c12015-03-12 22:30:58 +00002885 switch (options.m_synthetic_children_traversal)
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002886 {
Enrico Granataef238c12015-03-12 22:30:58 +00002887 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None:
2888 break;
2889 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic:
2890 if (root->IsSynthetic())
2891 {
2892 child_valobj_sp = root->GetNonSyntheticValue();
2893 if (child_valobj_sp.get())
2894 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2895 }
2896 break;
2897 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic:
2898 if (!root->IsSynthetic())
2899 {
2900 child_valobj_sp = root->GetSyntheticValue();
2901 if (child_valobj_sp.get())
2902 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2903 }
2904 break;
2905 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both:
2906 if (root->IsSynthetic())
2907 {
2908 child_valobj_sp = root->GetNonSyntheticValue();
2909 if (child_valobj_sp.get())
2910 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2911 }
2912 else
2913 {
2914 child_valobj_sp = root->GetSyntheticValue();
2915 if (child_valobj_sp.get())
2916 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2917 }
2918 break;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002919 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002920 }
2921
2922 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2923 // so we hit the "else" branch, and return an error
2924 if(child_valobj_sp.get()) // if it worked, just return
2925 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002926 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002927 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2928 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002929 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002930 }
2931 else
2932 {
2933 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002934 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2935 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002936 return ValueObjectSP();
2937 }
2938 }
2939 else // other layers do expand
2940 {
2941 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002942 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2943 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002944 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002945 root = child_valobj_sp;
2946 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002947 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002948 continue;
2949 }
Enrico Granataef238c12015-03-12 22:30:58 +00002950 else
Enrico Granata8c9d3562011-08-11 17:08:01 +00002951 {
Enrico Granataef238c12015-03-12 22:30:58 +00002952 switch (options.m_synthetic_children_traversal)
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002953 {
Enrico Granataef238c12015-03-12 22:30:58 +00002954 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None:
2955 break;
2956 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic:
2957 if (root->IsSynthetic())
2958 {
2959 child_valobj_sp = root->GetNonSyntheticValue();
2960 if (child_valobj_sp.get())
2961 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2962 }
2963 break;
2964 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic:
2965 if (!root->IsSynthetic())
2966 {
2967 child_valobj_sp = root->GetSyntheticValue();
2968 if (child_valobj_sp.get())
2969 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2970 }
2971 break;
2972 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both:
2973 if (root->IsSynthetic())
2974 {
2975 child_valobj_sp = root->GetNonSyntheticValue();
2976 if (child_valobj_sp.get())
2977 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2978 }
2979 else
2980 {
2981 child_valobj_sp = root->GetSyntheticValue();
2982 if (child_valobj_sp.get())
2983 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2984 }
2985 break;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002986 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002987 }
2988
2989 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2990 // so we hit the "else" branch, and return an error
2991 if(child_valobj_sp.get()) // if it worked, move on
2992 {
2993 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002994 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002995 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002996 continue;
2997 }
2998 else
2999 {
3000 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003001 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3002 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003003 return ValueObjectSP();
3004 }
3005 }
3006 break;
3007 }
3008 case '[':
3009 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003010 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 +00003011 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003012 if (!root_compiler_type_info.Test(eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003013 {
Enrico Granataef238c12015-03-12 22:30:58 +00003014 if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None) // ...only chance left is synthetic
Enrico Granata27b625e2011-08-09 01:04:56 +00003015 {
3016 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003017 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3018 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003019 return ValueObjectSP();
3020 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003021 }
3022 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3023 {
3024 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003025 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3026 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003027 return ValueObjectSP();
3028 }
3029 }
3030 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3031 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003032 if (!root_compiler_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003033 {
3034 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003035 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3036 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003037 return ValueObjectSP();
3038 }
3039 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
3040 {
3041 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003042 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3043 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003044 return root;
3045 }
3046 }
3047 const char *separator_position = ::strchr(expression_cstr+1,'-');
3048 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3049 if (!close_bracket_position) // if there is no ], this is a syntax error
3050 {
3051 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003052 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3053 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003054 return ValueObjectSP();
3055 }
3056 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3057 {
3058 char *end = NULL;
3059 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3060 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3061 {
3062 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003063 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3064 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003065 return ValueObjectSP();
3066 }
3067 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3068 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003069 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003070 {
3071 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003072 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3073 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003074 return root;
3075 }
3076 else
3077 {
3078 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003079 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3080 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003081 return ValueObjectSP();
3082 }
3083 }
3084 // from here on we do have a valid index
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003085 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003086 {
Greg Claytondaf515f2011-07-09 20:12:33 +00003087 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
3088 if (!child_valobj_sp)
Bruce Mitchener11d86362015-02-26 23:55:39 +00003089 child_valobj_sp = root->GetSyntheticArrayMember(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003090 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00003091 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
3092 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00003093 if (child_valobj_sp)
3094 {
3095 root = child_valobj_sp;
3096 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003097 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00003098 continue;
3099 }
3100 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003101 {
3102 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003103 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3104 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003105 return ValueObjectSP();
3106 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003107 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003108 else if (root_compiler_type_info.Test(eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003109 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003110 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 +00003111 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003112 {
3113 Error error;
3114 root = root->Dereference(error);
3115 if (error.Fail() || !root.get())
3116 {
3117 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003118 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3119 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003120 return ValueObjectSP();
3121 }
3122 else
3123 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003124 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003125 continue;
3126 }
3127 }
3128 else
3129 {
Greg Clayton99558cc42015-08-24 23:46:31 +00003130 if (root->GetCompilerType().GetMinimumLanguage() == eLanguageTypeObjC
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003131 && pointee_compiler_type_info.AllClear(eTypeIsPointer)
Greg Clayton84db9102012-03-26 23:03:23 +00003132 && root->HasSyntheticValue()
Enrico Granataef238c12015-03-12 22:30:58 +00003133 && (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic ||
3134 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both))
Enrico Granata27b625e2011-08-09 01:04:56 +00003135 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003136 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003137 }
3138 else
Bruce Mitchener11d86362015-02-26 23:55:39 +00003139 root = root->GetSyntheticArrayMember(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003140 if (!root.get())
3141 {
3142 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003143 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3144 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003145 return ValueObjectSP();
3146 }
3147 else
3148 {
3149 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003150 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003151 continue;
3152 }
3153 }
3154 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003155 else if (root_compiler_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003156 {
3157 root = root->GetSyntheticBitFieldChild(index, index, true);
3158 if (!root.get())
3159 {
3160 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003161 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3162 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003163 return ValueObjectSP();
3164 }
3165 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3166 {
3167 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003168 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3169 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003170 return root;
3171 }
3172 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003173 else if (root_compiler_type_info.Test(eTypeIsVector))
Enrico Granata08a1bb82013-06-19 00:00:45 +00003174 {
3175 root = root->GetChildAtIndex(index, true);
3176 if (!root.get())
3177 {
3178 *first_unparsed = expression_cstr;
3179 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3180 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3181 return ValueObjectSP();
3182 }
3183 else
3184 {
3185 *first_unparsed = end+1; // skip ]
3186 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3187 continue;
3188 }
3189 }
Enrico Granataef238c12015-03-12 22:30:58 +00003190 else if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic ||
3191 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both)
Enrico Granata27b625e2011-08-09 01:04:56 +00003192 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003193 if (root->HasSyntheticValue())
3194 root = root->GetSyntheticValue();
3195 else if (!root->IsSynthetic())
3196 {
3197 *first_unparsed = expression_cstr;
3198 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3199 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3200 return ValueObjectSP();
3201 }
3202 // if we are here, then root itself is a synthetic VO.. should be good to go
3203
Enrico Granata27b625e2011-08-09 01:04:56 +00003204 if (!root.get())
3205 {
3206 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003207 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3208 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3209 return ValueObjectSP();
3210 }
3211 root = root->GetChildAtIndex(index, true);
3212 if (!root.get())
3213 {
3214 *first_unparsed = expression_cstr;
3215 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3216 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003217 return ValueObjectSP();
3218 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00003219 else
3220 {
3221 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003222 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00003223 continue;
3224 }
Enrico Granata27b625e2011-08-09 01:04:56 +00003225 }
3226 else
3227 {
3228 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003229 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3230 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003231 return ValueObjectSP();
3232 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003233 }
3234 else // we have a low and a high index
3235 {
3236 char *end = NULL;
3237 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3238 if (!end || end != separator_position) // if something weird is in our way return an error
3239 {
3240 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003241 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3242 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003243 return ValueObjectSP();
3244 }
3245 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3246 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3247 {
3248 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003249 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3250 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003251 return ValueObjectSP();
3252 }
3253 if (index_lower > index_higher) // swap indices if required
3254 {
3255 unsigned long temp = index_lower;
3256 index_lower = index_higher;
3257 index_higher = temp;
3258 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003259 if (root_compiler_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003260 {
3261 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3262 if (!root.get())
3263 {
3264 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003265 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3266 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003267 return ValueObjectSP();
3268 }
3269 else
3270 {
3271 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003272 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3273 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003274 return root;
3275 }
3276 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003277 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 +00003278 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003279 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003280 {
3281 Error error;
3282 root = root->Dereference(error);
3283 if (error.Fail() || !root.get())
3284 {
3285 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003286 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3287 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003288 return ValueObjectSP();
3289 }
3290 else
3291 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003292 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003293 continue;
3294 }
3295 }
3296 else
3297 {
3298 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003299 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3300 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003301 return root;
3302 }
3303 }
3304 break;
3305 }
3306 default: // some non-separator is in the way
3307 {
3308 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003309 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3310 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003311 return ValueObjectSP();
3312 break;
3313 }
3314 }
3315 }
3316}
3317
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003318int
3319ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3320 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00003321 ValueObjectSP root,
3322 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003323 ExpressionPathScanEndReason* reason_to_stop,
3324 ExpressionPathEndResultType* final_result,
3325 const GetValueForExpressionPathOptions& options,
3326 ExpressionPathAftermath* what_next)
3327{
3328 if (!root.get())
3329 return 0;
3330
3331 *first_unparsed = expression_cstr;
3332
3333 while (true)
3334 {
3335
3336 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3337
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003338 CompilerType root_compiler_type = root->GetCompilerType();
3339 CompilerType pointee_compiler_type;
3340 Flags pointee_compiler_type_info;
3341 Flags root_compiler_type_info(root_compiler_type.GetTypeInfo(&pointee_compiler_type));
3342 if (pointee_compiler_type)
3343 pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003344
3345 if (!expression_cstr || *expression_cstr == '\0')
3346 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003347 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003348 list->Append(root);
3349 return 1;
3350 }
3351
3352 switch (*expression_cstr)
3353 {
3354 case '[':
3355 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003356 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 +00003357 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003358 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 +00003359 {
3360 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003361 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3362 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003363 return 0;
3364 }
3365 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3366 {
3367 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003368 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3369 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003370 return 0;
3371 }
3372 }
3373 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3374 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003375 if (!root_compiler_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003376 {
3377 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003378 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3379 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003380 return 0;
3381 }
3382 else // expand this into list
3383 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003384 const size_t max_index = root->GetNumChildren() - 1;
3385 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003386 {
3387 ValueObjectSP child =
3388 root->GetChildAtIndex(index, true);
3389 list->Append(child);
3390 }
3391 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003392 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3393 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003394 return max_index; // tell me number of items I added to the VOList
3395 }
3396 }
3397 const char *separator_position = ::strchr(expression_cstr+1,'-');
3398 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3399 if (!close_bracket_position) // if there is no ], this is a syntax error
3400 {
3401 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003402 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3403 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003404 return 0;
3405 }
3406 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3407 {
3408 char *end = NULL;
3409 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3410 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3411 {
3412 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003413 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3414 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003415 return 0;
3416 }
3417 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3418 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003419 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003420 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003421 const size_t max_index = root->GetNumChildren() - 1;
3422 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003423 {
3424 ValueObjectSP child =
3425 root->GetChildAtIndex(index, true);
3426 list->Append(child);
3427 }
3428 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003429 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3430 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003431 return max_index; // tell me number of items I added to the VOList
3432 }
3433 else
3434 {
3435 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003436 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3437 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003438 return 0;
3439 }
3440 }
3441 // from here on we do have a valid index
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003442 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003443 {
3444 root = root->GetChildAtIndex(index, true);
3445 if (!root.get())
3446 {
3447 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003448 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3449 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003450 return 0;
3451 }
3452 else
3453 {
3454 list->Append(root);
3455 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003456 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3457 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003458 return 1;
3459 }
3460 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003461 else if (root_compiler_type_info.Test(eTypeIsPointer))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003462 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003463 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 +00003464 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003465 {
3466 Error error;
3467 root = root->Dereference(error);
3468 if (error.Fail() || !root.get())
3469 {
3470 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003471 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3472 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003473 return 0;
3474 }
3475 else
3476 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003477 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003478 continue;
3479 }
3480 }
3481 else
3482 {
Bruce Mitchener11d86362015-02-26 23:55:39 +00003483 root = root->GetSyntheticArrayMember(index, true);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003484 if (!root.get())
3485 {
3486 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003487 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3488 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003489 return 0;
3490 }
3491 else
3492 {
3493 list->Append(root);
3494 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003495 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3496 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003497 return 1;
3498 }
3499 }
3500 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003501 else /*if (ClangASTContext::IsScalarType(root_compiler_type))*/
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003502 {
3503 root = root->GetSyntheticBitFieldChild(index, index, true);
3504 if (!root.get())
3505 {
3506 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003507 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3508 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003509 return 0;
3510 }
3511 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3512 {
3513 list->Append(root);
3514 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003515 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3516 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003517 return 1;
3518 }
3519 }
3520 }
3521 else // we have a low and a high index
3522 {
3523 char *end = NULL;
3524 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3525 if (!end || end != separator_position) // if something weird is in our way return an error
3526 {
3527 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003528 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3529 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003530 return 0;
3531 }
3532 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3533 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3534 {
3535 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003536 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3537 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003538 return 0;
3539 }
3540 if (index_lower > index_higher) // swap indices if required
3541 {
3542 unsigned long temp = index_lower;
3543 index_lower = index_higher;
3544 index_higher = temp;
3545 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003546 if (root_compiler_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003547 {
3548 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3549 if (!root.get())
3550 {
3551 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003552 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3553 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003554 return 0;
3555 }
3556 else
3557 {
3558 list->Append(root);
3559 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003560 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3561 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003562 return 1;
3563 }
3564 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003565 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 +00003566 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003567 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003568 {
3569 Error error;
3570 root = root->Dereference(error);
3571 if (error.Fail() || !root.get())
3572 {
3573 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003574 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3575 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003576 return 0;
3577 }
3578 else
3579 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003580 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003581 continue;
3582 }
3583 }
3584 else
3585 {
Johnny Chen44805302011-07-19 19:48:13 +00003586 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003587 index <= index_higher; index++)
3588 {
3589 ValueObjectSP child =
3590 root->GetChildAtIndex(index, true);
3591 list->Append(child);
3592 }
3593 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003594 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3595 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003596 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3597 }
3598 }
3599 break;
3600 }
3601 default: // some non-[ separator, or something entirely wrong, is in the way
3602 {
3603 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003604 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3605 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003606 return 0;
3607 break;
3608 }
3609 }
3610 }
3611}
3612
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003613void
3614ValueObject::LogValueObject (Log *log)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003615{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003616 if (log)
Enrico Granatad5957332015-06-03 20:43:54 +00003617 return LogValueObject (log, DumpValueObjectOptions(*this));
Greg Clayton1d3afba2010-10-05 00:00:42 +00003618}
3619
Enrico Granata0c489f52012-03-01 04:24:26 +00003620void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003621ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003622{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003623 if (log)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003624 {
3625 StreamString s;
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003626 Dump (s, options);
Greg Claytonf830dbb2012-03-22 18:15:37 +00003627 if (s.GetSize())
3628 log->PutCString(s.GetData());
3629 }
3630}
3631
3632void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003633ValueObject::Dump (Stream &s)
Enrico Granata0c489f52012-03-01 04:24:26 +00003634{
Enrico Granatad5957332015-06-03 20:43:54 +00003635 Dump (s, DumpValueObjectOptions(*this));
Enrico Granata0c489f52012-03-01 04:24:26 +00003636}
3637
3638void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003639ValueObject::Dump (Stream &s,
3640 const DumpValueObjectOptions& options)
Enrico Granata0c489f52012-03-01 04:24:26 +00003641{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003642 ValueObjectPrinter printer(this,&s,options);
3643 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003644}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003645
3646ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003647ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003648{
3649 ValueObjectSP valobj_sp;
3650
Enrico Granatac3e320a2011-08-02 17:27:39 +00003651 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003652 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003653 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003654
3655 DataExtractor data;
3656 data.SetByteOrder (m_data.GetByteOrder());
3657 data.SetAddressByteSize(m_data.GetAddressByteSize());
3658
Enrico Granata9f1e2042012-04-24 22:15:37 +00003659 if (IsBitfield())
3660 {
3661 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
Greg Clayton57ee3062013-07-11 22:46:58 +00003662 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Enrico Granata9f1e2042012-04-24 22:15:37 +00003663 }
3664 else
Greg Clayton57ee3062013-07-11 22:46:58 +00003665 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003666
3667 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton99558cc42015-08-24 23:46:31 +00003668 GetCompilerType(),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003669 name,
3670 data,
3671 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003672 }
Jim Ingham6035b672011-03-31 00:19:25 +00003673
3674 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003675 {
Greg Claytoneeb15652013-12-10 23:16:40 +00003676 ExecutionContext exe_ctx (GetExecutionContextRef());
3677 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003678 }
3679 return valobj_sp;
3680}
3681
Enrico Granata538a88a2014-10-09 18:24:30 +00003682ValueObjectSP
3683ValueObject::GetQualifiedRepresentationIfAvailable (lldb::DynamicValueType dynValue,
3684 bool synthValue)
3685{
3686 ValueObjectSP result_sp(GetSP());
3687
3688 switch (dynValue)
3689 {
3690 case lldb::eDynamicCanRunTarget:
3691 case lldb::eDynamicDontRunTarget:
3692 {
3693 if (!result_sp->IsDynamic())
3694 {
3695 if (result_sp->GetDynamicValue(dynValue))
3696 result_sp = result_sp->GetDynamicValue(dynValue);
3697 }
3698 }
3699 break;
3700 case lldb::eNoDynamicValues:
Enrico Granata538a88a2014-10-09 18:24:30 +00003701 {
3702 if (result_sp->IsDynamic())
3703 {
3704 if (result_sp->GetStaticValue())
3705 result_sp = result_sp->GetStaticValue();
3706 }
3707 }
3708 break;
3709 }
3710
3711 if (synthValue)
3712 {
3713 if (!result_sp->IsSynthetic())
3714 {
3715 if (result_sp->GetSyntheticValue())
3716 result_sp = result_sp->GetSyntheticValue();
3717 }
3718 }
3719 else
3720 {
3721 if (result_sp->IsSynthetic())
3722 {
3723 if (result_sp->GetNonSyntheticValue())
3724 result_sp = result_sp->GetNonSyntheticValue();
3725 }
3726 }
3727
3728 return result_sp;
3729}
3730
Greg Clayton759e7442014-07-19 00:12:57 +00003731lldb::addr_t
3732ValueObject::GetCPPVTableAddress (AddressType &address_type)
3733{
Greg Claytona1e5dc82015-08-11 22:53:00 +00003734 CompilerType pointee_type;
Greg Clayton99558cc42015-08-24 23:46:31 +00003735 CompilerType this_type(GetCompilerType());
Greg Clayton759e7442014-07-19 00:12:57 +00003736 uint32_t type_info = this_type.GetTypeInfo(&pointee_type);
3737 if (type_info)
3738 {
3739 bool ptr_or_ref = false;
Enrico Granata622be232014-10-21 20:52:14 +00003740 if (type_info & (eTypeIsPointer | eTypeIsReference))
Greg Clayton759e7442014-07-19 00:12:57 +00003741 {
3742 ptr_or_ref = true;
3743 type_info = pointee_type.GetTypeInfo();
3744 }
3745
Enrico Granata622be232014-10-21 20:52:14 +00003746 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus;
Greg Clayton759e7442014-07-19 00:12:57 +00003747 if ((type_info & cpp_class) == cpp_class)
3748 {
3749 if (ptr_or_ref)
3750 {
3751 address_type = GetAddressTypeOfChildren();
3752 return GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
3753 }
3754 else
3755 return GetAddressOf (false, &address_type);
3756 }
3757 }
3758
3759 address_type = eAddressTypeInvalid;
3760 return LLDB_INVALID_ADDRESS;
3761}
3762
Greg Claytonafacd142011-09-02 01:15:17 +00003763ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003764ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003765{
Jim Ingham58b59f92011-04-22 23:53:53 +00003766 if (m_deref_valobj)
3767 return m_deref_valobj->GetSP();
Chaoren Lind7bdc272015-07-31 00:35:40 +00003768
3769 const bool is_pointer_or_reference_type = IsPointerOrReferenceType();
3770 if (is_pointer_or_reference_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003771 {
3772 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003773 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003774
3775 std::string child_name_str;
3776 uint32_t child_byte_size = 0;
3777 int32_t child_byte_offset = 0;
3778 uint32_t child_bitfield_bit_size = 0;
3779 uint32_t child_bitfield_bit_offset = 0;
3780 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003781 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003782 const bool transparent_pointers = false;
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003783 CompilerType compiler_type = GetCompilerType();
3784 CompilerType child_compiler_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003785
Greg Claytoncc4d0142012-02-17 07:49:44 +00003786 ExecutionContext exe_ctx (GetExecutionContextRef());
Chaoren Lind7bdc272015-07-31 00:35:40 +00003787
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003788 child_compiler_type = compiler_type.GetChildCompilerTypeAtIndex (&exe_ctx,
3789 0,
3790 transparent_pointers,
3791 omit_empty_base_classes,
3792 ignore_array_bounds,
3793 child_name_str,
3794 child_byte_size,
3795 child_byte_offset,
3796 child_bitfield_bit_size,
3797 child_bitfield_bit_offset,
3798 child_is_base_class,
3799 child_is_deref_of_parent,
3800 this);
3801 if (child_compiler_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003802 {
3803 ConstString child_name;
3804 if (!child_name_str.empty())
3805 child_name.SetCString (child_name_str.c_str());
3806
Jim Ingham58b59f92011-04-22 23:53:53 +00003807 m_deref_valobj = new ValueObjectChild (*this,
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003808 child_compiler_type,
Jim Ingham58b59f92011-04-22 23:53:53 +00003809 child_name,
3810 child_byte_size,
3811 child_byte_offset,
3812 child_bitfield_bit_size,
3813 child_bitfield_bit_offset,
3814 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003815 child_is_deref_of_parent,
3816 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003817 }
3818 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003819
Jim Ingham58b59f92011-04-22 23:53:53 +00003820 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003821 {
3822 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003823 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003824 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003825 else
3826 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003827 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003828 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003829
Chaoren Lind7bdc272015-07-31 00:35:40 +00003830 if (is_pointer_or_reference_type)
Greg Clayton54979cd2010-12-15 05:08:08 +00003831 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3832 else
Chaoren Lind7bdc272015-07-31 00:35:40 +00003833 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 +00003834 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003835 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003836}
3837
Greg Claytonafacd142011-09-02 01:15:17 +00003838ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003839ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003840{
Jim Ingham78a685a2011-04-16 00:01:13 +00003841 if (m_addr_of_valobj_sp)
3842 return m_addr_of_valobj_sp;
3843
Greg Claytone0d378b2011-03-24 21:19:54 +00003844 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003845 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003846 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003847 error.Clear();
Siva Chandraa3747a92015-05-04 19:43:34 +00003848 if (addr != LLDB_INVALID_ADDRESS && address_type != eAddressTypeHost)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003849 {
3850 switch (address_type)
3851 {
3852 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003853 {
3854 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003855 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003856 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3857 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003858 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003859
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003860 case eAddressTypeFile:
3861 case eAddressTypeLoad:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003862 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003863 CompilerType compiler_type = GetCompilerType();
3864 if (compiler_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003865 {
3866 std::string name (1, '&');
3867 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003868 ExecutionContext exe_ctx (GetExecutionContextRef());
3869 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003870 compiler_type.GetPointerType(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003871 ConstString (name.c_str()),
3872 addr,
3873 eAddressTypeInvalid,
3874 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003875 }
3876 }
3877 break;
Siva Chandraa3747a92015-05-04 19:43:34 +00003878 default:
3879 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003880 }
3881 }
Sean Callananed185ab2013-04-19 19:47:32 +00003882 else
3883 {
3884 StreamString expr_path_strm;
3885 GetExpressionPath(expr_path_strm, true);
3886 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3887 }
3888
Jim Ingham78a685a2011-04-16 00:01:13 +00003889 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003890}
3891
Greg Clayton9a142cf2012-02-03 05:34:10 +00003892ValueObjectSP
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003893ValueObject::Cast (const CompilerType &compiler_type)
Greg Clayton9a142cf2012-02-03 05:34:10 +00003894{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003895 return ValueObjectCast::Create (*this, GetName(), compiler_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003896}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003897
Greg Claytonafacd142011-09-02 01:15:17 +00003898ValueObjectSP
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003899ValueObject::CastPointerType (const char *name, CompilerType &compiler_type)
Greg Claytonb2dcc362011-05-05 23:32:56 +00003900{
Greg Claytonafacd142011-09-02 01:15:17 +00003901 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003902 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003903 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003904
3905 if (ptr_value != LLDB_INVALID_ADDRESS)
3906 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003907 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003908 ExecutionContext exe_ctx (GetExecutionContextRef());
3909 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003910 name,
3911 ptr_addr,
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003912 compiler_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003913 }
3914 return valobj_sp;
3915}
3916
Greg Claytonafacd142011-09-02 01:15:17 +00003917ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003918ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3919{
Greg Claytonafacd142011-09-02 01:15:17 +00003920 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003921 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003922 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003923
3924 if (ptr_value != LLDB_INVALID_ADDRESS)
3925 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003926 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003927 ExecutionContext exe_ctx (GetExecutionContextRef());
3928 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003929 name,
3930 ptr_addr,
3931 type_sp);
3932 }
3933 return valobj_sp;
3934}
3935
Jim Ingham6035b672011-03-31 00:19:25 +00003936ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003937 m_mod_id(),
3938 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003939 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003940{
3941}
3942
3943ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003944 m_mod_id(),
3945 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003946 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003947{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003948 ExecutionContext exe_ctx(exe_scope);
3949 TargetSP target_sp (exe_ctx.GetTargetSP());
3950 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003951 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003952 m_exe_ctx_ref.SetTargetSP (target_sp);
3953 ProcessSP process_sp (exe_ctx.GetProcessSP());
3954 if (!process_sp)
3955 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003956
Greg Claytoncc4d0142012-02-17 07:49:44 +00003957 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003958 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003959 m_mod_id = process_sp->GetModID();
3960 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003961
Greg Claytoncc4d0142012-02-17 07:49:44 +00003962 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003963
Greg Claytoncc4d0142012-02-17 07:49:44 +00003964 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003965 {
3966 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003967 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003968 }
Jim Ingham6035b672011-03-31 00:19:25 +00003969
Greg Claytoncc4d0142012-02-17 07:49:44 +00003970 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003971 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003972 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003973
Jason Molendab57e4a12013-11-04 09:33:30 +00003974 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003975 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003976 {
3977 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003978 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003979 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003980 if (frame_sp)
3981 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003982 }
3983 }
3984 }
Jim Ingham6035b672011-03-31 00:19:25 +00003985}
3986
3987ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003988 m_mod_id(),
3989 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003990 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003991{
3992}
3993
3994ValueObject::EvaluationPoint::~EvaluationPoint ()
3995{
3996}
3997
Jim Ingham6035b672011-03-31 00:19:25 +00003998// This function checks the EvaluationPoint against the current process state. If the current
3999// state matches the evaluation point, or the evaluation point is already invalid, then we return
4000// false, meaning "no change". If the current state is different, we update our state, and return
4001// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
4002// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00004003// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00004004
4005bool
Enrico Granatabb642e52015-05-16 01:27:00 +00004006ValueObject::EvaluationPoint::SyncWithProcessState(bool accept_invalid_exe_ctx)
Jim Ingham6035b672011-03-31 00:19:25 +00004007{
Jim Ingham73ca05a2011-12-17 01:35:57 +00004008 // 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 +00004009 const bool thread_and_frame_only_if_stopped = true;
4010 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
Jim Ingham73ca05a2011-12-17 01:35:57 +00004011
Greg Claytoncc4d0142012-02-17 07:49:44 +00004012 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00004013 return false;
4014
Jim Ingham6035b672011-03-31 00:19:25 +00004015 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00004016 Process *process = exe_ctx.GetProcessPtr();
4017 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00004018 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00004019
Jim Ingham6035b672011-03-31 00:19:25 +00004020 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00004021 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00004022
Jim Ingham78a685a2011-04-16 00:01:13 +00004023 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
4024 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00004025 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00004026 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00004027
Greg Clayton23f59502012-07-17 03:23:13 +00004028 bool changed = false;
4029 const bool was_valid = m_mod_id.IsValid();
4030 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004031 {
4032 if (m_mod_id == current_mod_id)
4033 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00004034 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004035 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00004036 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004037 }
Jim Ingham9ee01152011-12-10 01:49:43 +00004038 else
4039 {
4040 m_mod_id = current_mod_id;
4041 m_needs_update = true;
4042 changed = true;
4043 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004044 }
Jim Ingham6035b672011-03-31 00:19:25 +00004045
Jim Ingham73ca05a2011-12-17 01:35:57 +00004046 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
4047 // That way we'll be sure to return a valid exe_scope.
4048 // 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 +00004049
Enrico Granatabb642e52015-05-16 01:27:00 +00004050 if (!accept_invalid_exe_ctx)
Jim Ingham6035b672011-03-31 00:19:25 +00004051 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004052 if (m_exe_ctx_ref.HasThreadRef())
Greg Clayton262f80d2011-07-06 16:49:27 +00004053 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004054 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
4055 if (thread_sp)
Greg Claytoncc4d0142012-02-17 07:49:44 +00004056 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004057 if (m_exe_ctx_ref.HasFrameRef())
Greg Claytoncc4d0142012-02-17 07:49:44 +00004058 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004059 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
4060 if (!frame_sp)
4061 {
4062 // We used to have a frame, but now it is gone
4063 SetInvalid();
4064 changed = was_valid;
4065 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00004066 }
4067 }
Enrico Granatabb642e52015-05-16 01:27:00 +00004068 else
4069 {
4070 // We used to have a thread, but now it is gone
4071 SetInvalid();
4072 changed = was_valid;
4073 }
Greg Clayton262f80d2011-07-06 16:49:27 +00004074 }
Jim Ingham6035b672011-03-31 00:19:25 +00004075 }
Enrico Granatabb642e52015-05-16 01:27:00 +00004076
Jim Ingham9ee01152011-12-10 01:49:43 +00004077 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00004078}
4079
Jim Ingham61be0902011-05-02 18:13:59 +00004080void
4081ValueObject::EvaluationPoint::SetUpdated ()
4082{
Greg Claytoncc4d0142012-02-17 07:49:44 +00004083 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
4084 if (process_sp)
4085 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00004086 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00004087}
4088
4089
Enrico Granataf2bbf712011-07-15 02:26:42 +00004090
4091void
Enrico Granata86cc9822012-03-19 22:58:49 +00004092ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004093{
Enrico Granata86cc9822012-03-19 22:58:49 +00004094 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4095 m_value_str.clear();
4096
4097 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4098 m_location_str.clear();
4099
4100 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
Enrico Granata86cc9822012-03-19 22:58:49 +00004101 m_summary_str.clear();
Enrico Granata86cc9822012-03-19 22:58:49 +00004102
4103 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4104 m_object_desc_str.clear();
4105
4106 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4107 {
4108 if (m_synthetic_value)
4109 m_synthetic_value = NULL;
4110 }
Enrico Granata744794a2014-09-05 21:46:22 +00004111
4112 if ((clear_mask & eClearUserVisibleDataItemsValidator) == eClearUserVisibleDataItemsValidator)
4113 m_validation_result.reset();
Johnny Chen44805302011-07-19 19:48:13 +00004114}
Enrico Granata9128ee22011-09-06 19:20:51 +00004115
4116SymbolContextScope *
4117ValueObject::GetSymbolContextScope()
4118{
4119 if (m_parent)
4120 {
4121 if (!m_parent->IsPointerOrReferenceType())
4122 return m_parent->GetSymbolContextScope();
4123 }
4124 return NULL;
4125}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004126
4127lldb::ValueObjectSP
4128ValueObject::CreateValueObjectFromExpression (const char* name,
4129 const char* expression,
4130 const ExecutionContext& exe_ctx)
4131{
Enrico Granata972be532014-12-17 21:18:43 +00004132 return CreateValueObjectFromExpression(name, expression, exe_ctx, EvaluateExpressionOptions());
4133}
4134
4135
4136lldb::ValueObjectSP
4137ValueObject::CreateValueObjectFromExpression (const char* name,
4138 const char* expression,
4139 const ExecutionContext& exe_ctx,
4140 const EvaluateExpressionOptions& options)
4141{
Enrico Granatab2698cd2012-09-13 18:27:09 +00004142 lldb::ValueObjectSP retval_sp;
4143 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4144 if (!target_sp)
4145 return retval_sp;
4146 if (!expression || !*expression)
4147 return retval_sp;
4148 target_sp->EvaluateExpression (expression,
4149 exe_ctx.GetFrameSP().get(),
Enrico Granata972be532014-12-17 21:18:43 +00004150 retval_sp,
4151 options);
Enrico Granatab2698cd2012-09-13 18:27:09 +00004152 if (retval_sp && name && *name)
4153 retval_sp->SetName(ConstString(name));
4154 return retval_sp;
4155}
4156
4157lldb::ValueObjectSP
4158ValueObject::CreateValueObjectFromAddress (const char* name,
4159 uint64_t address,
4160 const ExecutionContext& exe_ctx,
Greg Claytona1e5dc82015-08-11 22:53:00 +00004161 CompilerType type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004162{
Greg Clayton57ee3062013-07-11 22:46:58 +00004163 if (type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004164 {
Greg Claytona1e5dc82015-08-11 22:53:00 +00004165 CompilerType pointer_type(type.GetPointerType());
Greg Clayton57ee3062013-07-11 22:46:58 +00004166 if (pointer_type)
4167 {
4168 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4169 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4170 pointer_type,
4171 ConstString(name),
4172 buffer,
Enrico Granata972be532014-12-17 21:18:43 +00004173 exe_ctx.GetByteOrder(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004174 exe_ctx.GetAddressByteSize()));
4175 if (ptr_result_valobj_sp)
4176 {
4177 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4178 Error err;
4179 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4180 if (ptr_result_valobj_sp && name && *name)
4181 ptr_result_valobj_sp->SetName(ConstString(name));
4182 }
4183 return ptr_result_valobj_sp;
4184 }
Enrico Granatab2698cd2012-09-13 18:27:09 +00004185 }
Greg Clayton57ee3062013-07-11 22:46:58 +00004186 return lldb::ValueObjectSP();
Enrico Granatab2698cd2012-09-13 18:27:09 +00004187}
4188
4189lldb::ValueObjectSP
4190ValueObject::CreateValueObjectFromData (const char* name,
Enrico Granata7ca1c762014-03-31 23:02:25 +00004191 const DataExtractor& data,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004192 const ExecutionContext& exe_ctx,
Greg Claytona1e5dc82015-08-11 22:53:00 +00004193 CompilerType type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004194{
4195 lldb::ValueObjectSP new_value_sp;
4196 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004197 type,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004198 ConstString(name),
4199 data,
4200 LLDB_INVALID_ADDRESS);
4201 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4202 if (new_value_sp && name && *name)
4203 new_value_sp->SetName(ConstString(name));
4204 return new_value_sp;
4205}
Enrico Granata4873e522013-04-11 22:48:58 +00004206
4207ModuleSP
4208ValueObject::GetModule ()
4209{
4210 ValueObject* root(GetRoot());
4211 if (root != this)
4212 return root->GetModule();
4213 return lldb::ModuleSP();
4214}
4215
4216ValueObject*
4217ValueObject::GetRoot ()
4218{
4219 if (m_root)
4220 return m_root;
Enrico Granatade61eba2015-01-22 03:07:34 +00004221 return (m_root = FollowParentChain( [] (ValueObject* vo) -> bool {
4222 return (vo->m_parent != nullptr);
4223 }));
4224}
4225
4226ValueObject*
4227ValueObject::FollowParentChain (std::function<bool(ValueObject*)> f)
4228{
4229 ValueObject* vo = this;
4230 while (vo)
Enrico Granata4873e522013-04-11 22:48:58 +00004231 {
Enrico Granatade61eba2015-01-22 03:07:34 +00004232 if (f(vo) == false)
4233 break;
4234 vo = vo->m_parent;
Enrico Granata4873e522013-04-11 22:48:58 +00004235 }
Enrico Granatade61eba2015-01-22 03:07:34 +00004236 return vo;
Enrico Granata4873e522013-04-11 22:48:58 +00004237}
4238
4239AddressType
4240ValueObject::GetAddressTypeOfChildren()
4241{
4242 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
4243 {
4244 ValueObject* root(GetRoot());
4245 if (root != this)
4246 return root->GetAddressTypeOfChildren();
4247 }
4248 return m_address_type_of_ptr_or_ref_children;
4249}
4250
4251lldb::DynamicValueType
4252ValueObject::GetDynamicValueType ()
4253{
4254 ValueObject* with_dv_info = this;
4255 while (with_dv_info)
4256 {
4257 if (with_dv_info->HasDynamicValueTypeInfo())
4258 return with_dv_info->GetDynamicValueTypeImpl();
4259 with_dv_info = with_dv_info->m_parent;
4260 }
4261 return lldb::eNoDynamicValues;
4262}
Enrico Granata39d51412013-05-31 17:43:40 +00004263
Enrico Granata4873e522013-04-11 22:48:58 +00004264lldb::Format
4265ValueObject::GetFormat () const
4266{
4267 const ValueObject* with_fmt_info = this;
4268 while (with_fmt_info)
4269 {
4270 if (with_fmt_info->m_format != lldb::eFormatDefault)
4271 return with_fmt_info->m_format;
4272 with_fmt_info = with_fmt_info->m_parent;
4273 }
4274 return m_format;
4275}
Enrico Granatad07cfd32014-10-08 18:27:36 +00004276
Enrico Granatac1247f52014-11-06 21:23:20 +00004277lldb::LanguageType
4278ValueObject::GetPreferredDisplayLanguage ()
4279{
Enrico Granataed3228a2015-01-21 01:47:13 +00004280 lldb::LanguageType type = m_preferred_display_language;
4281 if (m_preferred_display_language == lldb::eLanguageTypeUnknown)
Enrico Granatac1247f52014-11-06 21:23:20 +00004282 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004283 if (GetRoot())
Enrico Granatac1247f52014-11-06 21:23:20 +00004284 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004285 if (GetRoot() == this)
Enrico Granatac1247f52014-11-06 21:23:20 +00004286 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004287 if (StackFrameSP frame_sp = GetFrameSP())
4288 {
4289 const SymbolContext& sc(frame_sp->GetSymbolContext(eSymbolContextCompUnit));
4290 if (CompileUnit* cu = sc.comp_unit)
4291 type = cu->GetLanguage();
4292 }
4293 }
4294 else
4295 {
4296 type = GetRoot()->GetPreferredDisplayLanguage();
Enrico Granatac1247f52014-11-06 21:23:20 +00004297 }
4298 }
Enrico Granatac1247f52014-11-06 21:23:20 +00004299 }
Enrico Granataed3228a2015-01-21 01:47:13 +00004300 return (m_preferred_display_language = type); // only compute it once
4301}
4302
4303void
4304ValueObject::SetPreferredDisplayLanguage (lldb::LanguageType lt)
4305{
4306 m_preferred_display_language = lt;
Enrico Granatac1247f52014-11-06 21:23:20 +00004307}
4308
Enrico Granata73e8c4d2015-10-07 02:36:35 +00004309void
4310ValueObject::SetPreferredDisplayLanguageIfNeeded (lldb::LanguageType lt)
4311{
4312 if (m_preferred_display_language == lldb::eLanguageTypeUnknown)
4313 SetPreferredDisplayLanguage(lt);
4314}
4315
Enrico Granatad07cfd32014-10-08 18:27:36 +00004316bool
4317ValueObject::CanProvideValue ()
4318{
Sean Callanan7375f3e2014-12-09 21:18:59 +00004319 // we need to support invalid types as providers of values because some bare-board
4320 // debugging scenarios have no notion of types, but still manage to have raw numeric
4321 // values for things like registers. sigh.
Greg Clayton99558cc42015-08-24 23:46:31 +00004322 const CompilerType &type(GetCompilerType());
Sean Callanan7375f3e2014-12-09 21:18:59 +00004323 return (false == type.IsValid()) || (0 != (type.GetTypeInfo() & eTypeHasValue));
4324}
4325
4326bool
4327ValueObject::IsChecksumEmpty ()
4328{
4329 return m_value_checksum.empty();
Enrico Granatad07cfd32014-10-08 18:27:36 +00004330}
Enrico Granata0c10a852014-12-08 23:13:56 +00004331
4332ValueObjectSP
4333ValueObject::Persist ()
4334{
4335 if (!UpdateValueIfNeeded())
4336 return nullptr;
4337
4338 TargetSP target_sp(GetTargetSP());
4339 if (!target_sp)
4340 return nullptr;
4341
Sean Callananb92bd752015-10-01 16:28:02 +00004342 PersistentExpressionState *persistent_state = target_sp->GetPersistentExpressionStateForLanguage(GetPreferredDisplayLanguage());
Sean Callanan8f1f9a12015-09-30 19:57:57 +00004343
4344 if (!persistent_state)
4345 return nullptr;
4346
4347 ConstString name(persistent_state->GetNextPersistentVariableName());
Enrico Granata0c10a852014-12-08 23:13:56 +00004348
Sean Callanan9301ec12015-10-01 23:07:06 +00004349 ValueObjectSP const_result_sp = ValueObjectConstResult::Create (target_sp.get(), GetValue(), name);
4350
4351 ExpressionVariableSP clang_var_sp = persistent_state->CreatePersistentVariable(const_result_sp);
4352 clang_var_sp->m_live_sp = clang_var_sp->m_frozen_sp;
4353 clang_var_sp->m_flags |= ExpressionVariable::EVIsProgramReference;
Enrico Granata0c10a852014-12-08 23:13:56 +00004354
4355 return clang_var_sp->GetValueObject();
4356}
Enrico Granatae29df232014-12-09 19:51:20 +00004357
4358bool
4359ValueObject::IsSyntheticChildrenGenerated ()
4360{
4361 return m_is_synthetic_children_generated;
4362}
4363
4364void
4365ValueObject::SetSyntheticChildrenGenerated (bool b)
4366{
4367 m_is_synthetic_children_generated = b;
4368}