blob: 29a4d403f28c755f249ab557f683d1f4f215a9b3 [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
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "lldb/Core/ValueObject.h"
13
14// C Includes
Greg Claytonf5e56de2010-09-14 23:36:40 +000015#include <stdlib.h>
16
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017// C++ Includes
18// Other libraries and framework includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "llvm/Support/raw_ostream.h"
Jim Ingham5a369122010-09-28 01:25:32 +000020#include "clang/AST/Type.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021
22// Project includes
23#include "lldb/Core/DataBufferHeap.h"
Enrico Granata4becb372011-06-29 22:27:15 +000024#include "lldb/Core/Debugger.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000025#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000026#include "lldb/Core/Module.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Core/StreamString.h"
Enrico Granata21fd13f2012-10-27 02:05:48 +000028#include "lldb/Core/ValueObjectCast.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Core/ValueObjectChild.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000030#include "lldb/Core/ValueObjectConstResult.h"
Jim Ingham78a685a2011-04-16 00:01:13 +000031#include "lldb/Core/ValueObjectDynamicValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032#include "lldb/Core/ValueObjectList.h"
Greg Claytonb2dcc362011-05-05 23:32:56 +000033#include "lldb/Core/ValueObjectMemory.h"
Enrico Granatad55546b2011-07-22 00:16:08 +000034#include "lldb/Core/ValueObjectSyntheticFilter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035
Enrico Granata5548cb52013-01-28 23:47:25 +000036#include "lldb/DataFormatters/DataVisualization.h"
Enrico Granata2206b482014-10-30 18:27:31 +000037#include "lldb/DataFormatters/StringPrinter.h"
Enrico Granata4d93b8c2013-09-30 19:11:51 +000038#include "lldb/DataFormatters/ValueObjectPrinter.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000039
Enrico Granata0c10a852014-12-08 23:13:56 +000040#include "lldb/Expression/ClangExpressionVariable.h"
41#include "lldb/Expression/ClangPersistentVariables.h"
42
Greg Clayton7fb56d02011-02-01 01:31:41 +000043#include "lldb/Host/Endian.h"
44
Enrico Granata61a80ba2011-08-12 16:42:31 +000045#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granataf2bbf712011-07-15 02:26:42 +000046#include "lldb/Interpreter/ScriptInterpreterPython.h"
47
Greg Claytone1a916a2010-07-21 22:12:05 +000048#include "lldb/Symbol/ClangASTType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049#include "lldb/Symbol/ClangASTContext.h"
Enrico Granatac1247f52014-11-06 21:23:20 +000050#include "lldb/Symbol/CompileUnit.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051#include "lldb/Symbol/Type.h"
52
Jim Ingham53c47f12010-09-10 23:12:17 +000053#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000054#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000055#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056#include "lldb/Target/Process.h"
57#include "lldb/Target/RegisterContext.h"
Greg Claytond5944cd2013-12-06 01:12:00 +000058#include "lldb/Target/SectionLoadList.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000059#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061
62using namespace lldb;
63using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000064using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065
Greg Claytonafacd142011-09-02 01:15:17 +000066static user_id_t g_value_obj_uid = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000067
68//----------------------------------------------------------------------
69// ValueObject constructor
70//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000071ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000072 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000073 m_parent (&parent),
Enrico Granata4873e522013-04-11 22:48:58 +000074 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +000075 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000076 m_name (),
77 m_data (),
78 m_value (),
79 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000080 m_value_str (),
81 m_old_value_str (),
82 m_location_str (),
83 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000084 m_object_desc_str (),
Enrico Granata744794a2014-09-05 21:46:22 +000085 m_validation_result(),
Jim Ingham58b59f92011-04-22 23:53:53 +000086 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000087 m_children (),
88 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000089 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000090 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000091 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000092 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +000093 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000094 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +000095 m_type_summary_sp(),
96 m_type_format_sp(),
97 m_synthetic_children_sp(),
Enrico Granata744794a2014-09-05 21:46:22 +000098 m_type_validator_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +000099 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000100 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
Sean Callanan7375f3e2014-12-09 21:18:59 +0000101 m_value_checksum(),
Enrico Granataed3228a2015-01-21 01:47:13 +0000102 m_preferred_display_language(lldb::eLanguageTypeUnknown),
Greg Clayton288bdf92010-09-02 02:59:18 +0000103 m_value_is_valid (false),
104 m_value_did_change (false),
105 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000106 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000107 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000108 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000109 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000110 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000111 m_is_getting_summary(false),
Enrico Granatae29df232014-12-09 19:51:20 +0000112 m_did_calculate_complete_objc_class_type(false),
113 m_is_synthetic_children_generated(parent.m_is_synthetic_children_generated)
Jim Ingham6035b672011-03-31 00:19:25 +0000114{
Jim Ingham58b59f92011-04-22 23:53:53 +0000115 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000116}
117
118//----------------------------------------------------------------------
119// ValueObject constructor
120//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000121ValueObject::ValueObject (ExecutionContextScope *exe_scope,
122 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000123 UserID (++g_value_obj_uid), // Unique identifier for every value object
124 m_parent (NULL),
Enrico Granata4873e522013-04-11 22:48:58 +0000125 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000126 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000127 m_name (),
128 m_data (),
129 m_value (),
130 m_error (),
131 m_value_str (),
132 m_old_value_str (),
133 m_location_str (),
134 m_summary_str (),
135 m_object_desc_str (),
Enrico Granata744794a2014-09-05 21:46:22 +0000136 m_validation_result(),
Jim Ingham58b59f92011-04-22 23:53:53 +0000137 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000138 m_children (),
139 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000140 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000141 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000142 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000143 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +0000144 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000145 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +0000146 m_type_summary_sp(),
147 m_type_format_sp(),
148 m_synthetic_children_sp(),
Enrico Granata744794a2014-09-05 21:46:22 +0000149 m_type_validator_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000150 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000151 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Sean Callanan7375f3e2014-12-09 21:18:59 +0000152 m_value_checksum(),
Enrico Granataed3228a2015-01-21 01:47:13 +0000153 m_preferred_display_language(lldb::eLanguageTypeUnknown),
Jim Ingham6035b672011-03-31 00:19:25 +0000154 m_value_is_valid (false),
155 m_value_did_change (false),
156 m_children_count_valid (false),
157 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000158 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000159 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000160 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000161 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000162 m_is_getting_summary(false),
Enrico Granatae29df232014-12-09 19:51:20 +0000163 m_did_calculate_complete_objc_class_type(false),
164 m_is_synthetic_children_generated(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000165{
Jim Ingham58b59f92011-04-22 23:53:53 +0000166 m_manager = new ValueObjectManager();
167 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000168}
169
170//----------------------------------------------------------------------
171// Destructor
172//----------------------------------------------------------------------
173ValueObject::~ValueObject ()
174{
175}
176
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000177bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000178ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000179{
Enrico Granata4becb372011-06-29 22:27:15 +0000180
Enrico Granata9128ee22011-09-06 19:20:51 +0000181 bool did_change_formats = false;
182
Enrico Granata0a3958e2011-07-02 00:25:22 +0000183 if (update_format)
Enrico Granata5548cb52013-01-28 23:47:25 +0000184 did_change_formats = UpdateFormatsIfNeeded();
Enrico Granata4becb372011-06-29 22:27:15 +0000185
Greg Claytonb71f3842010-10-05 03:13:51 +0000186 // If this is a constant value, then our success is predicated on whether
187 // we have an error or not
188 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000189 {
Enrico Granatab1c6c482013-10-09 00:33:55 +0000190 // if you are constant, things might still have changed behind your back
191 // (e.g. you are a frozen object and things have changed deeper than you cared to freeze-dry yourself)
192 // in this case, your value has not changed, but "computed" entries might have, so you might now have
193 // a different summary, or a different object description. clear these so we will recompute them
Enrico Granata9128ee22011-09-06 19:20:51 +0000194 if (update_format && !did_change_formats)
Enrico Granatab1c6c482013-10-09 00:33:55 +0000195 ClearUserVisibleData(eClearUserVisibleDataItemsSummary | eClearUserVisibleDataItemsDescription);
Greg Claytonb71f3842010-10-05 03:13:51 +0000196 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000197 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000198
Sean Callanan7375f3e2014-12-09 21:18:59 +0000199 bool first_update = IsChecksumEmpty();
Jim Ingham6035b672011-03-31 00:19:25 +0000200
201 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000202 {
Jim Ingham6035b672011-03-31 00:19:25 +0000203 m_update_point.SetUpdated();
204
205 // Save the old value using swap to avoid a string copy which
206 // also will clear our m_value_str
207 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000208 {
Jim Ingham6035b672011-03-31 00:19:25 +0000209 m_old_value_valid = false;
210 }
211 else
212 {
213 m_old_value_valid = true;
214 m_old_value_str.swap (m_value_str);
Enrico Granata86cc9822012-03-19 22:58:49 +0000215 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham6035b672011-03-31 00:19:25 +0000216 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000217
Enrico Granataf2bbf712011-07-15 02:26:42 +0000218 ClearUserVisibleData();
219
Greg Claytonefbc7d22012-03-09 04:23:44 +0000220 if (IsInScope())
Jim Ingham6035b672011-03-31 00:19:25 +0000221 {
Greg Claytonefbc7d22012-03-09 04:23:44 +0000222 const bool value_was_valid = GetValueIsValid();
223 SetValueDidChange (false);
224
225 m_error.Clear();
226
227 // Call the pure virtual function to update the value
Sean Callanan7375f3e2014-12-09 21:18:59 +0000228
229 bool need_compare_checksums = false;
230 llvm::SmallVector<uint8_t, 16> old_checksum;
231
232 if (!first_update && CanProvideValue())
233 {
234 need_compare_checksums = true;
235 old_checksum.resize(m_value_checksum.size());
236 std::copy(m_value_checksum.begin(), m_value_checksum.end(), old_checksum.begin());
237 }
238
Greg Claytonefbc7d22012-03-09 04:23:44 +0000239 bool success = UpdateValue ();
240
241 SetValueIsValid (success);
242
Sean Callanan7375f3e2014-12-09 21:18:59 +0000243 if (success)
244 {
245 const uint64_t max_checksum_size = 128;
246 m_data.Checksum(m_value_checksum,
247 max_checksum_size);
248 }
249 else
250 {
251 need_compare_checksums = false;
252 m_value_checksum.clear();
253 }
254
Enrico Granata20c321c2015-01-08 19:11:43 +0000255 assert (!need_compare_checksums || (!old_checksum.empty() && !m_value_checksum.empty()));
256
Greg Claytonefbc7d22012-03-09 04:23:44 +0000257 if (first_update)
258 SetValueDidChange (false);
259 else if (!m_value_did_change && success == false)
260 {
261 // The value wasn't gotten successfully, so we mark this
262 // as changed if the value used to be valid and now isn't
263 SetValueDidChange (value_was_valid);
264 }
Sean Callanan7375f3e2014-12-09 21:18:59 +0000265 else if (need_compare_checksums)
266 {
267 SetValueDidChange(memcmp(&old_checksum[0], &m_value_checksum[0], m_value_checksum.size()));
268 }
269
Greg Claytonefbc7d22012-03-09 04:23:44 +0000270 }
271 else
272 {
273 m_error.SetErrorString("out of scope");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000274 }
275 }
276 return m_error.Success();
277}
278
Enrico Granata9128ee22011-09-06 19:20:51 +0000279bool
Enrico Granata5548cb52013-01-28 23:47:25 +0000280ValueObject::UpdateFormatsIfNeeded()
Enrico Granata4becb372011-06-29 22:27:15 +0000281{
Greg Clayton5160ce52013-03-27 23:08:40 +0000282 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000283 if (log)
Enrico Granatad2284832012-10-17 22:23:56 +0000284 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000285 GetName().GetCString(), static_cast<void*>(this),
286 m_last_format_mgr_revision,
287 DataVisualization::GetCurrentRevision());
288
Enrico Granata9128ee22011-09-06 19:20:51 +0000289 bool any_change = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000290
Enrico Granata5548cb52013-01-28 23:47:25 +0000291 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()))
Enrico Granata4becb372011-06-29 22:27:15 +0000292 {
Enrico Granataa0db6ed2014-04-09 21:06:11 +0000293 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
294 any_change = true;
295
Enrico Granata852cc952013-10-08 19:03:22 +0000296 SetValueFormat(DataVisualization::GetFormat (*this, eNoDynamicValues));
Enrico Granata5548cb52013-01-28 23:47:25 +0000297 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000298#ifndef LLDB_DISABLE_PYTHON
Enrico Granata5548cb52013-01-28 23:47:25 +0000299 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000300#endif
Enrico Granata744794a2014-09-05 21:46:22 +0000301 SetValidator(DataVisualization::GetValidator(*this, GetDynamicValueType()));
Enrico Granata4becb372011-06-29 22:27:15 +0000302 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000303
Enrico Granata9128ee22011-09-06 19:20:51 +0000304 return any_change;
Enrico Granata4becb372011-06-29 22:27:15 +0000305}
306
Jim Ingham16e0c682011-08-12 23:34:31 +0000307void
308ValueObject::SetNeedsUpdate ()
309{
310 m_update_point.SetNeedsUpdate();
311 // We have to clear the value string here so ConstResult children will notice if their values are
312 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000313 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000314}
315
Enrico Granata13ac0e22012-10-17 19:03:34 +0000316void
Enrico Granatae3e91512012-10-22 18:18:36 +0000317ValueObject::ClearDynamicTypeInformation ()
Enrico Granata13ac0e22012-10-17 19:03:34 +0000318{
Enrico Granata38c54632013-10-30 00:04:29 +0000319 m_children_count_valid = false;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000320 m_did_calculate_complete_objc_class_type = false;
Enrico Granatae3e91512012-10-22 18:18:36 +0000321 m_last_format_mgr_revision = 0;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000322 m_override_type = ClangASTType();
Enrico Granatae3e91512012-10-22 18:18:36 +0000323 SetValueFormat(lldb::TypeFormatImplSP());
324 SetSummaryFormat(lldb::TypeSummaryImplSP());
325 SetSyntheticChildren(lldb::SyntheticChildrenSP());
Enrico Granata13ac0e22012-10-17 19:03:34 +0000326}
327
Sean Callanan72772842012-02-22 23:57:45 +0000328ClangASTType
329ValueObject::MaybeCalculateCompleteType ()
330{
Greg Clayton57ee3062013-07-11 22:46:58 +0000331 ClangASTType clang_type(GetClangTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000332
Sean Callanan72772842012-02-22 23:57:45 +0000333 if (m_did_calculate_complete_objc_class_type)
334 {
335 if (m_override_type.IsValid())
336 return m_override_type;
337 else
Greg Clayton57ee3062013-07-11 22:46:58 +0000338 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000339 }
340
Greg Clayton57ee3062013-07-11 22:46:58 +0000341 ClangASTType class_type;
342 bool is_pointer_type = false;
Sean Callanan72772842012-02-22 23:57:45 +0000343
Greg Clayton57ee3062013-07-11 22:46:58 +0000344 if (clang_type.IsObjCObjectPointerType(&class_type))
Sean Callanan72772842012-02-22 23:57:45 +0000345 {
346 is_pointer_type = true;
347 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000348 else if (clang_type.IsObjCObjectOrInterfaceType())
Sean Callanan72772842012-02-22 23:57:45 +0000349 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000350 class_type = clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000351 }
352 else
353 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000354 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000355 }
356
357 m_did_calculate_complete_objc_class_type = true;
358
Greg Clayton57ee3062013-07-11 22:46:58 +0000359 if (class_type)
Sean Callanan72772842012-02-22 23:57:45 +0000360 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000361 ConstString class_name (class_type.GetConstTypeName());
Sean Callanan72772842012-02-22 23:57:45 +0000362
Greg Clayton57ee3062013-07-11 22:46:58 +0000363 if (class_name)
364 {
365 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
366
367 if (process_sp)
368 {
369 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
370
371 if (objc_language_runtime)
372 {
373 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name);
374
375 if (complete_objc_class_type_sp)
376 {
377 ClangASTType complete_class(complete_objc_class_type_sp->GetClangFullType());
378
379 if (complete_class.GetCompleteType())
380 {
381 if (is_pointer_type)
382 {
383 m_override_type = complete_class.GetPointerType();
384 }
385 else
386 {
387 m_override_type = complete_class;
388 }
389
390 if (m_override_type.IsValid())
391 return m_override_type;
392 }
393 }
394 }
395 }
396 }
Sean Callanan72772842012-02-22 23:57:45 +0000397 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000398 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000399}
400
Greg Clayton57ee3062013-07-11 22:46:58 +0000401ClangASTType
Sean Callanan72772842012-02-22 23:57:45 +0000402ValueObject::GetClangType ()
403{
Greg Clayton57ee3062013-07-11 22:46:58 +0000404 return MaybeCalculateCompleteType();
Sean Callanan72772842012-02-22 23:57:45 +0000405}
406
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000407TypeImpl
408ValueObject::GetTypeImpl ()
409{
410 return TypeImpl(GetClangType());
411}
412
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000413DataExtractor &
414ValueObject::GetDataExtractor ()
415{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000416 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000417 return m_data;
418}
419
420const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000421ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000422{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000423 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000424 return m_error;
425}
426
427const ConstString &
428ValueObject::GetName() const
429{
430 return m_name;
431}
432
433const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000434ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000435{
Enrico Granata82fabf82013-04-30 20:45:04 +0000436 return GetLocationAsCStringImpl(m_value,
437 m_data);
438}
439
440const char *
441ValueObject::GetLocationAsCStringImpl (const Value& value,
442 const DataExtractor& data)
443{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000444 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000445 {
446 if (m_location_str.empty())
447 {
448 StreamString sstr;
Enrico Granata82fabf82013-04-30 20:45:04 +0000449
450 Value::ValueType value_type = value.GetValueType();
451
452 switch (value_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000453 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000454 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +0000455 case Value::eValueTypeVector:
Enrico Granata82fabf82013-04-30 20:45:04 +0000456 if (value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000457 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000458 RegisterInfo *reg_info = value.GetRegisterInfo();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000459 if (reg_info)
460 {
461 if (reg_info->name)
462 m_location_str = reg_info->name;
463 else if (reg_info->alt_name)
464 m_location_str = reg_info->alt_name;
Enrico Granata82fabf82013-04-30 20:45:04 +0000465 if (m_location_str.empty())
466 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000467 }
468 }
Enrico Granata82fabf82013-04-30 20:45:04 +0000469 if (m_location_str.empty())
470 m_location_str = (value_type == Value::eValueTypeVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000471 break;
472
473 case Value::eValueTypeLoadAddress:
474 case Value::eValueTypeFileAddress:
475 case Value::eValueTypeHostAddress:
476 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000477 uint32_t addr_nibble_size = data.GetAddressByteSize() * 2;
478 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000479 m_location_str.swap(sstr.GetString());
480 }
481 break;
482 }
483 }
484 }
485 return m_location_str.c_str();
486}
487
488Value &
489ValueObject::GetValue()
490{
491 return m_value;
492}
493
494const Value &
495ValueObject::GetValue() const
496{
497 return m_value;
498}
499
500bool
Jim Ingham6035b672011-03-31 00:19:25 +0000501ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000502{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000503 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
504 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000505 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000506 Value tmp_value(m_value);
Greg Clayton57ee3062013-07-11 22:46:58 +0000507 scalar = tmp_value.ResolveValue(&exe_ctx);
Greg Claytondcad5022011-12-29 01:26:56 +0000508 if (scalar.IsValid())
509 {
510 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
511 if (bitfield_bit_size)
512 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
513 return true;
514 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000515 }
Greg Claytondcad5022011-12-29 01:26:56 +0000516 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000517}
518
519bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000520ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000521{
Greg Clayton288bdf92010-09-02 02:59:18 +0000522 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000523}
524
525
526void
527ValueObject::SetValueIsValid (bool b)
528{
Greg Clayton288bdf92010-09-02 02:59:18 +0000529 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000530}
531
532bool
Jim Ingham6035b672011-03-31 00:19:25 +0000533ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000534{
Greg Clayton288bdf92010-09-02 02:59:18 +0000535 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000536}
537
538void
539ValueObject::SetValueDidChange (bool value_changed)
540{
Greg Clayton288bdf92010-09-02 02:59:18 +0000541 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000542}
543
544ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000545ValueObject::GetChildAtIndex (size_t idx, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000546{
547 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000548 // We may need to update our value if we are dynamic
549 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000550 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000551 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000552 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000553 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000554 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000555 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000556 // No we haven't created the child at this index, so lets have our
557 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000558 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000559 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000560
Enrico Granata9d60f602012-03-09 03:09:58 +0000561 ValueObject* child = m_children.GetChildAtIndex(idx);
562 if (child != NULL)
563 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000564 }
565 return child_sp;
566}
567
Enrico Granata3309d882013-01-12 01:00:22 +0000568ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000569ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
570 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000571{
572 if (idxs.size() == 0)
573 return GetSP();
574 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000575 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000576 {
577 root = root->GetChildAtIndex(idx, true);
578 if (!root)
579 {
580 if (index_of_error)
581 *index_of_error = idx;
582 return root;
583 }
584 }
585 return root;
586}
587
588ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000589ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
590 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000591{
592 if (idxs.size() == 0)
593 return GetSP();
594 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000595 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000596 {
597 root = root->GetChildAtIndex(idx.first, idx.second);
598 if (!root)
599 {
600 if (index_of_error)
601 *index_of_error = idx.first;
602 return root;
603 }
604 }
605 return root;
606}
607
608lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000609ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
610 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000611{
612 if (idxs.size() == 0)
613 return GetSP();
614 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000615 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000616 {
617 root = root->GetChildAtIndex(idx, true);
618 if (!root)
619 {
620 if (index_of_error)
621 *index_of_error = idx;
622 return root;
623 }
624 }
625 return root;
626}
627
628lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000629ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
630 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000631{
632 if (idxs.size() == 0)
633 return GetSP();
634 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000635 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000636 {
637 root = root->GetChildAtIndex(idx.first, idx.second);
638 if (!root)
639 {
640 if (index_of_error)
641 *index_of_error = idx.first;
642 return root;
643 }
644 }
645 return root;
646}
647
Enrico Granatae2e220a2013-09-12 00:48:47 +0000648lldb::ValueObjectSP
649ValueObject::GetChildAtNamePath (const std::initializer_list<ConstString> &names,
650 ConstString* name_of_error)
651{
652 if (names.size() == 0)
653 return GetSP();
654 ValueObjectSP root(GetSP());
655 for (ConstString name : names)
656 {
657 root = root->GetChildMemberWithName(name, true);
658 if (!root)
659 {
660 if (name_of_error)
661 *name_of_error = name;
662 return root;
663 }
664 }
665 return root;
666}
667
668lldb::ValueObjectSP
669ValueObject::GetChildAtNamePath (const std::vector<ConstString> &names,
670 ConstString* name_of_error)
671{
672 if (names.size() == 0)
673 return GetSP();
674 ValueObjectSP root(GetSP());
675 for (ConstString name : names)
676 {
677 root = root->GetChildMemberWithName(name, true);
678 if (!root)
679 {
680 if (name_of_error)
681 *name_of_error = name;
682 return root;
683 }
684 }
685 return root;
686}
687
688lldb::ValueObjectSP
689ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names,
690 ConstString* name_of_error)
691{
692 if (names.size() == 0)
693 return GetSP();
694 ValueObjectSP root(GetSP());
695 for (std::pair<ConstString, bool> name : names)
696 {
697 root = root->GetChildMemberWithName(name.first, name.second);
698 if (!root)
699 {
700 if (name_of_error)
701 *name_of_error = name.first;
702 return root;
703 }
704 }
705 return root;
706}
707
708lldb::ValueObjectSP
709ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names,
710 ConstString* name_of_error)
711{
712 if (names.size() == 0)
713 return GetSP();
714 ValueObjectSP root(GetSP());
715 for (std::pair<ConstString, bool> name : names)
716 {
717 root = root->GetChildMemberWithName(name.first, name.second);
718 if (!root)
719 {
720 if (name_of_error)
721 *name_of_error = name.first;
722 return root;
723 }
724 }
725 return root;
726}
727
Greg Claytonc7bece562013-01-25 18:06:21 +0000728size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000729ValueObject::GetIndexOfChildWithName (const ConstString &name)
730{
731 bool omit_empty_base_classes = true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000732 return GetClangType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000733}
734
735ValueObjectSP
736ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
737{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000738 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000739 // classes (which really aren't part of the expression path), so we
740 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000741 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000742
Greg Claytondea8cb42011-06-29 22:09:02 +0000743 // We may need to update our value if we are dynamic
744 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000745 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000746
747 std::vector<uint32_t> child_indexes;
Greg Claytondea8cb42011-06-29 22:09:02 +0000748 bool omit_empty_base_classes = true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000749 const size_t num_child_indexes = GetClangType().GetIndexOfChildMemberWithName (name.GetCString(),
750 omit_empty_base_classes,
751 child_indexes);
Greg Claytondea8cb42011-06-29 22:09:02 +0000752 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000753 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000754 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
755 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
756
757 child_sp = GetChildAtIndex(*pos, can_create);
758 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000759 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000760 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000761 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000762 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
763 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000764 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000765 else
766 {
767 child_sp.reset();
768 }
769
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000770 }
771 }
772 return child_sp;
773}
774
775
Greg Claytonc7bece562013-01-25 18:06:21 +0000776size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000777ValueObject::GetNumChildren ()
778{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000779 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000780 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000781 {
782 SetNumChildren (CalculateNumChildren());
783 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000784 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000785}
Greg Clayton4a792072012-10-23 01:50:10 +0000786
787bool
788ValueObject::MightHaveChildren()
789{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000790 bool has_children = false;
Greg Clayton2452ab72013-02-08 22:02:02 +0000791 const uint32_t type_info = GetTypeInfo();
792 if (type_info)
Greg Clayton4a792072012-10-23 01:50:10 +0000793 {
Enrico Granata622be232014-10-21 20:52:14 +0000794 if (type_info & (eTypeHasChildren |
795 eTypeIsPointer |
796 eTypeIsReference))
Greg Clayton4a792072012-10-23 01:50:10 +0000797 has_children = true;
798 }
799 else
800 {
801 has_children = GetNumChildren () > 0;
802 }
803 return has_children;
804}
805
806// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000807void
Greg Claytonc7bece562013-01-25 18:06:21 +0000808ValueObject::SetNumChildren (size_t num_children)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000809{
Greg Clayton288bdf92010-09-02 02:59:18 +0000810 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000811 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000812}
813
814void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000815ValueObject::SetName (const ConstString &name)
816{
817 m_name = name;
818}
819
Jim Ingham58b59f92011-04-22 23:53:53 +0000820ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000821ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000822{
Jim Ingham2eec4872011-05-07 00:10:58 +0000823 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000824
Greg Claytondea8cb42011-06-29 22:09:02 +0000825 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000826 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000827 std::string child_name_str;
828 uint32_t child_byte_size = 0;
829 int32_t child_byte_offset = 0;
830 uint32_t child_bitfield_bit_size = 0;
831 uint32_t child_bitfield_bit_offset = 0;
832 bool child_is_base_class = false;
833 bool child_is_deref_of_parent = false;
834
835 const bool transparent_pointers = synthetic_array_member == false;
Greg Clayton57ee3062013-07-11 22:46:58 +0000836 ClangASTType child_clang_type;
Greg Claytondea8cb42011-06-29 22:09:02 +0000837
Greg Claytoncc4d0142012-02-17 07:49:44 +0000838 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000839
Greg Clayton57ee3062013-07-11 22:46:58 +0000840 child_clang_type = GetClangType().GetChildClangTypeAtIndex (&exe_ctx,
Greg Clayton57ee3062013-07-11 22:46:58 +0000841 idx,
842 transparent_pointers,
843 omit_empty_base_classes,
844 ignore_array_bounds,
845 child_name_str,
846 child_byte_size,
847 child_byte_offset,
848 child_bitfield_bit_size,
849 child_bitfield_bit_offset,
850 child_is_base_class,
Greg Clayton759e7442014-07-19 00:12:57 +0000851 child_is_deref_of_parent,
852 this);
Greg Clayton4ef877f2012-12-06 02:33:54 +0000853 if (child_clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000854 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000855 if (synthetic_index)
856 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000857
Greg Claytondea8cb42011-06-29 22:09:02 +0000858 ConstString child_name;
859 if (!child_name_str.empty())
860 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000861
Greg Claytondea8cb42011-06-29 22:09:02 +0000862 valobj = new ValueObjectChild (*this,
Greg Claytondea8cb42011-06-29 22:09:02 +0000863 child_clang_type,
864 child_name,
865 child_byte_size,
866 child_byte_offset,
867 child_bitfield_bit_size,
868 child_bitfield_bit_offset,
869 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000870 child_is_deref_of_parent,
871 eAddressTypeInvalid);
872 //if (valobj)
873 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
874 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000875
Jim Ingham58b59f92011-04-22 23:53:53 +0000876 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000877}
878
Enrico Granata0c489f52012-03-01 04:24:26 +0000879bool
880ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
881 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000882{
Enrico Granatac1247f52014-11-06 21:23:20 +0000883 return GetSummaryAsCString(summary_ptr, destination, TypeSummaryOptions());
884}
885
886bool
887ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
888 std::string& destination,
889 const TypeSummaryOptions& options)
890{
Enrico Granata0c489f52012-03-01 04:24:26 +0000891 destination.clear();
892
893 // ideally we would like to bail out if passing NULL, but if we do so
894 // we end up not providing the summary for function pointers anymore
895 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
896 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000897
898 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000899
900 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
901 // information that we might care to see in a crash log. might be useful in very specific situations though.
902 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
903 GetTypeName().GetCString(),
904 GetName().GetCString(),
905 summary_ptr->GetDescription().c_str());*/
906
Enrico Granataff0f23d2014-12-10 02:00:45 +0000907 if (UpdateValueIfNeeded (false) && summary_ptr)
Enrico Granata0c489f52012-03-01 04:24:26 +0000908 {
Enrico Granataff0f23d2014-12-10 02:00:45 +0000909 if (HasSyntheticValue())
910 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
911 summary_ptr->FormatObject(this, destination, options);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000912 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000913 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000914 return !destination.empty();
915}
916
917const char *
918ValueObject::GetSummaryAsCString ()
919{
920 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
921 {
922 GetSummaryAsCString(GetSummaryFormat().get(),
Enrico Granatac1247f52014-11-06 21:23:20 +0000923 m_summary_str,
Enrico Granata49bfafb2014-11-18 23:36:25 +0000924 TypeSummaryOptions());
Enrico Granata0c489f52012-03-01 04:24:26 +0000925 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000926 if (m_summary_str.empty())
927 return NULL;
928 return m_summary_str.c_str();
929}
930
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000931bool
Enrico Granata49bfafb2014-11-18 23:36:25 +0000932ValueObject::GetSummaryAsCString (std::string& destination,
933 const TypeSummaryOptions& options)
934{
935 return GetSummaryAsCString(GetSummaryFormat().get(),
936 destination,
937 options);
938}
939
940bool
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000941ValueObject::IsCStringContainer(bool check_pointer)
942{
Greg Clayton57ee3062013-07-11 22:46:58 +0000943 ClangASTType pointee_or_element_clang_type;
944 const Flags type_flags (GetTypeInfo (&pointee_or_element_clang_type));
Enrico Granata622be232014-10-21 20:52:14 +0000945 bool is_char_arr_ptr (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Greg Clayton57ee3062013-07-11 22:46:58 +0000946 pointee_or_element_clang_type.IsCharType ());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000947 if (!is_char_arr_ptr)
948 return false;
949 if (!check_pointer)
950 return true;
Enrico Granata622be232014-10-21 20:52:14 +0000951 if (type_flags.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000952 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000953 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000954 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000955 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000956 return (cstr_address != LLDB_INVALID_ADDRESS);
957}
958
Enrico Granata9128ee22011-09-06 19:20:51 +0000959size_t
960ValueObject::GetPointeeData (DataExtractor& data,
961 uint32_t item_idx,
962 uint32_t item_count)
963{
Greg Clayton57ee3062013-07-11 22:46:58 +0000964 ClangASTType pointee_or_element_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +0000965 const uint32_t type_info = GetTypeInfo (&pointee_or_element_clang_type);
Enrico Granata622be232014-10-21 20:52:14 +0000966 const bool is_pointer_type = type_info & eTypeIsPointer;
967 const bool is_array_type = type_info & eTypeIsArray;
Greg Clayton2452ab72013-02-08 22:02:02 +0000968 if (!(is_pointer_type || is_array_type))
Enrico Granata9128ee22011-09-06 19:20:51 +0000969 return 0;
970
971 if (item_count == 0)
972 return 0;
973
Enrico Granata951bdd52015-01-28 01:09:45 +0000974 ExecutionContext exe_ctx (GetExecutionContextRef());
975
Greg Clayton526ae042015-02-12 00:34:25 +0000976 const uint64_t item_type_size = pointee_or_element_clang_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
Enrico Granata9128ee22011-09-06 19:20:51 +0000977 const uint64_t bytes = item_count * item_type_size;
Enrico Granata9128ee22011-09-06 19:20:51 +0000978 const uint64_t offset = item_idx * item_type_size;
979
980 if (item_idx == 0 && item_count == 1) // simply a deref
981 {
Greg Clayton2452ab72013-02-08 22:02:02 +0000982 if (is_pointer_type)
Enrico Granata9128ee22011-09-06 19:20:51 +0000983 {
984 Error error;
985 ValueObjectSP pointee_sp = Dereference(error);
986 if (error.Fail() || pointee_sp.get() == NULL)
987 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +0000988 return pointee_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +0000989 }
990 else
991 {
992 ValueObjectSP child_sp = GetChildAtIndex(0, true);
993 if (child_sp.get() == NULL)
994 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +0000995 Error error;
996 return child_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +0000997 }
998 return true;
999 }
1000 else /* (items > 1) */
1001 {
1002 Error error;
1003 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
1004 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
1005
1006 AddressType addr_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001007 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001008
Enrico Granata9128ee22011-09-06 19:20:51 +00001009 switch (addr_type)
1010 {
1011 case eAddressTypeFile:
1012 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001013 ModuleSP module_sp (GetModule());
1014 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001015 {
Enrico Granata9c2efe32012-08-07 01:49:34 +00001016 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +00001017 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001018 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001019 ExecutionContext exe_ctx (GetExecutionContextRef());
1020 Target* target = exe_ctx.GetTargetPtr();
1021 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +00001022 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001023 heap_buf_ptr->SetByteSize(bytes);
1024 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
1025 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +00001026 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001027 data.SetData(data_sp);
1028 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +00001029 }
1030 }
1031 }
1032 }
1033 break;
1034 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +00001035 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001036 ExecutionContext exe_ctx (GetExecutionContextRef());
1037 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +00001038 if (process)
1039 {
1040 heap_buf_ptr->SetByteSize(bytes);
1041 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
Enrico Granata5e1480c2013-10-30 17:52:44 +00001042 if (error.Success() || bytes_read > 0)
Enrico Granata9128ee22011-09-06 19:20:51 +00001043 {
1044 data.SetData(data_sp);
1045 return bytes_read;
1046 }
1047 }
1048 }
1049 break;
1050 case eAddressTypeHost:
1051 {
Greg Clayton526ae042015-02-12 00:34:25 +00001052 const uint64_t max_bytes = GetClangType().GetByteSize(exe_ctx.GetBestExecutionContextScope());
Greg Clayton2452ab72013-02-08 22:02:02 +00001053 if (max_bytes > offset)
1054 {
1055 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
1056 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
1057 data.SetData(data_sp);
1058 return bytes_read;
1059 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001060 }
1061 break;
1062 case eAddressTypeInvalid:
Enrico Granata9128ee22011-09-06 19:20:51 +00001063 break;
1064 }
1065 }
1066 return 0;
1067}
1068
Greg Claytonfaac1112013-03-14 18:31:44 +00001069uint64_t
Sean Callanan866e91c2014-02-28 22:27:53 +00001070ValueObject::GetData (DataExtractor& data, Error &error)
Enrico Granata9128ee22011-09-06 19:20:51 +00001071{
1072 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001073 ExecutionContext exe_ctx (GetExecutionContextRef());
Sean Callanan866e91c2014-02-28 22:27:53 +00001074 error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001075 if (error.Fail())
Sean Callananed185ab2013-04-19 19:47:32 +00001076 {
1077 if (m_data.GetByteSize())
1078 {
1079 data = m_data;
1080 return data.GetByteSize();
1081 }
1082 else
1083 {
1084 return 0;
1085 }
1086 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001087 data.SetAddressByteSize(m_data.GetAddressByteSize());
1088 data.SetByteOrder(m_data.GetByteOrder());
1089 return data.GetByteSize();
1090}
1091
Sean Callanan389823e2013-04-13 01:21:23 +00001092bool
1093ValueObject::SetData (DataExtractor &data, Error &error)
1094{
1095 error.Clear();
1096 // Make sure our value is up to date first so that our location and location
1097 // type is valid.
1098 if (!UpdateValueIfNeeded(false))
1099 {
1100 error.SetErrorString("unable to read value");
1101 return false;
1102 }
1103
1104 uint64_t count = 0;
Greg Clayton57ee3062013-07-11 22:46:58 +00001105 const Encoding encoding = GetClangType().GetEncoding(count);
Sean Callanan389823e2013-04-13 01:21:23 +00001106
1107 const size_t byte_size = GetByteSize();
1108
1109 Value::ValueType value_type = m_value.GetValueType();
1110
1111 switch (value_type)
1112 {
1113 case Value::eValueTypeScalar:
1114 {
1115 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1116
1117 if (!set_error.Success())
1118 {
1119 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1120 return false;
1121 }
1122 }
1123 break;
1124 case Value::eValueTypeLoadAddress:
1125 {
1126 // If it is a load address, then the scalar value is the storage location
1127 // of the data, and we have to shove this value down to that load location.
1128 ExecutionContext exe_ctx (GetExecutionContextRef());
1129 Process *process = exe_ctx.GetProcessPtr();
1130 if (process)
1131 {
1132 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1133 size_t bytes_written = process->WriteMemory(target_addr,
1134 data.GetDataStart(),
1135 byte_size,
1136 error);
1137 if (!error.Success())
1138 return false;
1139 if (bytes_written != byte_size)
1140 {
1141 error.SetErrorString("unable to write value to memory");
1142 return false;
1143 }
1144 }
1145 }
1146 break;
1147 case Value::eValueTypeHostAddress:
1148 {
1149 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1150 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1151 m_data.SetData(buffer_sp, 0);
1152 data.CopyByteOrderedData (0,
1153 byte_size,
1154 const_cast<uint8_t *>(m_data.GetDataStart()),
1155 byte_size,
1156 m_data.GetByteOrder());
1157 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1158 }
1159 break;
1160 case Value::eValueTypeFileAddress:
1161 case Value::eValueTypeVector:
1162 break;
1163 }
1164
1165 // If we have reached this point, then we have successfully changed the value.
1166 SetNeedsUpdate();
1167 return true;
1168}
1169
Enrico Granata9128ee22011-09-06 19:20:51 +00001170// will compute strlen(str), but without consuming more than
1171// maxlen bytes out of str (this serves the purpose of reading
1172// chunks of a string without having to worry about
1173// missing NULL terminators in the chunk)
1174// of course, if strlen(str) > maxlen, the function will return
1175// maxlen_value (which should be != maxlen, because that allows you
1176// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1177static uint32_t
1178strlen_or_inf (const char* str,
1179 uint32_t maxlen,
1180 uint32_t maxlen_value)
1181{
1182 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +00001183 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +00001184 {
Greg Clayton8dd5c172011-10-05 22:19:51 +00001185 while(*str)
1186 {
1187 len++;str++;
Greg Clayton2452ab72013-02-08 22:02:02 +00001188 if (len >= maxlen)
Greg Clayton8dd5c172011-10-05 22:19:51 +00001189 return maxlen_value;
1190 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001191 }
1192 return len;
1193}
1194
Enrico Granata2206b482014-10-30 18:27:31 +00001195static bool
1196CopyStringDataToBufferSP(const StreamString& source,
1197 lldb::DataBufferSP& destination)
1198{
1199 destination.reset(new DataBufferHeap(source.GetSize()+1,0));
1200 memcpy(destination->GetBytes(), source.GetString().c_str(), source.GetSize());
1201 return true;
1202}
1203
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001204size_t
Enrico Granata2206b482014-10-30 18:27:31 +00001205ValueObject::ReadPointedString (lldb::DataBufferSP& buffer_sp,
Greg Claytoncc4d0142012-02-17 07:49:44 +00001206 Error& error,
1207 uint32_t max_length,
1208 bool honor_array,
1209 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001210{
Enrico Granata2206b482014-10-30 18:27:31 +00001211 StreamString s;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001212 ExecutionContext exe_ctx (GetExecutionContextRef());
1213 Target* target = exe_ctx.GetTargetPtr();
Enrico Granata2206b482014-10-30 18:27:31 +00001214
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001215 if (!target)
1216 {
1217 s << "<no target to read from>";
1218 error.SetErrorString("no target to read from");
Enrico Granata2206b482014-10-30 18:27:31 +00001219 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001220 return 0;
1221 }
1222
1223 if (max_length == 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001224 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001225
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001226 size_t bytes_read = 0;
1227 size_t total_bytes_read = 0;
1228
Greg Clayton57ee3062013-07-11 22:46:58 +00001229 ClangASTType clang_type = GetClangType();
1230 ClangASTType elem_or_pointee_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001231 const Flags type_flags (GetTypeInfo (&elem_or_pointee_clang_type));
Enrico Granata622be232014-10-21 20:52:14 +00001232 if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Greg Clayton57ee3062013-07-11 22:46:58 +00001233 elem_or_pointee_clang_type.IsCharType ())
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001234 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001235 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1236 AddressType cstr_address_type = eAddressTypeInvalid;
1237
1238 size_t cstr_len = 0;
1239 bool capped_data = false;
Enrico Granata622be232014-10-21 20:52:14 +00001240 if (type_flags.Test (eTypeIsArray))
Greg Claytoncc4d0142012-02-17 07:49:44 +00001241 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001242 // We have an array
Greg Clayton57ee3062013-07-11 22:46:58 +00001243 uint64_t array_size = 0;
1244 if (clang_type.IsArrayType(NULL, &array_size, NULL))
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001245 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001246 cstr_len = array_size;
1247 if (cstr_len > max_length)
1248 {
1249 capped_data = true;
1250 cstr_len = max_length;
1251 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001252 }
1253 cstr_address = GetAddressOf (true, &cstr_address_type);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001254 }
1255 else
1256 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001257 // We have a pointer
1258 cstr_address = GetPointerValue (&cstr_address_type);
1259 }
1260
1261 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1262 {
1263 s << "<invalid address>";
1264 error.SetErrorString("invalid address");
Enrico Granata2206b482014-10-30 18:27:31 +00001265 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001266 return 0;
1267 }
Enrico Granata2206b482014-10-30 18:27:31 +00001268
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001269 Address cstr_so_addr (cstr_address);
1270 DataExtractor data;
1271 if (cstr_len > 0 && honor_array)
1272 {
1273 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1274 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1275 GetPointeeData(data, 0, cstr_len);
Enrico Granata2206b482014-10-30 18:27:31 +00001276
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001277 if ((bytes_read = data.GetByteSize()) > 0)
1278 {
1279 total_bytes_read = bytes_read;
Enrico Granata2206b482014-10-30 18:27:31 +00001280 for (size_t offset = 0; offset < bytes_read; offset++)
1281 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001282 if (capped_data)
1283 s << "...";
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001284 }
1285 }
1286 else
1287 {
1288 cstr_len = max_length;
1289 const size_t k_max_buf_size = 64;
Enrico Granata2206b482014-10-30 18:27:31 +00001290
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001291 size_t offset = 0;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001292
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001293 int cstr_len_displayed = -1;
1294 bool capped_cstr = false;
1295 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1296 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1297 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001298 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001299 total_bytes_read += bytes_read;
1300 const char *cstr = data.PeekCStr(0);
1301 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1302 if (len > k_max_buf_size)
1303 len = k_max_buf_size;
Enrico Granata2206b482014-10-30 18:27:31 +00001304
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001305 if (cstr_len_displayed < 0)
1306 cstr_len_displayed = len;
Enrico Granata2206b482014-10-30 18:27:31 +00001307
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001308 if (len == 0)
1309 break;
1310 cstr_len_displayed += len;
1311 if (len > bytes_read)
1312 len = bytes_read;
1313 if (len > cstr_len)
1314 len = cstr_len;
1315
Enrico Granata2206b482014-10-30 18:27:31 +00001316 for (size_t offset = 0; offset < bytes_read; offset++)
1317 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001318
1319 if (len < k_max_buf_size)
1320 break;
1321
1322 if (len >= cstr_len)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001323 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001324 capped_cstr = true;
1325 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001326 }
Enrico Granata2206b482014-10-30 18:27:31 +00001327
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001328 cstr_len -= len;
1329 offset += len;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001330 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001331
1332 if (cstr_len_displayed >= 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001333 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001334 if (capped_cstr)
1335 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001336 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001337 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001338 }
1339 else
1340 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001341 error.SetErrorString("not a string object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001342 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001343 }
Enrico Granata2206b482014-10-30 18:27:31 +00001344 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001345 return total_bytes_read;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001346}
1347
Enrico Granata744794a2014-09-05 21:46:22 +00001348std::pair<TypeValidatorResult, std::string>
1349ValueObject::GetValidationStatus ()
1350{
1351 if (!UpdateValueIfNeeded(true))
1352 return {TypeValidatorResult::Success,""}; // not the validator's job to discuss update problems
1353
1354 if (m_validation_result.hasValue())
1355 return m_validation_result.getValue();
1356
1357 if (!m_type_validator_sp)
1358 return {TypeValidatorResult::Success,""}; // no validator no failure
1359
1360 auto outcome = m_type_validator_sp->FormatObject(this);
1361
1362 return (m_validation_result = {outcome.m_result,outcome.m_message}).getValue();
1363}
1364
Jim Ingham53c47f12010-09-10 23:12:17 +00001365const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001366ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001367{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001368
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001369 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001370 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001371
1372 if (!m_object_desc_str.empty())
1373 return m_object_desc_str.c_str();
1374
Greg Claytoncc4d0142012-02-17 07:49:44 +00001375 ExecutionContext exe_ctx (GetExecutionContextRef());
1376 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001377 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001378 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001379
Jim Ingham53c47f12010-09-10 23:12:17 +00001380 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001381
Greg Claytonafacd142011-09-02 01:15:17 +00001382 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001383 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1384
Jim Inghama2cf2632010-12-23 02:29:54 +00001385 if (runtime == NULL)
1386 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001387 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Greg Clayton57ee3062013-07-11 22:46:58 +00001388 ClangASTType clang_type = GetClangType();
1389 if (clang_type)
Jim Inghama2cf2632010-12-23 02:29:54 +00001390 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001391 bool is_signed;
Greg Clayton57ee3062013-07-11 22:46:58 +00001392 if (clang_type.IsIntegerType (is_signed) || clang_type.IsPointerType ())
Jim Inghamb7603bb2011-03-18 00:05:18 +00001393 {
Greg Claytonafacd142011-09-02 01:15:17 +00001394 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001395 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001396 }
1397 }
1398
Jim Ingham8d543de2011-03-31 23:01:21 +00001399 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001400 {
1401 m_object_desc_str.append (s.GetData());
1402 }
Sean Callanan672ad942010-10-23 00:18:49 +00001403
1404 if (m_object_desc_str.empty())
1405 return NULL;
1406 else
1407 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001408}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001409
Enrico Granata0c489f52012-03-01 04:24:26 +00001410bool
Enrico Granata4939b982013-12-22 09:24:22 +00001411ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format,
1412 std::string& destination)
1413{
1414 if (UpdateValueIfNeeded(false))
1415 return format.FormatObject(this,destination);
1416 else
1417 return false;
1418}
1419
1420bool
Enrico Granata0c489f52012-03-01 04:24:26 +00001421ValueObject::GetValueAsCString (lldb::Format format,
1422 std::string& destination)
1423{
Enrico Granata30f287f2013-12-28 08:44:02 +00001424 return GetValueAsCString(TypeFormatImpl_Format(format),destination);
Enrico Granata0c489f52012-03-01 04:24:26 +00001425}
1426
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001427const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001428ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001429{
Enrico Granatab294fd22013-05-31 19:18:19 +00001430 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001431 {
Enrico Granata4939b982013-12-22 09:24:22 +00001432 lldb::TypeFormatImplSP format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001433 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001434 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001435 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001436 if (m_type_format_sp)
Enrico Granata4939b982013-12-22 09:24:22 +00001437 format_sp = m_type_format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001438 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001439 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001440 if (m_is_bitfield_for_scalar)
1441 my_format = eFormatUnsigned;
1442 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001443 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001444 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001445 {
1446 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1447 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001448 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001449 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001450 else
1451 {
Enrico Granatad07cfd32014-10-08 18:27:36 +00001452 my_format = GetValue().GetClangType().GetFormat();
Enrico Granata0c489f52012-03-01 04:24:26 +00001453 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001454 }
1455 }
1456 }
Enrico Granatab294fd22013-05-31 19:18:19 +00001457 if (my_format != m_last_format || m_value_str.empty())
Enrico Granata297e69f2012-03-06 23:21:16 +00001458 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001459 m_last_format = my_format;
Enrico Granata4939b982013-12-22 09:24:22 +00001460 if (!format_sp)
Enrico Granata30f287f2013-12-28 08:44:02 +00001461 format_sp.reset(new TypeFormatImpl_Format(my_format));
Enrico Granata4939b982013-12-22 09:24:22 +00001462 if (GetValueAsCString(*format_sp.get(), m_value_str))
Enrico Granata297e69f2012-03-06 23:21:16 +00001463 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001464 if (!m_value_did_change && m_old_value_valid)
1465 {
1466 // The value was gotten successfully, so we consider the
1467 // value as changed if the value string differs
1468 SetValueDidChange (m_old_value_str != m_value_str);
1469 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001470 }
1471 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001472 }
1473 if (m_value_str.empty())
1474 return NULL;
1475 return m_value_str.c_str();
1476}
1477
Enrico Granatac3e320a2011-08-02 17:27:39 +00001478// if > 8bytes, 0 is returned. this method should mostly be used
1479// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001480uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001481ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001482{
1483 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001484 if (CanProvideValue())
Enrico Granatac3e320a2011-08-02 17:27:39 +00001485 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001486 Scalar scalar;
1487 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001488 {
1489 if (success)
1490 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001491 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001492 }
1493 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001494 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001495
1496 if (success)
1497 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001498 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001499}
1500
Enrico Granatad7373f62013-10-31 18:57:50 +00001501int64_t
1502ValueObject::GetValueAsSigned (int64_t fail_value, bool *success)
1503{
1504 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001505 if (CanProvideValue())
Enrico Granatad7373f62013-10-31 18:57:50 +00001506 {
1507 Scalar scalar;
1508 if (ResolveValue (scalar))
1509 {
1510 if (success)
1511 *success = true;
Tamas Berghammer5a9919f2015-01-23 10:54:21 +00001512 return scalar.SLongLong(fail_value);
Enrico Granatad7373f62013-10-31 18:57:50 +00001513 }
1514 // fallthrough, otherwise...
1515 }
1516
1517 if (success)
1518 *success = false;
Tamas Berghammer5a9919f2015-01-23 10:54:21 +00001519 return fail_value;
Enrico Granatad7373f62013-10-31 18:57:50 +00001520}
1521
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001522// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1523// this call up to date by returning true for your new special cases. We will eventually move
1524// to checking this call result before trying to display special cases
1525bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001526ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1527 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001528{
Greg Clayton57ee3062013-07-11 22:46:58 +00001529 Flags flags(GetTypeInfo());
Enrico Granata622be232014-10-21 20:52:14 +00001530 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001531 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001532 {
1533 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001534 (custom_format == eFormatCString ||
1535 custom_format == eFormatCharArray ||
1536 custom_format == eFormatChar ||
1537 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001538 return true;
1539
Enrico Granata622be232014-10-21 20:52:14 +00001540 if (flags.Test(eTypeIsArray))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001541 {
Greg Claytonafacd142011-09-02 01:15:17 +00001542 if ((custom_format == eFormatBytes) ||
1543 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001544 return true;
1545
Greg Claytonafacd142011-09-02 01:15:17 +00001546 if ((custom_format == eFormatVectorOfChar) ||
1547 (custom_format == eFormatVectorOfFloat32) ||
1548 (custom_format == eFormatVectorOfFloat64) ||
1549 (custom_format == eFormatVectorOfSInt16) ||
1550 (custom_format == eFormatVectorOfSInt32) ||
1551 (custom_format == eFormatVectorOfSInt64) ||
1552 (custom_format == eFormatVectorOfSInt8) ||
1553 (custom_format == eFormatVectorOfUInt128) ||
1554 (custom_format == eFormatVectorOfUInt16) ||
1555 (custom_format == eFormatVectorOfUInt32) ||
1556 (custom_format == eFormatVectorOfUInt64) ||
1557 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001558 return true;
1559 }
1560 }
1561 return false;
1562}
1563
Enrico Granata9fc19442011-07-06 02:13:41 +00001564bool
1565ValueObject::DumpPrintableRepresentation(Stream& s,
1566 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001567 Format custom_format,
Enrico Granata0dba9b32014-01-08 01:36:59 +00001568 PrintableRepresentationSpecialCases special,
1569 bool do_dump_error)
Enrico Granata9fc19442011-07-06 02:13:41 +00001570{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001571
Greg Clayton57ee3062013-07-11 22:46:58 +00001572 Flags flags(GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001573
Enrico Granata86cc9822012-03-19 22:58:49 +00001574 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1575 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1576
1577 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001578 {
Enrico Granata622be232014-10-21 20:52:14 +00001579 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001580 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001581 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001582 // when being asked to get a printable display an array or pointer type directly,
1583 // try to "do the right thing"
1584
1585 if (IsCStringContainer(true) &&
1586 (custom_format == eFormatCString ||
1587 custom_format == eFormatCharArray ||
1588 custom_format == eFormatChar ||
1589 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001590 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001591 Error error;
Enrico Granata2206b482014-10-30 18:27:31 +00001592 lldb::DataBufferSP buffer_sp;
1593 ReadPointedString(buffer_sp,
Enrico Granata86cc9822012-03-19 22:58:49 +00001594 error,
1595 0,
1596 (custom_format == eFormatVectorOfChar) ||
1597 (custom_format == eFormatCharArray));
Enrico Granataebdc1ac2014-11-05 21:20:48 +00001598 lldb_private::formatters::ReadBufferAndDumpToStreamOptions options(*this);
Enrico Granata2206b482014-10-30 18:27:31 +00001599 options.SetData(DataExtractor(buffer_sp, lldb::eByteOrderInvalid, 8)); // none of this matters for a string - pass some defaults
1600 options.SetStream(&s);
1601 options.SetPrefixToken(0);
1602 options.SetQuote('"');
1603 options.SetSourceSize(buffer_sp->GetByteSize());
Enrico Granata2206b482014-10-30 18:27:31 +00001604 lldb_private::formatters::ReadBufferAndDumpToStream<lldb_private::formatters::StringElementType::ASCII>(options);
Enrico Granata86cc9822012-03-19 22:58:49 +00001605 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001606 }
1607
Enrico Granata86cc9822012-03-19 22:58:49 +00001608 if (custom_format == eFormatEnum)
1609 return false;
1610
1611 // this only works for arrays, because I have no way to know when
1612 // the pointed memory ends, and no special \0 end of data marker
Enrico Granata622be232014-10-21 20:52:14 +00001613 if (flags.Test(eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001614 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001615 if ((custom_format == eFormatBytes) ||
1616 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001617 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001618 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001619
1620 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001621 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001622 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001623
1624 if (low)
1625 s << ',';
1626
1627 ValueObjectSP child = GetChildAtIndex(low,true);
1628 if (!child.get())
1629 {
1630 s << "<invalid child>";
1631 continue;
1632 }
1633 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1634 }
1635
1636 s << ']';
1637
1638 return true;
1639 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001640
Enrico Granata86cc9822012-03-19 22:58:49 +00001641 if ((custom_format == eFormatVectorOfChar) ||
1642 (custom_format == eFormatVectorOfFloat32) ||
1643 (custom_format == eFormatVectorOfFloat64) ||
1644 (custom_format == eFormatVectorOfSInt16) ||
1645 (custom_format == eFormatVectorOfSInt32) ||
1646 (custom_format == eFormatVectorOfSInt64) ||
1647 (custom_format == eFormatVectorOfSInt8) ||
1648 (custom_format == eFormatVectorOfUInt128) ||
1649 (custom_format == eFormatVectorOfUInt16) ||
1650 (custom_format == eFormatVectorOfUInt32) ||
1651 (custom_format == eFormatVectorOfUInt64) ||
1652 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1653 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001654 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001655
1656 Format format = FormatManager::GetSingleItemFormat(custom_format);
1657
1658 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001659 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001660 {
1661
1662 if (low)
1663 s << ',';
1664
1665 ValueObjectSP child = GetChildAtIndex(low,true);
1666 if (!child.get())
1667 {
1668 s << "<invalid child>";
1669 continue;
1670 }
1671 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1672 }
1673
1674 s << ']';
1675
1676 return true;
1677 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001678 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001679
1680 if ((custom_format == eFormatBoolean) ||
1681 (custom_format == eFormatBinary) ||
1682 (custom_format == eFormatChar) ||
1683 (custom_format == eFormatCharPrintable) ||
1684 (custom_format == eFormatComplexFloat) ||
1685 (custom_format == eFormatDecimal) ||
1686 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001687 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001688 (custom_format == eFormatFloat) ||
1689 (custom_format == eFormatOctal) ||
1690 (custom_format == eFormatOSType) ||
1691 (custom_format == eFormatUnicode16) ||
1692 (custom_format == eFormatUnicode32) ||
1693 (custom_format == eFormatUnsigned) ||
1694 (custom_format == eFormatPointer) ||
1695 (custom_format == eFormatComplexInteger) ||
1696 (custom_format == eFormatComplex) ||
1697 (custom_format == eFormatDefault)) // use the [] operator
1698 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001699 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001700 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001701
1702 if (only_special)
1703 return false;
1704
Enrico Granata86cc9822012-03-19 22:58:49 +00001705 bool var_success = false;
1706
1707 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001708 const char *cstr = NULL;
Enrico Granata2c75f112013-06-21 00:04:51 +00001709
1710 // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1711 // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1712 // area for cases where our desired output is not backed by some other longer-term storage
Greg Claytonc7bece562013-01-25 18:06:21 +00001713 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001714
Enrico Granata465f4bc2014-02-15 01:24:44 +00001715 if (custom_format != eFormatInvalid)
Enrico Granata86cc9822012-03-19 22:58:49 +00001716 SetFormat(custom_format);
1717
1718 switch(val_obj_display)
1719 {
1720 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001721 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001722 break;
1723
1724 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001725 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001726 break;
1727
1728 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001729 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001730 break;
1731
1732 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001733 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001734 break;
1735
1736 case eValueObjectRepresentationStyleChildrenCount:
Deepak Panickal99fbc072014-03-03 15:39:47 +00001737 strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren());
Greg Claytonc7bece562013-01-25 18:06:21 +00001738 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001739 break;
1740
1741 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001742 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001743 break;
Enrico Granata2c75f112013-06-21 00:04:51 +00001744
1745 case eValueObjectRepresentationStyleName:
1746 cstr = GetName().AsCString();
1747 break;
1748
1749 case eValueObjectRepresentationStyleExpressionPath:
1750 GetExpressionPath(strm, false);
1751 cstr = strm.GetString().c_str();
1752 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001753 }
1754
Greg Claytonc7bece562013-01-25 18:06:21 +00001755 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001756 {
1757 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001758 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001759 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1760 {
Enrico Granatad07cfd32014-10-08 18:27:36 +00001761 if (!CanProvideValue())
Enrico Granata86cc9822012-03-19 22:58:49 +00001762 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001763 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1764 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001765 }
1766 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001767 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001768 }
1769 }
1770
Greg Claytonc7bece562013-01-25 18:06:21 +00001771 if (cstr)
1772 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001773 else
1774 {
1775 if (m_error.Fail())
Enrico Granata0dba9b32014-01-08 01:36:59 +00001776 {
1777 if (do_dump_error)
1778 s.Printf("<%s>", m_error.AsCString());
1779 else
1780 return false;
1781 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001782 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1783 s.PutCString("<no summary available>");
1784 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1785 s.PutCString("<no value available>");
1786 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1787 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1788 else
1789 s.PutCString("<no printable representation>");
1790 }
1791
1792 // we should only return false here if we could not do *anything*
1793 // even if we have an error message as output, that's a success
1794 // from our callers' perspective, so return true
1795 var_success = true;
Enrico Granata465f4bc2014-02-15 01:24:44 +00001796
1797 if (custom_format != eFormatInvalid)
1798 SetFormat(eFormatDefault);
Enrico Granata86cc9822012-03-19 22:58:49 +00001799 }
1800
Enrico Granataf4efecd2011-07-12 22:56:10 +00001801 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001802}
1803
Greg Clayton737b9322010-09-13 03:32:57 +00001804addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001805ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001806{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001807 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001808 return LLDB_INVALID_ADDRESS;
1809
Greg Clayton73b472d2010-10-27 03:32:59 +00001810 switch (m_value.GetValueType())
1811 {
1812 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001813 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001814 if (scalar_is_load_address)
1815 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001816 if(address_type)
1817 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001818 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1819 }
1820 break;
1821
1822 case Value::eValueTypeLoadAddress:
1823 case Value::eValueTypeFileAddress:
1824 case Value::eValueTypeHostAddress:
1825 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001826 if(address_type)
1827 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001828 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1829 }
1830 break;
1831 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001832 if (address_type)
1833 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001834 return LLDB_INVALID_ADDRESS;
1835}
1836
1837addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001838ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001839{
Greg Claytonafacd142011-09-02 01:15:17 +00001840 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001841 if(address_type)
1842 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001843
Enrico Granatac3e320a2011-08-02 17:27:39 +00001844 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001845 return address;
1846
Greg Clayton73b472d2010-10-27 03:32:59 +00001847 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001848 {
1849 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001850 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001851 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001852 break;
1853
Enrico Granata9128ee22011-09-06 19:20:51 +00001854 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001855 case Value::eValueTypeLoadAddress:
1856 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001857 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001858 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001859 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001860 }
1861 break;
1862 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001863
Enrico Granata9128ee22011-09-06 19:20:51 +00001864 if (address_type)
1865 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001866
Greg Clayton737b9322010-09-13 03:32:57 +00001867 return address;
1868}
1869
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001870bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001871ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001872{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001873 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001874 // Make sure our value is up to date first so that our location and location
1875 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001876 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001877 {
1878 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001879 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001880 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001881
Greg Claytonfaac1112013-03-14 18:31:44 +00001882 uint64_t count = 0;
Greg Clayton57ee3062013-07-11 22:46:58 +00001883 const Encoding encoding = GetClangType().GetEncoding (count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001884
Greg Claytonb1320972010-07-14 00:18:15 +00001885 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001886
Jim Ingham16e0c682011-08-12 23:34:31 +00001887 Value::ValueType value_type = m_value.GetValueType();
1888
1889 if (value_type == Value::eValueTypeScalar)
1890 {
1891 // If the value is already a scalar, then let the scalar change itself:
1892 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1893 }
1894 else if (byte_size <= Scalar::GetMaxByteSize())
1895 {
1896 // If the value fits in a scalar, then make a new scalar and again let the
1897 // scalar code do the conversion, then figure out where to put the new value.
1898 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001899 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1900 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001901 {
Jim Ingham4b536182011-08-09 02:12:22 +00001902 switch (value_type)
1903 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001904 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001905 {
1906 // If it is a load address, then the scalar value is the storage location
1907 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001908 ExecutionContext exe_ctx (GetExecutionContextRef());
1909 Process *process = exe_ctx.GetProcessPtr();
1910 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001911 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001912 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001913 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1914 new_scalar,
1915 byte_size,
1916 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001917 if (!error.Success())
1918 return false;
1919 if (bytes_written != byte_size)
1920 {
1921 error.SetErrorString("unable to write value to memory");
1922 return false;
1923 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001924 }
1925 }
Jim Ingham4b536182011-08-09 02:12:22 +00001926 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001927 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001928 {
1929 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1930 DataExtractor new_data;
1931 new_data.SetByteOrder (m_data.GetByteOrder());
1932
1933 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1934 m_data.SetData(buffer_sp, 0);
1935 bool success = new_scalar.GetData(new_data);
1936 if (success)
1937 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001938 new_data.CopyByteOrderedData (0,
1939 byte_size,
1940 const_cast<uint8_t *>(m_data.GetDataStart()),
1941 byte_size,
1942 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001943 }
1944 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1945
1946 }
Jim Ingham4b536182011-08-09 02:12:22 +00001947 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001948 case Value::eValueTypeFileAddress:
1949 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001950 case Value::eValueTypeVector:
1951 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001952 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001953 }
1954 else
1955 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001956 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001957 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001958 }
1959 else
1960 {
1961 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001962 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001963 return false;
1964 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001965
1966 // If we have reached this point, then we have successfully changed the value.
1967 SetNeedsUpdate();
1968 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001969}
1970
Greg Clayton81e871e2012-02-04 02:27:34 +00001971bool
1972ValueObject::GetDeclaration (Declaration &decl)
1973{
1974 decl.Clear();
1975 return false;
1976}
1977
Greg Clayton84db9102012-03-26 23:03:23 +00001978ConstString
1979ValueObject::GetTypeName()
1980{
Greg Clayton57ee3062013-07-11 22:46:58 +00001981 return GetClangType().GetConstTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00001982}
1983
1984ConstString
Enrico Granatae8daa2f2014-05-17 19:14:17 +00001985ValueObject::GetDisplayTypeName()
1986{
1987 return GetTypeName();
1988}
1989
1990ConstString
Greg Clayton84db9102012-03-26 23:03:23 +00001991ValueObject::GetQualifiedTypeName()
1992{
Greg Clayton57ee3062013-07-11 22:46:58 +00001993 return GetClangType().GetConstQualifiedTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00001994}
1995
1996
Greg Claytonafacd142011-09-02 01:15:17 +00001997LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001998ValueObject::GetObjectRuntimeLanguage ()
1999{
Greg Clayton57ee3062013-07-11 22:46:58 +00002000 return GetClangType().GetMinimumLanguage ();
Jim Ingham5a369122010-09-28 01:25:32 +00002001}
2002
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002003void
Jim Ingham58b59f92011-04-22 23:53:53 +00002004ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002005{
Jim Ingham58b59f92011-04-22 23:53:53 +00002006 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002007}
2008
2009ValueObjectSP
2010ValueObject::GetSyntheticChild (const ConstString &key) const
2011{
2012 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00002013 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002014 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00002015 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002016 return synthetic_child_sp;
2017}
2018
Greg Clayton2452ab72013-02-08 22:02:02 +00002019uint32_t
Greg Clayton57ee3062013-07-11 22:46:58 +00002020ValueObject::GetTypeInfo (ClangASTType *pointee_or_element_clang_type)
Greg Clayton2452ab72013-02-08 22:02:02 +00002021{
Greg Clayton57ee3062013-07-11 22:46:58 +00002022 return GetClangType().GetTypeInfo (pointee_or_element_clang_type);
Greg Clayton2452ab72013-02-08 22:02:02 +00002023}
2024
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002025bool
2026ValueObject::IsPointerType ()
2027{
Greg Clayton57ee3062013-07-11 22:46:58 +00002028 return GetClangType().IsPointerType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002029}
2030
Jim Inghamb7603bb2011-03-18 00:05:18 +00002031bool
Greg Claytondaf515f2011-07-09 20:12:33 +00002032ValueObject::IsArrayType ()
2033{
Greg Clayton57ee3062013-07-11 22:46:58 +00002034 return GetClangType().IsArrayType (NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00002035}
2036
2037bool
Enrico Granata9fc19442011-07-06 02:13:41 +00002038ValueObject::IsScalarType ()
2039{
Greg Clayton57ee3062013-07-11 22:46:58 +00002040 return GetClangType().IsScalarType ();
Enrico Granata9fc19442011-07-06 02:13:41 +00002041}
2042
2043bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00002044ValueObject::IsIntegerType (bool &is_signed)
2045{
Greg Clayton57ee3062013-07-11 22:46:58 +00002046 return GetClangType().IsIntegerType (is_signed);
Jim Inghamb7603bb2011-03-18 00:05:18 +00002047}
Greg Clayton73b472d2010-10-27 03:32:59 +00002048
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002049bool
2050ValueObject::IsPointerOrReferenceType ()
2051{
Greg Clayton57ee3062013-07-11 22:46:58 +00002052 return GetClangType().IsPointerOrReferenceType ();
Greg Clayton007d5be2011-05-30 00:49:24 +00002053}
2054
2055bool
Greg Claytondea8cb42011-06-29 22:09:02 +00002056ValueObject::IsPossibleDynamicType ()
2057{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002058 ExecutionContext exe_ctx (GetExecutionContextRef());
2059 Process *process = exe_ctx.GetProcessPtr();
2060 if (process)
2061 return process->IsPossibleDynamicValue(*this);
2062 else
Greg Clayton57ee3062013-07-11 22:46:58 +00002063 return GetClangType().IsPossibleDynamicType (NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00002064}
2065
Enrico Granata9e7b3882012-12-13 23:50:33 +00002066bool
Enrico Granata560558e2015-02-11 02:35:39 +00002067ValueObject::IsRuntimeSupportValue ()
2068{
2069 Process *process(GetProcessSP().get());
2070 if (process)
2071 {
2072 LanguageRuntime *runtime = process->GetLanguageRuntime(GetObjectRuntimeLanguage());
2073 if (!runtime)
2074 runtime = process->GetObjCLanguageRuntime();
2075 if (runtime)
2076 return runtime->IsRuntimeSupportValue(*this);
2077 }
2078 return false;
2079}
2080
2081bool
Enrico Granata9e7b3882012-12-13 23:50:33 +00002082ValueObject::IsObjCNil ()
2083{
Enrico Granata622be232014-10-21 20:52:14 +00002084 const uint32_t mask = eTypeIsObjC | eTypeIsPointer;
Greg Clayton57ee3062013-07-11 22:46:58 +00002085 bool isObjCpointer = (((GetClangType().GetTypeInfo(NULL)) & mask) == mask);
Enrico Granata7277d202013-03-15 23:33:15 +00002086 if (!isObjCpointer)
2087 return false;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002088 bool canReadValue = true;
2089 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
Enrico Granata7277d202013-03-15 23:33:15 +00002090 return canReadValue && isZero;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002091}
2092
Greg Claytondaf515f2011-07-09 20:12:33 +00002093// This allows you to create an array member using and index
2094// that doesn't not fall in the normal bounds of the array.
2095// Many times structure can be defined as:
2096// struct Collection
2097// {
2098// uint32_t item_count;
2099// Item item_array[0];
2100// };
2101// The size of the "item_array" is 1, but many times in practice
2102// there are more items in "item_array".
2103
2104ValueObjectSP
Bruce Mitchener11d86362015-02-26 23:55:39 +00002105ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00002106{
2107 ValueObjectSP synthetic_child_sp;
Bruce Mitchener11d86362015-02-26 23:55:39 +00002108 if (IsPointerType () || IsArrayType())
Greg Claytondaf515f2011-07-09 20:12:33 +00002109 {
2110 char index_str[64];
Deepak Panickal99fbc072014-03-03 15:39:47 +00002111 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
Greg Claytondaf515f2011-07-09 20:12:33 +00002112 ConstString index_const_str(index_str);
2113 // Check if we have already created a synthetic array member in this
2114 // valid object. If we have we will re-use it.
2115 synthetic_child_sp = GetSyntheticChild (index_const_str);
2116 if (!synthetic_child_sp)
2117 {
2118 ValueObject *synthetic_child;
2119 // We haven't made a synthetic array member for INDEX yet, so
2120 // lets make one and cache it for any future reference.
2121 synthetic_child = CreateChildAtIndex(0, true, index);
Bruce Mitchener11d86362015-02-26 23:55:39 +00002122
Greg Claytondaf515f2011-07-09 20:12:33 +00002123 // Cache the value if we got one back...
2124 if (synthetic_child)
2125 {
2126 AddSyntheticChild(index_const_str, synthetic_child);
2127 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002128 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00002129 synthetic_child_sp->m_is_array_item_for_pointer = true;
2130 }
2131 }
2132 }
2133 return synthetic_child_sp;
2134}
2135
Enrico Granata9fc19442011-07-06 02:13:41 +00002136ValueObjectSP
2137ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2138{
2139 ValueObjectSP synthetic_child_sp;
2140 if (IsScalarType ())
2141 {
2142 char index_str[64];
2143 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2144 ConstString index_const_str(index_str);
2145 // Check if we have already created a synthetic array member in this
2146 // valid object. If we have we will re-use it.
2147 synthetic_child_sp = GetSyntheticChild (index_const_str);
2148 if (!synthetic_child_sp)
2149 {
Enrico Granata9fc19442011-07-06 02:13:41 +00002150 // We haven't made a synthetic array member for INDEX yet, so
2151 // lets make one and cache it for any future reference.
Greg Clayton57ee3062013-07-11 22:46:58 +00002152 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
2153 GetClangType(),
2154 index_const_str,
2155 GetByteSize(),
2156 0,
2157 to-from+1,
2158 from,
2159 false,
2160 false,
2161 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002162
2163 // Cache the value if we got one back...
2164 if (synthetic_child)
2165 {
2166 AddSyntheticChild(index_const_str, synthetic_child);
2167 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002168 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002169 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2170 }
2171 }
2172 }
2173 return synthetic_child_sp;
2174}
2175
Greg Claytonafacd142011-09-02 01:15:17 +00002176ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00002177ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
2178{
2179
2180 ValueObjectSP synthetic_child_sp;
2181
2182 char name_str[64];
2183 snprintf(name_str, sizeof(name_str), "@%i", offset);
2184 ConstString name_const_str(name_str);
2185
2186 // Check if we have already created a synthetic array member in this
2187 // valid object. If we have we will re-use it.
2188 synthetic_child_sp = GetSyntheticChild (name_const_str);
2189
2190 if (synthetic_child_sp.get())
2191 return synthetic_child_sp;
2192
2193 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002194 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002195
Enrico Granata951bdd52015-01-28 01:09:45 +00002196 ExecutionContext exe_ctx (GetExecutionContextRef());
2197
Enrico Granata6f3533f2011-07-29 19:53:35 +00002198 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
Greg Clayton57ee3062013-07-11 22:46:58 +00002199 type,
Enrico Granata6f3533f2011-07-29 19:53:35 +00002200 name_const_str,
Greg Clayton526ae042015-02-12 00:34:25 +00002201 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
Enrico Granata6f3533f2011-07-29 19:53:35 +00002202 offset,
2203 0,
2204 0,
2205 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002206 false,
2207 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002208 if (synthetic_child)
2209 {
2210 AddSyntheticChild(name_const_str, synthetic_child);
2211 synthetic_child_sp = synthetic_child->GetSP();
2212 synthetic_child_sp->SetName(name_const_str);
2213 synthetic_child_sp->m_is_child_at_offset = true;
2214 }
2215 return synthetic_child_sp;
2216}
2217
Enrico Granata32556cd2014-08-26 20:54:04 +00002218ValueObjectSP
Enrico Granata59953f02014-08-26 21:35:30 +00002219ValueObject::GetSyntheticBase (uint32_t offset, const ClangASTType& type, bool can_create)
Enrico Granata32556cd2014-08-26 20:54:04 +00002220{
2221 ValueObjectSP synthetic_child_sp;
2222
2223 char name_str[64];
2224 snprintf(name_str, sizeof(name_str), "%s", type.GetTypeName().AsCString("<unknown>"));
2225 ConstString name_const_str(name_str);
2226
2227 // Check if we have already created a synthetic array member in this
2228 // valid object. If we have we will re-use it.
2229 synthetic_child_sp = GetSyntheticChild (name_const_str);
2230
2231 if (synthetic_child_sp.get())
2232 return synthetic_child_sp;
2233
2234 if (!can_create)
2235 return ValueObjectSP();
2236
Enrico Granata32556cd2014-08-26 20:54:04 +00002237 const bool is_base_class = true;
2238
Enrico Granata951bdd52015-01-28 01:09:45 +00002239 ExecutionContext exe_ctx (GetExecutionContextRef());
2240
Enrico Granata32556cd2014-08-26 20:54:04 +00002241 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2242 type,
2243 name_const_str,
Greg Clayton526ae042015-02-12 00:34:25 +00002244 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
Enrico Granata32556cd2014-08-26 20:54:04 +00002245 offset,
2246 0,
2247 0,
2248 is_base_class,
2249 false,
2250 eAddressTypeInvalid);
2251 if (synthetic_child)
2252 {
2253 AddSyntheticChild(name_const_str, synthetic_child);
2254 synthetic_child_sp = synthetic_child->GetSP();
2255 synthetic_child_sp->SetName(name_const_str);
2256 }
2257 return synthetic_child_sp;
2258}
2259
2260
Enrico Granatad55546b2011-07-22 00:16:08 +00002261// your expression path needs to have a leading . or ->
2262// (unless it somehow "looks like" an array, in which case it has
2263// a leading [ symbol). while the [ is meaningful and should be shown
2264// to the user, . and -> are just parser design, but by no means
2265// added information for the user.. strip them off
2266static const char*
2267SkipLeadingExpressionPathSeparators(const char* expression)
2268{
2269 if (!expression || !expression[0])
2270 return expression;
2271 if (expression[0] == '.')
2272 return expression+1;
2273 if (expression[0] == '-' && expression[1] == '>')
2274 return expression+2;
2275 return expression;
2276}
2277
Greg Claytonafacd142011-09-02 01:15:17 +00002278ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002279ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2280{
2281 ValueObjectSP synthetic_child_sp;
2282 ConstString name_const_string(expression);
2283 // Check if we have already created a synthetic array member in this
2284 // valid object. If we have we will re-use it.
2285 synthetic_child_sp = GetSyntheticChild (name_const_string);
2286 if (!synthetic_child_sp)
2287 {
2288 // We haven't made a synthetic array member for expression yet, so
2289 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002290 synthetic_child_sp = GetValueForExpressionPath(expression,
2291 NULL, NULL, NULL,
Enrico Granataef238c12015-03-12 22:30:58 +00002292 GetValueForExpressionPathOptions().SetSyntheticChildrenTraversal(GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None));
Enrico Granatad55546b2011-07-22 00:16:08 +00002293
2294 // Cache the value if we got one back...
2295 if (synthetic_child_sp.get())
2296 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002297 // 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 +00002298 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002299 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002300 }
2301 }
2302 return synthetic_child_sp;
2303}
2304
2305void
Enrico Granata86cc9822012-03-19 22:58:49 +00002306ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002307{
Enrico Granata86cc9822012-03-19 22:58:49 +00002308 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002309 return;
2310
Enrico Granatac5bc4122012-03-27 02:35:13 +00002311 TargetSP target_sp(GetTargetSP());
Enrico Granata5d5f60c2013-09-24 22:58:37 +00002312 if (target_sp && target_sp->GetEnableSyntheticValue() == false)
Enrico Granatac5bc4122012-03-27 02:35:13 +00002313 {
2314 m_synthetic_value = NULL;
2315 return;
2316 }
2317
Enrico Granatae3e91512012-10-22 18:18:36 +00002318 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2319
Enrico Granata5548cb52013-01-28 23:47:25 +00002320 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002321 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002322
Enrico Granata0c489f52012-03-01 04:24:26 +00002323 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002324 return;
2325
Enrico Granatae3e91512012-10-22 18:18:36 +00002326 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2327 return;
2328
Enrico Granata86cc9822012-03-19 22:58:49 +00002329 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002330}
2331
Jim Ingham78a685a2011-04-16 00:01:13 +00002332void
Greg Claytonafacd142011-09-02 01:15:17 +00002333ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002334{
Greg Claytonafacd142011-09-02 01:15:17 +00002335 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002336 return;
2337
Jim Ingham58b59f92011-04-22 23:53:53 +00002338 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002339 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002340 ExecutionContext exe_ctx (GetExecutionContextRef());
2341 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002342 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002343 {
2344 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002345 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002346 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002347 }
2348}
2349
Jim Ingham58b59f92011-04-22 23:53:53 +00002350ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002351ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002352{
Greg Claytonafacd142011-09-02 01:15:17 +00002353 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002354 return ValueObjectSP();
2355
2356 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002357 {
Jim Ingham2837b762011-05-04 03:43:18 +00002358 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002359 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002360 if (m_dynamic_value)
2361 return m_dynamic_value->GetSP();
2362 else
2363 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002364}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002365
Jim Ingham60dbabb2011-12-08 19:44:08 +00002366ValueObjectSP
2367ValueObject::GetStaticValue()
2368{
2369 return GetSP();
2370}
2371
Enrico Granata886147f2012-05-08 18:47:08 +00002372lldb::ValueObjectSP
2373ValueObject::GetNonSyntheticValue ()
2374{
2375 return GetSP();
2376}
2377
Enrico Granatad55546b2011-07-22 00:16:08 +00002378ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002379ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002380{
Enrico Granata86cc9822012-03-19 22:58:49 +00002381 if (use_synthetic == false)
2382 return ValueObjectSP();
2383
Enrico Granatad55546b2011-07-22 00:16:08 +00002384 CalculateSyntheticValue(use_synthetic);
2385
2386 if (m_synthetic_value)
2387 return m_synthetic_value->GetSP();
2388 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002389 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002390}
2391
Greg Claytone221f822011-01-21 01:59:00 +00002392bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002393ValueObject::HasSyntheticValue()
2394{
Enrico Granata5548cb52013-01-28 23:47:25 +00002395 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002396
Enrico Granata0c489f52012-03-01 04:24:26 +00002397 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002398 return false;
2399
Enrico Granata86cc9822012-03-19 22:58:49 +00002400 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002401
2402 if (m_synthetic_value)
2403 return true;
2404 else
2405 return false;
2406}
2407
2408bool
Greg Claytone221f822011-01-21 01:59:00 +00002409ValueObject::GetBaseClassPath (Stream &s)
2410{
2411 if (IsBaseClass())
2412 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002413 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Clayton57ee3062013-07-11 22:46:58 +00002414 ClangASTType clang_type = GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002415 std::string cxx_class_name;
Greg Clayton57ee3062013-07-11 22:46:58 +00002416 bool this_had_base_class = clang_type.GetCXXClassName (cxx_class_name);
Greg Claytone221f822011-01-21 01:59:00 +00002417 if (this_had_base_class)
2418 {
2419 if (parent_had_base_class)
2420 s.PutCString("::");
2421 s.PutCString(cxx_class_name.c_str());
2422 }
2423 return parent_had_base_class || this_had_base_class;
2424 }
2425 return false;
2426}
2427
2428
2429ValueObject *
2430ValueObject::GetNonBaseClassParent()
2431{
Jim Ingham78a685a2011-04-16 00:01:13 +00002432 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002433 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002434 if (GetParent()->IsBaseClass())
2435 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002436 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002437 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002438 }
2439 return NULL;
2440}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002441
Enrico Granataa3c8f042014-08-19 22:29:08 +00002442
2443bool
2444ValueObject::IsBaseClass (uint32_t& depth)
2445{
2446 if (!IsBaseClass())
2447 {
2448 depth = 0;
2449 return false;
2450 }
2451 if (GetParent())
2452 {
2453 GetParent()->IsBaseClass(depth);
2454 depth = depth + 1;
2455 return true;
2456 }
2457 // TODO: a base of no parent? weird..
2458 depth = 1;
2459 return true;
2460}
2461
Greg Clayton1d3afba2010-10-05 00:00:42 +00002462void
Enrico Granata4becb372011-06-29 22:27:15 +00002463ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002464{
Enrico Granata986fa5f2014-12-09 21:41:16 +00002465 // synthetic children do not actually "exist" as part of the hierarchy, and sometimes they are consed up in ways
2466 // that don't make sense from an underlying language/API standpoint. So, use a special code path here to return
2467 // something that can hopefully be used in expression
2468 if (m_is_synthetic_children_generated)
2469 {
2470 UpdateValueIfNeeded();
2471
2472 if (m_value.GetValueType() == Value::eValueTypeLoadAddress)
2473 {
2474 if (IsPointerOrReferenceType())
2475 {
2476 s.Printf("((%s)0x%" PRIx64 ")",
2477 GetTypeName().AsCString("void"),
2478 GetValueAsUnsigned(0));
2479 return;
2480 }
2481 else
2482 {
2483 uint64_t load_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
2484 if (load_addr != LLDB_INVALID_ADDRESS)
2485 {
2486 s.Printf("(*( (%s *)0x%" PRIx64 "))",
2487 GetTypeName().AsCString("void"),
2488 load_addr);
2489 return;
2490 }
2491 }
2492 }
2493
2494 if (CanProvideValue())
2495 {
2496 s.Printf("((%s)%s)",
2497 GetTypeName().AsCString("void"),
2498 GetValueAsCString());
2499 return;
2500 }
2501
2502 return;
2503 }
2504
Greg Claytone221f822011-01-21 01:59:00 +00002505 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002506
Enrico Granata86cc9822012-03-19 22:58:49 +00002507 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002508 {
Enrico Granata4becb372011-06-29 22:27:15 +00002509 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2510 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2511 // the eHonorPointers mode is meant to produce strings in this latter format
2512 s.PutCString("*(");
2513 }
Greg Claytone221f822011-01-21 01:59:00 +00002514
Enrico Granata4becb372011-06-29 22:27:15 +00002515 ValueObject* parent = GetParent();
2516
2517 if (parent)
2518 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002519
2520 // if we are a deref_of_parent just because we are synthetic array
2521 // members made up to allow ptr[%d] syntax to work in variable
2522 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002523 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002524 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002525
Greg Claytone221f822011-01-21 01:59:00 +00002526 if (!IsBaseClass())
2527 {
2528 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002529 {
Greg Claytone221f822011-01-21 01:59:00 +00002530 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2531 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002532 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002533 ClangASTType non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002534 if (non_base_class_parent_clang_type)
2535 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002536 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002537 {
2538 s.PutCString("->");
2539 }
Enrico Granata4becb372011-06-29 22:27:15 +00002540 else
2541 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002542 const uint32_t non_base_class_parent_type_info = non_base_class_parent_clang_type.GetTypeInfo();
2543
Enrico Granata622be232014-10-21 20:52:14 +00002544 if (non_base_class_parent_type_info & eTypeIsPointer)
Enrico Granata4becb372011-06-29 22:27:15 +00002545 {
2546 s.PutCString("->");
2547 }
Enrico Granata622be232014-10-21 20:52:14 +00002548 else if ((non_base_class_parent_type_info & eTypeHasChildren) &&
2549 !(non_base_class_parent_type_info & eTypeIsArray))
Enrico Granata4becb372011-06-29 22:27:15 +00002550 {
2551 s.PutChar('.');
2552 }
Greg Claytone221f822011-01-21 01:59:00 +00002553 }
2554 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002555 }
Greg Claytone221f822011-01-21 01:59:00 +00002556
2557 const char *name = GetName().GetCString();
2558 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002559 {
Greg Claytone221f822011-01-21 01:59:00 +00002560 if (qualify_cxx_base_classes)
2561 {
2562 if (GetBaseClassPath (s))
2563 s.PutCString("::");
2564 }
2565 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002566 }
2567 }
2568 }
2569
Enrico Granata86cc9822012-03-19 22:58:49 +00002570 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002571 {
Greg Claytone221f822011-01-21 01:59:00 +00002572 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002573 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002574}
2575
Greg Claytonafacd142011-09-02 01:15:17 +00002576ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002577ValueObject::GetValueForExpressionPath(const char* expression,
2578 const char** first_unparsed,
2579 ExpressionPathScanEndReason* reason_to_stop,
2580 ExpressionPathEndResultType* final_value_type,
2581 const GetValueForExpressionPathOptions& options,
2582 ExpressionPathAftermath* final_task_on_target)
2583{
2584
2585 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002586 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2587 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002588 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002589
2590 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2591 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2592 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2593 final_value_type ? final_value_type : &dummy_final_value_type,
2594 options,
2595 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2596
Enrico Granata86cc9822012-03-19 22:58:49 +00002597 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002598 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002599
Enrico Granata86cc9822012-03-19 22:58:49 +00002600 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 +00002601 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002602 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002603 {
2604 Error error;
2605 ValueObjectSP final_value = ret_val->Dereference(error);
2606 if (error.Fail() || !final_value.get())
2607 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002608 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002609 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002610 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002611 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002612 return ValueObjectSP();
2613 }
2614 else
2615 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002616 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002617 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002618 return final_value;
2619 }
2620 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002621 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002622 {
2623 Error error;
2624 ValueObjectSP final_value = ret_val->AddressOf(error);
2625 if (error.Fail() || !final_value.get())
2626 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002627 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002628 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002629 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002630 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002631 return ValueObjectSP();
2632 }
2633 else
2634 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002635 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002636 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002637 return final_value;
2638 }
2639 }
2640 }
2641 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2642}
2643
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002644int
2645ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002646 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002647 const char** first_unparsed,
2648 ExpressionPathScanEndReason* reason_to_stop,
2649 ExpressionPathEndResultType* final_value_type,
2650 const GetValueForExpressionPathOptions& options,
2651 ExpressionPathAftermath* final_task_on_target)
2652{
2653 const char* dummy_first_unparsed;
2654 ExpressionPathScanEndReason dummy_reason_to_stop;
2655 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002656 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002657
2658 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2659 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2660 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2661 final_value_type ? final_value_type : &dummy_final_value_type,
2662 options,
2663 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2664
2665 if (!ret_val.get()) // if there are errors, I add nothing to the list
2666 return 0;
2667
Enrico Granata86ea8d82012-03-29 01:34:34 +00002668 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002669 {
2670 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002671 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002672 {
2673 list->Append(ret_val);
2674 return 1;
2675 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002676 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 +00002677 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002678 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002679 {
2680 Error error;
2681 ValueObjectSP final_value = ret_val->Dereference(error);
2682 if (error.Fail() || !final_value.get())
2683 {
Greg Clayton23f59502012-07-17 03:23:13 +00002684 if (reason_to_stop)
2685 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2686 if (final_value_type)
2687 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002688 return 0;
2689 }
2690 else
2691 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002692 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002693 list->Append(final_value);
2694 return 1;
2695 }
2696 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002697 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002698 {
2699 Error error;
2700 ValueObjectSP final_value = ret_val->AddressOf(error);
2701 if (error.Fail() || !final_value.get())
2702 {
Greg Clayton23f59502012-07-17 03:23:13 +00002703 if (reason_to_stop)
2704 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2705 if (final_value_type)
2706 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002707 return 0;
2708 }
2709 else
2710 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002711 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002712 list->Append(final_value);
2713 return 1;
2714 }
2715 }
2716 }
2717 }
2718 else
2719 {
2720 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2721 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2722 ret_val,
2723 list,
2724 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2725 final_value_type ? final_value_type : &dummy_final_value_type,
2726 options,
2727 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2728 }
2729 // in any non-covered case, just do the obviously right thing
2730 list->Append(ret_val);
2731 return 1;
2732}
2733
Greg Claytonafacd142011-09-02 01:15:17 +00002734ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002735ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2736 const char** first_unparsed,
2737 ExpressionPathScanEndReason* reason_to_stop,
2738 ExpressionPathEndResultType* final_result,
2739 const GetValueForExpressionPathOptions& options,
2740 ExpressionPathAftermath* what_next)
2741{
2742 ValueObjectSP root = GetSP();
2743
2744 if (!root.get())
2745 return ValueObjectSP();
2746
2747 *first_unparsed = expression_cstr;
2748
2749 while (true)
2750 {
2751
2752 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2753
Greg Clayton57ee3062013-07-11 22:46:58 +00002754 ClangASTType root_clang_type = root->GetClangType();
2755 ClangASTType pointee_clang_type;
2756 Flags pointee_clang_type_info;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002757
Greg Clayton57ee3062013-07-11 22:46:58 +00002758 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002759 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00002760 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002761
2762 if (!expression_cstr || *expression_cstr == '\0')
2763 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002764 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002765 return root;
2766 }
2767
2768 switch (*expression_cstr)
2769 {
2770 case '-':
2771 {
2772 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granata622be232014-10-21 20:52:14 +00002773 root_clang_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 +00002774 {
2775 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002776 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2777 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002778 return ValueObjectSP();
2779 }
Enrico Granata622be232014-10-21 20:52:14 +00002780 if (root_clang_type_info.Test(eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2781 root_clang_type_info.Test(eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002782 options.m_no_fragile_ivar)
2783 {
2784 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002785 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2786 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002787 return ValueObjectSP();
2788 }
2789 if (expression_cstr[1] != '>')
2790 {
2791 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002792 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2793 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002794 return ValueObjectSP();
2795 }
2796 expression_cstr++; // skip the -
2797 }
2798 case '.': // or fallthrough from ->
2799 {
2800 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granata622be232014-10-21 20:52:14 +00002801 root_clang_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 +00002802 {
2803 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002804 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2805 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002806 return ValueObjectSP();
2807 }
2808 expression_cstr++; // skip .
2809 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2810 ConstString child_name;
2811 if (!next_separator) // if no other separator just expand this last layer
2812 {
2813 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002814 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2815
2816 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002817 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002818 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002819 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2820 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002821 return child_valobj_sp;
2822 }
Enrico Granataef238c12015-03-12 22:30:58 +00002823 else
Enrico Granata8c9d3562011-08-11 17:08:01 +00002824 {
Enrico Granataef238c12015-03-12 22:30:58 +00002825 switch (options.m_synthetic_children_traversal)
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002826 {
Enrico Granataef238c12015-03-12 22:30:58 +00002827 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None:
2828 break;
2829 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic:
2830 if (root->IsSynthetic())
2831 {
2832 child_valobj_sp = root->GetNonSyntheticValue();
2833 if (child_valobj_sp.get())
2834 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2835 }
2836 break;
2837 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic:
2838 if (!root->IsSynthetic())
2839 {
2840 child_valobj_sp = root->GetSyntheticValue();
2841 if (child_valobj_sp.get())
2842 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2843 }
2844 break;
2845 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both:
2846 if (root->IsSynthetic())
2847 {
2848 child_valobj_sp = root->GetNonSyntheticValue();
2849 if (child_valobj_sp.get())
2850 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2851 }
2852 else
2853 {
2854 child_valobj_sp = root->GetSyntheticValue();
2855 if (child_valobj_sp.get())
2856 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2857 }
2858 break;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002859 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002860 }
2861
2862 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2863 // so we hit the "else" branch, and return an error
2864 if(child_valobj_sp.get()) // if it worked, just return
2865 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002866 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002867 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2868 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002869 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002870 }
2871 else
2872 {
2873 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002874 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2875 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002876 return ValueObjectSP();
2877 }
2878 }
2879 else // other layers do expand
2880 {
2881 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002882 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2883 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002884 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002885 root = child_valobj_sp;
2886 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002887 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002888 continue;
2889 }
Enrico Granataef238c12015-03-12 22:30:58 +00002890 else
Enrico Granata8c9d3562011-08-11 17:08:01 +00002891 {
Enrico Granataef238c12015-03-12 22:30:58 +00002892 switch (options.m_synthetic_children_traversal)
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002893 {
Enrico Granataef238c12015-03-12 22:30:58 +00002894 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None:
2895 break;
2896 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic:
2897 if (root->IsSynthetic())
2898 {
2899 child_valobj_sp = root->GetNonSyntheticValue();
2900 if (child_valobj_sp.get())
2901 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2902 }
2903 break;
2904 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic:
2905 if (!root->IsSynthetic())
2906 {
2907 child_valobj_sp = root->GetSyntheticValue();
2908 if (child_valobj_sp.get())
2909 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2910 }
2911 break;
2912 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both:
2913 if (root->IsSynthetic())
2914 {
2915 child_valobj_sp = root->GetNonSyntheticValue();
2916 if (child_valobj_sp.get())
2917 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2918 }
2919 else
2920 {
2921 child_valobj_sp = root->GetSyntheticValue();
2922 if (child_valobj_sp.get())
2923 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2924 }
2925 break;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002926 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002927 }
2928
2929 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2930 // so we hit the "else" branch, and return an error
2931 if(child_valobj_sp.get()) // if it worked, move on
2932 {
2933 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002934 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002935 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002936 continue;
2937 }
2938 else
2939 {
2940 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002941 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2942 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002943 return ValueObjectSP();
2944 }
2945 }
2946 break;
2947 }
2948 case '[':
2949 {
Enrico Granata622be232014-10-21 20:52:14 +00002950 if (!root_clang_type_info.Test(eTypeIsArray) && !root_clang_type_info.Test(eTypeIsPointer) && !root_clang_type_info.Test(eTypeIsVector)) // if this is not a T[] nor a T*
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002951 {
Enrico Granata622be232014-10-21 20:52:14 +00002952 if (!root_clang_type_info.Test(eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002953 {
Enrico Granataef238c12015-03-12 22:30:58 +00002954 if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None) // ...only chance left is synthetic
Enrico Granata27b625e2011-08-09 01:04:56 +00002955 {
2956 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002957 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2958 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002959 return ValueObjectSP();
2960 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002961 }
2962 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2963 {
2964 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002965 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2966 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002967 return ValueObjectSP();
2968 }
2969 }
2970 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2971 {
Enrico Granata622be232014-10-21 20:52:14 +00002972 if (!root_clang_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002973 {
2974 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002975 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2976 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002977 return ValueObjectSP();
2978 }
2979 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2980 {
2981 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002982 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2983 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002984 return root;
2985 }
2986 }
2987 const char *separator_position = ::strchr(expression_cstr+1,'-');
2988 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2989 if (!close_bracket_position) // if there is no ], this is a syntax error
2990 {
2991 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002992 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2993 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002994 return ValueObjectSP();
2995 }
2996 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2997 {
2998 char *end = NULL;
2999 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3000 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3001 {
3002 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003003 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3004 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003005 return ValueObjectSP();
3006 }
3007 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3008 {
Enrico Granata622be232014-10-21 20:52:14 +00003009 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003010 {
3011 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003012 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3013 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003014 return root;
3015 }
3016 else
3017 {
3018 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003019 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3020 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003021 return ValueObjectSP();
3022 }
3023 }
3024 // from here on we do have a valid index
Enrico Granata622be232014-10-21 20:52:14 +00003025 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003026 {
Greg Claytondaf515f2011-07-09 20:12:33 +00003027 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
3028 if (!child_valobj_sp)
Bruce Mitchener11d86362015-02-26 23:55:39 +00003029 child_valobj_sp = root->GetSyntheticArrayMember(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003030 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00003031 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
3032 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00003033 if (child_valobj_sp)
3034 {
3035 root = child_valobj_sp;
3036 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003037 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00003038 continue;
3039 }
3040 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003041 {
3042 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003043 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3044 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003045 return ValueObjectSP();
3046 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003047 }
Enrico Granata622be232014-10-21 20:52:14 +00003048 else if (root_clang_type_info.Test(eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003049 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003050 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
Enrico Granata622be232014-10-21 20:52:14 +00003051 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003052 {
3053 Error error;
3054 root = root->Dereference(error);
3055 if (error.Fail() || !root.get())
3056 {
3057 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003058 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3059 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003060 return ValueObjectSP();
3061 }
3062 else
3063 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003064 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003065 continue;
3066 }
3067 }
3068 else
3069 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003070 if (root->GetClangType().GetMinimumLanguage() == eLanguageTypeObjC
Enrico Granata622be232014-10-21 20:52:14 +00003071 && pointee_clang_type_info.AllClear(eTypeIsPointer)
Greg Clayton84db9102012-03-26 23:03:23 +00003072 && root->HasSyntheticValue()
Enrico Granataef238c12015-03-12 22:30:58 +00003073 && (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic ||
3074 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both))
Enrico Granata27b625e2011-08-09 01:04:56 +00003075 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003076 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003077 }
3078 else
Bruce Mitchener11d86362015-02-26 23:55:39 +00003079 root = root->GetSyntheticArrayMember(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003080 if (!root.get())
3081 {
3082 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003083 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3084 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003085 return ValueObjectSP();
3086 }
3087 else
3088 {
3089 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003090 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003091 continue;
3092 }
3093 }
3094 }
Enrico Granata622be232014-10-21 20:52:14 +00003095 else if (root_clang_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003096 {
3097 root = root->GetSyntheticBitFieldChild(index, index, true);
3098 if (!root.get())
3099 {
3100 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003101 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3102 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003103 return ValueObjectSP();
3104 }
3105 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3106 {
3107 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003108 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3109 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003110 return root;
3111 }
3112 }
Enrico Granata622be232014-10-21 20:52:14 +00003113 else if (root_clang_type_info.Test(eTypeIsVector))
Enrico Granata08a1bb82013-06-19 00:00:45 +00003114 {
3115 root = root->GetChildAtIndex(index, true);
3116 if (!root.get())
3117 {
3118 *first_unparsed = expression_cstr;
3119 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3120 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3121 return ValueObjectSP();
3122 }
3123 else
3124 {
3125 *first_unparsed = end+1; // skip ]
3126 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3127 continue;
3128 }
3129 }
Enrico Granataef238c12015-03-12 22:30:58 +00003130 else if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic ||
3131 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both)
Enrico Granata27b625e2011-08-09 01:04:56 +00003132 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003133 if (root->HasSyntheticValue())
3134 root = root->GetSyntheticValue();
3135 else if (!root->IsSynthetic())
3136 {
3137 *first_unparsed = expression_cstr;
3138 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3139 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3140 return ValueObjectSP();
3141 }
3142 // if we are here, then root itself is a synthetic VO.. should be good to go
3143
Enrico Granata27b625e2011-08-09 01:04:56 +00003144 if (!root.get())
3145 {
3146 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003147 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3148 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3149 return ValueObjectSP();
3150 }
3151 root = root->GetChildAtIndex(index, true);
3152 if (!root.get())
3153 {
3154 *first_unparsed = expression_cstr;
3155 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3156 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003157 return ValueObjectSP();
3158 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00003159 else
3160 {
3161 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003162 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00003163 continue;
3164 }
Enrico Granata27b625e2011-08-09 01:04:56 +00003165 }
3166 else
3167 {
3168 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003169 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3170 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003171 return ValueObjectSP();
3172 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003173 }
3174 else // we have a low and a high index
3175 {
3176 char *end = NULL;
3177 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3178 if (!end || end != separator_position) // if something weird is in our way return an error
3179 {
3180 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003181 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3182 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003183 return ValueObjectSP();
3184 }
3185 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3186 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3187 {
3188 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003189 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3190 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003191 return ValueObjectSP();
3192 }
3193 if (index_lower > index_higher) // swap indices if required
3194 {
3195 unsigned long temp = index_lower;
3196 index_lower = index_higher;
3197 index_higher = temp;
3198 }
Enrico Granata622be232014-10-21 20:52:14 +00003199 if (root_clang_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003200 {
3201 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3202 if (!root.get())
3203 {
3204 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003205 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3206 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003207 return ValueObjectSP();
3208 }
3209 else
3210 {
3211 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003212 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3213 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003214 return root;
3215 }
3216 }
Enrico Granata622be232014-10-21 20:52:14 +00003217 else if (root_clang_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 +00003218 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granata622be232014-10-21 20:52:14 +00003219 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003220 {
3221 Error error;
3222 root = root->Dereference(error);
3223 if (error.Fail() || !root.get())
3224 {
3225 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003226 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3227 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003228 return ValueObjectSP();
3229 }
3230 else
3231 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003232 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003233 continue;
3234 }
3235 }
3236 else
3237 {
3238 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003239 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3240 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003241 return root;
3242 }
3243 }
3244 break;
3245 }
3246 default: // some non-separator is in the way
3247 {
3248 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003249 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3250 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003251 return ValueObjectSP();
3252 break;
3253 }
3254 }
3255 }
3256}
3257
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003258int
3259ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3260 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00003261 ValueObjectSP root,
3262 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003263 ExpressionPathScanEndReason* reason_to_stop,
3264 ExpressionPathEndResultType* final_result,
3265 const GetValueForExpressionPathOptions& options,
3266 ExpressionPathAftermath* what_next)
3267{
3268 if (!root.get())
3269 return 0;
3270
3271 *first_unparsed = expression_cstr;
3272
3273 while (true)
3274 {
3275
3276 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3277
Greg Clayton57ee3062013-07-11 22:46:58 +00003278 ClangASTType root_clang_type = root->GetClangType();
3279 ClangASTType pointee_clang_type;
3280 Flags pointee_clang_type_info;
3281 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003282 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00003283 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003284
3285 if (!expression_cstr || *expression_cstr == '\0')
3286 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003287 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003288 list->Append(root);
3289 return 1;
3290 }
3291
3292 switch (*expression_cstr)
3293 {
3294 case '[':
3295 {
Enrico Granata622be232014-10-21 20:52:14 +00003296 if (!root_clang_type_info.Test(eTypeIsArray) && !root_clang_type_info.Test(eTypeIsPointer)) // if this is not a T[] nor a T*
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003297 {
Enrico Granata622be232014-10-21 20:52:14 +00003298 if (!root_clang_type_info.Test(eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003299 {
3300 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003301 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3302 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003303 return 0;
3304 }
3305 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3306 {
3307 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003308 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3309 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003310 return 0;
3311 }
3312 }
3313 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3314 {
Enrico Granata622be232014-10-21 20:52:14 +00003315 if (!root_clang_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003316 {
3317 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003318 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3319 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003320 return 0;
3321 }
3322 else // expand this into list
3323 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003324 const size_t max_index = root->GetNumChildren() - 1;
3325 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003326 {
3327 ValueObjectSP child =
3328 root->GetChildAtIndex(index, true);
3329 list->Append(child);
3330 }
3331 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003332 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3333 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003334 return max_index; // tell me number of items I added to the VOList
3335 }
3336 }
3337 const char *separator_position = ::strchr(expression_cstr+1,'-');
3338 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3339 if (!close_bracket_position) // if there is no ], this is a syntax error
3340 {
3341 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003342 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3343 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003344 return 0;
3345 }
3346 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3347 {
3348 char *end = NULL;
3349 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3350 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3351 {
3352 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003353 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3354 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003355 return 0;
3356 }
3357 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3358 {
Enrico Granata622be232014-10-21 20:52:14 +00003359 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003360 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003361 const size_t max_index = root->GetNumChildren() - 1;
3362 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003363 {
3364 ValueObjectSP child =
3365 root->GetChildAtIndex(index, true);
3366 list->Append(child);
3367 }
3368 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003369 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3370 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003371 return max_index; // tell me number of items I added to the VOList
3372 }
3373 else
3374 {
3375 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003376 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3377 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003378 return 0;
3379 }
3380 }
3381 // from here on we do have a valid index
Enrico Granata622be232014-10-21 20:52:14 +00003382 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003383 {
3384 root = root->GetChildAtIndex(index, true);
3385 if (!root.get())
3386 {
3387 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003388 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3389 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003390 return 0;
3391 }
3392 else
3393 {
3394 list->Append(root);
3395 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003396 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3397 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003398 return 1;
3399 }
3400 }
Enrico Granata622be232014-10-21 20:52:14 +00003401 else if (root_clang_type_info.Test(eTypeIsPointer))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003402 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003403 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
Enrico Granata622be232014-10-21 20:52:14 +00003404 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003405 {
3406 Error error;
3407 root = root->Dereference(error);
3408 if (error.Fail() || !root.get())
3409 {
3410 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003411 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3412 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003413 return 0;
3414 }
3415 else
3416 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003417 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003418 continue;
3419 }
3420 }
3421 else
3422 {
Bruce Mitchener11d86362015-02-26 23:55:39 +00003423 root = root->GetSyntheticArrayMember(index, true);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003424 if (!root.get())
3425 {
3426 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003427 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3428 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003429 return 0;
3430 }
3431 else
3432 {
3433 list->Append(root);
3434 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003435 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3436 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003437 return 1;
3438 }
3439 }
3440 }
3441 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3442 {
3443 root = root->GetSyntheticBitFieldChild(index, index, true);
3444 if (!root.get())
3445 {
3446 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003447 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3448 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003449 return 0;
3450 }
3451 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3452 {
3453 list->Append(root);
3454 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003455 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3456 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003457 return 1;
3458 }
3459 }
3460 }
3461 else // we have a low and a high index
3462 {
3463 char *end = NULL;
3464 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3465 if (!end || end != separator_position) // if something weird is in our way return an error
3466 {
3467 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003468 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3469 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003470 return 0;
3471 }
3472 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3473 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3474 {
3475 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003476 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3477 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003478 return 0;
3479 }
3480 if (index_lower > index_higher) // swap indices if required
3481 {
3482 unsigned long temp = index_lower;
3483 index_lower = index_higher;
3484 index_higher = temp;
3485 }
Enrico Granata622be232014-10-21 20:52:14 +00003486 if (root_clang_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003487 {
3488 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3489 if (!root.get())
3490 {
3491 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003492 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3493 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003494 return 0;
3495 }
3496 else
3497 {
3498 list->Append(root);
3499 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003500 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3501 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003502 return 1;
3503 }
3504 }
Enrico Granata622be232014-10-21 20:52:14 +00003505 else if (root_clang_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 +00003506 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granata622be232014-10-21 20:52:14 +00003507 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003508 {
3509 Error error;
3510 root = root->Dereference(error);
3511 if (error.Fail() || !root.get())
3512 {
3513 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003514 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3515 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003516 return 0;
3517 }
3518 else
3519 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003520 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003521 continue;
3522 }
3523 }
3524 else
3525 {
Johnny Chen44805302011-07-19 19:48:13 +00003526 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003527 index <= index_higher; index++)
3528 {
3529 ValueObjectSP child =
3530 root->GetChildAtIndex(index, true);
3531 list->Append(child);
3532 }
3533 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003534 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3535 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003536 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3537 }
3538 }
3539 break;
3540 }
3541 default: // some non-[ separator, or something entirely wrong, is in the way
3542 {
3543 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003544 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3545 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003546 return 0;
3547 break;
3548 }
3549 }
3550 }
3551}
3552
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003553void
3554ValueObject::LogValueObject (Log *log)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003555{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003556 if (log)
3557 return LogValueObject (log, DumpValueObjectOptions::DefaultOptions());
Greg Clayton1d3afba2010-10-05 00:00:42 +00003558}
3559
Enrico Granata0c489f52012-03-01 04:24:26 +00003560void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003561ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003562{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003563 if (log)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003564 {
3565 StreamString s;
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003566 Dump (s, options);
Greg Claytonf830dbb2012-03-22 18:15:37 +00003567 if (s.GetSize())
3568 log->PutCString(s.GetData());
3569 }
3570}
3571
3572void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003573ValueObject::Dump (Stream &s)
Enrico Granata0c489f52012-03-01 04:24:26 +00003574{
Enrico Granata78639912014-12-20 01:41:27 +00003575 Dump (s, DumpValueObjectOptions::DefaultOptions());
Enrico Granata0c489f52012-03-01 04:24:26 +00003576}
3577
3578void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003579ValueObject::Dump (Stream &s,
3580 const DumpValueObjectOptions& options)
Enrico Granata0c489f52012-03-01 04:24:26 +00003581{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003582 ValueObjectPrinter printer(this,&s,options);
3583 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003584}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003585
3586ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003587ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003588{
3589 ValueObjectSP valobj_sp;
3590
Enrico Granatac3e320a2011-08-02 17:27:39 +00003591 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003592 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003593 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003594
3595 DataExtractor data;
3596 data.SetByteOrder (m_data.GetByteOrder());
3597 data.SetAddressByteSize(m_data.GetAddressByteSize());
3598
Enrico Granata9f1e2042012-04-24 22:15:37 +00003599 if (IsBitfield())
3600 {
3601 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
Greg Clayton57ee3062013-07-11 22:46:58 +00003602 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Enrico Granata9f1e2042012-04-24 22:15:37 +00003603 }
3604 else
Greg Clayton57ee3062013-07-11 22:46:58 +00003605 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003606
3607 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003608 GetClangType(),
3609 name,
3610 data,
3611 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003612 }
Jim Ingham6035b672011-03-31 00:19:25 +00003613
3614 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003615 {
Greg Claytoneeb15652013-12-10 23:16:40 +00003616 ExecutionContext exe_ctx (GetExecutionContextRef());
3617 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003618 }
3619 return valobj_sp;
3620}
3621
Enrico Granata538a88a2014-10-09 18:24:30 +00003622ValueObjectSP
3623ValueObject::GetQualifiedRepresentationIfAvailable (lldb::DynamicValueType dynValue,
3624 bool synthValue)
3625{
3626 ValueObjectSP result_sp(GetSP());
3627
3628 switch (dynValue)
3629 {
3630 case lldb::eDynamicCanRunTarget:
3631 case lldb::eDynamicDontRunTarget:
3632 {
3633 if (!result_sp->IsDynamic())
3634 {
3635 if (result_sp->GetDynamicValue(dynValue))
3636 result_sp = result_sp->GetDynamicValue(dynValue);
3637 }
3638 }
3639 break;
3640 case lldb::eNoDynamicValues:
Enrico Granata538a88a2014-10-09 18:24:30 +00003641 {
3642 if (result_sp->IsDynamic())
3643 {
3644 if (result_sp->GetStaticValue())
3645 result_sp = result_sp->GetStaticValue();
3646 }
3647 }
3648 break;
3649 }
3650
3651 if (synthValue)
3652 {
3653 if (!result_sp->IsSynthetic())
3654 {
3655 if (result_sp->GetSyntheticValue())
3656 result_sp = result_sp->GetSyntheticValue();
3657 }
3658 }
3659 else
3660 {
3661 if (result_sp->IsSynthetic())
3662 {
3663 if (result_sp->GetNonSyntheticValue())
3664 result_sp = result_sp->GetNonSyntheticValue();
3665 }
3666 }
3667
3668 return result_sp;
3669}
3670
Greg Clayton759e7442014-07-19 00:12:57 +00003671lldb::addr_t
3672ValueObject::GetCPPVTableAddress (AddressType &address_type)
3673{
3674 ClangASTType pointee_type;
3675 ClangASTType this_type(GetClangType());
3676 uint32_t type_info = this_type.GetTypeInfo(&pointee_type);
3677 if (type_info)
3678 {
3679 bool ptr_or_ref = false;
Enrico Granata622be232014-10-21 20:52:14 +00003680 if (type_info & (eTypeIsPointer | eTypeIsReference))
Greg Clayton759e7442014-07-19 00:12:57 +00003681 {
3682 ptr_or_ref = true;
3683 type_info = pointee_type.GetTypeInfo();
3684 }
3685
Enrico Granata622be232014-10-21 20:52:14 +00003686 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus;
Greg Clayton759e7442014-07-19 00:12:57 +00003687 if ((type_info & cpp_class) == cpp_class)
3688 {
3689 if (ptr_or_ref)
3690 {
3691 address_type = GetAddressTypeOfChildren();
3692 return GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
3693 }
3694 else
3695 return GetAddressOf (false, &address_type);
3696 }
3697 }
3698
3699 address_type = eAddressTypeInvalid;
3700 return LLDB_INVALID_ADDRESS;
3701}
3702
Greg Claytonafacd142011-09-02 01:15:17 +00003703ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003704ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003705{
Jim Ingham58b59f92011-04-22 23:53:53 +00003706 if (m_deref_valobj)
3707 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003708
Greg Clayton54979cd2010-12-15 05:08:08 +00003709 const bool is_pointer_type = IsPointerType();
3710 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003711 {
3712 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003713 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003714
3715 std::string child_name_str;
3716 uint32_t child_byte_size = 0;
3717 int32_t child_byte_offset = 0;
3718 uint32_t child_bitfield_bit_size = 0;
3719 uint32_t child_bitfield_bit_offset = 0;
3720 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003721 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003722 const bool transparent_pointers = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00003723 ClangASTType clang_type = GetClangType();
3724 ClangASTType child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003725
Greg Claytoncc4d0142012-02-17 07:49:44 +00003726 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003727
Greg Clayton57ee3062013-07-11 22:46:58 +00003728 child_clang_type = clang_type.GetChildClangTypeAtIndex (&exe_ctx,
Greg Clayton57ee3062013-07-11 22:46:58 +00003729 0,
3730 transparent_pointers,
3731 omit_empty_base_classes,
3732 ignore_array_bounds,
3733 child_name_str,
3734 child_byte_size,
3735 child_byte_offset,
3736 child_bitfield_bit_size,
3737 child_bitfield_bit_offset,
3738 child_is_base_class,
Greg Clayton759e7442014-07-19 00:12:57 +00003739 child_is_deref_of_parent,
3740 this);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003741 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003742 {
3743 ConstString child_name;
3744 if (!child_name_str.empty())
3745 child_name.SetCString (child_name_str.c_str());
3746
Jim Ingham58b59f92011-04-22 23:53:53 +00003747 m_deref_valobj = new ValueObjectChild (*this,
Jim Ingham58b59f92011-04-22 23:53:53 +00003748 child_clang_type,
3749 child_name,
3750 child_byte_size,
3751 child_byte_offset,
3752 child_bitfield_bit_size,
3753 child_bitfield_bit_offset,
3754 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003755 child_is_deref_of_parent,
3756 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003757 }
3758 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003759
Jim Ingham58b59f92011-04-22 23:53:53 +00003760 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003761 {
3762 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003763 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003764 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003765 else
3766 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003767 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003768 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003769
3770 if (is_pointer_type)
3771 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3772 else
3773 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003774 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003775 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003776}
3777
Greg Claytonafacd142011-09-02 01:15:17 +00003778ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003779ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003780{
Jim Ingham78a685a2011-04-16 00:01:13 +00003781 if (m_addr_of_valobj_sp)
3782 return m_addr_of_valobj_sp;
3783
Greg Claytone0d378b2011-03-24 21:19:54 +00003784 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003785 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003786 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003787 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003788 if (addr != LLDB_INVALID_ADDRESS)
3789 {
3790 switch (address_type)
3791 {
3792 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003793 {
3794 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003795 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003796 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3797 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003798 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003799
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003800 case eAddressTypeFile:
3801 case eAddressTypeLoad:
3802 case eAddressTypeHost:
3803 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003804 ClangASTType clang_type = GetClangType();
3805 if (clang_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003806 {
3807 std::string name (1, '&');
3808 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003809 ExecutionContext exe_ctx (GetExecutionContextRef());
3810 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00003811 clang_type.GetPointerType(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003812 ConstString (name.c_str()),
3813 addr,
3814 eAddressTypeInvalid,
3815 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003816 }
3817 }
3818 break;
3819 }
3820 }
Sean Callananed185ab2013-04-19 19:47:32 +00003821 else
3822 {
3823 StreamString expr_path_strm;
3824 GetExpressionPath(expr_path_strm, true);
3825 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3826 }
3827
Jim Ingham78a685a2011-04-16 00:01:13 +00003828 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003829}
3830
Greg Clayton9a142cf2012-02-03 05:34:10 +00003831ValueObjectSP
3832ValueObject::Cast (const ClangASTType &clang_ast_type)
3833{
Greg Clayton81e871e2012-02-04 02:27:34 +00003834 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003835}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003836
Greg Claytonafacd142011-09-02 01:15:17 +00003837ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003838ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3839{
Greg Claytonafacd142011-09-02 01:15:17 +00003840 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003841 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003842 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003843
3844 if (ptr_value != LLDB_INVALID_ADDRESS)
3845 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003846 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003847 ExecutionContext exe_ctx (GetExecutionContextRef());
3848 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003849 name,
3850 ptr_addr,
3851 clang_ast_type);
3852 }
3853 return valobj_sp;
3854}
3855
Greg Claytonafacd142011-09-02 01:15:17 +00003856ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003857ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3858{
Greg Claytonafacd142011-09-02 01:15:17 +00003859 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003860 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003861 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003862
3863 if (ptr_value != LLDB_INVALID_ADDRESS)
3864 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003865 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003866 ExecutionContext exe_ctx (GetExecutionContextRef());
3867 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003868 name,
3869 ptr_addr,
3870 type_sp);
3871 }
3872 return valobj_sp;
3873}
3874
Jim Ingham6035b672011-03-31 00:19:25 +00003875ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003876 m_mod_id(),
3877 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003878 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003879{
3880}
3881
3882ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003883 m_mod_id(),
3884 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003885 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003886{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003887 ExecutionContext exe_ctx(exe_scope);
3888 TargetSP target_sp (exe_ctx.GetTargetSP());
3889 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003890 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003891 m_exe_ctx_ref.SetTargetSP (target_sp);
3892 ProcessSP process_sp (exe_ctx.GetProcessSP());
3893 if (!process_sp)
3894 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003895
Greg Claytoncc4d0142012-02-17 07:49:44 +00003896 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003897 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003898 m_mod_id = process_sp->GetModID();
3899 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003900
Greg Claytoncc4d0142012-02-17 07:49:44 +00003901 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003902
Greg Claytoncc4d0142012-02-17 07:49:44 +00003903 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003904 {
3905 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003906 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003907 }
Jim Ingham6035b672011-03-31 00:19:25 +00003908
Greg Claytoncc4d0142012-02-17 07:49:44 +00003909 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003910 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003911 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003912
Jason Molendab57e4a12013-11-04 09:33:30 +00003913 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003914 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003915 {
3916 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003917 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003918 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003919 if (frame_sp)
3920 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003921 }
3922 }
3923 }
Jim Ingham6035b672011-03-31 00:19:25 +00003924}
3925
3926ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003927 m_mod_id(),
3928 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003929 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003930{
3931}
3932
3933ValueObject::EvaluationPoint::~EvaluationPoint ()
3934{
3935}
3936
Jim Ingham6035b672011-03-31 00:19:25 +00003937// This function checks the EvaluationPoint against the current process state. If the current
3938// state matches the evaluation point, or the evaluation point is already invalid, then we return
3939// false, meaning "no change". If the current state is different, we update our state, and return
3940// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3941// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003942// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003943
3944bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003945ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003946{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003947
3948 // 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 +00003949 const bool thread_and_frame_only_if_stopped = true;
3950 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
Jim Ingham73ca05a2011-12-17 01:35:57 +00003951
Greg Claytoncc4d0142012-02-17 07:49:44 +00003952 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003953 return false;
3954
Jim Ingham6035b672011-03-31 00:19:25 +00003955 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003956 Process *process = exe_ctx.GetProcessPtr();
3957 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003958 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003959
Jim Ingham6035b672011-03-31 00:19:25 +00003960 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003961 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003962
Jim Ingham78a685a2011-04-16 00:01:13 +00003963 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3964 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003965 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003966 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003967
Greg Clayton23f59502012-07-17 03:23:13 +00003968 bool changed = false;
3969 const bool was_valid = m_mod_id.IsValid();
3970 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003971 {
3972 if (m_mod_id == current_mod_id)
3973 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003974 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003975 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003976 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003977 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003978 else
3979 {
3980 m_mod_id = current_mod_id;
3981 m_needs_update = true;
3982 changed = true;
3983 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003984 }
Jim Ingham6035b672011-03-31 00:19:25 +00003985
Jim Ingham73ca05a2011-12-17 01:35:57 +00003986 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3987 // That way we'll be sure to return a valid exe_scope.
3988 // 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 +00003989
Greg Claytoncc4d0142012-02-17 07:49:44 +00003990 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003991 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003992 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3993 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003994 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003995 if (m_exe_ctx_ref.HasFrameRef())
3996 {
Jason Molendab57e4a12013-11-04 09:33:30 +00003997 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003998 if (!frame_sp)
3999 {
4000 // We used to have a frame, but now it is gone
4001 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00004002 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00004003 }
4004 }
Greg Clayton262f80d2011-07-06 16:49:27 +00004005 }
Jim Ingham6035b672011-03-31 00:19:25 +00004006 else
4007 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00004008 // We used to have a thread, but now it is gone
4009 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00004010 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00004011 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00004012
Jim Ingham6035b672011-03-31 00:19:25 +00004013 }
Jim Ingham9ee01152011-12-10 01:49:43 +00004014 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00004015}
4016
Jim Ingham61be0902011-05-02 18:13:59 +00004017void
4018ValueObject::EvaluationPoint::SetUpdated ()
4019{
Greg Claytoncc4d0142012-02-17 07:49:44 +00004020 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
4021 if (process_sp)
4022 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00004023 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00004024}
4025
4026
Enrico Granataf2bbf712011-07-15 02:26:42 +00004027
4028void
Enrico Granata86cc9822012-03-19 22:58:49 +00004029ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004030{
Enrico Granata86cc9822012-03-19 22:58:49 +00004031 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4032 m_value_str.clear();
4033
4034 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4035 m_location_str.clear();
4036
4037 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
Enrico Granata86cc9822012-03-19 22:58:49 +00004038 m_summary_str.clear();
Enrico Granata86cc9822012-03-19 22:58:49 +00004039
4040 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4041 m_object_desc_str.clear();
4042
4043 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4044 {
4045 if (m_synthetic_value)
4046 m_synthetic_value = NULL;
4047 }
Enrico Granata744794a2014-09-05 21:46:22 +00004048
4049 if ((clear_mask & eClearUserVisibleDataItemsValidator) == eClearUserVisibleDataItemsValidator)
4050 m_validation_result.reset();
Johnny Chen44805302011-07-19 19:48:13 +00004051}
Enrico Granata9128ee22011-09-06 19:20:51 +00004052
4053SymbolContextScope *
4054ValueObject::GetSymbolContextScope()
4055{
4056 if (m_parent)
4057 {
4058 if (!m_parent->IsPointerOrReferenceType())
4059 return m_parent->GetSymbolContextScope();
4060 }
4061 return NULL;
4062}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004063
4064lldb::ValueObjectSP
4065ValueObject::CreateValueObjectFromExpression (const char* name,
4066 const char* expression,
4067 const ExecutionContext& exe_ctx)
4068{
Enrico Granata972be532014-12-17 21:18:43 +00004069 return CreateValueObjectFromExpression(name, expression, exe_ctx, EvaluateExpressionOptions());
4070}
4071
4072
4073lldb::ValueObjectSP
4074ValueObject::CreateValueObjectFromExpression (const char* name,
4075 const char* expression,
4076 const ExecutionContext& exe_ctx,
4077 const EvaluateExpressionOptions& options)
4078{
Enrico Granatab2698cd2012-09-13 18:27:09 +00004079 lldb::ValueObjectSP retval_sp;
4080 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4081 if (!target_sp)
4082 return retval_sp;
4083 if (!expression || !*expression)
4084 return retval_sp;
4085 target_sp->EvaluateExpression (expression,
4086 exe_ctx.GetFrameSP().get(),
Enrico Granata972be532014-12-17 21:18:43 +00004087 retval_sp,
4088 options);
Enrico Granatab2698cd2012-09-13 18:27:09 +00004089 if (retval_sp && name && *name)
4090 retval_sp->SetName(ConstString(name));
4091 return retval_sp;
4092}
4093
4094lldb::ValueObjectSP
4095ValueObject::CreateValueObjectFromAddress (const char* name,
4096 uint64_t address,
4097 const ExecutionContext& exe_ctx,
4098 ClangASTType type)
4099{
Greg Clayton57ee3062013-07-11 22:46:58 +00004100 if (type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004101 {
Greg Clayton57ee3062013-07-11 22:46:58 +00004102 ClangASTType pointer_type(type.GetPointerType());
4103 if (pointer_type)
4104 {
4105 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4106 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4107 pointer_type,
4108 ConstString(name),
4109 buffer,
Enrico Granata972be532014-12-17 21:18:43 +00004110 exe_ctx.GetByteOrder(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004111 exe_ctx.GetAddressByteSize()));
4112 if (ptr_result_valobj_sp)
4113 {
4114 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4115 Error err;
4116 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4117 if (ptr_result_valobj_sp && name && *name)
4118 ptr_result_valobj_sp->SetName(ConstString(name));
4119 }
4120 return ptr_result_valobj_sp;
4121 }
Enrico Granatab2698cd2012-09-13 18:27:09 +00004122 }
Greg Clayton57ee3062013-07-11 22:46:58 +00004123 return lldb::ValueObjectSP();
Enrico Granatab2698cd2012-09-13 18:27:09 +00004124}
4125
4126lldb::ValueObjectSP
4127ValueObject::CreateValueObjectFromData (const char* name,
Enrico Granata7ca1c762014-03-31 23:02:25 +00004128 const DataExtractor& data,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004129 const ExecutionContext& exe_ctx,
4130 ClangASTType type)
4131{
4132 lldb::ValueObjectSP new_value_sp;
4133 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004134 type,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004135 ConstString(name),
4136 data,
4137 LLDB_INVALID_ADDRESS);
4138 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4139 if (new_value_sp && name && *name)
4140 new_value_sp->SetName(ConstString(name));
4141 return new_value_sp;
4142}
Enrico Granata4873e522013-04-11 22:48:58 +00004143
4144ModuleSP
4145ValueObject::GetModule ()
4146{
4147 ValueObject* root(GetRoot());
4148 if (root != this)
4149 return root->GetModule();
4150 return lldb::ModuleSP();
4151}
4152
4153ValueObject*
4154ValueObject::GetRoot ()
4155{
4156 if (m_root)
4157 return m_root;
Enrico Granatade61eba2015-01-22 03:07:34 +00004158 return (m_root = FollowParentChain( [] (ValueObject* vo) -> bool {
4159 return (vo->m_parent != nullptr);
4160 }));
4161}
4162
4163ValueObject*
4164ValueObject::FollowParentChain (std::function<bool(ValueObject*)> f)
4165{
4166 ValueObject* vo = this;
4167 while (vo)
Enrico Granata4873e522013-04-11 22:48:58 +00004168 {
Enrico Granatade61eba2015-01-22 03:07:34 +00004169 if (f(vo) == false)
4170 break;
4171 vo = vo->m_parent;
Enrico Granata4873e522013-04-11 22:48:58 +00004172 }
Enrico Granatade61eba2015-01-22 03:07:34 +00004173 return vo;
Enrico Granata4873e522013-04-11 22:48:58 +00004174}
4175
4176AddressType
4177ValueObject::GetAddressTypeOfChildren()
4178{
4179 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
4180 {
4181 ValueObject* root(GetRoot());
4182 if (root != this)
4183 return root->GetAddressTypeOfChildren();
4184 }
4185 return m_address_type_of_ptr_or_ref_children;
4186}
4187
4188lldb::DynamicValueType
4189ValueObject::GetDynamicValueType ()
4190{
4191 ValueObject* with_dv_info = this;
4192 while (with_dv_info)
4193 {
4194 if (with_dv_info->HasDynamicValueTypeInfo())
4195 return with_dv_info->GetDynamicValueTypeImpl();
4196 with_dv_info = with_dv_info->m_parent;
4197 }
4198 return lldb::eNoDynamicValues;
4199}
Enrico Granata39d51412013-05-31 17:43:40 +00004200
Enrico Granata4873e522013-04-11 22:48:58 +00004201lldb::Format
4202ValueObject::GetFormat () const
4203{
4204 const ValueObject* with_fmt_info = this;
4205 while (with_fmt_info)
4206 {
4207 if (with_fmt_info->m_format != lldb::eFormatDefault)
4208 return with_fmt_info->m_format;
4209 with_fmt_info = with_fmt_info->m_parent;
4210 }
4211 return m_format;
4212}
Enrico Granatad07cfd32014-10-08 18:27:36 +00004213
Enrico Granatac1247f52014-11-06 21:23:20 +00004214lldb::LanguageType
4215ValueObject::GetPreferredDisplayLanguage ()
4216{
Enrico Granataed3228a2015-01-21 01:47:13 +00004217 lldb::LanguageType type = m_preferred_display_language;
4218 if (m_preferred_display_language == lldb::eLanguageTypeUnknown)
Enrico Granatac1247f52014-11-06 21:23:20 +00004219 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004220 if (GetRoot())
Enrico Granatac1247f52014-11-06 21:23:20 +00004221 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004222 if (GetRoot() == this)
Enrico Granatac1247f52014-11-06 21:23:20 +00004223 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004224 if (StackFrameSP frame_sp = GetFrameSP())
4225 {
4226 const SymbolContext& sc(frame_sp->GetSymbolContext(eSymbolContextCompUnit));
4227 if (CompileUnit* cu = sc.comp_unit)
4228 type = cu->GetLanguage();
4229 }
4230 }
4231 else
4232 {
4233 type = GetRoot()->GetPreferredDisplayLanguage();
Enrico Granatac1247f52014-11-06 21:23:20 +00004234 }
4235 }
Enrico Granatac1247f52014-11-06 21:23:20 +00004236 }
Enrico Granataed3228a2015-01-21 01:47:13 +00004237 return (m_preferred_display_language = type); // only compute it once
4238}
4239
4240void
4241ValueObject::SetPreferredDisplayLanguage (lldb::LanguageType lt)
4242{
4243 m_preferred_display_language = lt;
Enrico Granatac1247f52014-11-06 21:23:20 +00004244}
4245
Enrico Granatad07cfd32014-10-08 18:27:36 +00004246bool
4247ValueObject::CanProvideValue ()
4248{
Sean Callanan7375f3e2014-12-09 21:18:59 +00004249 // we need to support invalid types as providers of values because some bare-board
4250 // debugging scenarios have no notion of types, but still manage to have raw numeric
4251 // values for things like registers. sigh.
4252 const ClangASTType &type(GetClangType());
4253 return (false == type.IsValid()) || (0 != (type.GetTypeInfo() & eTypeHasValue));
4254}
4255
4256bool
4257ValueObject::IsChecksumEmpty ()
4258{
4259 return m_value_checksum.empty();
Enrico Granatad07cfd32014-10-08 18:27:36 +00004260}
Enrico Granata0c10a852014-12-08 23:13:56 +00004261
4262ValueObjectSP
4263ValueObject::Persist ()
4264{
4265 if (!UpdateValueIfNeeded())
4266 return nullptr;
4267
4268 TargetSP target_sp(GetTargetSP());
4269 if (!target_sp)
4270 return nullptr;
4271
4272 ConstString name(target_sp->GetPersistentVariables().GetNextPersistentVariableName());
4273
4274 ClangExpressionVariableSP clang_var_sp(new ClangExpressionVariable(target_sp.get(), GetValue(), name));
4275 if (clang_var_sp)
4276 {
4277 clang_var_sp->m_live_sp = clang_var_sp->m_frozen_sp;
4278 clang_var_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
4279 target_sp->GetPersistentVariables().AddVariable(clang_var_sp);
4280 }
4281
4282 return clang_var_sp->GetValueObject();
4283}
Enrico Granatae29df232014-12-09 19:51:20 +00004284
4285bool
4286ValueObject::IsSyntheticChildrenGenerated ()
4287{
4288 return m_is_synthetic_children_generated;
4289}
4290
4291void
4292ValueObject::SetSyntheticChildrenGenerated (bool b)
4293{
4294 m_is_synthetic_children_generated = b;
4295}