blob: fa3f1ff76dbb55da1dc89f815e239d1009971309 [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),
Enrico Granatadc62ffd2015-11-09 19:27:34 +0000100 m_language_flags(0),
Greg Clayton288bdf92010-09-02 02:59:18 +0000101 m_value_is_valid (false),
102 m_value_did_change (false),
103 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000104 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000105 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000106 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000107 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000108 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000109 m_is_getting_summary(false),
Enrico Granatae29df232014-12-09 19:51:20 +0000110 m_did_calculate_complete_objc_class_type(false),
111 m_is_synthetic_children_generated(parent.m_is_synthetic_children_generated)
Jim Ingham6035b672011-03-31 00:19:25 +0000112{
Jim Ingham58b59f92011-04-22 23:53:53 +0000113 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000114}
115
116//----------------------------------------------------------------------
117// ValueObject constructor
118//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000119ValueObject::ValueObject (ExecutionContextScope *exe_scope,
120 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000121 UserID (++g_value_obj_uid), // Unique identifier for every value object
122 m_parent (NULL),
Enrico Granata4873e522013-04-11 22:48:58 +0000123 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000124 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000125 m_name (),
126 m_data (),
127 m_value (),
128 m_error (),
129 m_value_str (),
130 m_old_value_str (),
131 m_location_str (),
132 m_summary_str (),
133 m_object_desc_str (),
Enrico Granata744794a2014-09-05 21:46:22 +0000134 m_validation_result(),
Jim Ingham58b59f92011-04-22 23:53:53 +0000135 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000136 m_children (),
137 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000138 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000139 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000140 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000141 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +0000142 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000143 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +0000144 m_type_summary_sp(),
145 m_type_format_sp(),
146 m_synthetic_children_sp(),
Enrico Granata744794a2014-09-05 21:46:22 +0000147 m_type_validator_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000148 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000149 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Sean Callanan7375f3e2014-12-09 21:18:59 +0000150 m_value_checksum(),
Enrico Granataed3228a2015-01-21 01:47:13 +0000151 m_preferred_display_language(lldb::eLanguageTypeUnknown),
Enrico Granatadc62ffd2015-11-09 19:27:34 +0000152 m_language_flags(0),
Jim Ingham6035b672011-03-31 00:19:25 +0000153 m_value_is_valid (false),
154 m_value_did_change (false),
155 m_children_count_valid (false),
156 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000157 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000158 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000159 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000160 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000161 m_is_getting_summary(false),
Enrico Granatae29df232014-12-09 19:51:20 +0000162 m_did_calculate_complete_objc_class_type(false),
163 m_is_synthetic_children_generated(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000164{
Jim Ingham58b59f92011-04-22 23:53:53 +0000165 m_manager = new ValueObjectManager();
166 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000167}
168
169//----------------------------------------------------------------------
170// Destructor
171//----------------------------------------------------------------------
172ValueObject::~ValueObject ()
173{
174}
175
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000176bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000177ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000178{
Enrico Granata4becb372011-06-29 22:27:15 +0000179
Enrico Granata9128ee22011-09-06 19:20:51 +0000180 bool did_change_formats = false;
181
Enrico Granata0a3958e2011-07-02 00:25:22 +0000182 if (update_format)
Enrico Granata5548cb52013-01-28 23:47:25 +0000183 did_change_formats = UpdateFormatsIfNeeded();
Enrico Granata4becb372011-06-29 22:27:15 +0000184
Greg Claytonb71f3842010-10-05 03:13:51 +0000185 // If this is a constant value, then our success is predicated on whether
186 // we have an error or not
187 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000188 {
Enrico Granatab1c6c482013-10-09 00:33:55 +0000189 // if you are constant, things might still have changed behind your back
190 // (e.g. you are a frozen object and things have changed deeper than you cared to freeze-dry yourself)
191 // in this case, your value has not changed, but "computed" entries might have, so you might now have
192 // a different summary, or a different object description. clear these so we will recompute them
Enrico Granata9128ee22011-09-06 19:20:51 +0000193 if (update_format && !did_change_formats)
Enrico Granatab1c6c482013-10-09 00:33:55 +0000194 ClearUserVisibleData(eClearUserVisibleDataItemsSummary | eClearUserVisibleDataItemsDescription);
Greg Claytonb71f3842010-10-05 03:13:51 +0000195 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000196 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000197
Sean Callanan7375f3e2014-12-09 21:18:59 +0000198 bool first_update = IsChecksumEmpty();
Jim Ingham6035b672011-03-31 00:19:25 +0000199
Enrico Granatabb642e52015-05-16 01:27:00 +0000200 if (NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000201 {
Jim Ingham6035b672011-03-31 00:19:25 +0000202 m_update_point.SetUpdated();
203
204 // Save the old value using swap to avoid a string copy which
205 // also will clear our m_value_str
206 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000207 {
Jim Ingham6035b672011-03-31 00:19:25 +0000208 m_old_value_valid = false;
209 }
210 else
211 {
212 m_old_value_valid = true;
213 m_old_value_str.swap (m_value_str);
Enrico Granata86cc9822012-03-19 22:58:49 +0000214 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham6035b672011-03-31 00:19:25 +0000215 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000216
Enrico Granataf2bbf712011-07-15 02:26:42 +0000217 ClearUserVisibleData();
218
Greg Claytonefbc7d22012-03-09 04:23:44 +0000219 if (IsInScope())
Jim Ingham6035b672011-03-31 00:19:25 +0000220 {
Greg Claytonefbc7d22012-03-09 04:23:44 +0000221 const bool value_was_valid = GetValueIsValid();
222 SetValueDidChange (false);
223
224 m_error.Clear();
225
226 // Call the pure virtual function to update the value
Sean Callanan7375f3e2014-12-09 21:18:59 +0000227
228 bool need_compare_checksums = false;
229 llvm::SmallVector<uint8_t, 16> old_checksum;
230
231 if (!first_update && CanProvideValue())
232 {
233 need_compare_checksums = true;
234 old_checksum.resize(m_value_checksum.size());
235 std::copy(m_value_checksum.begin(), m_value_checksum.end(), old_checksum.begin());
236 }
237
Greg Claytonefbc7d22012-03-09 04:23:44 +0000238 bool success = UpdateValue ();
239
240 SetValueIsValid (success);
241
Sean Callanan7375f3e2014-12-09 21:18:59 +0000242 if (success)
243 {
244 const uint64_t max_checksum_size = 128;
245 m_data.Checksum(m_value_checksum,
246 max_checksum_size);
247 }
248 else
249 {
250 need_compare_checksums = false;
251 m_value_checksum.clear();
252 }
253
Enrico Granata20c321c2015-01-08 19:11:43 +0000254 assert (!need_compare_checksums || (!old_checksum.empty() && !m_value_checksum.empty()));
255
Greg Claytonefbc7d22012-03-09 04:23:44 +0000256 if (first_update)
257 SetValueDidChange (false);
258 else if (!m_value_did_change && success == false)
259 {
260 // The value wasn't gotten successfully, so we mark this
261 // as changed if the value used to be valid and now isn't
262 SetValueDidChange (value_was_valid);
263 }
Sean Callanan7375f3e2014-12-09 21:18:59 +0000264 else if (need_compare_checksums)
265 {
266 SetValueDidChange(memcmp(&old_checksum[0], &m_value_checksum[0], m_value_checksum.size()));
267 }
268
Greg Claytonefbc7d22012-03-09 04:23:44 +0000269 }
270 else
271 {
272 m_error.SetErrorString("out of scope");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000273 }
274 }
275 return m_error.Success();
276}
277
Enrico Granata9128ee22011-09-06 19:20:51 +0000278bool
Enrico Granata5548cb52013-01-28 23:47:25 +0000279ValueObject::UpdateFormatsIfNeeded()
Enrico Granata4becb372011-06-29 22:27:15 +0000280{
Enrico Granata4edfef42015-10-06 17:55:14 +0000281 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_DATAFORMATTERS));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000282 if (log)
Enrico Granatad2284832012-10-17 22:23:56 +0000283 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000284 GetName().GetCString(), static_cast<void*>(this),
285 m_last_format_mgr_revision,
286 DataVisualization::GetCurrentRevision());
287
Enrico Granata9128ee22011-09-06 19:20:51 +0000288 bool any_change = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000289
Enrico Granata5548cb52013-01-28 23:47:25 +0000290 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()))
Enrico Granata4becb372011-06-29 22:27:15 +0000291 {
Enrico Granataa0db6ed2014-04-09 21:06:11 +0000292 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
293 any_change = true;
294
Enrico Granata852cc952013-10-08 19:03:22 +0000295 SetValueFormat(DataVisualization::GetFormat (*this, eNoDynamicValues));
Enrico Granata5548cb52013-01-28 23:47:25 +0000296 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000297#ifndef LLDB_DISABLE_PYTHON
Enrico Granata5548cb52013-01-28 23:47:25 +0000298 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000299#endif
Enrico Granata744794a2014-09-05 21:46:22 +0000300 SetValidator(DataVisualization::GetValidator(*this, GetDynamicValueType()));
Enrico Granata4becb372011-06-29 22:27:15 +0000301 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000302
Enrico Granata9128ee22011-09-06 19:20:51 +0000303 return any_change;
Enrico Granata4becb372011-06-29 22:27:15 +0000304}
305
Jim Ingham16e0c682011-08-12 23:34:31 +0000306void
307ValueObject::SetNeedsUpdate ()
308{
309 m_update_point.SetNeedsUpdate();
310 // We have to clear the value string here so ConstResult children will notice if their values are
311 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000312 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000313}
314
Enrico Granata13ac0e22012-10-17 19:03:34 +0000315void
Enrico Granatae3e91512012-10-22 18:18:36 +0000316ValueObject::ClearDynamicTypeInformation ()
Enrico Granata13ac0e22012-10-17 19:03:34 +0000317{
Enrico Granata38c54632013-10-30 00:04:29 +0000318 m_children_count_valid = false;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000319 m_did_calculate_complete_objc_class_type = false;
Enrico Granatae3e91512012-10-22 18:18:36 +0000320 m_last_format_mgr_revision = 0;
Greg Claytona1e5dc82015-08-11 22:53:00 +0000321 m_override_type = CompilerType();
Enrico Granatae3e91512012-10-22 18:18:36 +0000322 SetValueFormat(lldb::TypeFormatImplSP());
323 SetSummaryFormat(lldb::TypeSummaryImplSP());
324 SetSyntheticChildren(lldb::SyntheticChildrenSP());
Enrico Granata13ac0e22012-10-17 19:03:34 +0000325}
326
Greg Claytona1e5dc82015-08-11 22:53:00 +0000327CompilerType
Sean Callanan72772842012-02-22 23:57:45 +0000328ValueObject::MaybeCalculateCompleteType ()
329{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000330 CompilerType compiler_type(GetCompilerTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000331
Sean Callanan72772842012-02-22 23:57:45 +0000332 if (m_did_calculate_complete_objc_class_type)
333 {
334 if (m_override_type.IsValid())
335 return m_override_type;
336 else
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000337 return compiler_type;
Sean Callanan72772842012-02-22 23:57:45 +0000338 }
339
Greg Claytona1e5dc82015-08-11 22:53:00 +0000340 CompilerType class_type;
Greg Clayton57ee3062013-07-11 22:46:58 +0000341 bool is_pointer_type = false;
Sean Callanan72772842012-02-22 23:57:45 +0000342
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000343 if (ClangASTContext::IsObjCObjectPointerType(compiler_type, &class_type))
Sean Callanan72772842012-02-22 23:57:45 +0000344 {
345 is_pointer_type = true;
346 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000347 else if (ClangASTContext::IsObjCObjectOrInterfaceType(compiler_type))
Sean Callanan72772842012-02-22 23:57:45 +0000348 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000349 class_type = compiler_type;
Sean Callanan72772842012-02-22 23:57:45 +0000350 }
351 else
352 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000353 return compiler_type;
Sean Callanan72772842012-02-22 23:57:45 +0000354 }
355
356 m_did_calculate_complete_objc_class_type = true;
357
Greg Clayton57ee3062013-07-11 22:46:58 +0000358 if (class_type)
Sean Callanan72772842012-02-22 23:57:45 +0000359 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000360 ConstString class_name (class_type.GetConstTypeName());
Sean Callanan72772842012-02-22 23:57:45 +0000361
Greg Clayton57ee3062013-07-11 22:46:58 +0000362 if (class_name)
363 {
364 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
365
366 if (process_sp)
367 {
368 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
369
370 if (objc_language_runtime)
371 {
372 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name);
373
374 if (complete_objc_class_type_sp)
375 {
Greg Clayton99558cc42015-08-24 23:46:31 +0000376 CompilerType complete_class(complete_objc_class_type_sp->GetFullCompilerType ());
Greg Clayton57ee3062013-07-11 22:46:58 +0000377
378 if (complete_class.GetCompleteType())
379 {
380 if (is_pointer_type)
381 {
382 m_override_type = complete_class.GetPointerType();
383 }
384 else
385 {
386 m_override_type = complete_class;
387 }
388
389 if (m_override_type.IsValid())
390 return m_override_type;
391 }
392 }
393 }
394 }
395 }
Sean Callanan72772842012-02-22 23:57:45 +0000396 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000397 return compiler_type;
Sean Callanan72772842012-02-22 23:57:45 +0000398}
399
Greg Claytona1e5dc82015-08-11 22:53:00 +0000400CompilerType
Greg Clayton99558cc42015-08-24 23:46:31 +0000401ValueObject::GetCompilerType ()
Sean Callanan72772842012-02-22 23:57:45 +0000402{
Greg Clayton57ee3062013-07-11 22:46:58 +0000403 return MaybeCalculateCompleteType();
Sean Callanan72772842012-02-22 23:57:45 +0000404}
405
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000406TypeImpl
407ValueObject::GetTypeImpl ()
408{
Greg Clayton99558cc42015-08-24 23:46:31 +0000409 return TypeImpl(GetCompilerType());
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000410}
411
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000412DataExtractor &
413ValueObject::GetDataExtractor ()
414{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000415 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000416 return m_data;
417}
418
419const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000420ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000421{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000422 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000423 return m_error;
424}
425
426const ConstString &
427ValueObject::GetName() const
428{
429 return m_name;
430}
431
432const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000433ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000434{
Enrico Granata82fabf82013-04-30 20:45:04 +0000435 return GetLocationAsCStringImpl(m_value,
436 m_data);
437}
438
439const char *
440ValueObject::GetLocationAsCStringImpl (const Value& value,
441 const DataExtractor& data)
442{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000443 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000444 {
445 if (m_location_str.empty())
446 {
447 StreamString sstr;
Enrico Granata82fabf82013-04-30 20:45:04 +0000448
449 Value::ValueType value_type = value.GetValueType();
450
451 switch (value_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000452 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000453 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +0000454 case Value::eValueTypeVector:
Enrico Granata82fabf82013-04-30 20:45:04 +0000455 if (value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000456 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000457 RegisterInfo *reg_info = value.GetRegisterInfo();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000458 if (reg_info)
459 {
460 if (reg_info->name)
461 m_location_str = reg_info->name;
462 else if (reg_info->alt_name)
463 m_location_str = reg_info->alt_name;
Enrico Granata82fabf82013-04-30 20:45:04 +0000464 if (m_location_str.empty())
465 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000466 }
467 }
Enrico Granata82fabf82013-04-30 20:45:04 +0000468 if (m_location_str.empty())
469 m_location_str = (value_type == Value::eValueTypeVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000470 break;
471
472 case Value::eValueTypeLoadAddress:
473 case Value::eValueTypeFileAddress:
474 case Value::eValueTypeHostAddress:
475 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000476 uint32_t addr_nibble_size = data.GetAddressByteSize() * 2;
477 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000478 m_location_str.swap(sstr.GetString());
479 }
480 break;
481 }
482 }
483 }
484 return m_location_str.c_str();
485}
486
487Value &
488ValueObject::GetValue()
489{
490 return m_value;
491}
492
493const Value &
494ValueObject::GetValue() const
495{
496 return m_value;
497}
498
499bool
Jim Ingham6035b672011-03-31 00:19:25 +0000500ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000501{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000502 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
503 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000504 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000505 Value tmp_value(m_value);
Greg Clayton57ee3062013-07-11 22:46:58 +0000506 scalar = tmp_value.ResolveValue(&exe_ctx);
Greg Claytondcad5022011-12-29 01:26:56 +0000507 if (scalar.IsValid())
508 {
509 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
510 if (bitfield_bit_size)
511 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
512 return true;
513 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000514 }
Greg Claytondcad5022011-12-29 01:26:56 +0000515 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000516}
517
518bool
Jim Ingham98e6daf2015-10-31 00:02:18 +0000519ValueObject::IsLogicalTrue (Error& error)
520{
Enrico Granata407b5c62015-11-02 21:52:05 +0000521 if (Language *language = Language::FindPlugin(GetObjectRuntimeLanguage()))
522 {
523 LazyBool is_logical_true = language->IsLogicalTrue(*this, error);
524 switch (is_logical_true)
525 {
526 case eLazyBoolYes:
527 case eLazyBoolNo:
528 return (is_logical_true == true);
529 case eLazyBoolCalculate:
Enrico Granata407b5c62015-11-02 21:52:05 +0000530 break;
531 }
532 }
533
Jim Ingham98e6daf2015-10-31 00:02:18 +0000534 Scalar scalar_value;
535
536 if (!ResolveValue (scalar_value))
537 {
538 error.SetErrorString("failed to get a scalar result");
539 return false;
540 }
541
542 bool ret;
543 if (scalar_value.ULongLong(1) == 0)
544 ret = false;
545 else
546 ret = true;
547 error.Clear();
548 return ret;
549}
550
551bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000552ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000553{
Greg Clayton288bdf92010-09-02 02:59:18 +0000554 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000555}
556
557
558void
559ValueObject::SetValueIsValid (bool b)
560{
Greg Clayton288bdf92010-09-02 02:59:18 +0000561 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000562}
563
564bool
Jim Ingham6035b672011-03-31 00:19:25 +0000565ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000566{
Greg Clayton288bdf92010-09-02 02:59:18 +0000567 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000568}
569
570void
571ValueObject::SetValueDidChange (bool value_changed)
572{
Greg Clayton288bdf92010-09-02 02:59:18 +0000573 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000574}
575
576ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000577ValueObject::GetChildAtIndex (size_t idx, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000578{
579 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000580 // We may need to update our value if we are dynamic
581 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000582 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000583 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000584 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000585 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000586 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000587 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000588 // No we haven't created the child at this index, so lets have our
589 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000590 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000591 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000592
Enrico Granata9d60f602012-03-09 03:09:58 +0000593 ValueObject* child = m_children.GetChildAtIndex(idx);
594 if (child != NULL)
595 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000596 }
597 return child_sp;
598}
599
Enrico Granata3309d882013-01-12 01:00:22 +0000600ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000601ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
602 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000603{
604 if (idxs.size() == 0)
605 return GetSP();
606 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000607 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000608 {
609 root = root->GetChildAtIndex(idx, true);
610 if (!root)
611 {
612 if (index_of_error)
613 *index_of_error = idx;
614 return root;
615 }
616 }
617 return root;
618}
619
620ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000621ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
622 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000623{
624 if (idxs.size() == 0)
625 return GetSP();
626 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000627 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000628 {
629 root = root->GetChildAtIndex(idx.first, idx.second);
630 if (!root)
631 {
632 if (index_of_error)
633 *index_of_error = idx.first;
634 return root;
635 }
636 }
637 return root;
638}
639
640lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000641ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
642 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000643{
644 if (idxs.size() == 0)
645 return GetSP();
646 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000647 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000648 {
649 root = root->GetChildAtIndex(idx, true);
650 if (!root)
651 {
652 if (index_of_error)
653 *index_of_error = idx;
654 return root;
655 }
656 }
657 return root;
658}
659
660lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000661ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
662 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000663{
664 if (idxs.size() == 0)
665 return GetSP();
666 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000667 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000668 {
669 root = root->GetChildAtIndex(idx.first, idx.second);
670 if (!root)
671 {
672 if (index_of_error)
673 *index_of_error = idx.first;
674 return root;
675 }
676 }
677 return root;
678}
679
Enrico Granatae2e220a2013-09-12 00:48:47 +0000680lldb::ValueObjectSP
681ValueObject::GetChildAtNamePath (const std::initializer_list<ConstString> &names,
682 ConstString* name_of_error)
683{
684 if (names.size() == 0)
685 return GetSP();
686 ValueObjectSP root(GetSP());
687 for (ConstString name : names)
688 {
689 root = root->GetChildMemberWithName(name, true);
690 if (!root)
691 {
692 if (name_of_error)
693 *name_of_error = name;
694 return root;
695 }
696 }
697 return root;
698}
699
700lldb::ValueObjectSP
701ValueObject::GetChildAtNamePath (const std::vector<ConstString> &names,
702 ConstString* name_of_error)
703{
704 if (names.size() == 0)
705 return GetSP();
706 ValueObjectSP root(GetSP());
707 for (ConstString name : names)
708 {
709 root = root->GetChildMemberWithName(name, true);
710 if (!root)
711 {
712 if (name_of_error)
713 *name_of_error = name;
714 return root;
715 }
716 }
717 return root;
718}
719
720lldb::ValueObjectSP
721ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names,
722 ConstString* name_of_error)
723{
724 if (names.size() == 0)
725 return GetSP();
726 ValueObjectSP root(GetSP());
727 for (std::pair<ConstString, bool> name : names)
728 {
729 root = root->GetChildMemberWithName(name.first, name.second);
730 if (!root)
731 {
732 if (name_of_error)
733 *name_of_error = name.first;
734 return root;
735 }
736 }
737 return root;
738}
739
740lldb::ValueObjectSP
741ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names,
742 ConstString* name_of_error)
743{
744 if (names.size() == 0)
745 return GetSP();
746 ValueObjectSP root(GetSP());
747 for (std::pair<ConstString, bool> name : names)
748 {
749 root = root->GetChildMemberWithName(name.first, name.second);
750 if (!root)
751 {
752 if (name_of_error)
753 *name_of_error = name.first;
754 return root;
755 }
756 }
757 return root;
758}
759
Greg Claytonc7bece562013-01-25 18:06:21 +0000760size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000761ValueObject::GetIndexOfChildWithName (const ConstString &name)
762{
763 bool omit_empty_base_classes = true;
Greg Clayton99558cc42015-08-24 23:46:31 +0000764 return GetCompilerType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000765}
766
767ValueObjectSP
768ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
769{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000770 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000771 // classes (which really aren't part of the expression path), so we
772 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000773 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000774
Greg Claytondea8cb42011-06-29 22:09:02 +0000775 // We may need to update our value if we are dynamic
776 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000777 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000778
779 std::vector<uint32_t> child_indexes;
Greg Claytondea8cb42011-06-29 22:09:02 +0000780 bool omit_empty_base_classes = true;
Greg Clayton99558cc42015-08-24 23:46:31 +0000781 const size_t num_child_indexes = GetCompilerType().GetIndexOfChildMemberWithName (name.GetCString(),
Greg Clayton57ee3062013-07-11 22:46:58 +0000782 omit_empty_base_classes,
783 child_indexes);
Greg Claytondea8cb42011-06-29 22:09:02 +0000784 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000785 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000786 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
787 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
788
789 child_sp = GetChildAtIndex(*pos, can_create);
790 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000791 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000792 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000793 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000794 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
795 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000796 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000797 else
798 {
799 child_sp.reset();
800 }
801
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000802 }
803 }
804 return child_sp;
805}
806
807
Greg Claytonc7bece562013-01-25 18:06:21 +0000808size_t
Siva Chandra9ac7a6c2015-10-21 19:28:08 +0000809ValueObject::GetNumChildren (uint32_t max)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000810{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000811 UpdateValueIfNeeded();
Siva Chandra9ac7a6c2015-10-21 19:28:08 +0000812
813 if (max < UINT32_MAX)
814 {
815 if (m_children_count_valid)
816 {
817 size_t children_count = m_children.GetChildrenCount();
818 return children_count <= max ? children_count : max;
819 }
820 else
821 return CalculateNumChildren(max);
822 }
823
Greg Clayton288bdf92010-09-02 02:59:18 +0000824 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000825 {
826 SetNumChildren (CalculateNumChildren());
827 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000828 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000829}
Greg Clayton4a792072012-10-23 01:50:10 +0000830
831bool
832ValueObject::MightHaveChildren()
833{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000834 bool has_children = false;
Greg Clayton2452ab72013-02-08 22:02:02 +0000835 const uint32_t type_info = GetTypeInfo();
836 if (type_info)
Greg Clayton4a792072012-10-23 01:50:10 +0000837 {
Enrico Granata622be232014-10-21 20:52:14 +0000838 if (type_info & (eTypeHasChildren |
839 eTypeIsPointer |
840 eTypeIsReference))
Greg Clayton4a792072012-10-23 01:50:10 +0000841 has_children = true;
842 }
843 else
844 {
845 has_children = GetNumChildren () > 0;
846 }
847 return has_children;
848}
849
850// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000851void
Greg Claytonc7bece562013-01-25 18:06:21 +0000852ValueObject::SetNumChildren (size_t num_children)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000853{
Greg Clayton288bdf92010-09-02 02:59:18 +0000854 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000855 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000856}
857
858void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000859ValueObject::SetName (const ConstString &name)
860{
861 m_name = name;
862}
863
Jim Ingham58b59f92011-04-22 23:53:53 +0000864ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000865ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000866{
Jim Ingham2eec4872011-05-07 00:10:58 +0000867 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000868
Greg Claytondea8cb42011-06-29 22:09:02 +0000869 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000870 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000871 std::string child_name_str;
872 uint32_t child_byte_size = 0;
873 int32_t child_byte_offset = 0;
874 uint32_t child_bitfield_bit_size = 0;
875 uint32_t child_bitfield_bit_offset = 0;
876 bool child_is_base_class = false;
877 bool child_is_deref_of_parent = false;
Enrico Granatadc62ffd2015-11-09 19:27:34 +0000878 uint64_t language_flags = 0;
Greg Claytondea8cb42011-06-29 22:09:02 +0000879
880 const bool transparent_pointers = synthetic_array_member == false;
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000881 CompilerType child_compiler_type;
Greg Claytondea8cb42011-06-29 22:09:02 +0000882
Greg Claytoncc4d0142012-02-17 07:49:44 +0000883 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000884
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000885 child_compiler_type = GetCompilerType().GetChildCompilerTypeAtIndex (&exe_ctx,
886 idx,
887 transparent_pointers,
888 omit_empty_base_classes,
889 ignore_array_bounds,
890 child_name_str,
891 child_byte_size,
892 child_byte_offset,
893 child_bitfield_bit_size,
894 child_bitfield_bit_offset,
895 child_is_base_class,
896 child_is_deref_of_parent,
Enrico Granatadc62ffd2015-11-09 19:27:34 +0000897 this,
898 language_flags);
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000899 if (child_compiler_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000900 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000901 if (synthetic_index)
902 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000903
Greg Claytondea8cb42011-06-29 22:09:02 +0000904 ConstString child_name;
905 if (!child_name_str.empty())
906 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000907
Greg Claytondea8cb42011-06-29 22:09:02 +0000908 valobj = new ValueObjectChild (*this,
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000909 child_compiler_type,
Greg Claytondea8cb42011-06-29 22:09:02 +0000910 child_name,
911 child_byte_size,
912 child_byte_offset,
913 child_bitfield_bit_size,
914 child_bitfield_bit_offset,
915 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000916 child_is_deref_of_parent,
Enrico Granatadc62ffd2015-11-09 19:27:34 +0000917 eAddressTypeInvalid,
918 language_flags);
Enrico Granata9128ee22011-09-06 19:20:51 +0000919 //if (valobj)
920 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
921 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000922
Jim Ingham58b59f92011-04-22 23:53:53 +0000923 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000924}
925
Enrico Granata0c489f52012-03-01 04:24:26 +0000926bool
927ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
Enrico Granata31fda932015-10-07 01:41:23 +0000928 std::string& destination,
929 lldb::LanguageType lang)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000930{
Enrico Granata31fda932015-10-07 01:41:23 +0000931 return GetSummaryAsCString(summary_ptr, destination, TypeSummaryOptions().SetLanguage(lang));
Enrico Granatac1247f52014-11-06 21:23:20 +0000932}
933
934bool
935ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
936 std::string& destination,
937 const TypeSummaryOptions& options)
938{
Enrico Granata0c489f52012-03-01 04:24:26 +0000939 destination.clear();
Enrico Granata31fda932015-10-07 01:41:23 +0000940
Enrico Granata0c489f52012-03-01 04:24:26 +0000941 // ideally we would like to bail out if passing NULL, but if we do so
942 // we end up not providing the summary for function pointers anymore
943 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
944 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000945
946 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000947
Enrico Granata31fda932015-10-07 01:41:23 +0000948 TypeSummaryOptions actual_options(options);
949
950 if (actual_options.GetLanguage() == lldb::eLanguageTypeUnknown)
951 actual_options.SetLanguage(GetPreferredDisplayLanguage());
952
Enrico Granataf18c03e2012-04-04 17:34:10 +0000953 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
954 // information that we might care to see in a crash log. might be useful in very specific situations though.
955 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
Enrico Granata31fda932015-10-07 01:41:23 +0000956 GetTypeName().GetCString(),
957 GetName().GetCString(),
958 summary_ptr->GetDescription().c_str());*/
Enrico Granataf18c03e2012-04-04 17:34:10 +0000959
Enrico Granataff0f23d2014-12-10 02:00:45 +0000960 if (UpdateValueIfNeeded (false) && summary_ptr)
Enrico Granata0c489f52012-03-01 04:24:26 +0000961 {
Enrico Granataff0f23d2014-12-10 02:00:45 +0000962 if (HasSyntheticValue())
963 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 +0000964 summary_ptr->FormatObject(this, destination, actual_options);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000965 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000966 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000967 return !destination.empty();
968}
969
970const char *
Enrico Granata31fda932015-10-07 01:41:23 +0000971ValueObject::GetSummaryAsCString (lldb::LanguageType lang)
Enrico Granata0c489f52012-03-01 04:24:26 +0000972{
973 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
974 {
Enrico Granata31fda932015-10-07 01:41:23 +0000975 TypeSummaryOptions summary_options;
976 summary_options.SetLanguage(lang);
Enrico Granata0c489f52012-03-01 04:24:26 +0000977 GetSummaryAsCString(GetSummaryFormat().get(),
Enrico Granatac1247f52014-11-06 21:23:20 +0000978 m_summary_str,
Enrico Granata31fda932015-10-07 01:41:23 +0000979 summary_options);
Enrico Granata0c489f52012-03-01 04:24:26 +0000980 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000981 if (m_summary_str.empty())
982 return NULL;
983 return m_summary_str.c_str();
984}
985
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000986bool
Enrico Granata49bfafb2014-11-18 23:36:25 +0000987ValueObject::GetSummaryAsCString (std::string& destination,
988 const TypeSummaryOptions& options)
989{
990 return GetSummaryAsCString(GetSummaryFormat().get(),
Enrico Granata31fda932015-10-07 01:41:23 +0000991 destination,
992 options);
Enrico Granata49bfafb2014-11-18 23:36:25 +0000993}
994
995bool
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000996ValueObject::IsCStringContainer(bool check_pointer)
997{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000998 CompilerType pointee_or_element_compiler_type;
999 const Flags type_flags (GetTypeInfo (&pointee_or_element_compiler_type));
Enrico Granata622be232014-10-21 20:52:14 +00001000 bool is_char_arr_ptr (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001001 pointee_or_element_compiler_type.IsCharType ());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001002 if (!is_char_arr_ptr)
1003 return false;
1004 if (!check_pointer)
1005 return true;
Enrico Granata622be232014-10-21 20:52:14 +00001006 if (type_flags.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001007 return true;
Greg Claytonafacd142011-09-02 01:15:17 +00001008 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001009 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +00001010 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001011 return (cstr_address != LLDB_INVALID_ADDRESS);
1012}
1013
Enrico Granata9128ee22011-09-06 19:20:51 +00001014size_t
1015ValueObject::GetPointeeData (DataExtractor& data,
1016 uint32_t item_idx,
1017 uint32_t item_count)
1018{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001019 CompilerType pointee_or_element_compiler_type;
1020 const uint32_t type_info = GetTypeInfo (&pointee_or_element_compiler_type);
Enrico Granata622be232014-10-21 20:52:14 +00001021 const bool is_pointer_type = type_info & eTypeIsPointer;
1022 const bool is_array_type = type_info & eTypeIsArray;
Greg Clayton2452ab72013-02-08 22:02:02 +00001023 if (!(is_pointer_type || is_array_type))
Enrico Granata9128ee22011-09-06 19:20:51 +00001024 return 0;
1025
1026 if (item_count == 0)
1027 return 0;
1028
Enrico Granata951bdd52015-01-28 01:09:45 +00001029 ExecutionContext exe_ctx (GetExecutionContextRef());
1030
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001031 const uint64_t item_type_size = pointee_or_element_compiler_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
Enrico Granata9128ee22011-09-06 19:20:51 +00001032 const uint64_t bytes = item_count * item_type_size;
Enrico Granata9128ee22011-09-06 19:20:51 +00001033 const uint64_t offset = item_idx * item_type_size;
1034
1035 if (item_idx == 0 && item_count == 1) // simply a deref
1036 {
Greg Clayton2452ab72013-02-08 22:02:02 +00001037 if (is_pointer_type)
Enrico Granata9128ee22011-09-06 19:20:51 +00001038 {
1039 Error error;
1040 ValueObjectSP pointee_sp = Dereference(error);
1041 if (error.Fail() || pointee_sp.get() == NULL)
1042 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +00001043 return pointee_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +00001044 }
1045 else
1046 {
1047 ValueObjectSP child_sp = GetChildAtIndex(0, true);
1048 if (child_sp.get() == NULL)
1049 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +00001050 Error error;
1051 return child_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +00001052 }
1053 return true;
1054 }
1055 else /* (items > 1) */
1056 {
1057 Error error;
1058 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
1059 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
1060
1061 AddressType addr_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001062 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001063
Enrico Granata9128ee22011-09-06 19:20:51 +00001064 switch (addr_type)
1065 {
1066 case eAddressTypeFile:
1067 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001068 ModuleSP module_sp (GetModule());
1069 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001070 {
Enrico Granata9c2efe32012-08-07 01:49:34 +00001071 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +00001072 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001073 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001074 ExecutionContext exe_ctx (GetExecutionContextRef());
1075 Target* target = exe_ctx.GetTargetPtr();
1076 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +00001077 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001078 heap_buf_ptr->SetByteSize(bytes);
1079 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
1080 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +00001081 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001082 data.SetData(data_sp);
1083 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +00001084 }
1085 }
1086 }
1087 }
1088 break;
1089 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +00001090 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001091 ExecutionContext exe_ctx (GetExecutionContextRef());
1092 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +00001093 if (process)
1094 {
1095 heap_buf_ptr->SetByteSize(bytes);
1096 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
Enrico Granata5e1480c2013-10-30 17:52:44 +00001097 if (error.Success() || bytes_read > 0)
Enrico Granata9128ee22011-09-06 19:20:51 +00001098 {
1099 data.SetData(data_sp);
1100 return bytes_read;
1101 }
1102 }
1103 }
1104 break;
1105 case eAddressTypeHost:
1106 {
Greg Clayton99558cc42015-08-24 23:46:31 +00001107 const uint64_t max_bytes = GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope());
Greg Clayton2452ab72013-02-08 22:02:02 +00001108 if (max_bytes > offset)
1109 {
1110 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
Siva Chandrae32f2b52015-05-05 00:41:35 +00001111 addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Enrico Granata7339b9d2015-11-03 02:34:43 +00001112 if (addr == 0 || addr == LLDB_INVALID_ADDRESS)
Siva Chandrae32f2b52015-05-05 00:41:35 +00001113 break;
Greg Clayton2452ab72013-02-08 22:02:02 +00001114 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
1115 data.SetData(data_sp);
1116 return bytes_read;
1117 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001118 }
1119 break;
1120 case eAddressTypeInvalid:
Enrico Granata9128ee22011-09-06 19:20:51 +00001121 break;
1122 }
1123 }
1124 return 0;
1125}
1126
Greg Claytonfaac1112013-03-14 18:31:44 +00001127uint64_t
Sean Callanan866e91c2014-02-28 22:27:53 +00001128ValueObject::GetData (DataExtractor& data, Error &error)
Enrico Granata9128ee22011-09-06 19:20:51 +00001129{
1130 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001131 ExecutionContext exe_ctx (GetExecutionContextRef());
Sean Callanan866e91c2014-02-28 22:27:53 +00001132 error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001133 if (error.Fail())
Sean Callananed185ab2013-04-19 19:47:32 +00001134 {
1135 if (m_data.GetByteSize())
1136 {
1137 data = m_data;
1138 return data.GetByteSize();
1139 }
1140 else
1141 {
1142 return 0;
1143 }
1144 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001145 data.SetAddressByteSize(m_data.GetAddressByteSize());
1146 data.SetByteOrder(m_data.GetByteOrder());
1147 return data.GetByteSize();
1148}
1149
Sean Callanan389823e2013-04-13 01:21:23 +00001150bool
1151ValueObject::SetData (DataExtractor &data, Error &error)
1152{
1153 error.Clear();
1154 // Make sure our value is up to date first so that our location and location
1155 // type is valid.
1156 if (!UpdateValueIfNeeded(false))
1157 {
1158 error.SetErrorString("unable to read value");
1159 return false;
1160 }
1161
1162 uint64_t count = 0;
Greg Clayton99558cc42015-08-24 23:46:31 +00001163 const Encoding encoding = GetCompilerType().GetEncoding(count);
Sean Callanan389823e2013-04-13 01:21:23 +00001164
1165 const size_t byte_size = GetByteSize();
1166
1167 Value::ValueType value_type = m_value.GetValueType();
1168
1169 switch (value_type)
1170 {
1171 case Value::eValueTypeScalar:
1172 {
1173 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1174
1175 if (!set_error.Success())
1176 {
1177 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1178 return false;
1179 }
1180 }
1181 break;
1182 case Value::eValueTypeLoadAddress:
1183 {
1184 // If it is a load address, then the scalar value is the storage location
1185 // of the data, and we have to shove this value down to that load location.
1186 ExecutionContext exe_ctx (GetExecutionContextRef());
1187 Process *process = exe_ctx.GetProcessPtr();
1188 if (process)
1189 {
1190 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1191 size_t bytes_written = process->WriteMemory(target_addr,
1192 data.GetDataStart(),
1193 byte_size,
1194 error);
1195 if (!error.Success())
1196 return false;
1197 if (bytes_written != byte_size)
1198 {
1199 error.SetErrorString("unable to write value to memory");
1200 return false;
1201 }
1202 }
1203 }
1204 break;
1205 case Value::eValueTypeHostAddress:
1206 {
1207 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1208 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1209 m_data.SetData(buffer_sp, 0);
1210 data.CopyByteOrderedData (0,
1211 byte_size,
1212 const_cast<uint8_t *>(m_data.GetDataStart()),
1213 byte_size,
1214 m_data.GetByteOrder());
1215 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1216 }
1217 break;
1218 case Value::eValueTypeFileAddress:
1219 case Value::eValueTypeVector:
1220 break;
1221 }
1222
1223 // If we have reached this point, then we have successfully changed the value.
1224 SetNeedsUpdate();
1225 return true;
1226}
1227
Enrico Granata9128ee22011-09-06 19:20:51 +00001228// will compute strlen(str), but without consuming more than
1229// maxlen bytes out of str (this serves the purpose of reading
1230// chunks of a string without having to worry about
1231// missing NULL terminators in the chunk)
1232// of course, if strlen(str) > maxlen, the function will return
1233// maxlen_value (which should be != maxlen, because that allows you
1234// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1235static uint32_t
1236strlen_or_inf (const char* str,
1237 uint32_t maxlen,
1238 uint32_t maxlen_value)
1239{
1240 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +00001241 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +00001242 {
Greg Clayton8dd5c172011-10-05 22:19:51 +00001243 while(*str)
1244 {
1245 len++;str++;
Greg Clayton2452ab72013-02-08 22:02:02 +00001246 if (len >= maxlen)
Greg Clayton8dd5c172011-10-05 22:19:51 +00001247 return maxlen_value;
1248 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001249 }
1250 return len;
1251}
1252
Enrico Granata2206b482014-10-30 18:27:31 +00001253static bool
1254CopyStringDataToBufferSP(const StreamString& source,
1255 lldb::DataBufferSP& destination)
1256{
1257 destination.reset(new DataBufferHeap(source.GetSize()+1,0));
1258 memcpy(destination->GetBytes(), source.GetString().c_str(), source.GetSize());
1259 return true;
1260}
1261
Enrico Granatab7662922015-11-04 00:02:08 +00001262std::pair<size_t,bool>
Enrico Granata2206b482014-10-30 18:27:31 +00001263ValueObject::ReadPointedString (lldb::DataBufferSP& buffer_sp,
Greg Claytoncc4d0142012-02-17 07:49:44 +00001264 Error& error,
1265 uint32_t max_length,
1266 bool honor_array,
1267 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001268{
Enrico Granatab7662922015-11-04 00:02:08 +00001269 bool was_capped = false;
Enrico Granata2206b482014-10-30 18:27:31 +00001270 StreamString s;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001271 ExecutionContext exe_ctx (GetExecutionContextRef());
1272 Target* target = exe_ctx.GetTargetPtr();
Enrico Granata2206b482014-10-30 18:27:31 +00001273
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001274 if (!target)
1275 {
1276 s << "<no target to read from>";
1277 error.SetErrorString("no target to read from");
Enrico Granata2206b482014-10-30 18:27:31 +00001278 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granatab7662922015-11-04 00:02:08 +00001279 return {0,was_capped};
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001280 }
1281
1282 if (max_length == 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001283 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001284
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001285 size_t bytes_read = 0;
1286 size_t total_bytes_read = 0;
1287
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001288 CompilerType compiler_type = GetCompilerType();
1289 CompilerType elem_or_pointee_compiler_type;
1290 const Flags type_flags (GetTypeInfo (&elem_or_pointee_compiler_type));
Enrico Granata622be232014-10-21 20:52:14 +00001291 if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001292 elem_or_pointee_compiler_type.IsCharType ())
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001293 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001294 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1295 AddressType cstr_address_type = eAddressTypeInvalid;
1296
1297 size_t cstr_len = 0;
1298 bool capped_data = false;
Enrico Granata622be232014-10-21 20:52:14 +00001299 if (type_flags.Test (eTypeIsArray))
Greg Claytoncc4d0142012-02-17 07:49:44 +00001300 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001301 // We have an array
Greg Clayton57ee3062013-07-11 22:46:58 +00001302 uint64_t array_size = 0;
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001303 if (compiler_type.IsArrayType(NULL, &array_size, NULL))
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001304 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001305 cstr_len = array_size;
1306 if (cstr_len > max_length)
1307 {
1308 capped_data = true;
1309 cstr_len = max_length;
1310 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001311 }
1312 cstr_address = GetAddressOf (true, &cstr_address_type);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001313 }
1314 else
1315 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001316 // We have a pointer
1317 cstr_address = GetPointerValue (&cstr_address_type);
1318 }
1319
1320 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1321 {
1322 s << "<invalid address>";
1323 error.SetErrorString("invalid address");
Enrico Granata2206b482014-10-30 18:27:31 +00001324 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granatab7662922015-11-04 00:02:08 +00001325 return {0,was_capped};
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001326 }
Enrico Granata2206b482014-10-30 18:27:31 +00001327
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001328 Address cstr_so_addr (cstr_address);
1329 DataExtractor data;
1330 if (cstr_len > 0 && honor_array)
1331 {
1332 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1333 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1334 GetPointeeData(data, 0, cstr_len);
Enrico Granata2206b482014-10-30 18:27:31 +00001335
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001336 if ((bytes_read = data.GetByteSize()) > 0)
1337 {
1338 total_bytes_read = bytes_read;
Enrico Granata2206b482014-10-30 18:27:31 +00001339 for (size_t offset = 0; offset < bytes_read; offset++)
1340 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001341 if (capped_data)
Enrico Granatab7662922015-11-04 00:02:08 +00001342 was_capped = true;
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001343 }
1344 }
1345 else
1346 {
1347 cstr_len = max_length;
1348 const size_t k_max_buf_size = 64;
Enrico Granata2206b482014-10-30 18:27:31 +00001349
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001350 size_t offset = 0;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001351
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001352 int cstr_len_displayed = -1;
1353 bool capped_cstr = false;
1354 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1355 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1356 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001357 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001358 total_bytes_read += bytes_read;
1359 const char *cstr = data.PeekCStr(0);
1360 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1361 if (len > k_max_buf_size)
1362 len = k_max_buf_size;
Enrico Granata2206b482014-10-30 18:27:31 +00001363
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001364 if (cstr_len_displayed < 0)
1365 cstr_len_displayed = len;
Enrico Granata2206b482014-10-30 18:27:31 +00001366
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001367 if (len == 0)
1368 break;
1369 cstr_len_displayed += len;
1370 if (len > bytes_read)
1371 len = bytes_read;
1372 if (len > cstr_len)
1373 len = cstr_len;
1374
Enrico Granata2206b482014-10-30 18:27:31 +00001375 for (size_t offset = 0; offset < bytes_read; offset++)
1376 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001377
1378 if (len < k_max_buf_size)
1379 break;
1380
1381 if (len >= cstr_len)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001382 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001383 capped_cstr = true;
1384 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001385 }
Enrico Granata2206b482014-10-30 18:27:31 +00001386
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001387 cstr_len -= len;
1388 offset += len;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001389 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001390
1391 if (cstr_len_displayed >= 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001392 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001393 if (capped_cstr)
Enrico Granatab7662922015-11-04 00:02:08 +00001394 was_capped = true;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001395 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001396 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001397 }
1398 else
1399 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001400 error.SetErrorString("not a string object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001401 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001402 }
Enrico Granata2206b482014-10-30 18:27:31 +00001403 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granatab7662922015-11-04 00:02:08 +00001404 return {total_bytes_read,was_capped};
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001405}
1406
Enrico Granata744794a2014-09-05 21:46:22 +00001407std::pair<TypeValidatorResult, std::string>
1408ValueObject::GetValidationStatus ()
1409{
1410 if (!UpdateValueIfNeeded(true))
1411 return {TypeValidatorResult::Success,""}; // not the validator's job to discuss update problems
1412
1413 if (m_validation_result.hasValue())
1414 return m_validation_result.getValue();
1415
1416 if (!m_type_validator_sp)
1417 return {TypeValidatorResult::Success,""}; // no validator no failure
1418
1419 auto outcome = m_type_validator_sp->FormatObject(this);
1420
1421 return (m_validation_result = {outcome.m_result,outcome.m_message}).getValue();
1422}
1423
Jim Ingham53c47f12010-09-10 23:12:17 +00001424const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001425ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001426{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001427
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001428 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001429 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001430
1431 if (!m_object_desc_str.empty())
1432 return m_object_desc_str.c_str();
1433
Greg Claytoncc4d0142012-02-17 07:49:44 +00001434 ExecutionContext exe_ctx (GetExecutionContextRef());
1435 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001436 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001437 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001438
Jim Ingham53c47f12010-09-10 23:12:17 +00001439 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001440
Greg Claytonafacd142011-09-02 01:15:17 +00001441 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001442 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1443
Jim Inghama2cf2632010-12-23 02:29:54 +00001444 if (runtime == NULL)
1445 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001446 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001447 CompilerType compiler_type = GetCompilerType();
1448 if (compiler_type)
Jim Inghama2cf2632010-12-23 02:29:54 +00001449 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001450 bool is_signed;
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001451 if (compiler_type.IsIntegerType (is_signed) || compiler_type.IsPointerType ())
Jim Inghamb7603bb2011-03-18 00:05:18 +00001452 {
Greg Claytonafacd142011-09-02 01:15:17 +00001453 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001454 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001455 }
1456 }
1457
Jim Ingham8d543de2011-03-31 23:01:21 +00001458 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001459 {
1460 m_object_desc_str.append (s.GetData());
1461 }
Sean Callanan672ad942010-10-23 00:18:49 +00001462
1463 if (m_object_desc_str.empty())
1464 return NULL;
1465 else
1466 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001467}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001468
Enrico Granata0c489f52012-03-01 04:24:26 +00001469bool
Enrico Granata4939b982013-12-22 09:24:22 +00001470ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format,
1471 std::string& destination)
1472{
1473 if (UpdateValueIfNeeded(false))
1474 return format.FormatObject(this,destination);
1475 else
1476 return false;
1477}
1478
1479bool
Enrico Granata0c489f52012-03-01 04:24:26 +00001480ValueObject::GetValueAsCString (lldb::Format format,
1481 std::string& destination)
1482{
Enrico Granata30f287f2013-12-28 08:44:02 +00001483 return GetValueAsCString(TypeFormatImpl_Format(format),destination);
Enrico Granata0c489f52012-03-01 04:24:26 +00001484}
1485
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001486const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001487ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001488{
Enrico Granatab294fd22013-05-31 19:18:19 +00001489 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001490 {
Enrico Granata4939b982013-12-22 09:24:22 +00001491 lldb::TypeFormatImplSP format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001492 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001493 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001494 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001495 if (m_type_format_sp)
Enrico Granata4939b982013-12-22 09:24:22 +00001496 format_sp = m_type_format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001497 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001498 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001499 if (m_is_bitfield_for_scalar)
1500 my_format = eFormatUnsigned;
1501 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001502 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001503 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001504 {
1505 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1506 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001507 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001508 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001509 else
1510 {
Greg Clayton99558cc42015-08-24 23:46:31 +00001511 my_format = GetValue().GetCompilerType().GetFormat();
Enrico Granata0c489f52012-03-01 04:24:26 +00001512 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001513 }
1514 }
1515 }
Enrico Granatab294fd22013-05-31 19:18:19 +00001516 if (my_format != m_last_format || m_value_str.empty())
Enrico Granata297e69f2012-03-06 23:21:16 +00001517 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001518 m_last_format = my_format;
Enrico Granata4939b982013-12-22 09:24:22 +00001519 if (!format_sp)
Enrico Granata30f287f2013-12-28 08:44:02 +00001520 format_sp.reset(new TypeFormatImpl_Format(my_format));
Enrico Granata4939b982013-12-22 09:24:22 +00001521 if (GetValueAsCString(*format_sp.get(), m_value_str))
Enrico Granata297e69f2012-03-06 23:21:16 +00001522 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001523 if (!m_value_did_change && m_old_value_valid)
1524 {
1525 // The value was gotten successfully, so we consider the
1526 // value as changed if the value string differs
1527 SetValueDidChange (m_old_value_str != m_value_str);
1528 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001529 }
1530 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001531 }
1532 if (m_value_str.empty())
1533 return NULL;
1534 return m_value_str.c_str();
1535}
1536
Enrico Granatac3e320a2011-08-02 17:27:39 +00001537// if > 8bytes, 0 is returned. this method should mostly be used
1538// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001539uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001540ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001541{
1542 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001543 if (CanProvideValue())
Enrico Granatac3e320a2011-08-02 17:27:39 +00001544 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001545 Scalar scalar;
1546 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001547 {
1548 if (success)
1549 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001550 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001551 }
1552 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001553 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001554
1555 if (success)
1556 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001557 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001558}
1559
Enrico Granatad7373f62013-10-31 18:57:50 +00001560int64_t
1561ValueObject::GetValueAsSigned (int64_t fail_value, bool *success)
1562{
1563 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001564 if (CanProvideValue())
Enrico Granatad7373f62013-10-31 18:57:50 +00001565 {
1566 Scalar scalar;
1567 if (ResolveValue (scalar))
1568 {
1569 if (success)
1570 *success = true;
Tamas Berghammer5a9919f2015-01-23 10:54:21 +00001571 return scalar.SLongLong(fail_value);
Enrico Granatad7373f62013-10-31 18:57:50 +00001572 }
1573 // fallthrough, otherwise...
1574 }
1575
1576 if (success)
1577 *success = false;
Tamas Berghammer5a9919f2015-01-23 10:54:21 +00001578 return fail_value;
Enrico Granatad7373f62013-10-31 18:57:50 +00001579}
1580
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001581// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1582// this call up to date by returning true for your new special cases. We will eventually move
1583// to checking this call result before trying to display special cases
1584bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001585ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1586 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001587{
Greg Clayton57ee3062013-07-11 22:46:58 +00001588 Flags flags(GetTypeInfo());
Enrico Granata622be232014-10-21 20:52:14 +00001589 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001590 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001591 {
1592 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001593 (custom_format == eFormatCString ||
1594 custom_format == eFormatCharArray ||
1595 custom_format == eFormatChar ||
1596 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001597 return true;
1598
Enrico Granata622be232014-10-21 20:52:14 +00001599 if (flags.Test(eTypeIsArray))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001600 {
Greg Claytonafacd142011-09-02 01:15:17 +00001601 if ((custom_format == eFormatBytes) ||
1602 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001603 return true;
1604
Greg Claytonafacd142011-09-02 01:15:17 +00001605 if ((custom_format == eFormatVectorOfChar) ||
1606 (custom_format == eFormatVectorOfFloat32) ||
1607 (custom_format == eFormatVectorOfFloat64) ||
1608 (custom_format == eFormatVectorOfSInt16) ||
1609 (custom_format == eFormatVectorOfSInt32) ||
1610 (custom_format == eFormatVectorOfSInt64) ||
1611 (custom_format == eFormatVectorOfSInt8) ||
1612 (custom_format == eFormatVectorOfUInt128) ||
1613 (custom_format == eFormatVectorOfUInt16) ||
1614 (custom_format == eFormatVectorOfUInt32) ||
1615 (custom_format == eFormatVectorOfUInt64) ||
1616 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001617 return true;
1618 }
1619 }
1620 return false;
1621}
1622
Enrico Granata9fc19442011-07-06 02:13:41 +00001623bool
1624ValueObject::DumpPrintableRepresentation(Stream& s,
1625 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001626 Format custom_format,
Enrico Granata0dba9b32014-01-08 01:36:59 +00001627 PrintableRepresentationSpecialCases special,
1628 bool do_dump_error)
Enrico Granata9fc19442011-07-06 02:13:41 +00001629{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001630
Greg Clayton57ee3062013-07-11 22:46:58 +00001631 Flags flags(GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001632
Enrico Granata86cc9822012-03-19 22:58:49 +00001633 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1634 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1635
1636 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001637 {
Enrico Granata622be232014-10-21 20:52:14 +00001638 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001639 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001640 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001641 // when being asked to get a printable display an array or pointer type directly,
1642 // try to "do the right thing"
1643
1644 if (IsCStringContainer(true) &&
1645 (custom_format == eFormatCString ||
1646 custom_format == eFormatCharArray ||
1647 custom_format == eFormatChar ||
1648 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001649 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001650 Error error;
Enrico Granata2206b482014-10-30 18:27:31 +00001651 lldb::DataBufferSP buffer_sp;
Enrico Granatab7662922015-11-04 00:02:08 +00001652 std::pair<size_t, bool> read_string = ReadPointedString(buffer_sp,
1653 error,
1654 0,
1655 (custom_format == eFormatVectorOfChar) ||
1656 (custom_format == eFormatCharArray));
Enrico Granataac494532015-09-09 22:30:24 +00001657 lldb_private::formatters::StringPrinter::ReadBufferAndDumpToStreamOptions options(*this);
Enrico Granata2206b482014-10-30 18:27:31 +00001658 options.SetData(DataExtractor(buffer_sp, lldb::eByteOrderInvalid, 8)); // none of this matters for a string - pass some defaults
1659 options.SetStream(&s);
1660 options.SetPrefixToken(0);
1661 options.SetQuote('"');
1662 options.SetSourceSize(buffer_sp->GetByteSize());
Enrico Granatab7662922015-11-04 00:02:08 +00001663 options.SetIsTruncated(read_string.second);
Enrico Granataac494532015-09-09 22:30:24 +00001664 formatters::StringPrinter::ReadBufferAndDumpToStream<lldb_private::formatters::StringPrinter::StringElementType::ASCII>(options);
Enrico Granata86cc9822012-03-19 22:58:49 +00001665 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001666 }
1667
Enrico Granata86cc9822012-03-19 22:58:49 +00001668 if (custom_format == eFormatEnum)
1669 return false;
1670
1671 // this only works for arrays, because I have no way to know when
1672 // the pointed memory ends, and no special \0 end of data marker
Enrico Granata622be232014-10-21 20:52:14 +00001673 if (flags.Test(eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001674 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001675 if ((custom_format == eFormatBytes) ||
1676 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001677 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001678 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001679
1680 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001681 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001682 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001683
1684 if (low)
1685 s << ',';
1686
1687 ValueObjectSP child = GetChildAtIndex(low,true);
1688 if (!child.get())
1689 {
1690 s << "<invalid child>";
1691 continue;
1692 }
1693 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1694 }
1695
1696 s << ']';
1697
1698 return true;
1699 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001700
Enrico Granata86cc9822012-03-19 22:58:49 +00001701 if ((custom_format == eFormatVectorOfChar) ||
1702 (custom_format == eFormatVectorOfFloat32) ||
1703 (custom_format == eFormatVectorOfFloat64) ||
1704 (custom_format == eFormatVectorOfSInt16) ||
1705 (custom_format == eFormatVectorOfSInt32) ||
1706 (custom_format == eFormatVectorOfSInt64) ||
1707 (custom_format == eFormatVectorOfSInt8) ||
1708 (custom_format == eFormatVectorOfUInt128) ||
1709 (custom_format == eFormatVectorOfUInt16) ||
1710 (custom_format == eFormatVectorOfUInt32) ||
1711 (custom_format == eFormatVectorOfUInt64) ||
1712 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1713 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001714 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001715
1716 Format format = FormatManager::GetSingleItemFormat(custom_format);
1717
1718 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001719 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001720 {
1721
1722 if (low)
1723 s << ',';
1724
1725 ValueObjectSP child = GetChildAtIndex(low,true);
1726 if (!child.get())
1727 {
1728 s << "<invalid child>";
1729 continue;
1730 }
1731 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1732 }
1733
1734 s << ']';
1735
1736 return true;
1737 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001738 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001739
1740 if ((custom_format == eFormatBoolean) ||
1741 (custom_format == eFormatBinary) ||
1742 (custom_format == eFormatChar) ||
1743 (custom_format == eFormatCharPrintable) ||
1744 (custom_format == eFormatComplexFloat) ||
1745 (custom_format == eFormatDecimal) ||
1746 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001747 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001748 (custom_format == eFormatFloat) ||
1749 (custom_format == eFormatOctal) ||
1750 (custom_format == eFormatOSType) ||
1751 (custom_format == eFormatUnicode16) ||
1752 (custom_format == eFormatUnicode32) ||
1753 (custom_format == eFormatUnsigned) ||
1754 (custom_format == eFormatPointer) ||
1755 (custom_format == eFormatComplexInteger) ||
1756 (custom_format == eFormatComplex) ||
1757 (custom_format == eFormatDefault)) // use the [] operator
1758 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001759 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001760 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001761
1762 if (only_special)
1763 return false;
1764
Enrico Granata86cc9822012-03-19 22:58:49 +00001765 bool var_success = false;
1766
1767 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001768 const char *cstr = NULL;
Enrico Granata2c75f112013-06-21 00:04:51 +00001769
1770 // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1771 // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1772 // area for cases where our desired output is not backed by some other longer-term storage
Greg Claytonc7bece562013-01-25 18:06:21 +00001773 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001774
Enrico Granata465f4bc2014-02-15 01:24:44 +00001775 if (custom_format != eFormatInvalid)
Enrico Granata86cc9822012-03-19 22:58:49 +00001776 SetFormat(custom_format);
1777
1778 switch(val_obj_display)
1779 {
1780 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001781 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001782 break;
1783
1784 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001785 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001786 break;
1787
1788 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001789 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001790 break;
1791
1792 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001793 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001794 break;
1795
1796 case eValueObjectRepresentationStyleChildrenCount:
Deepak Panickal99fbc072014-03-03 15:39:47 +00001797 strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren());
Greg Claytonc7bece562013-01-25 18:06:21 +00001798 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001799 break;
1800
1801 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001802 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001803 break;
Enrico Granata2c75f112013-06-21 00:04:51 +00001804
1805 case eValueObjectRepresentationStyleName:
1806 cstr = GetName().AsCString();
1807 break;
1808
1809 case eValueObjectRepresentationStyleExpressionPath:
1810 GetExpressionPath(strm, false);
1811 cstr = strm.GetString().c_str();
1812 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001813 }
1814
Greg Claytonc7bece562013-01-25 18:06:21 +00001815 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001816 {
1817 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001818 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001819 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1820 {
Enrico Granatad07cfd32014-10-08 18:27:36 +00001821 if (!CanProvideValue())
Enrico Granata86cc9822012-03-19 22:58:49 +00001822 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001823 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1824 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001825 }
1826 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001827 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001828 }
1829 }
1830
Greg Claytonc7bece562013-01-25 18:06:21 +00001831 if (cstr)
1832 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001833 else
1834 {
1835 if (m_error.Fail())
Enrico Granata0dba9b32014-01-08 01:36:59 +00001836 {
1837 if (do_dump_error)
1838 s.Printf("<%s>", m_error.AsCString());
1839 else
1840 return false;
1841 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001842 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1843 s.PutCString("<no summary available>");
1844 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1845 s.PutCString("<no value available>");
1846 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1847 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1848 else
1849 s.PutCString("<no printable representation>");
1850 }
1851
1852 // we should only return false here if we could not do *anything*
1853 // even if we have an error message as output, that's a success
1854 // from our callers' perspective, so return true
1855 var_success = true;
Enrico Granata465f4bc2014-02-15 01:24:44 +00001856
1857 if (custom_format != eFormatInvalid)
1858 SetFormat(eFormatDefault);
Enrico Granata86cc9822012-03-19 22:58:49 +00001859 }
1860
Enrico Granataf4efecd2011-07-12 22:56:10 +00001861 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001862}
1863
Greg Clayton737b9322010-09-13 03:32:57 +00001864addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001865ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001866{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001867 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001868 return LLDB_INVALID_ADDRESS;
1869
Greg Clayton73b472d2010-10-27 03:32:59 +00001870 switch (m_value.GetValueType())
1871 {
1872 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001873 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001874 if (scalar_is_load_address)
1875 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001876 if(address_type)
1877 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001878 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1879 }
1880 break;
1881
1882 case Value::eValueTypeLoadAddress:
1883 case Value::eValueTypeFileAddress:
Greg Clayton73b472d2010-10-27 03:32:59 +00001884 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001885 if(address_type)
1886 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001887 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1888 }
1889 break;
Siva Chandraa3747a92015-05-04 19:43:34 +00001890 case Value::eValueTypeHostAddress:
Siva Chandrae32f2b52015-05-05 00:41:35 +00001891 {
1892 if(address_type)
1893 *address_type = m_value.GetValueAddressType ();
1894 return LLDB_INVALID_ADDRESS;
1895 }
Siva Chandraa3747a92015-05-04 19:43:34 +00001896 break;
Greg Clayton73b472d2010-10-27 03:32:59 +00001897 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001898 if (address_type)
1899 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001900 return LLDB_INVALID_ADDRESS;
1901}
1902
1903addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001904ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001905{
Greg Claytonafacd142011-09-02 01:15:17 +00001906 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001907 if(address_type)
1908 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001909
Enrico Granatac3e320a2011-08-02 17:27:39 +00001910 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001911 return address;
1912
Greg Clayton73b472d2010-10-27 03:32:59 +00001913 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001914 {
1915 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001916 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001917 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001918 break;
1919
Enrico Granata9128ee22011-09-06 19:20:51 +00001920 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001921 case Value::eValueTypeLoadAddress:
1922 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001923 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001924 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001925 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001926 }
1927 break;
1928 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001929
Enrico Granata9128ee22011-09-06 19:20:51 +00001930 if (address_type)
1931 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001932
Greg Clayton737b9322010-09-13 03:32:57 +00001933 return address;
1934}
1935
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001936bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001937ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001938{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001939 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001940 // Make sure our value is up to date first so that our location and location
1941 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001942 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001943 {
1944 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001945 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001946 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001947
Greg Claytonfaac1112013-03-14 18:31:44 +00001948 uint64_t count = 0;
Greg Clayton99558cc42015-08-24 23:46:31 +00001949 const Encoding encoding = GetCompilerType().GetEncoding (count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001950
Greg Claytonb1320972010-07-14 00:18:15 +00001951 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001952
Jim Ingham16e0c682011-08-12 23:34:31 +00001953 Value::ValueType value_type = m_value.GetValueType();
1954
1955 if (value_type == Value::eValueTypeScalar)
1956 {
1957 // If the value is already a scalar, then let the scalar change itself:
1958 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1959 }
Sagar Thakur8536fd12015-08-20 09:12:46 +00001960 else if (byte_size <= 16)
Jim Ingham16e0c682011-08-12 23:34:31 +00001961 {
1962 // If the value fits in a scalar, then make a new scalar and again let the
1963 // scalar code do the conversion, then figure out where to put the new value.
1964 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001965 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1966 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001967 {
Jim Ingham4b536182011-08-09 02:12:22 +00001968 switch (value_type)
1969 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001970 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001971 {
1972 // If it is a load address, then the scalar value is the storage location
1973 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001974 ExecutionContext exe_ctx (GetExecutionContextRef());
1975 Process *process = exe_ctx.GetProcessPtr();
1976 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001977 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001978 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001979 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1980 new_scalar,
1981 byte_size,
1982 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001983 if (!error.Success())
1984 return false;
1985 if (bytes_written != byte_size)
1986 {
1987 error.SetErrorString("unable to write value to memory");
1988 return false;
1989 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001990 }
1991 }
Jim Ingham4b536182011-08-09 02:12:22 +00001992 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001993 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001994 {
1995 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1996 DataExtractor new_data;
1997 new_data.SetByteOrder (m_data.GetByteOrder());
1998
1999 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
2000 m_data.SetData(buffer_sp, 0);
2001 bool success = new_scalar.GetData(new_data);
2002 if (success)
2003 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002004 new_data.CopyByteOrderedData (0,
2005 byte_size,
2006 const_cast<uint8_t *>(m_data.GetDataStart()),
2007 byte_size,
2008 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00002009 }
2010 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
2011
2012 }
Jim Ingham4b536182011-08-09 02:12:22 +00002013 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00002014 case Value::eValueTypeFileAddress:
2015 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00002016 case Value::eValueTypeVector:
2017 break;
Jim Ingham4b536182011-08-09 02:12:22 +00002018 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002019 }
2020 else
2021 {
Jim Ingham16e0c682011-08-12 23:34:31 +00002022 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002023 }
Jim Ingham16e0c682011-08-12 23:34:31 +00002024 }
2025 else
2026 {
2027 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00002028 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002029 return false;
2030 }
Jim Ingham16e0c682011-08-12 23:34:31 +00002031
2032 // If we have reached this point, then we have successfully changed the value.
2033 SetNeedsUpdate();
2034 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002035}
2036
Greg Clayton81e871e2012-02-04 02:27:34 +00002037bool
2038ValueObject::GetDeclaration (Declaration &decl)
2039{
2040 decl.Clear();
2041 return false;
2042}
2043
Greg Clayton84db9102012-03-26 23:03:23 +00002044ConstString
2045ValueObject::GetTypeName()
2046{
Greg Clayton99558cc42015-08-24 23:46:31 +00002047 return GetCompilerType().GetConstTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00002048}
2049
2050ConstString
Enrico Granatae8daa2f2014-05-17 19:14:17 +00002051ValueObject::GetDisplayTypeName()
2052{
2053 return GetTypeName();
2054}
2055
2056ConstString
Greg Clayton84db9102012-03-26 23:03:23 +00002057ValueObject::GetQualifiedTypeName()
2058{
Greg Clayton99558cc42015-08-24 23:46:31 +00002059 return GetCompilerType().GetConstQualifiedTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00002060}
2061
2062
Greg Claytonafacd142011-09-02 01:15:17 +00002063LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00002064ValueObject::GetObjectRuntimeLanguage ()
2065{
Greg Clayton99558cc42015-08-24 23:46:31 +00002066 return GetCompilerType().GetMinimumLanguage ();
Jim Ingham5a369122010-09-28 01:25:32 +00002067}
2068
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002069void
Jim Ingham58b59f92011-04-22 23:53:53 +00002070ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002071{
Jim Ingham58b59f92011-04-22 23:53:53 +00002072 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002073}
2074
2075ValueObjectSP
2076ValueObject::GetSyntheticChild (const ConstString &key) const
2077{
2078 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00002079 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002080 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00002081 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002082 return synthetic_child_sp;
2083}
2084
Greg Clayton2452ab72013-02-08 22:02:02 +00002085uint32_t
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002086ValueObject::GetTypeInfo (CompilerType *pointee_or_element_compiler_type)
Greg Clayton2452ab72013-02-08 22:02:02 +00002087{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002088 return GetCompilerType().GetTypeInfo (pointee_or_element_compiler_type);
Greg Clayton2452ab72013-02-08 22:02:02 +00002089}
2090
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002091bool
2092ValueObject::IsPointerType ()
2093{
Greg Clayton99558cc42015-08-24 23:46:31 +00002094 return GetCompilerType().IsPointerType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002095}
2096
Jim Inghamb7603bb2011-03-18 00:05:18 +00002097bool
Greg Claytondaf515f2011-07-09 20:12:33 +00002098ValueObject::IsArrayType ()
2099{
Greg Clayton99558cc42015-08-24 23:46:31 +00002100 return GetCompilerType().IsArrayType (NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00002101}
2102
2103bool
Enrico Granata9fc19442011-07-06 02:13:41 +00002104ValueObject::IsScalarType ()
2105{
Greg Clayton99558cc42015-08-24 23:46:31 +00002106 return GetCompilerType().IsScalarType ();
Enrico Granata9fc19442011-07-06 02:13:41 +00002107}
2108
2109bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00002110ValueObject::IsIntegerType (bool &is_signed)
2111{
Greg Clayton99558cc42015-08-24 23:46:31 +00002112 return GetCompilerType().IsIntegerType (is_signed);
Jim Inghamb7603bb2011-03-18 00:05:18 +00002113}
Greg Clayton73b472d2010-10-27 03:32:59 +00002114
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002115bool
2116ValueObject::IsPointerOrReferenceType ()
2117{
Greg Clayton99558cc42015-08-24 23:46:31 +00002118 return GetCompilerType().IsPointerOrReferenceType ();
Greg Clayton007d5be2011-05-30 00:49:24 +00002119}
2120
2121bool
Greg Claytondea8cb42011-06-29 22:09:02 +00002122ValueObject::IsPossibleDynamicType ()
2123{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002124 ExecutionContext exe_ctx (GetExecutionContextRef());
2125 Process *process = exe_ctx.GetProcessPtr();
2126 if (process)
2127 return process->IsPossibleDynamicValue(*this);
2128 else
Greg Clayton99558cc42015-08-24 23:46:31 +00002129 return GetCompilerType().IsPossibleDynamicType (NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00002130}
2131
Enrico Granata9e7b3882012-12-13 23:50:33 +00002132bool
Enrico Granata560558e2015-02-11 02:35:39 +00002133ValueObject::IsRuntimeSupportValue ()
2134{
2135 Process *process(GetProcessSP().get());
2136 if (process)
2137 {
2138 LanguageRuntime *runtime = process->GetLanguageRuntime(GetObjectRuntimeLanguage());
2139 if (!runtime)
2140 runtime = process->GetObjCLanguageRuntime();
2141 if (runtime)
2142 return runtime->IsRuntimeSupportValue(*this);
2143 }
2144 return false;
2145}
2146
2147bool
Enrico Granata608d67c2015-11-10 22:39:15 +00002148ValueObject::IsNilReference ()
Enrico Granata9e7b3882012-12-13 23:50:33 +00002149{
Enrico Granata608d67c2015-11-10 22:39:15 +00002150 if (Language *language = Language::FindPlugin(GetObjectRuntimeLanguage()))
2151 {
2152 return language->IsNilReference(*this);
2153 }
2154 return false;
2155}
2156
2157bool
2158ValueObject::IsUninitializedReference ()
2159{
2160 if (Language *language = Language::FindPlugin(GetObjectRuntimeLanguage()))
2161 {
2162 return language->IsUninitializedReference(*this);
2163 }
2164 return false;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002165}
2166
Greg Claytondaf515f2011-07-09 20:12:33 +00002167// This allows you to create an array member using and index
2168// that doesn't not fall in the normal bounds of the array.
2169// Many times structure can be defined as:
2170// struct Collection
2171// {
2172// uint32_t item_count;
2173// Item item_array[0];
2174// };
2175// The size of the "item_array" is 1, but many times in practice
2176// there are more items in "item_array".
2177
2178ValueObjectSP
Bruce Mitchener11d86362015-02-26 23:55:39 +00002179ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00002180{
2181 ValueObjectSP synthetic_child_sp;
Bruce Mitchener11d86362015-02-26 23:55:39 +00002182 if (IsPointerType () || IsArrayType())
Greg Claytondaf515f2011-07-09 20:12:33 +00002183 {
2184 char index_str[64];
Deepak Panickal99fbc072014-03-03 15:39:47 +00002185 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
Greg Claytondaf515f2011-07-09 20:12:33 +00002186 ConstString index_const_str(index_str);
2187 // Check if we have already created a synthetic array member in this
2188 // valid object. If we have we will re-use it.
2189 synthetic_child_sp = GetSyntheticChild (index_const_str);
2190 if (!synthetic_child_sp)
2191 {
2192 ValueObject *synthetic_child;
2193 // We haven't made a synthetic array member for INDEX yet, so
2194 // lets make one and cache it for any future reference.
2195 synthetic_child = CreateChildAtIndex(0, true, index);
Bruce Mitchener11d86362015-02-26 23:55:39 +00002196
Greg Claytondaf515f2011-07-09 20:12:33 +00002197 // Cache the value if we got one back...
2198 if (synthetic_child)
2199 {
2200 AddSyntheticChild(index_const_str, synthetic_child);
2201 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002202 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00002203 synthetic_child_sp->m_is_array_item_for_pointer = true;
2204 }
2205 }
2206 }
2207 return synthetic_child_sp;
2208}
2209
Enrico Granata9fc19442011-07-06 02:13:41 +00002210ValueObjectSP
2211ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2212{
2213 ValueObjectSP synthetic_child_sp;
2214 if (IsScalarType ())
2215 {
2216 char index_str[64];
2217 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2218 ConstString index_const_str(index_str);
2219 // Check if we have already created a synthetic array member in this
2220 // valid object. If we have we will re-use it.
2221 synthetic_child_sp = GetSyntheticChild (index_const_str);
2222 if (!synthetic_child_sp)
2223 {
Enrico Granata9fc19442011-07-06 02:13:41 +00002224 // We haven't made a synthetic array member for INDEX yet, so
2225 // lets make one and cache it for any future reference.
Greg Clayton57ee3062013-07-11 22:46:58 +00002226 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
Greg Clayton99558cc42015-08-24 23:46:31 +00002227 GetCompilerType(),
Greg Clayton57ee3062013-07-11 22:46:58 +00002228 index_const_str,
2229 GetByteSize(),
2230 0,
2231 to-from+1,
2232 from,
2233 false,
2234 false,
Enrico Granatadc62ffd2015-11-09 19:27:34 +00002235 eAddressTypeInvalid,
2236 0);
Enrico Granata9fc19442011-07-06 02:13:41 +00002237
2238 // Cache the value if we got one back...
2239 if (synthetic_child)
2240 {
2241 AddSyntheticChild(index_const_str, synthetic_child);
2242 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002243 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002244 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2245 }
2246 }
2247 }
2248 return synthetic_child_sp;
2249}
2250
Greg Claytonafacd142011-09-02 01:15:17 +00002251ValueObjectSP
Greg Claytona1e5dc82015-08-11 22:53:00 +00002252ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const CompilerType& type, bool can_create)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002253{
2254
2255 ValueObjectSP synthetic_child_sp;
2256
2257 char name_str[64];
2258 snprintf(name_str, sizeof(name_str), "@%i", offset);
2259 ConstString name_const_str(name_str);
2260
2261 // Check if we have already created a synthetic array member in this
2262 // valid object. If we have we will re-use it.
2263 synthetic_child_sp = GetSyntheticChild (name_const_str);
2264
2265 if (synthetic_child_sp.get())
2266 return synthetic_child_sp;
2267
2268 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002269 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002270
Enrico Granata951bdd52015-01-28 01:09:45 +00002271 ExecutionContext exe_ctx (GetExecutionContextRef());
2272
Enrico Granata6f3533f2011-07-29 19:53:35 +00002273 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
Greg Clayton57ee3062013-07-11 22:46:58 +00002274 type,
Enrico Granata6f3533f2011-07-29 19:53:35 +00002275 name_const_str,
Greg Clayton526ae042015-02-12 00:34:25 +00002276 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
Enrico Granata6f3533f2011-07-29 19:53:35 +00002277 offset,
2278 0,
2279 0,
2280 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002281 false,
Enrico Granatadc62ffd2015-11-09 19:27:34 +00002282 eAddressTypeInvalid,
2283 0);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002284 if (synthetic_child)
2285 {
2286 AddSyntheticChild(name_const_str, synthetic_child);
2287 synthetic_child_sp = synthetic_child->GetSP();
2288 synthetic_child_sp->SetName(name_const_str);
2289 synthetic_child_sp->m_is_child_at_offset = true;
2290 }
2291 return synthetic_child_sp;
2292}
2293
Enrico Granata32556cd2014-08-26 20:54:04 +00002294ValueObjectSP
Greg Claytona1e5dc82015-08-11 22:53:00 +00002295ValueObject::GetSyntheticBase (uint32_t offset, const CompilerType& type, bool can_create)
Enrico Granata32556cd2014-08-26 20:54:04 +00002296{
2297 ValueObjectSP synthetic_child_sp;
2298
2299 char name_str[64];
2300 snprintf(name_str, sizeof(name_str), "%s", type.GetTypeName().AsCString("<unknown>"));
2301 ConstString name_const_str(name_str);
2302
2303 // Check if we have already created a synthetic array member in this
2304 // valid object. If we have we will re-use it.
2305 synthetic_child_sp = GetSyntheticChild (name_const_str);
2306
2307 if (synthetic_child_sp.get())
2308 return synthetic_child_sp;
2309
2310 if (!can_create)
2311 return ValueObjectSP();
2312
Enrico Granata32556cd2014-08-26 20:54:04 +00002313 const bool is_base_class = true;
2314
Enrico Granata951bdd52015-01-28 01:09:45 +00002315 ExecutionContext exe_ctx (GetExecutionContextRef());
2316
Enrico Granata32556cd2014-08-26 20:54:04 +00002317 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2318 type,
2319 name_const_str,
Greg Clayton526ae042015-02-12 00:34:25 +00002320 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
Enrico Granata32556cd2014-08-26 20:54:04 +00002321 offset,
2322 0,
2323 0,
2324 is_base_class,
2325 false,
Enrico Granatadc62ffd2015-11-09 19:27:34 +00002326 eAddressTypeInvalid,
2327 0);
Enrico Granata32556cd2014-08-26 20:54:04 +00002328 if (synthetic_child)
2329 {
2330 AddSyntheticChild(name_const_str, synthetic_child);
2331 synthetic_child_sp = synthetic_child->GetSP();
2332 synthetic_child_sp->SetName(name_const_str);
2333 }
2334 return synthetic_child_sp;
2335}
2336
2337
Enrico Granatad55546b2011-07-22 00:16:08 +00002338// your expression path needs to have a leading . or ->
2339// (unless it somehow "looks like" an array, in which case it has
2340// a leading [ symbol). while the [ is meaningful and should be shown
2341// to the user, . and -> are just parser design, but by no means
2342// added information for the user.. strip them off
2343static const char*
2344SkipLeadingExpressionPathSeparators(const char* expression)
2345{
2346 if (!expression || !expression[0])
2347 return expression;
2348 if (expression[0] == '.')
2349 return expression+1;
2350 if (expression[0] == '-' && expression[1] == '>')
2351 return expression+2;
2352 return expression;
2353}
2354
Greg Claytonafacd142011-09-02 01:15:17 +00002355ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002356ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2357{
2358 ValueObjectSP synthetic_child_sp;
2359 ConstString name_const_string(expression);
2360 // Check if we have already created a synthetic array member in this
2361 // valid object. If we have we will re-use it.
2362 synthetic_child_sp = GetSyntheticChild (name_const_string);
2363 if (!synthetic_child_sp)
2364 {
2365 // We haven't made a synthetic array member for expression yet, so
2366 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002367 synthetic_child_sp = GetValueForExpressionPath(expression,
2368 NULL, NULL, NULL,
Enrico Granataef238c12015-03-12 22:30:58 +00002369 GetValueForExpressionPathOptions().SetSyntheticChildrenTraversal(GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None));
Enrico Granatad55546b2011-07-22 00:16:08 +00002370
2371 // Cache the value if we got one back...
2372 if (synthetic_child_sp.get())
2373 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002374 // 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 +00002375 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002376 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002377 }
2378 }
2379 return synthetic_child_sp;
2380}
2381
2382void
Enrico Granata86cc9822012-03-19 22:58:49 +00002383ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002384{
Enrico Granata86cc9822012-03-19 22:58:49 +00002385 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002386 return;
2387
Enrico Granatac5bc4122012-03-27 02:35:13 +00002388 TargetSP target_sp(GetTargetSP());
Enrico Granata5d5f60c2013-09-24 22:58:37 +00002389 if (target_sp && target_sp->GetEnableSyntheticValue() == false)
Enrico Granatac5bc4122012-03-27 02:35:13 +00002390 {
2391 m_synthetic_value = NULL;
2392 return;
2393 }
2394
Enrico Granatae3e91512012-10-22 18:18:36 +00002395 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2396
Enrico Granata5548cb52013-01-28 23:47:25 +00002397 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002398 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002399
Enrico Granata0c489f52012-03-01 04:24:26 +00002400 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002401 return;
2402
Enrico Granatae3e91512012-10-22 18:18:36 +00002403 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2404 return;
2405
Enrico Granata86cc9822012-03-19 22:58:49 +00002406 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002407}
2408
Jim Ingham78a685a2011-04-16 00:01:13 +00002409void
Greg Claytonafacd142011-09-02 01:15:17 +00002410ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002411{
Greg Claytonafacd142011-09-02 01:15:17 +00002412 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002413 return;
2414
Jim Ingham58b59f92011-04-22 23:53:53 +00002415 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002416 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002417 ExecutionContext exe_ctx (GetExecutionContextRef());
2418 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002419 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002420 {
2421 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002422 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002423 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002424 }
2425}
2426
Jim Ingham58b59f92011-04-22 23:53:53 +00002427ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002428ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002429{
Greg Claytonafacd142011-09-02 01:15:17 +00002430 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002431 return ValueObjectSP();
2432
2433 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002434 {
Jim Ingham2837b762011-05-04 03:43:18 +00002435 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002436 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002437 if (m_dynamic_value)
2438 return m_dynamic_value->GetSP();
2439 else
2440 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002441}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002442
Jim Ingham60dbabb2011-12-08 19:44:08 +00002443ValueObjectSP
2444ValueObject::GetStaticValue()
2445{
2446 return GetSP();
2447}
2448
Enrico Granata886147f2012-05-08 18:47:08 +00002449lldb::ValueObjectSP
2450ValueObject::GetNonSyntheticValue ()
2451{
2452 return GetSP();
2453}
2454
Enrico Granatad55546b2011-07-22 00:16:08 +00002455ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002456ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002457{
Enrico Granata86cc9822012-03-19 22:58:49 +00002458 if (use_synthetic == false)
2459 return ValueObjectSP();
2460
Enrico Granatad55546b2011-07-22 00:16:08 +00002461 CalculateSyntheticValue(use_synthetic);
2462
2463 if (m_synthetic_value)
2464 return m_synthetic_value->GetSP();
2465 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002466 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002467}
2468
Greg Claytone221f822011-01-21 01:59:00 +00002469bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002470ValueObject::HasSyntheticValue()
2471{
Enrico Granata5548cb52013-01-28 23:47:25 +00002472 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002473
Enrico Granata0c489f52012-03-01 04:24:26 +00002474 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002475 return false;
2476
Enrico Granata86cc9822012-03-19 22:58:49 +00002477 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002478
2479 if (m_synthetic_value)
2480 return true;
2481 else
2482 return false;
2483}
2484
2485bool
Greg Claytone221f822011-01-21 01:59:00 +00002486ValueObject::GetBaseClassPath (Stream &s)
2487{
2488 if (IsBaseClass())
2489 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002490 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002491 CompilerType compiler_type = GetCompilerType();
Greg Claytone221f822011-01-21 01:59:00 +00002492 std::string cxx_class_name;
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002493 bool this_had_base_class = ClangASTContext::GetCXXClassName (compiler_type, cxx_class_name);
Greg Claytone221f822011-01-21 01:59:00 +00002494 if (this_had_base_class)
2495 {
2496 if (parent_had_base_class)
2497 s.PutCString("::");
2498 s.PutCString(cxx_class_name.c_str());
2499 }
2500 return parent_had_base_class || this_had_base_class;
2501 }
2502 return false;
2503}
2504
2505
2506ValueObject *
2507ValueObject::GetNonBaseClassParent()
2508{
Jim Ingham78a685a2011-04-16 00:01:13 +00002509 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002510 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002511 if (GetParent()->IsBaseClass())
2512 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002513 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002514 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002515 }
2516 return NULL;
2517}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002518
Enrico Granataa3c8f042014-08-19 22:29:08 +00002519
2520bool
2521ValueObject::IsBaseClass (uint32_t& depth)
2522{
2523 if (!IsBaseClass())
2524 {
2525 depth = 0;
2526 return false;
2527 }
2528 if (GetParent())
2529 {
2530 GetParent()->IsBaseClass(depth);
2531 depth = depth + 1;
2532 return true;
2533 }
2534 // TODO: a base of no parent? weird..
2535 depth = 1;
2536 return true;
2537}
2538
Greg Clayton1d3afba2010-10-05 00:00:42 +00002539void
Enrico Granata4becb372011-06-29 22:27:15 +00002540ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002541{
Enrico Granata986fa5f2014-12-09 21:41:16 +00002542 // synthetic children do not actually "exist" as part of the hierarchy, and sometimes they are consed up in ways
2543 // that don't make sense from an underlying language/API standpoint. So, use a special code path here to return
2544 // something that can hopefully be used in expression
2545 if (m_is_synthetic_children_generated)
2546 {
2547 UpdateValueIfNeeded();
2548
2549 if (m_value.GetValueType() == Value::eValueTypeLoadAddress)
2550 {
2551 if (IsPointerOrReferenceType())
2552 {
2553 s.Printf("((%s)0x%" PRIx64 ")",
2554 GetTypeName().AsCString("void"),
2555 GetValueAsUnsigned(0));
2556 return;
2557 }
2558 else
2559 {
2560 uint64_t load_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
2561 if (load_addr != LLDB_INVALID_ADDRESS)
2562 {
2563 s.Printf("(*( (%s *)0x%" PRIx64 "))",
2564 GetTypeName().AsCString("void"),
2565 load_addr);
2566 return;
2567 }
2568 }
2569 }
2570
2571 if (CanProvideValue())
2572 {
2573 s.Printf("((%s)%s)",
2574 GetTypeName().AsCString("void"),
2575 GetValueAsCString());
2576 return;
2577 }
2578
2579 return;
2580 }
2581
Greg Claytone221f822011-01-21 01:59:00 +00002582 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002583
Enrico Granata86cc9822012-03-19 22:58:49 +00002584 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002585 {
Enrico Granata4becb372011-06-29 22:27:15 +00002586 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2587 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2588 // the eHonorPointers mode is meant to produce strings in this latter format
2589 s.PutCString("*(");
2590 }
Greg Claytone221f822011-01-21 01:59:00 +00002591
Enrico Granata4becb372011-06-29 22:27:15 +00002592 ValueObject* parent = GetParent();
2593
2594 if (parent)
2595 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002596
2597 // if we are a deref_of_parent just because we are synthetic array
2598 // members made up to allow ptr[%d] syntax to work in variable
2599 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002600 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002601 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002602
Greg Claytone221f822011-01-21 01:59:00 +00002603 if (!IsBaseClass())
2604 {
2605 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002606 {
Greg Claytone221f822011-01-21 01:59:00 +00002607 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2608 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002609 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002610 CompilerType non_base_class_parent_compiler_type = non_base_class_parent->GetCompilerType();
2611 if (non_base_class_parent_compiler_type)
Greg Claytone221f822011-01-21 01:59:00 +00002612 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002613 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002614 {
2615 s.PutCString("->");
2616 }
Enrico Granata4becb372011-06-29 22:27:15 +00002617 else
2618 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002619 const uint32_t non_base_class_parent_type_info = non_base_class_parent_compiler_type.GetTypeInfo();
Greg Clayton57ee3062013-07-11 22:46:58 +00002620
Enrico Granata622be232014-10-21 20:52:14 +00002621 if (non_base_class_parent_type_info & eTypeIsPointer)
Enrico Granata4becb372011-06-29 22:27:15 +00002622 {
2623 s.PutCString("->");
2624 }
Enrico Granata622be232014-10-21 20:52:14 +00002625 else if ((non_base_class_parent_type_info & eTypeHasChildren) &&
2626 !(non_base_class_parent_type_info & eTypeIsArray))
Enrico Granata4becb372011-06-29 22:27:15 +00002627 {
2628 s.PutChar('.');
2629 }
Greg Claytone221f822011-01-21 01:59:00 +00002630 }
2631 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002632 }
Greg Claytone221f822011-01-21 01:59:00 +00002633
2634 const char *name = GetName().GetCString();
2635 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002636 {
Greg Claytone221f822011-01-21 01:59:00 +00002637 if (qualify_cxx_base_classes)
2638 {
2639 if (GetBaseClassPath (s))
2640 s.PutCString("::");
2641 }
2642 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002643 }
2644 }
2645 }
2646
Enrico Granata86cc9822012-03-19 22:58:49 +00002647 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002648 {
Greg Claytone221f822011-01-21 01:59:00 +00002649 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002650 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002651}
2652
Greg Claytonafacd142011-09-02 01:15:17 +00002653ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002654ValueObject::GetValueForExpressionPath(const char* expression,
2655 const char** first_unparsed,
2656 ExpressionPathScanEndReason* reason_to_stop,
2657 ExpressionPathEndResultType* final_value_type,
2658 const GetValueForExpressionPathOptions& options,
2659 ExpressionPathAftermath* final_task_on_target)
2660{
2661
2662 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002663 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2664 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002665 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002666
2667 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2668 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2669 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2670 final_value_type ? final_value_type : &dummy_final_value_type,
2671 options,
2672 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2673
Enrico Granata86cc9822012-03-19 22:58:49 +00002674 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002675 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002676
Enrico Granata86cc9822012-03-19 22:58:49 +00002677 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 +00002678 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002679 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002680 {
2681 Error error;
2682 ValueObjectSP final_value = ret_val->Dereference(error);
2683 if (error.Fail() || !final_value.get())
2684 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002685 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002686 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002687 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002688 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002689 return ValueObjectSP();
2690 }
2691 else
2692 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002693 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002694 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002695 return final_value;
2696 }
2697 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002698 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002699 {
2700 Error error;
2701 ValueObjectSP final_value = ret_val->AddressOf(error);
2702 if (error.Fail() || !final_value.get())
2703 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002704 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002705 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002706 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002707 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002708 return ValueObjectSP();
2709 }
2710 else
2711 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002712 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002713 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002714 return final_value;
2715 }
2716 }
2717 }
2718 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2719}
2720
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002721int
2722ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002723 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002724 const char** first_unparsed,
2725 ExpressionPathScanEndReason* reason_to_stop,
2726 ExpressionPathEndResultType* final_value_type,
2727 const GetValueForExpressionPathOptions& options,
2728 ExpressionPathAftermath* final_task_on_target)
2729{
2730 const char* dummy_first_unparsed;
2731 ExpressionPathScanEndReason dummy_reason_to_stop;
2732 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002733 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002734
2735 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2736 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2737 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2738 final_value_type ? final_value_type : &dummy_final_value_type,
2739 options,
2740 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2741
2742 if (!ret_val.get()) // if there are errors, I add nothing to the list
2743 return 0;
2744
Enrico Granata86ea8d82012-03-29 01:34:34 +00002745 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002746 {
2747 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002748 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002749 {
2750 list->Append(ret_val);
2751 return 1;
2752 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002753 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 +00002754 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002755 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002756 {
2757 Error error;
2758 ValueObjectSP final_value = ret_val->Dereference(error);
2759 if (error.Fail() || !final_value.get())
2760 {
Greg Clayton23f59502012-07-17 03:23:13 +00002761 if (reason_to_stop)
2762 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2763 if (final_value_type)
2764 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002765 return 0;
2766 }
2767 else
2768 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002769 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002770 list->Append(final_value);
2771 return 1;
2772 }
2773 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002774 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002775 {
2776 Error error;
2777 ValueObjectSP final_value = ret_val->AddressOf(error);
2778 if (error.Fail() || !final_value.get())
2779 {
Greg Clayton23f59502012-07-17 03:23:13 +00002780 if (reason_to_stop)
2781 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2782 if (final_value_type)
2783 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002784 return 0;
2785 }
2786 else
2787 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002788 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002789 list->Append(final_value);
2790 return 1;
2791 }
2792 }
2793 }
2794 }
2795 else
2796 {
2797 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2798 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2799 ret_val,
2800 list,
2801 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2802 final_value_type ? final_value_type : &dummy_final_value_type,
2803 options,
2804 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2805 }
2806 // in any non-covered case, just do the obviously right thing
2807 list->Append(ret_val);
2808 return 1;
2809}
2810
Greg Claytonafacd142011-09-02 01:15:17 +00002811ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002812ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2813 const char** first_unparsed,
2814 ExpressionPathScanEndReason* reason_to_stop,
2815 ExpressionPathEndResultType* final_result,
2816 const GetValueForExpressionPathOptions& options,
2817 ExpressionPathAftermath* what_next)
2818{
2819 ValueObjectSP root = GetSP();
2820
2821 if (!root.get())
2822 return ValueObjectSP();
2823
2824 *first_unparsed = expression_cstr;
2825
2826 while (true)
2827 {
2828
2829 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2830
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002831 CompilerType root_compiler_type = root->GetCompilerType();
2832 CompilerType pointee_compiler_type;
2833 Flags pointee_compiler_type_info;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002834
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002835 Flags root_compiler_type_info(root_compiler_type.GetTypeInfo(&pointee_compiler_type));
2836 if (pointee_compiler_type)
2837 pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002838
2839 if (!expression_cstr || *expression_cstr == '\0')
2840 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002841 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002842 return root;
2843 }
2844
2845 switch (*expression_cstr)
2846 {
2847 case '-':
2848 {
2849 if (options.m_check_dot_vs_arrow_syntax &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002850 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 +00002851 {
2852 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002853 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2854 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002855 return ValueObjectSP();
2856 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002857 if (root_compiler_type_info.Test(eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2858 root_compiler_type_info.Test(eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002859 options.m_no_fragile_ivar)
2860 {
2861 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002862 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2863 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002864 return ValueObjectSP();
2865 }
2866 if (expression_cstr[1] != '>')
2867 {
2868 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002869 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2870 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002871 return ValueObjectSP();
2872 }
2873 expression_cstr++; // skip the -
2874 }
2875 case '.': // or fallthrough from ->
2876 {
2877 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002878 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 +00002879 {
2880 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002881 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2882 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002883 return ValueObjectSP();
2884 }
2885 expression_cstr++; // skip .
2886 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2887 ConstString child_name;
2888 if (!next_separator) // if no other separator just expand this last layer
2889 {
2890 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002891 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2892
2893 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002894 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002895 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002896 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2897 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002898 return child_valobj_sp;
2899 }
Enrico Granataef238c12015-03-12 22:30:58 +00002900 else
Enrico Granata8c9d3562011-08-11 17:08:01 +00002901 {
Enrico Granataef238c12015-03-12 22:30:58 +00002902 switch (options.m_synthetic_children_traversal)
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002903 {
Enrico Granataef238c12015-03-12 22:30:58 +00002904 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None:
2905 break;
2906 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic:
2907 if (root->IsSynthetic())
2908 {
2909 child_valobj_sp = root->GetNonSyntheticValue();
2910 if (child_valobj_sp.get())
2911 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2912 }
2913 break;
2914 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic:
2915 if (!root->IsSynthetic())
2916 {
2917 child_valobj_sp = root->GetSyntheticValue();
2918 if (child_valobj_sp.get())
2919 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2920 }
2921 break;
2922 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both:
2923 if (root->IsSynthetic())
2924 {
2925 child_valobj_sp = root->GetNonSyntheticValue();
2926 if (child_valobj_sp.get())
2927 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2928 }
2929 else
2930 {
2931 child_valobj_sp = root->GetSyntheticValue();
2932 if (child_valobj_sp.get())
2933 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2934 }
2935 break;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002936 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002937 }
2938
2939 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2940 // so we hit the "else" branch, and return an error
2941 if(child_valobj_sp.get()) // if it worked, just return
2942 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002943 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002944 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2945 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002946 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002947 }
2948 else
2949 {
2950 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002951 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2952 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002953 return ValueObjectSP();
2954 }
2955 }
2956 else // other layers do expand
2957 {
2958 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002959 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2960 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002961 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002962 root = child_valobj_sp;
2963 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002964 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002965 continue;
2966 }
Enrico Granataef238c12015-03-12 22:30:58 +00002967 else
Enrico Granata8c9d3562011-08-11 17:08:01 +00002968 {
Enrico Granataef238c12015-03-12 22:30:58 +00002969 switch (options.m_synthetic_children_traversal)
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002970 {
Enrico Granataef238c12015-03-12 22:30:58 +00002971 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None:
2972 break;
2973 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic:
2974 if (root->IsSynthetic())
2975 {
2976 child_valobj_sp = root->GetNonSyntheticValue();
2977 if (child_valobj_sp.get())
2978 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2979 }
2980 break;
2981 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic:
2982 if (!root->IsSynthetic())
2983 {
2984 child_valobj_sp = root->GetSyntheticValue();
2985 if (child_valobj_sp.get())
2986 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2987 }
2988 break;
2989 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both:
2990 if (root->IsSynthetic())
2991 {
2992 child_valobj_sp = root->GetNonSyntheticValue();
2993 if (child_valobj_sp.get())
2994 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2995 }
2996 else
2997 {
2998 child_valobj_sp = root->GetSyntheticValue();
2999 if (child_valobj_sp.get())
3000 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
3001 }
3002 break;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00003003 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00003004 }
3005
3006 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
3007 // so we hit the "else" branch, and return an error
3008 if(child_valobj_sp.get()) // if it worked, move on
3009 {
3010 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003011 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00003012 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003013 continue;
3014 }
3015 else
3016 {
3017 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003018 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3019 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003020 return ValueObjectSP();
3021 }
3022 }
3023 break;
3024 }
3025 case '[':
3026 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003027 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 +00003028 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003029 if (!root_compiler_type_info.Test(eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003030 {
Enrico Granataef238c12015-03-12 22:30:58 +00003031 if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None) // ...only chance left is synthetic
Enrico Granata27b625e2011-08-09 01:04:56 +00003032 {
3033 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003034 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3035 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003036 return ValueObjectSP();
3037 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003038 }
3039 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3040 {
3041 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003042 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3043 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003044 return ValueObjectSP();
3045 }
3046 }
3047 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3048 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003049 if (!root_compiler_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003050 {
3051 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003052 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3053 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003054 return ValueObjectSP();
3055 }
3056 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
3057 {
3058 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003059 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3060 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003061 return root;
3062 }
3063 }
3064 const char *separator_position = ::strchr(expression_cstr+1,'-');
3065 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3066 if (!close_bracket_position) // if there is no ], this is a syntax error
3067 {
3068 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003069 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3070 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003071 return ValueObjectSP();
3072 }
3073 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3074 {
3075 char *end = NULL;
3076 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3077 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3078 {
3079 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003080 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3081 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003082 return ValueObjectSP();
3083 }
3084 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3085 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003086 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003087 {
3088 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003089 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3090 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003091 return root;
3092 }
3093 else
3094 {
3095 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003096 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3097 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003098 return ValueObjectSP();
3099 }
3100 }
3101 // from here on we do have a valid index
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003102 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003103 {
Greg Claytondaf515f2011-07-09 20:12:33 +00003104 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
3105 if (!child_valobj_sp)
Bruce Mitchener11d86362015-02-26 23:55:39 +00003106 child_valobj_sp = root->GetSyntheticArrayMember(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003107 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00003108 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
3109 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00003110 if (child_valobj_sp)
3111 {
3112 root = child_valobj_sp;
3113 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003114 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00003115 continue;
3116 }
3117 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003118 {
3119 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003120 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3121 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003122 return ValueObjectSP();
3123 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003124 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003125 else if (root_compiler_type_info.Test(eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003126 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003127 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 +00003128 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003129 {
3130 Error error;
3131 root = root->Dereference(error);
3132 if (error.Fail() || !root.get())
3133 {
3134 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003135 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3136 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003137 return ValueObjectSP();
3138 }
3139 else
3140 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003141 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003142 continue;
3143 }
3144 }
3145 else
3146 {
Greg Clayton99558cc42015-08-24 23:46:31 +00003147 if (root->GetCompilerType().GetMinimumLanguage() == eLanguageTypeObjC
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003148 && pointee_compiler_type_info.AllClear(eTypeIsPointer)
Greg Clayton84db9102012-03-26 23:03:23 +00003149 && root->HasSyntheticValue()
Enrico Granataef238c12015-03-12 22:30:58 +00003150 && (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic ||
3151 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both))
Enrico Granata27b625e2011-08-09 01:04:56 +00003152 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003153 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003154 }
3155 else
Bruce Mitchener11d86362015-02-26 23:55:39 +00003156 root = root->GetSyntheticArrayMember(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003157 if (!root.get())
3158 {
3159 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003160 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3161 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003162 return ValueObjectSP();
3163 }
3164 else
3165 {
3166 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003167 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003168 continue;
3169 }
3170 }
3171 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003172 else if (root_compiler_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003173 {
3174 root = root->GetSyntheticBitFieldChild(index, index, true);
3175 if (!root.get())
3176 {
3177 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003178 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3179 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003180 return ValueObjectSP();
3181 }
3182 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3183 {
3184 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003185 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3186 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003187 return root;
3188 }
3189 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003190 else if (root_compiler_type_info.Test(eTypeIsVector))
Enrico Granata08a1bb82013-06-19 00:00:45 +00003191 {
3192 root = root->GetChildAtIndex(index, true);
3193 if (!root.get())
3194 {
3195 *first_unparsed = expression_cstr;
3196 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3197 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3198 return ValueObjectSP();
3199 }
3200 else
3201 {
3202 *first_unparsed = end+1; // skip ]
3203 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3204 continue;
3205 }
3206 }
Enrico Granataef238c12015-03-12 22:30:58 +00003207 else if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic ||
3208 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both)
Enrico Granata27b625e2011-08-09 01:04:56 +00003209 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003210 if (root->HasSyntheticValue())
3211 root = root->GetSyntheticValue();
3212 else if (!root->IsSynthetic())
3213 {
3214 *first_unparsed = expression_cstr;
3215 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3216 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3217 return ValueObjectSP();
3218 }
3219 // if we are here, then root itself is a synthetic VO.. should be good to go
3220
Enrico Granata27b625e2011-08-09 01:04:56 +00003221 if (!root.get())
3222 {
3223 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003224 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3225 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3226 return ValueObjectSP();
3227 }
3228 root = root->GetChildAtIndex(index, true);
3229 if (!root.get())
3230 {
3231 *first_unparsed = expression_cstr;
3232 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3233 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003234 return ValueObjectSP();
3235 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00003236 else
3237 {
3238 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003239 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00003240 continue;
3241 }
Enrico Granata27b625e2011-08-09 01:04:56 +00003242 }
3243 else
3244 {
3245 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003246 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3247 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003248 return ValueObjectSP();
3249 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003250 }
3251 else // we have a low and a high index
3252 {
3253 char *end = NULL;
3254 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3255 if (!end || end != separator_position) // if something weird is in our way return an error
3256 {
3257 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003258 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3259 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003260 return ValueObjectSP();
3261 }
3262 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3263 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3264 {
3265 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003266 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3267 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003268 return ValueObjectSP();
3269 }
3270 if (index_lower > index_higher) // swap indices if required
3271 {
3272 unsigned long temp = index_lower;
3273 index_lower = index_higher;
3274 index_higher = temp;
3275 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003276 if (root_compiler_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003277 {
3278 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3279 if (!root.get())
3280 {
3281 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003282 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3283 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003284 return ValueObjectSP();
3285 }
3286 else
3287 {
3288 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003289 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3290 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003291 return root;
3292 }
3293 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003294 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 +00003295 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003296 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003297 {
3298 Error error;
3299 root = root->Dereference(error);
3300 if (error.Fail() || !root.get())
3301 {
3302 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003303 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3304 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003305 return ValueObjectSP();
3306 }
3307 else
3308 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003309 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003310 continue;
3311 }
3312 }
3313 else
3314 {
3315 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003316 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3317 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003318 return root;
3319 }
3320 }
3321 break;
3322 }
3323 default: // some non-separator is in the way
3324 {
3325 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003326 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3327 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003328 return ValueObjectSP();
3329 break;
3330 }
3331 }
3332 }
3333}
3334
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003335int
3336ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3337 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00003338 ValueObjectSP root,
3339 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003340 ExpressionPathScanEndReason* reason_to_stop,
3341 ExpressionPathEndResultType* final_result,
3342 const GetValueForExpressionPathOptions& options,
3343 ExpressionPathAftermath* what_next)
3344{
3345 if (!root.get())
3346 return 0;
3347
3348 *first_unparsed = expression_cstr;
3349
3350 while (true)
3351 {
3352
3353 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3354
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003355 CompilerType root_compiler_type = root->GetCompilerType();
3356 CompilerType pointee_compiler_type;
3357 Flags pointee_compiler_type_info;
3358 Flags root_compiler_type_info(root_compiler_type.GetTypeInfo(&pointee_compiler_type));
3359 if (pointee_compiler_type)
3360 pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003361
3362 if (!expression_cstr || *expression_cstr == '\0')
3363 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003364 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003365 list->Append(root);
3366 return 1;
3367 }
3368
3369 switch (*expression_cstr)
3370 {
3371 case '[':
3372 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003373 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 +00003374 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003375 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 +00003376 {
3377 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003378 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3379 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003380 return 0;
3381 }
3382 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3383 {
3384 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003385 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3386 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003387 return 0;
3388 }
3389 }
3390 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3391 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003392 if (!root_compiler_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003393 {
3394 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003395 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3396 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003397 return 0;
3398 }
3399 else // expand this into list
3400 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003401 const size_t max_index = root->GetNumChildren() - 1;
3402 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003403 {
3404 ValueObjectSP child =
3405 root->GetChildAtIndex(index, true);
3406 list->Append(child);
3407 }
3408 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003409 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3410 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003411 return max_index; // tell me number of items I added to the VOList
3412 }
3413 }
3414 const char *separator_position = ::strchr(expression_cstr+1,'-');
3415 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3416 if (!close_bracket_position) // if there is no ], this is a syntax error
3417 {
3418 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003419 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3420 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003421 return 0;
3422 }
3423 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3424 {
3425 char *end = NULL;
3426 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3427 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3428 {
3429 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003430 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3431 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003432 return 0;
3433 }
3434 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3435 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003436 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003437 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003438 const size_t max_index = root->GetNumChildren() - 1;
3439 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003440 {
3441 ValueObjectSP child =
3442 root->GetChildAtIndex(index, true);
3443 list->Append(child);
3444 }
3445 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003446 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3447 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003448 return max_index; // tell me number of items I added to the VOList
3449 }
3450 else
3451 {
3452 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003453 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3454 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003455 return 0;
3456 }
3457 }
3458 // from here on we do have a valid index
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003459 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003460 {
3461 root = root->GetChildAtIndex(index, true);
3462 if (!root.get())
3463 {
3464 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003465 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3466 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003467 return 0;
3468 }
3469 else
3470 {
3471 list->Append(root);
3472 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003473 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3474 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003475 return 1;
3476 }
3477 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003478 else if (root_compiler_type_info.Test(eTypeIsPointer))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003479 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003480 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 +00003481 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003482 {
3483 Error error;
3484 root = root->Dereference(error);
3485 if (error.Fail() || !root.get())
3486 {
3487 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003488 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3489 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003490 return 0;
3491 }
3492 else
3493 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003494 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003495 continue;
3496 }
3497 }
3498 else
3499 {
Bruce Mitchener11d86362015-02-26 23:55:39 +00003500 root = root->GetSyntheticArrayMember(index, true);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003501 if (!root.get())
3502 {
3503 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003504 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3505 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003506 return 0;
3507 }
3508 else
3509 {
3510 list->Append(root);
3511 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003512 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3513 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003514 return 1;
3515 }
3516 }
3517 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003518 else /*if (ClangASTContext::IsScalarType(root_compiler_type))*/
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003519 {
3520 root = root->GetSyntheticBitFieldChild(index, index, true);
3521 if (!root.get())
3522 {
3523 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003524 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3525 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003526 return 0;
3527 }
3528 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3529 {
3530 list->Append(root);
3531 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003532 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3533 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003534 return 1;
3535 }
3536 }
3537 }
3538 else // we have a low and a high index
3539 {
3540 char *end = NULL;
3541 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3542 if (!end || end != separator_position) // if something weird is in our way return an error
3543 {
3544 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003545 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3546 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003547 return 0;
3548 }
3549 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3550 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3551 {
3552 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003553 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3554 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003555 return 0;
3556 }
3557 if (index_lower > index_higher) // swap indices if required
3558 {
3559 unsigned long temp = index_lower;
3560 index_lower = index_higher;
3561 index_higher = temp;
3562 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003563 if (root_compiler_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003564 {
3565 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3566 if (!root.get())
3567 {
3568 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003569 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3570 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003571 return 0;
3572 }
3573 else
3574 {
3575 list->Append(root);
3576 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003577 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3578 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003579 return 1;
3580 }
3581 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003582 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 +00003583 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003584 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003585 {
3586 Error error;
3587 root = root->Dereference(error);
3588 if (error.Fail() || !root.get())
3589 {
3590 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003591 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3592 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003593 return 0;
3594 }
3595 else
3596 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003597 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003598 continue;
3599 }
3600 }
3601 else
3602 {
Johnny Chen44805302011-07-19 19:48:13 +00003603 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003604 index <= index_higher; index++)
3605 {
3606 ValueObjectSP child =
3607 root->GetChildAtIndex(index, true);
3608 list->Append(child);
3609 }
3610 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003611 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3612 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003613 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3614 }
3615 }
3616 break;
3617 }
3618 default: // some non-[ separator, or something entirely wrong, is in the way
3619 {
3620 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003621 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3622 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003623 return 0;
3624 break;
3625 }
3626 }
3627 }
3628}
3629
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003630void
3631ValueObject::LogValueObject (Log *log)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003632{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003633 if (log)
Enrico Granatad5957332015-06-03 20:43:54 +00003634 return LogValueObject (log, DumpValueObjectOptions(*this));
Greg Clayton1d3afba2010-10-05 00:00:42 +00003635}
3636
Enrico Granata0c489f52012-03-01 04:24:26 +00003637void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003638ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003639{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003640 if (log)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003641 {
3642 StreamString s;
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003643 Dump (s, options);
Greg Claytonf830dbb2012-03-22 18:15:37 +00003644 if (s.GetSize())
3645 log->PutCString(s.GetData());
3646 }
3647}
3648
3649void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003650ValueObject::Dump (Stream &s)
Enrico Granata0c489f52012-03-01 04:24:26 +00003651{
Enrico Granatad5957332015-06-03 20:43:54 +00003652 Dump (s, DumpValueObjectOptions(*this));
Enrico Granata0c489f52012-03-01 04:24:26 +00003653}
3654
3655void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003656ValueObject::Dump (Stream &s,
3657 const DumpValueObjectOptions& options)
Enrico Granata0c489f52012-03-01 04:24:26 +00003658{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003659 ValueObjectPrinter printer(this,&s,options);
3660 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003661}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003662
3663ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003664ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003665{
3666 ValueObjectSP valobj_sp;
3667
Enrico Granatac3e320a2011-08-02 17:27:39 +00003668 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003669 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003670 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003671
3672 DataExtractor data;
3673 data.SetByteOrder (m_data.GetByteOrder());
3674 data.SetAddressByteSize(m_data.GetAddressByteSize());
3675
Enrico Granata9f1e2042012-04-24 22:15:37 +00003676 if (IsBitfield())
3677 {
3678 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
Greg Clayton57ee3062013-07-11 22:46:58 +00003679 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Enrico Granata9f1e2042012-04-24 22:15:37 +00003680 }
3681 else
Greg Clayton57ee3062013-07-11 22:46:58 +00003682 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003683
3684 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton99558cc42015-08-24 23:46:31 +00003685 GetCompilerType(),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003686 name,
3687 data,
3688 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003689 }
Jim Ingham6035b672011-03-31 00:19:25 +00003690
3691 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003692 {
Greg Claytoneeb15652013-12-10 23:16:40 +00003693 ExecutionContext exe_ctx (GetExecutionContextRef());
3694 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003695 }
3696 return valobj_sp;
3697}
3698
Enrico Granata538a88a2014-10-09 18:24:30 +00003699ValueObjectSP
3700ValueObject::GetQualifiedRepresentationIfAvailable (lldb::DynamicValueType dynValue,
3701 bool synthValue)
3702{
3703 ValueObjectSP result_sp(GetSP());
3704
3705 switch (dynValue)
3706 {
3707 case lldb::eDynamicCanRunTarget:
3708 case lldb::eDynamicDontRunTarget:
3709 {
3710 if (!result_sp->IsDynamic())
3711 {
3712 if (result_sp->GetDynamicValue(dynValue))
3713 result_sp = result_sp->GetDynamicValue(dynValue);
3714 }
3715 }
3716 break;
3717 case lldb::eNoDynamicValues:
Enrico Granata538a88a2014-10-09 18:24:30 +00003718 {
3719 if (result_sp->IsDynamic())
3720 {
3721 if (result_sp->GetStaticValue())
3722 result_sp = result_sp->GetStaticValue();
3723 }
3724 }
3725 break;
3726 }
3727
3728 if (synthValue)
3729 {
3730 if (!result_sp->IsSynthetic())
3731 {
3732 if (result_sp->GetSyntheticValue())
3733 result_sp = result_sp->GetSyntheticValue();
3734 }
3735 }
3736 else
3737 {
3738 if (result_sp->IsSynthetic())
3739 {
3740 if (result_sp->GetNonSyntheticValue())
3741 result_sp = result_sp->GetNonSyntheticValue();
3742 }
3743 }
3744
3745 return result_sp;
3746}
3747
Greg Clayton759e7442014-07-19 00:12:57 +00003748lldb::addr_t
3749ValueObject::GetCPPVTableAddress (AddressType &address_type)
3750{
Greg Claytona1e5dc82015-08-11 22:53:00 +00003751 CompilerType pointee_type;
Greg Clayton99558cc42015-08-24 23:46:31 +00003752 CompilerType this_type(GetCompilerType());
Greg Clayton759e7442014-07-19 00:12:57 +00003753 uint32_t type_info = this_type.GetTypeInfo(&pointee_type);
3754 if (type_info)
3755 {
3756 bool ptr_or_ref = false;
Enrico Granata622be232014-10-21 20:52:14 +00003757 if (type_info & (eTypeIsPointer | eTypeIsReference))
Greg Clayton759e7442014-07-19 00:12:57 +00003758 {
3759 ptr_or_ref = true;
3760 type_info = pointee_type.GetTypeInfo();
3761 }
3762
Enrico Granata622be232014-10-21 20:52:14 +00003763 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus;
Greg Clayton759e7442014-07-19 00:12:57 +00003764 if ((type_info & cpp_class) == cpp_class)
3765 {
3766 if (ptr_or_ref)
3767 {
3768 address_type = GetAddressTypeOfChildren();
3769 return GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
3770 }
3771 else
3772 return GetAddressOf (false, &address_type);
3773 }
3774 }
3775
3776 address_type = eAddressTypeInvalid;
3777 return LLDB_INVALID_ADDRESS;
3778}
3779
Greg Claytonafacd142011-09-02 01:15:17 +00003780ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003781ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003782{
Jim Ingham58b59f92011-04-22 23:53:53 +00003783 if (m_deref_valobj)
3784 return m_deref_valobj->GetSP();
Chaoren Lind7bdc272015-07-31 00:35:40 +00003785
3786 const bool is_pointer_or_reference_type = IsPointerOrReferenceType();
3787 if (is_pointer_or_reference_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003788 {
3789 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003790 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003791
3792 std::string child_name_str;
3793 uint32_t child_byte_size = 0;
3794 int32_t child_byte_offset = 0;
3795 uint32_t child_bitfield_bit_size = 0;
3796 uint32_t child_bitfield_bit_offset = 0;
3797 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003798 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003799 const bool transparent_pointers = false;
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003800 CompilerType compiler_type = GetCompilerType();
3801 CompilerType child_compiler_type;
Enrico Granatadc62ffd2015-11-09 19:27:34 +00003802 uint64_t language_flags;
Jim Inghamd555bac2011-06-24 22:03:24 +00003803
Greg Claytoncc4d0142012-02-17 07:49:44 +00003804 ExecutionContext exe_ctx (GetExecutionContextRef());
Chaoren Lind7bdc272015-07-31 00:35:40 +00003805
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003806 child_compiler_type = compiler_type.GetChildCompilerTypeAtIndex (&exe_ctx,
3807 0,
3808 transparent_pointers,
3809 omit_empty_base_classes,
3810 ignore_array_bounds,
3811 child_name_str,
3812 child_byte_size,
3813 child_byte_offset,
3814 child_bitfield_bit_size,
3815 child_bitfield_bit_offset,
3816 child_is_base_class,
3817 child_is_deref_of_parent,
Enrico Granatadc62ffd2015-11-09 19:27:34 +00003818 this,
3819 language_flags);
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003820 if (child_compiler_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003821 {
3822 ConstString child_name;
3823 if (!child_name_str.empty())
3824 child_name.SetCString (child_name_str.c_str());
3825
Jim Ingham58b59f92011-04-22 23:53:53 +00003826 m_deref_valobj = new ValueObjectChild (*this,
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003827 child_compiler_type,
Jim Ingham58b59f92011-04-22 23:53:53 +00003828 child_name,
3829 child_byte_size,
3830 child_byte_offset,
3831 child_bitfield_bit_size,
3832 child_bitfield_bit_offset,
3833 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003834 child_is_deref_of_parent,
Enrico Granatadc62ffd2015-11-09 19:27:34 +00003835 eAddressTypeInvalid,
3836 language_flags);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003837 }
3838 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003839
Jim Ingham58b59f92011-04-22 23:53:53 +00003840 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003841 {
3842 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003843 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003844 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003845 else
3846 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003847 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003848 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003849
Chaoren Lind7bdc272015-07-31 00:35:40 +00003850 if (is_pointer_or_reference_type)
Greg Clayton54979cd2010-12-15 05:08:08 +00003851 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3852 else
Chaoren Lind7bdc272015-07-31 00:35:40 +00003853 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 +00003854 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003855 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003856}
3857
Greg Claytonafacd142011-09-02 01:15:17 +00003858ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003859ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003860{
Jim Ingham78a685a2011-04-16 00:01:13 +00003861 if (m_addr_of_valobj_sp)
3862 return m_addr_of_valobj_sp;
3863
Greg Claytone0d378b2011-03-24 21:19:54 +00003864 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003865 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003866 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003867 error.Clear();
Siva Chandraa3747a92015-05-04 19:43:34 +00003868 if (addr != LLDB_INVALID_ADDRESS && address_type != eAddressTypeHost)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003869 {
3870 switch (address_type)
3871 {
3872 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003873 {
3874 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003875 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003876 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3877 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003878 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003879
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003880 case eAddressTypeFile:
3881 case eAddressTypeLoad:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003882 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003883 CompilerType compiler_type = GetCompilerType();
3884 if (compiler_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003885 {
3886 std::string name (1, '&');
3887 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003888 ExecutionContext exe_ctx (GetExecutionContextRef());
3889 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003890 compiler_type.GetPointerType(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003891 ConstString (name.c_str()),
3892 addr,
3893 eAddressTypeInvalid,
3894 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003895 }
3896 }
3897 break;
Siva Chandraa3747a92015-05-04 19:43:34 +00003898 default:
3899 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003900 }
3901 }
Sean Callananed185ab2013-04-19 19:47:32 +00003902 else
3903 {
3904 StreamString expr_path_strm;
3905 GetExpressionPath(expr_path_strm, true);
3906 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3907 }
3908
Jim Ingham78a685a2011-04-16 00:01:13 +00003909 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003910}
3911
Greg Clayton9a142cf2012-02-03 05:34:10 +00003912ValueObjectSP
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003913ValueObject::Cast (const CompilerType &compiler_type)
Greg Clayton9a142cf2012-02-03 05:34:10 +00003914{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003915 return ValueObjectCast::Create (*this, GetName(), compiler_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003916}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003917
Greg Claytonafacd142011-09-02 01:15:17 +00003918ValueObjectSP
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003919ValueObject::CastPointerType (const char *name, CompilerType &compiler_type)
Greg Claytonb2dcc362011-05-05 23:32:56 +00003920{
Greg Claytonafacd142011-09-02 01:15:17 +00003921 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003922 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003923 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003924
3925 if (ptr_value != LLDB_INVALID_ADDRESS)
3926 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003927 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003928 ExecutionContext exe_ctx (GetExecutionContextRef());
3929 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003930 name,
3931 ptr_addr,
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003932 compiler_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003933 }
3934 return valobj_sp;
3935}
3936
Greg Claytonafacd142011-09-02 01:15:17 +00003937ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003938ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3939{
Greg Claytonafacd142011-09-02 01:15:17 +00003940 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003941 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003942 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003943
3944 if (ptr_value != LLDB_INVALID_ADDRESS)
3945 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003946 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003947 ExecutionContext exe_ctx (GetExecutionContextRef());
3948 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003949 name,
3950 ptr_addr,
3951 type_sp);
3952 }
3953 return valobj_sp;
3954}
3955
Jim Ingham6035b672011-03-31 00:19:25 +00003956ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003957 m_mod_id(),
3958 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003959 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003960{
3961}
3962
3963ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003964 m_mod_id(),
3965 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003966 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003967{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003968 ExecutionContext exe_ctx(exe_scope);
3969 TargetSP target_sp (exe_ctx.GetTargetSP());
3970 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003971 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003972 m_exe_ctx_ref.SetTargetSP (target_sp);
3973 ProcessSP process_sp (exe_ctx.GetProcessSP());
3974 if (!process_sp)
3975 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003976
Greg Claytoncc4d0142012-02-17 07:49:44 +00003977 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003978 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003979 m_mod_id = process_sp->GetModID();
3980 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003981
Greg Claytoncc4d0142012-02-17 07:49:44 +00003982 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003983
Greg Claytoncc4d0142012-02-17 07:49:44 +00003984 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003985 {
3986 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003987 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003988 }
Jim Ingham6035b672011-03-31 00:19:25 +00003989
Greg Claytoncc4d0142012-02-17 07:49:44 +00003990 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003991 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003992 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003993
Jason Molendab57e4a12013-11-04 09:33:30 +00003994 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003995 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003996 {
3997 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003998 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003999 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00004000 if (frame_sp)
4001 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00004002 }
4003 }
4004 }
Jim Ingham6035b672011-03-31 00:19:25 +00004005}
4006
4007ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00004008 m_mod_id(),
4009 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
Sean Callanan7375f3e2014-12-09 21:18:59 +00004010 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00004011{
4012}
4013
4014ValueObject::EvaluationPoint::~EvaluationPoint ()
4015{
4016}
4017
Jim Ingham6035b672011-03-31 00:19:25 +00004018// This function checks the EvaluationPoint against the current process state. If the current
4019// state matches the evaluation point, or the evaluation point is already invalid, then we return
4020// false, meaning "no change". If the current state is different, we update our state, and return
4021// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
4022// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00004023// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00004024
4025bool
Enrico Granatabb642e52015-05-16 01:27:00 +00004026ValueObject::EvaluationPoint::SyncWithProcessState(bool accept_invalid_exe_ctx)
Jim Ingham6035b672011-03-31 00:19:25 +00004027{
Jim Ingham73ca05a2011-12-17 01:35:57 +00004028 // 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 +00004029 const bool thread_and_frame_only_if_stopped = true;
4030 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
Jim Ingham73ca05a2011-12-17 01:35:57 +00004031
Greg Claytoncc4d0142012-02-17 07:49:44 +00004032 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00004033 return false;
4034
Jim Ingham6035b672011-03-31 00:19:25 +00004035 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00004036 Process *process = exe_ctx.GetProcessPtr();
4037 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00004038 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00004039
Jim Ingham6035b672011-03-31 00:19:25 +00004040 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00004041 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00004042
Jim Ingham78a685a2011-04-16 00:01:13 +00004043 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
4044 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00004045 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00004046 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00004047
Greg Clayton23f59502012-07-17 03:23:13 +00004048 bool changed = false;
4049 const bool was_valid = m_mod_id.IsValid();
4050 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004051 {
4052 if (m_mod_id == current_mod_id)
4053 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00004054 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004055 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00004056 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004057 }
Jim Ingham9ee01152011-12-10 01:49:43 +00004058 else
4059 {
4060 m_mod_id = current_mod_id;
4061 m_needs_update = true;
4062 changed = true;
4063 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004064 }
Jim Ingham6035b672011-03-31 00:19:25 +00004065
Jim Ingham73ca05a2011-12-17 01:35:57 +00004066 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
4067 // That way we'll be sure to return a valid exe_scope.
4068 // 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 +00004069
Enrico Granatabb642e52015-05-16 01:27:00 +00004070 if (!accept_invalid_exe_ctx)
Jim Ingham6035b672011-03-31 00:19:25 +00004071 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004072 if (m_exe_ctx_ref.HasThreadRef())
Greg Clayton262f80d2011-07-06 16:49:27 +00004073 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004074 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
4075 if (thread_sp)
Greg Claytoncc4d0142012-02-17 07:49:44 +00004076 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004077 if (m_exe_ctx_ref.HasFrameRef())
Greg Claytoncc4d0142012-02-17 07:49:44 +00004078 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004079 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
4080 if (!frame_sp)
4081 {
4082 // We used to have a frame, but now it is gone
4083 SetInvalid();
4084 changed = was_valid;
4085 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00004086 }
4087 }
Enrico Granatabb642e52015-05-16 01:27:00 +00004088 else
4089 {
4090 // We used to have a thread, but now it is gone
4091 SetInvalid();
4092 changed = was_valid;
4093 }
Greg Clayton262f80d2011-07-06 16:49:27 +00004094 }
Jim Ingham6035b672011-03-31 00:19:25 +00004095 }
Enrico Granatabb642e52015-05-16 01:27:00 +00004096
Jim Ingham9ee01152011-12-10 01:49:43 +00004097 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00004098}
4099
Jim Ingham61be0902011-05-02 18:13:59 +00004100void
4101ValueObject::EvaluationPoint::SetUpdated ()
4102{
Greg Claytoncc4d0142012-02-17 07:49:44 +00004103 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
4104 if (process_sp)
4105 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00004106 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00004107}
4108
4109
Enrico Granataf2bbf712011-07-15 02:26:42 +00004110
4111void
Enrico Granata86cc9822012-03-19 22:58:49 +00004112ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004113{
Enrico Granata86cc9822012-03-19 22:58:49 +00004114 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4115 m_value_str.clear();
4116
4117 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4118 m_location_str.clear();
4119
4120 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
Enrico Granata86cc9822012-03-19 22:58:49 +00004121 m_summary_str.clear();
Enrico Granata86cc9822012-03-19 22:58:49 +00004122
4123 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4124 m_object_desc_str.clear();
4125
4126 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4127 {
4128 if (m_synthetic_value)
4129 m_synthetic_value = NULL;
4130 }
Enrico Granata744794a2014-09-05 21:46:22 +00004131
4132 if ((clear_mask & eClearUserVisibleDataItemsValidator) == eClearUserVisibleDataItemsValidator)
4133 m_validation_result.reset();
Johnny Chen44805302011-07-19 19:48:13 +00004134}
Enrico Granata9128ee22011-09-06 19:20:51 +00004135
4136SymbolContextScope *
4137ValueObject::GetSymbolContextScope()
4138{
4139 if (m_parent)
4140 {
4141 if (!m_parent->IsPointerOrReferenceType())
4142 return m_parent->GetSymbolContextScope();
4143 }
4144 return NULL;
4145}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004146
4147lldb::ValueObjectSP
4148ValueObject::CreateValueObjectFromExpression (const char* name,
4149 const char* expression,
4150 const ExecutionContext& exe_ctx)
4151{
Enrico Granata972be532014-12-17 21:18:43 +00004152 return CreateValueObjectFromExpression(name, expression, exe_ctx, EvaluateExpressionOptions());
4153}
4154
4155
4156lldb::ValueObjectSP
4157ValueObject::CreateValueObjectFromExpression (const char* name,
4158 const char* expression,
4159 const ExecutionContext& exe_ctx,
4160 const EvaluateExpressionOptions& options)
4161{
Enrico Granatab2698cd2012-09-13 18:27:09 +00004162 lldb::ValueObjectSP retval_sp;
4163 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4164 if (!target_sp)
4165 return retval_sp;
4166 if (!expression || !*expression)
4167 return retval_sp;
4168 target_sp->EvaluateExpression (expression,
4169 exe_ctx.GetFrameSP().get(),
Enrico Granata972be532014-12-17 21:18:43 +00004170 retval_sp,
4171 options);
Enrico Granatab2698cd2012-09-13 18:27:09 +00004172 if (retval_sp && name && *name)
4173 retval_sp->SetName(ConstString(name));
4174 return retval_sp;
4175}
4176
4177lldb::ValueObjectSP
4178ValueObject::CreateValueObjectFromAddress (const char* name,
4179 uint64_t address,
4180 const ExecutionContext& exe_ctx,
Greg Claytona1e5dc82015-08-11 22:53:00 +00004181 CompilerType type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004182{
Greg Clayton57ee3062013-07-11 22:46:58 +00004183 if (type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004184 {
Greg Claytona1e5dc82015-08-11 22:53:00 +00004185 CompilerType pointer_type(type.GetPointerType());
Greg Clayton57ee3062013-07-11 22:46:58 +00004186 if (pointer_type)
4187 {
4188 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4189 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4190 pointer_type,
4191 ConstString(name),
4192 buffer,
Enrico Granata972be532014-12-17 21:18:43 +00004193 exe_ctx.GetByteOrder(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004194 exe_ctx.GetAddressByteSize()));
4195 if (ptr_result_valobj_sp)
4196 {
4197 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4198 Error err;
4199 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4200 if (ptr_result_valobj_sp && name && *name)
4201 ptr_result_valobj_sp->SetName(ConstString(name));
4202 }
4203 return ptr_result_valobj_sp;
4204 }
Enrico Granatab2698cd2012-09-13 18:27:09 +00004205 }
Greg Clayton57ee3062013-07-11 22:46:58 +00004206 return lldb::ValueObjectSP();
Enrico Granatab2698cd2012-09-13 18:27:09 +00004207}
4208
4209lldb::ValueObjectSP
4210ValueObject::CreateValueObjectFromData (const char* name,
Enrico Granata7ca1c762014-03-31 23:02:25 +00004211 const DataExtractor& data,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004212 const ExecutionContext& exe_ctx,
Greg Claytona1e5dc82015-08-11 22:53:00 +00004213 CompilerType type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004214{
4215 lldb::ValueObjectSP new_value_sp;
4216 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004217 type,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004218 ConstString(name),
4219 data,
4220 LLDB_INVALID_ADDRESS);
4221 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4222 if (new_value_sp && name && *name)
4223 new_value_sp->SetName(ConstString(name));
4224 return new_value_sp;
4225}
Enrico Granata4873e522013-04-11 22:48:58 +00004226
4227ModuleSP
4228ValueObject::GetModule ()
4229{
4230 ValueObject* root(GetRoot());
4231 if (root != this)
4232 return root->GetModule();
4233 return lldb::ModuleSP();
4234}
4235
4236ValueObject*
4237ValueObject::GetRoot ()
4238{
4239 if (m_root)
4240 return m_root;
Enrico Granatade61eba2015-01-22 03:07:34 +00004241 return (m_root = FollowParentChain( [] (ValueObject* vo) -> bool {
4242 return (vo->m_parent != nullptr);
4243 }));
4244}
4245
4246ValueObject*
4247ValueObject::FollowParentChain (std::function<bool(ValueObject*)> f)
4248{
4249 ValueObject* vo = this;
4250 while (vo)
Enrico Granata4873e522013-04-11 22:48:58 +00004251 {
Enrico Granatade61eba2015-01-22 03:07:34 +00004252 if (f(vo) == false)
4253 break;
4254 vo = vo->m_parent;
Enrico Granata4873e522013-04-11 22:48:58 +00004255 }
Enrico Granatade61eba2015-01-22 03:07:34 +00004256 return vo;
Enrico Granata4873e522013-04-11 22:48:58 +00004257}
4258
4259AddressType
4260ValueObject::GetAddressTypeOfChildren()
4261{
4262 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
4263 {
4264 ValueObject* root(GetRoot());
4265 if (root != this)
4266 return root->GetAddressTypeOfChildren();
4267 }
4268 return m_address_type_of_ptr_or_ref_children;
4269}
4270
4271lldb::DynamicValueType
4272ValueObject::GetDynamicValueType ()
4273{
4274 ValueObject* with_dv_info = this;
4275 while (with_dv_info)
4276 {
4277 if (with_dv_info->HasDynamicValueTypeInfo())
4278 return with_dv_info->GetDynamicValueTypeImpl();
4279 with_dv_info = with_dv_info->m_parent;
4280 }
4281 return lldb::eNoDynamicValues;
4282}
Enrico Granata39d51412013-05-31 17:43:40 +00004283
Enrico Granata4873e522013-04-11 22:48:58 +00004284lldb::Format
4285ValueObject::GetFormat () const
4286{
4287 const ValueObject* with_fmt_info = this;
4288 while (with_fmt_info)
4289 {
4290 if (with_fmt_info->m_format != lldb::eFormatDefault)
4291 return with_fmt_info->m_format;
4292 with_fmt_info = with_fmt_info->m_parent;
4293 }
4294 return m_format;
4295}
Enrico Granatad07cfd32014-10-08 18:27:36 +00004296
Enrico Granatac1247f52014-11-06 21:23:20 +00004297lldb::LanguageType
4298ValueObject::GetPreferredDisplayLanguage ()
4299{
Enrico Granataed3228a2015-01-21 01:47:13 +00004300 lldb::LanguageType type = m_preferred_display_language;
4301 if (m_preferred_display_language == lldb::eLanguageTypeUnknown)
Enrico Granatac1247f52014-11-06 21:23:20 +00004302 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004303 if (GetRoot())
Enrico Granatac1247f52014-11-06 21:23:20 +00004304 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004305 if (GetRoot() == this)
Enrico Granatac1247f52014-11-06 21:23:20 +00004306 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004307 if (StackFrameSP frame_sp = GetFrameSP())
4308 {
4309 const SymbolContext& sc(frame_sp->GetSymbolContext(eSymbolContextCompUnit));
4310 if (CompileUnit* cu = sc.comp_unit)
4311 type = cu->GetLanguage();
4312 }
4313 }
4314 else
4315 {
4316 type = GetRoot()->GetPreferredDisplayLanguage();
Enrico Granatac1247f52014-11-06 21:23:20 +00004317 }
4318 }
Enrico Granatac1247f52014-11-06 21:23:20 +00004319 }
Enrico Granataed3228a2015-01-21 01:47:13 +00004320 return (m_preferred_display_language = type); // only compute it once
4321}
4322
4323void
4324ValueObject::SetPreferredDisplayLanguage (lldb::LanguageType lt)
4325{
4326 m_preferred_display_language = lt;
Enrico Granatac1247f52014-11-06 21:23:20 +00004327}
4328
Enrico Granata73e8c4d2015-10-07 02:36:35 +00004329void
4330ValueObject::SetPreferredDisplayLanguageIfNeeded (lldb::LanguageType lt)
4331{
4332 if (m_preferred_display_language == lldb::eLanguageTypeUnknown)
4333 SetPreferredDisplayLanguage(lt);
4334}
4335
Enrico Granatad07cfd32014-10-08 18:27:36 +00004336bool
4337ValueObject::CanProvideValue ()
4338{
Sean Callanan7375f3e2014-12-09 21:18:59 +00004339 // we need to support invalid types as providers of values because some bare-board
4340 // debugging scenarios have no notion of types, but still manage to have raw numeric
4341 // values for things like registers. sigh.
Greg Clayton99558cc42015-08-24 23:46:31 +00004342 const CompilerType &type(GetCompilerType());
Sean Callanan7375f3e2014-12-09 21:18:59 +00004343 return (false == type.IsValid()) || (0 != (type.GetTypeInfo() & eTypeHasValue));
4344}
4345
4346bool
4347ValueObject::IsChecksumEmpty ()
4348{
4349 return m_value_checksum.empty();
Enrico Granatad07cfd32014-10-08 18:27:36 +00004350}
Enrico Granata0c10a852014-12-08 23:13:56 +00004351
4352ValueObjectSP
4353ValueObject::Persist ()
4354{
4355 if (!UpdateValueIfNeeded())
4356 return nullptr;
4357
4358 TargetSP target_sp(GetTargetSP());
4359 if (!target_sp)
4360 return nullptr;
4361
Sean Callananb92bd752015-10-01 16:28:02 +00004362 PersistentExpressionState *persistent_state = target_sp->GetPersistentExpressionStateForLanguage(GetPreferredDisplayLanguage());
Sean Callanan8f1f9a12015-09-30 19:57:57 +00004363
4364 if (!persistent_state)
4365 return nullptr;
4366
4367 ConstString name(persistent_state->GetNextPersistentVariableName());
Enrico Granata0c10a852014-12-08 23:13:56 +00004368
Sean Callanan9301ec12015-10-01 23:07:06 +00004369 ValueObjectSP const_result_sp = ValueObjectConstResult::Create (target_sp.get(), GetValue(), name);
4370
4371 ExpressionVariableSP clang_var_sp = persistent_state->CreatePersistentVariable(const_result_sp);
4372 clang_var_sp->m_live_sp = clang_var_sp->m_frozen_sp;
4373 clang_var_sp->m_flags |= ExpressionVariable::EVIsProgramReference;
Enrico Granata0c10a852014-12-08 23:13:56 +00004374
4375 return clang_var_sp->GetValueObject();
4376}
Enrico Granatae29df232014-12-09 19:51:20 +00004377
4378bool
4379ValueObject::IsSyntheticChildrenGenerated ()
4380{
4381 return m_is_synthetic_children_generated;
4382}
4383
4384void
4385ValueObject::SetSyntheticChildrenGenerated (bool b)
4386{
4387 m_is_synthetic_children_generated = b;
4388}
Enrico Granatadc62ffd2015-11-09 19:27:34 +00004389
4390uint64_t
4391ValueObject::GetLanguageFlags ()
4392{
4393 return m_language_flags;
4394}
4395
4396void
4397ValueObject::SetLanguageFlags (uint64_t flags)
4398{
4399 m_language_flags = flags;
4400}