blob: 33e968d1c1b71d963a063cd56ed95245b52f4e9e [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(),
Greg Clayton288bdf92010-09-02 02:59:18 +0000102 m_value_is_valid (false),
103 m_value_did_change (false),
104 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000105 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000106 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000107 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000108 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000109 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000110 m_is_getting_summary(false),
Enrico Granatae29df232014-12-09 19:51:20 +0000111 m_did_calculate_complete_objc_class_type(false),
112 m_is_synthetic_children_generated(parent.m_is_synthetic_children_generated)
Jim Ingham6035b672011-03-31 00:19:25 +0000113{
Jim Ingham58b59f92011-04-22 23:53:53 +0000114 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000115}
116
117//----------------------------------------------------------------------
118// ValueObject constructor
119//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000120ValueObject::ValueObject (ExecutionContextScope *exe_scope,
121 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000122 UserID (++g_value_obj_uid), // Unique identifier for every value object
123 m_parent (NULL),
Enrico Granata4873e522013-04-11 22:48:58 +0000124 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000125 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000126 m_name (),
127 m_data (),
128 m_value (),
129 m_error (),
130 m_value_str (),
131 m_old_value_str (),
132 m_location_str (),
133 m_summary_str (),
134 m_object_desc_str (),
Enrico Granata744794a2014-09-05 21:46:22 +0000135 m_validation_result(),
Jim Ingham58b59f92011-04-22 23:53:53 +0000136 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000137 m_children (),
138 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000139 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000140 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000141 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000142 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +0000143 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000144 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +0000145 m_type_summary_sp(),
146 m_type_format_sp(),
147 m_synthetic_children_sp(),
Enrico Granata744794a2014-09-05 21:46:22 +0000148 m_type_validator_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000149 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000150 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Sean Callanan7375f3e2014-12-09 21:18:59 +0000151 m_value_checksum(),
Jim Ingham6035b672011-03-31 00:19:25 +0000152 m_value_is_valid (false),
153 m_value_did_change (false),
154 m_children_count_valid (false),
155 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000156 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000157 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000158 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000159 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000160 m_is_getting_summary(false),
Enrico Granatae29df232014-12-09 19:51:20 +0000161 m_did_calculate_complete_objc_class_type(false),
162 m_is_synthetic_children_generated(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000163{
Jim Ingham58b59f92011-04-22 23:53:53 +0000164 m_manager = new ValueObjectManager();
165 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000166}
167
168//----------------------------------------------------------------------
169// Destructor
170//----------------------------------------------------------------------
171ValueObject::~ValueObject ()
172{
173}
174
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000175bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000176ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000177{
Enrico Granata4becb372011-06-29 22:27:15 +0000178
Enrico Granata9128ee22011-09-06 19:20:51 +0000179 bool did_change_formats = false;
180
Enrico Granata0a3958e2011-07-02 00:25:22 +0000181 if (update_format)
Enrico Granata5548cb52013-01-28 23:47:25 +0000182 did_change_formats = UpdateFormatsIfNeeded();
Enrico Granata4becb372011-06-29 22:27:15 +0000183
Greg Claytonb71f3842010-10-05 03:13:51 +0000184 // If this is a constant value, then our success is predicated on whether
185 // we have an error or not
186 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000187 {
Enrico Granatab1c6c482013-10-09 00:33:55 +0000188 // if you are constant, things might still have changed behind your back
189 // (e.g. you are a frozen object and things have changed deeper than you cared to freeze-dry yourself)
190 // in this case, your value has not changed, but "computed" entries might have, so you might now have
191 // a different summary, or a different object description. clear these so we will recompute them
Enrico Granata9128ee22011-09-06 19:20:51 +0000192 if (update_format && !did_change_formats)
Enrico Granatab1c6c482013-10-09 00:33:55 +0000193 ClearUserVisibleData(eClearUserVisibleDataItemsSummary | eClearUserVisibleDataItemsDescription);
Greg Claytonb71f3842010-10-05 03:13:51 +0000194 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000195 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000196
Sean Callanan7375f3e2014-12-09 21:18:59 +0000197 bool first_update = IsChecksumEmpty();
Jim Ingham6035b672011-03-31 00:19:25 +0000198
199 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000200 {
Jim Ingham6035b672011-03-31 00:19:25 +0000201 m_update_point.SetUpdated();
202
203 // Save the old value using swap to avoid a string copy which
204 // also will clear our m_value_str
205 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000206 {
Jim Ingham6035b672011-03-31 00:19:25 +0000207 m_old_value_valid = false;
208 }
209 else
210 {
211 m_old_value_valid = true;
212 m_old_value_str.swap (m_value_str);
Enrico Granata86cc9822012-03-19 22:58:49 +0000213 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham6035b672011-03-31 00:19:25 +0000214 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000215
Enrico Granataf2bbf712011-07-15 02:26:42 +0000216 ClearUserVisibleData();
217
Greg Claytonefbc7d22012-03-09 04:23:44 +0000218 if (IsInScope())
Jim Ingham6035b672011-03-31 00:19:25 +0000219 {
Greg Claytonefbc7d22012-03-09 04:23:44 +0000220 const bool value_was_valid = GetValueIsValid();
221 SetValueDidChange (false);
222
223 m_error.Clear();
224
225 // Call the pure virtual function to update the value
Sean Callanan7375f3e2014-12-09 21:18:59 +0000226
227 bool need_compare_checksums = false;
228 llvm::SmallVector<uint8_t, 16> old_checksum;
229
230 if (!first_update && CanProvideValue())
231 {
232 need_compare_checksums = true;
233 old_checksum.resize(m_value_checksum.size());
234 std::copy(m_value_checksum.begin(), m_value_checksum.end(), old_checksum.begin());
235 }
236
Greg Claytonefbc7d22012-03-09 04:23:44 +0000237 bool success = UpdateValue ();
238
239 SetValueIsValid (success);
240
Sean Callanan7375f3e2014-12-09 21:18:59 +0000241 if (success)
242 {
243 const uint64_t max_checksum_size = 128;
244 m_data.Checksum(m_value_checksum,
245 max_checksum_size);
246 }
247 else
248 {
249 need_compare_checksums = false;
250 m_value_checksum.clear();
251 }
252
253 assert (old_checksum.empty() == !need_compare_checksums);
254
Greg Claytonefbc7d22012-03-09 04:23:44 +0000255 if (first_update)
256 SetValueDidChange (false);
257 else if (!m_value_did_change && success == false)
258 {
259 // The value wasn't gotten successfully, so we mark this
260 // as changed if the value used to be valid and now isn't
261 SetValueDidChange (value_was_valid);
262 }
Sean Callanan7375f3e2014-12-09 21:18:59 +0000263 else if (need_compare_checksums)
264 {
265 SetValueDidChange(memcmp(&old_checksum[0], &m_value_checksum[0], m_value_checksum.size()));
266 }
267
Greg Claytonefbc7d22012-03-09 04:23:44 +0000268 }
269 else
270 {
271 m_error.SetErrorString("out of scope");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000272 }
273 }
274 return m_error.Success();
275}
276
Enrico Granata9128ee22011-09-06 19:20:51 +0000277bool
Enrico Granata5548cb52013-01-28 23:47:25 +0000278ValueObject::UpdateFormatsIfNeeded()
Enrico Granata4becb372011-06-29 22:27:15 +0000279{
Greg Clayton5160ce52013-03-27 23:08:40 +0000280 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000281 if (log)
Enrico Granatad2284832012-10-17 22:23:56 +0000282 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000283 GetName().GetCString(), static_cast<void*>(this),
284 m_last_format_mgr_revision,
285 DataVisualization::GetCurrentRevision());
286
Enrico Granata9128ee22011-09-06 19:20:51 +0000287 bool any_change = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000288
Enrico Granata5548cb52013-01-28 23:47:25 +0000289 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()))
Enrico Granata4becb372011-06-29 22:27:15 +0000290 {
Enrico Granataa0db6ed2014-04-09 21:06:11 +0000291 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
292 any_change = true;
293
Enrico Granata852cc952013-10-08 19:03:22 +0000294 SetValueFormat(DataVisualization::GetFormat (*this, eNoDynamicValues));
Enrico Granata5548cb52013-01-28 23:47:25 +0000295 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000296#ifndef LLDB_DISABLE_PYTHON
Enrico Granata5548cb52013-01-28 23:47:25 +0000297 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000298#endif
Enrico Granata744794a2014-09-05 21:46:22 +0000299 SetValidator(DataVisualization::GetValidator(*this, GetDynamicValueType()));
Enrico Granata4becb372011-06-29 22:27:15 +0000300 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000301
Enrico Granata9128ee22011-09-06 19:20:51 +0000302 return any_change;
Enrico Granata4becb372011-06-29 22:27:15 +0000303}
304
Jim Ingham16e0c682011-08-12 23:34:31 +0000305void
306ValueObject::SetNeedsUpdate ()
307{
308 m_update_point.SetNeedsUpdate();
309 // We have to clear the value string here so ConstResult children will notice if their values are
310 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000311 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000312}
313
Enrico Granata13ac0e22012-10-17 19:03:34 +0000314void
Enrico Granatae3e91512012-10-22 18:18:36 +0000315ValueObject::ClearDynamicTypeInformation ()
Enrico Granata13ac0e22012-10-17 19:03:34 +0000316{
Enrico Granata38c54632013-10-30 00:04:29 +0000317 m_children_count_valid = false;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000318 m_did_calculate_complete_objc_class_type = false;
Enrico Granatae3e91512012-10-22 18:18:36 +0000319 m_last_format_mgr_revision = 0;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000320 m_override_type = ClangASTType();
Enrico Granatae3e91512012-10-22 18:18:36 +0000321 SetValueFormat(lldb::TypeFormatImplSP());
322 SetSummaryFormat(lldb::TypeSummaryImplSP());
323 SetSyntheticChildren(lldb::SyntheticChildrenSP());
Enrico Granata13ac0e22012-10-17 19:03:34 +0000324}
325
Sean Callanan72772842012-02-22 23:57:45 +0000326ClangASTType
327ValueObject::MaybeCalculateCompleteType ()
328{
Greg Clayton57ee3062013-07-11 22:46:58 +0000329 ClangASTType clang_type(GetClangTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000330
Sean Callanan72772842012-02-22 23:57:45 +0000331 if (m_did_calculate_complete_objc_class_type)
332 {
333 if (m_override_type.IsValid())
334 return m_override_type;
335 else
Greg Clayton57ee3062013-07-11 22:46:58 +0000336 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000337 }
338
Greg Clayton57ee3062013-07-11 22:46:58 +0000339 ClangASTType class_type;
340 bool is_pointer_type = false;
Sean Callanan72772842012-02-22 23:57:45 +0000341
Greg Clayton57ee3062013-07-11 22:46:58 +0000342 if (clang_type.IsObjCObjectPointerType(&class_type))
Sean Callanan72772842012-02-22 23:57:45 +0000343 {
344 is_pointer_type = true;
345 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000346 else if (clang_type.IsObjCObjectOrInterfaceType())
Sean Callanan72772842012-02-22 23:57:45 +0000347 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000348 class_type = clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000349 }
350 else
351 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000352 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000353 }
354
355 m_did_calculate_complete_objc_class_type = true;
356
Greg Clayton57ee3062013-07-11 22:46:58 +0000357 if (class_type)
Sean Callanan72772842012-02-22 23:57:45 +0000358 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000359 ConstString class_name (class_type.GetConstTypeName());
Sean Callanan72772842012-02-22 23:57:45 +0000360
Greg Clayton57ee3062013-07-11 22:46:58 +0000361 if (class_name)
362 {
363 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
364
365 if (process_sp)
366 {
367 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
368
369 if (objc_language_runtime)
370 {
371 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name);
372
373 if (complete_objc_class_type_sp)
374 {
375 ClangASTType complete_class(complete_objc_class_type_sp->GetClangFullType());
376
377 if (complete_class.GetCompleteType())
378 {
379 if (is_pointer_type)
380 {
381 m_override_type = complete_class.GetPointerType();
382 }
383 else
384 {
385 m_override_type = complete_class;
386 }
387
388 if (m_override_type.IsValid())
389 return m_override_type;
390 }
391 }
392 }
393 }
394 }
Sean Callanan72772842012-02-22 23:57:45 +0000395 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000396 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000397}
398
Greg Clayton57ee3062013-07-11 22:46:58 +0000399ClangASTType
Sean Callanan72772842012-02-22 23:57:45 +0000400ValueObject::GetClangType ()
401{
Greg Clayton57ee3062013-07-11 22:46:58 +0000402 return MaybeCalculateCompleteType();
Sean Callanan72772842012-02-22 23:57:45 +0000403}
404
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000405TypeImpl
406ValueObject::GetTypeImpl ()
407{
408 return TypeImpl(GetClangType());
409}
410
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000411DataExtractor &
412ValueObject::GetDataExtractor ()
413{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000414 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000415 return m_data;
416}
417
418const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000419ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000420{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000421 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000422 return m_error;
423}
424
425const ConstString &
426ValueObject::GetName() const
427{
428 return m_name;
429}
430
431const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000432ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000433{
Enrico Granata82fabf82013-04-30 20:45:04 +0000434 return GetLocationAsCStringImpl(m_value,
435 m_data);
436}
437
438const char *
439ValueObject::GetLocationAsCStringImpl (const Value& value,
440 const DataExtractor& data)
441{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000442 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000443 {
444 if (m_location_str.empty())
445 {
446 StreamString sstr;
Enrico Granata82fabf82013-04-30 20:45:04 +0000447
448 Value::ValueType value_type = value.GetValueType();
449
450 switch (value_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000451 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000452 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +0000453 case Value::eValueTypeVector:
Enrico Granata82fabf82013-04-30 20:45:04 +0000454 if (value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000455 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000456 RegisterInfo *reg_info = value.GetRegisterInfo();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000457 if (reg_info)
458 {
459 if (reg_info->name)
460 m_location_str = reg_info->name;
461 else if (reg_info->alt_name)
462 m_location_str = reg_info->alt_name;
Enrico Granata82fabf82013-04-30 20:45:04 +0000463 if (m_location_str.empty())
464 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000465 }
466 }
Enrico Granata82fabf82013-04-30 20:45:04 +0000467 if (m_location_str.empty())
468 m_location_str = (value_type == Value::eValueTypeVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000469 break;
470
471 case Value::eValueTypeLoadAddress:
472 case Value::eValueTypeFileAddress:
473 case Value::eValueTypeHostAddress:
474 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000475 uint32_t addr_nibble_size = data.GetAddressByteSize() * 2;
476 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000477 m_location_str.swap(sstr.GetString());
478 }
479 break;
480 }
481 }
482 }
483 return m_location_str.c_str();
484}
485
486Value &
487ValueObject::GetValue()
488{
489 return m_value;
490}
491
492const Value &
493ValueObject::GetValue() const
494{
495 return m_value;
496}
497
498bool
Jim Ingham6035b672011-03-31 00:19:25 +0000499ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000500{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000501 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
502 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000503 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000504 Value tmp_value(m_value);
Greg Clayton57ee3062013-07-11 22:46:58 +0000505 scalar = tmp_value.ResolveValue(&exe_ctx);
Greg Claytondcad5022011-12-29 01:26:56 +0000506 if (scalar.IsValid())
507 {
508 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
509 if (bitfield_bit_size)
510 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
511 return true;
512 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000513 }
Greg Claytondcad5022011-12-29 01:26:56 +0000514 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000515}
516
517bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000518ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000519{
Greg Clayton288bdf92010-09-02 02:59:18 +0000520 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000521}
522
523
524void
525ValueObject::SetValueIsValid (bool b)
526{
Greg Clayton288bdf92010-09-02 02:59:18 +0000527 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000528}
529
530bool
Jim Ingham6035b672011-03-31 00:19:25 +0000531ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000532{
Greg Clayton288bdf92010-09-02 02:59:18 +0000533 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000534}
535
536void
537ValueObject::SetValueDidChange (bool value_changed)
538{
Greg Clayton288bdf92010-09-02 02:59:18 +0000539 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000540}
541
542ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000543ValueObject::GetChildAtIndex (size_t idx, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000544{
545 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000546 // We may need to update our value if we are dynamic
547 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000548 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000549 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000550 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000551 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000552 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000553 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000554 // No we haven't created the child at this index, so lets have our
555 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000556 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000557 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000558
Enrico Granata9d60f602012-03-09 03:09:58 +0000559 ValueObject* child = m_children.GetChildAtIndex(idx);
560 if (child != NULL)
561 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000562 }
563 return child_sp;
564}
565
Enrico Granata3309d882013-01-12 01:00:22 +0000566ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000567ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
568 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000569{
570 if (idxs.size() == 0)
571 return GetSP();
572 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000573 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000574 {
575 root = root->GetChildAtIndex(idx, true);
576 if (!root)
577 {
578 if (index_of_error)
579 *index_of_error = idx;
580 return root;
581 }
582 }
583 return root;
584}
585
586ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000587ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
588 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000589{
590 if (idxs.size() == 0)
591 return GetSP();
592 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000593 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000594 {
595 root = root->GetChildAtIndex(idx.first, idx.second);
596 if (!root)
597 {
598 if (index_of_error)
599 *index_of_error = idx.first;
600 return root;
601 }
602 }
603 return root;
604}
605
606lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000607ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
608 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000609{
610 if (idxs.size() == 0)
611 return GetSP();
612 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000613 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000614 {
615 root = root->GetChildAtIndex(idx, true);
616 if (!root)
617 {
618 if (index_of_error)
619 *index_of_error = idx;
620 return root;
621 }
622 }
623 return root;
624}
625
626lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000627ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
628 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000629{
630 if (idxs.size() == 0)
631 return GetSP();
632 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000633 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000634 {
635 root = root->GetChildAtIndex(idx.first, idx.second);
636 if (!root)
637 {
638 if (index_of_error)
639 *index_of_error = idx.first;
640 return root;
641 }
642 }
643 return root;
644}
645
Enrico Granatae2e220a2013-09-12 00:48:47 +0000646lldb::ValueObjectSP
647ValueObject::GetChildAtNamePath (const std::initializer_list<ConstString> &names,
648 ConstString* name_of_error)
649{
650 if (names.size() == 0)
651 return GetSP();
652 ValueObjectSP root(GetSP());
653 for (ConstString name : names)
654 {
655 root = root->GetChildMemberWithName(name, true);
656 if (!root)
657 {
658 if (name_of_error)
659 *name_of_error = name;
660 return root;
661 }
662 }
663 return root;
664}
665
666lldb::ValueObjectSP
667ValueObject::GetChildAtNamePath (const std::vector<ConstString> &names,
668 ConstString* name_of_error)
669{
670 if (names.size() == 0)
671 return GetSP();
672 ValueObjectSP root(GetSP());
673 for (ConstString name : names)
674 {
675 root = root->GetChildMemberWithName(name, true);
676 if (!root)
677 {
678 if (name_of_error)
679 *name_of_error = name;
680 return root;
681 }
682 }
683 return root;
684}
685
686lldb::ValueObjectSP
687ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names,
688 ConstString* name_of_error)
689{
690 if (names.size() == 0)
691 return GetSP();
692 ValueObjectSP root(GetSP());
693 for (std::pair<ConstString, bool> name : names)
694 {
695 root = root->GetChildMemberWithName(name.first, name.second);
696 if (!root)
697 {
698 if (name_of_error)
699 *name_of_error = name.first;
700 return root;
701 }
702 }
703 return root;
704}
705
706lldb::ValueObjectSP
707ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names,
708 ConstString* name_of_error)
709{
710 if (names.size() == 0)
711 return GetSP();
712 ValueObjectSP root(GetSP());
713 for (std::pair<ConstString, bool> name : names)
714 {
715 root = root->GetChildMemberWithName(name.first, name.second);
716 if (!root)
717 {
718 if (name_of_error)
719 *name_of_error = name.first;
720 return root;
721 }
722 }
723 return root;
724}
725
Greg Claytonc7bece562013-01-25 18:06:21 +0000726size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000727ValueObject::GetIndexOfChildWithName (const ConstString &name)
728{
729 bool omit_empty_base_classes = true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000730 return GetClangType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000731}
732
733ValueObjectSP
734ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
735{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000736 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000737 // classes (which really aren't part of the expression path), so we
738 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000739 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000740
Greg Claytondea8cb42011-06-29 22:09:02 +0000741 // We may need to update our value if we are dynamic
742 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000743 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000744
745 std::vector<uint32_t> child_indexes;
Greg Claytondea8cb42011-06-29 22:09:02 +0000746 bool omit_empty_base_classes = true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000747 const size_t num_child_indexes = GetClangType().GetIndexOfChildMemberWithName (name.GetCString(),
748 omit_empty_base_classes,
749 child_indexes);
Greg Claytondea8cb42011-06-29 22:09:02 +0000750 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000751 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000752 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
753 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
754
755 child_sp = GetChildAtIndex(*pos, can_create);
756 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000757 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000758 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000759 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000760 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
761 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000762 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000763 else
764 {
765 child_sp.reset();
766 }
767
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000768 }
769 }
770 return child_sp;
771}
772
773
Greg Claytonc7bece562013-01-25 18:06:21 +0000774size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000775ValueObject::GetNumChildren ()
776{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000777 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000778 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000779 {
780 SetNumChildren (CalculateNumChildren());
781 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000782 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000783}
Greg Clayton4a792072012-10-23 01:50:10 +0000784
785bool
786ValueObject::MightHaveChildren()
787{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000788 bool has_children = false;
Greg Clayton2452ab72013-02-08 22:02:02 +0000789 const uint32_t type_info = GetTypeInfo();
790 if (type_info)
Greg Clayton4a792072012-10-23 01:50:10 +0000791 {
Enrico Granata622be232014-10-21 20:52:14 +0000792 if (type_info & (eTypeHasChildren |
793 eTypeIsPointer |
794 eTypeIsReference))
Greg Clayton4a792072012-10-23 01:50:10 +0000795 has_children = true;
796 }
797 else
798 {
799 has_children = GetNumChildren () > 0;
800 }
801 return has_children;
802}
803
804// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000805void
Greg Claytonc7bece562013-01-25 18:06:21 +0000806ValueObject::SetNumChildren (size_t num_children)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000807{
Greg Clayton288bdf92010-09-02 02:59:18 +0000808 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000809 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000810}
811
812void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000813ValueObject::SetName (const ConstString &name)
814{
815 m_name = name;
816}
817
Jim Ingham58b59f92011-04-22 23:53:53 +0000818ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000819ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000820{
Jim Ingham2eec4872011-05-07 00:10:58 +0000821 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000822
Greg Claytondea8cb42011-06-29 22:09:02 +0000823 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000824 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000825 std::string child_name_str;
826 uint32_t child_byte_size = 0;
827 int32_t child_byte_offset = 0;
828 uint32_t child_bitfield_bit_size = 0;
829 uint32_t child_bitfield_bit_offset = 0;
830 bool child_is_base_class = false;
831 bool child_is_deref_of_parent = false;
832
833 const bool transparent_pointers = synthetic_array_member == false;
Greg Clayton57ee3062013-07-11 22:46:58 +0000834 ClangASTType child_clang_type;
Greg Claytondea8cb42011-06-29 22:09:02 +0000835
Greg Claytoncc4d0142012-02-17 07:49:44 +0000836 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000837
Greg Clayton57ee3062013-07-11 22:46:58 +0000838 child_clang_type = GetClangType().GetChildClangTypeAtIndex (&exe_ctx,
Greg Clayton57ee3062013-07-11 22:46:58 +0000839 idx,
840 transparent_pointers,
841 omit_empty_base_classes,
842 ignore_array_bounds,
843 child_name_str,
844 child_byte_size,
845 child_byte_offset,
846 child_bitfield_bit_size,
847 child_bitfield_bit_offset,
848 child_is_base_class,
Greg Clayton759e7442014-07-19 00:12:57 +0000849 child_is_deref_of_parent,
850 this);
Greg Clayton4ef877f2012-12-06 02:33:54 +0000851 if (child_clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000852 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000853 if (synthetic_index)
854 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000855
Greg Claytondea8cb42011-06-29 22:09:02 +0000856 ConstString child_name;
857 if (!child_name_str.empty())
858 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000859
Greg Claytondea8cb42011-06-29 22:09:02 +0000860 valobj = new ValueObjectChild (*this,
Greg Claytondea8cb42011-06-29 22:09:02 +0000861 child_clang_type,
862 child_name,
863 child_byte_size,
864 child_byte_offset,
865 child_bitfield_bit_size,
866 child_bitfield_bit_offset,
867 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000868 child_is_deref_of_parent,
869 eAddressTypeInvalid);
870 //if (valobj)
871 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
872 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000873
Jim Ingham58b59f92011-04-22 23:53:53 +0000874 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000875}
876
Enrico Granata0c489f52012-03-01 04:24:26 +0000877bool
878ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
879 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000880{
Enrico Granatac1247f52014-11-06 21:23:20 +0000881 return GetSummaryAsCString(summary_ptr, destination, TypeSummaryOptions());
882}
883
884bool
885ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
886 std::string& destination,
887 const TypeSummaryOptions& options)
888{
Enrico Granata0c489f52012-03-01 04:24:26 +0000889 destination.clear();
890
891 // ideally we would like to bail out if passing NULL, but if we do so
892 // we end up not providing the summary for function pointers anymore
893 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
894 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000895
896 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000897
898 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
899 // information that we might care to see in a crash log. might be useful in very specific situations though.
900 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
901 GetTypeName().GetCString(),
902 GetName().GetCString(),
903 summary_ptr->GetDescription().c_str());*/
904
Enrico Granata0c489f52012-03-01 04:24:26 +0000905 if (UpdateValueIfNeeded (false))
906 {
907 if (summary_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000908 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000909 if (HasSyntheticValue())
910 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
Enrico Granataf35bc632014-11-06 21:55:30 +0000911 summary_ptr->FormatObject(this, destination, options);
Enrico Granata0c489f52012-03-01 04:24:26 +0000912 }
913 else
914 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000915 ClangASTType clang_type = GetClangType();
Enrico Granata0c489f52012-03-01 04:24:26 +0000916
917 // Do some default printout for function pointers
918 if (clang_type)
Enrico Granata4becb372011-06-29 22:27:15 +0000919 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000920 if (clang_type.IsFunctionPointerType ())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000921 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000922 StreamString sstr;
Enrico Granata0c489f52012-03-01 04:24:26 +0000923 AddressType func_ptr_address_type = eAddressTypeInvalid;
924 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
925 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000926 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000927 switch (func_ptr_address_type)
Jim Ingham6035b672011-03-31 00:19:25 +0000928 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000929 case eAddressTypeInvalid:
930 case eAddressTypeFile:
931 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000932
Greg Claytoncc4d0142012-02-17 07:49:44 +0000933 case eAddressTypeLoad:
Enrico Granata0c489f52012-03-01 04:24:26 +0000934 {
935 ExecutionContext exe_ctx (GetExecutionContextRef());
936
937 Address so_addr;
938 Target *target = exe_ctx.GetTargetPtr();
939 if (target && target->GetSectionLoadList().IsEmpty() == false)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000940 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000941 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000942 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000943 so_addr.Dump (&sstr,
944 exe_ctx.GetBestExecutionContextScope(),
945 Address::DumpStyleResolvedDescription,
946 Address::DumpStyleSectionNameOffset);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000947 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000948 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000949 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000950 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000951
Greg Claytoncc4d0142012-02-17 07:49:44 +0000952 case eAddressTypeHost:
953 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +0000954 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000955 }
956 if (sstr.GetSize() > 0)
957 {
958 destination.assign (1, '(');
959 destination.append (sstr.GetData(), sstr.GetSize());
960 destination.append (1, ')');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000961 }
962 }
963 }
964 }
965 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000966 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000967 return !destination.empty();
968}
969
970const char *
971ValueObject::GetSummaryAsCString ()
972{
973 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
974 {
975 GetSummaryAsCString(GetSummaryFormat().get(),
Enrico Granatac1247f52014-11-06 21:23:20 +0000976 m_summary_str,
Enrico Granata49bfafb2014-11-18 23:36:25 +0000977 TypeSummaryOptions());
Enrico Granata0c489f52012-03-01 04:24:26 +0000978 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000979 if (m_summary_str.empty())
980 return NULL;
981 return m_summary_str.c_str();
982}
983
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000984bool
Enrico Granata49bfafb2014-11-18 23:36:25 +0000985ValueObject::GetSummaryAsCString (std::string& destination,
986 const TypeSummaryOptions& options)
987{
988 return GetSummaryAsCString(GetSummaryFormat().get(),
989 destination,
990 options);
991}
992
993bool
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000994ValueObject::IsCStringContainer(bool check_pointer)
995{
Greg Clayton57ee3062013-07-11 22:46:58 +0000996 ClangASTType pointee_or_element_clang_type;
997 const Flags type_flags (GetTypeInfo (&pointee_or_element_clang_type));
Enrico Granata622be232014-10-21 20:52:14 +0000998 bool is_char_arr_ptr (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Greg Clayton57ee3062013-07-11 22:46:58 +0000999 pointee_or_element_clang_type.IsCharType ());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001000 if (!is_char_arr_ptr)
1001 return false;
1002 if (!check_pointer)
1003 return true;
Enrico Granata622be232014-10-21 20:52:14 +00001004 if (type_flags.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001005 return true;
Greg Claytonafacd142011-09-02 01:15:17 +00001006 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001007 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +00001008 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001009 return (cstr_address != LLDB_INVALID_ADDRESS);
1010}
1011
Enrico Granata9128ee22011-09-06 19:20:51 +00001012size_t
1013ValueObject::GetPointeeData (DataExtractor& data,
1014 uint32_t item_idx,
1015 uint32_t item_count)
1016{
Greg Clayton57ee3062013-07-11 22:46:58 +00001017 ClangASTType pointee_or_element_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001018 const uint32_t type_info = GetTypeInfo (&pointee_or_element_clang_type);
Enrico Granata622be232014-10-21 20:52:14 +00001019 const bool is_pointer_type = type_info & eTypeIsPointer;
1020 const bool is_array_type = type_info & eTypeIsArray;
Greg Clayton2452ab72013-02-08 22:02:02 +00001021 if (!(is_pointer_type || is_array_type))
Enrico Granata9128ee22011-09-06 19:20:51 +00001022 return 0;
1023
1024 if (item_count == 0)
1025 return 0;
1026
Greg Clayton57ee3062013-07-11 22:46:58 +00001027 const uint64_t item_type_size = pointee_or_element_clang_type.GetByteSize();
Enrico Granata9128ee22011-09-06 19:20:51 +00001028 const uint64_t bytes = item_count * item_type_size;
Enrico Granata9128ee22011-09-06 19:20:51 +00001029 const uint64_t offset = item_idx * item_type_size;
1030
1031 if (item_idx == 0 && item_count == 1) // simply a deref
1032 {
Greg Clayton2452ab72013-02-08 22:02:02 +00001033 if (is_pointer_type)
Enrico Granata9128ee22011-09-06 19:20:51 +00001034 {
1035 Error error;
1036 ValueObjectSP pointee_sp = Dereference(error);
1037 if (error.Fail() || pointee_sp.get() == NULL)
1038 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +00001039 return pointee_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +00001040 }
1041 else
1042 {
1043 ValueObjectSP child_sp = GetChildAtIndex(0, true);
1044 if (child_sp.get() == NULL)
1045 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +00001046 Error error;
1047 return child_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +00001048 }
1049 return true;
1050 }
1051 else /* (items > 1) */
1052 {
1053 Error error;
1054 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
1055 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
1056
1057 AddressType addr_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001058 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001059
Enrico Granata9128ee22011-09-06 19:20:51 +00001060 switch (addr_type)
1061 {
1062 case eAddressTypeFile:
1063 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001064 ModuleSP module_sp (GetModule());
1065 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001066 {
Enrico Granata9c2efe32012-08-07 01:49:34 +00001067 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +00001068 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001069 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001070 ExecutionContext exe_ctx (GetExecutionContextRef());
1071 Target* target = exe_ctx.GetTargetPtr();
1072 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +00001073 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001074 heap_buf_ptr->SetByteSize(bytes);
1075 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
1076 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +00001077 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001078 data.SetData(data_sp);
1079 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +00001080 }
1081 }
1082 }
1083 }
1084 break;
1085 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +00001086 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001087 ExecutionContext exe_ctx (GetExecutionContextRef());
1088 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +00001089 if (process)
1090 {
1091 heap_buf_ptr->SetByteSize(bytes);
1092 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
Enrico Granata5e1480c2013-10-30 17:52:44 +00001093 if (error.Success() || bytes_read > 0)
Enrico Granata9128ee22011-09-06 19:20:51 +00001094 {
1095 data.SetData(data_sp);
1096 return bytes_read;
1097 }
1098 }
1099 }
1100 break;
1101 case eAddressTypeHost:
1102 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001103 const uint64_t max_bytes = GetClangType().GetByteSize();
Greg Clayton2452ab72013-02-08 22:02:02 +00001104 if (max_bytes > offset)
1105 {
1106 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
1107 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
1108 data.SetData(data_sp);
1109 return bytes_read;
1110 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001111 }
1112 break;
1113 case eAddressTypeInvalid:
Enrico Granata9128ee22011-09-06 19:20:51 +00001114 break;
1115 }
1116 }
1117 return 0;
1118}
1119
Greg Claytonfaac1112013-03-14 18:31:44 +00001120uint64_t
Sean Callanan866e91c2014-02-28 22:27:53 +00001121ValueObject::GetData (DataExtractor& data, Error &error)
Enrico Granata9128ee22011-09-06 19:20:51 +00001122{
1123 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001124 ExecutionContext exe_ctx (GetExecutionContextRef());
Sean Callanan866e91c2014-02-28 22:27:53 +00001125 error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001126 if (error.Fail())
Sean Callananed185ab2013-04-19 19:47:32 +00001127 {
1128 if (m_data.GetByteSize())
1129 {
1130 data = m_data;
1131 return data.GetByteSize();
1132 }
1133 else
1134 {
1135 return 0;
1136 }
1137 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001138 data.SetAddressByteSize(m_data.GetAddressByteSize());
1139 data.SetByteOrder(m_data.GetByteOrder());
1140 return data.GetByteSize();
1141}
1142
Sean Callanan389823e2013-04-13 01:21:23 +00001143bool
1144ValueObject::SetData (DataExtractor &data, Error &error)
1145{
1146 error.Clear();
1147 // Make sure our value is up to date first so that our location and location
1148 // type is valid.
1149 if (!UpdateValueIfNeeded(false))
1150 {
1151 error.SetErrorString("unable to read value");
1152 return false;
1153 }
1154
1155 uint64_t count = 0;
Greg Clayton57ee3062013-07-11 22:46:58 +00001156 const Encoding encoding = GetClangType().GetEncoding(count);
Sean Callanan389823e2013-04-13 01:21:23 +00001157
1158 const size_t byte_size = GetByteSize();
1159
1160 Value::ValueType value_type = m_value.GetValueType();
1161
1162 switch (value_type)
1163 {
1164 case Value::eValueTypeScalar:
1165 {
1166 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1167
1168 if (!set_error.Success())
1169 {
1170 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1171 return false;
1172 }
1173 }
1174 break;
1175 case Value::eValueTypeLoadAddress:
1176 {
1177 // If it is a load address, then the scalar value is the storage location
1178 // of the data, and we have to shove this value down to that load location.
1179 ExecutionContext exe_ctx (GetExecutionContextRef());
1180 Process *process = exe_ctx.GetProcessPtr();
1181 if (process)
1182 {
1183 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1184 size_t bytes_written = process->WriteMemory(target_addr,
1185 data.GetDataStart(),
1186 byte_size,
1187 error);
1188 if (!error.Success())
1189 return false;
1190 if (bytes_written != byte_size)
1191 {
1192 error.SetErrorString("unable to write value to memory");
1193 return false;
1194 }
1195 }
1196 }
1197 break;
1198 case Value::eValueTypeHostAddress:
1199 {
1200 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1201 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1202 m_data.SetData(buffer_sp, 0);
1203 data.CopyByteOrderedData (0,
1204 byte_size,
1205 const_cast<uint8_t *>(m_data.GetDataStart()),
1206 byte_size,
1207 m_data.GetByteOrder());
1208 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1209 }
1210 break;
1211 case Value::eValueTypeFileAddress:
1212 case Value::eValueTypeVector:
1213 break;
1214 }
1215
1216 // If we have reached this point, then we have successfully changed the value.
1217 SetNeedsUpdate();
1218 return true;
1219}
1220
Enrico Granata9128ee22011-09-06 19:20:51 +00001221// will compute strlen(str), but without consuming more than
1222// maxlen bytes out of str (this serves the purpose of reading
1223// chunks of a string without having to worry about
1224// missing NULL terminators in the chunk)
1225// of course, if strlen(str) > maxlen, the function will return
1226// maxlen_value (which should be != maxlen, because that allows you
1227// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1228static uint32_t
1229strlen_or_inf (const char* str,
1230 uint32_t maxlen,
1231 uint32_t maxlen_value)
1232{
1233 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +00001234 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +00001235 {
Greg Clayton8dd5c172011-10-05 22:19:51 +00001236 while(*str)
1237 {
1238 len++;str++;
Greg Clayton2452ab72013-02-08 22:02:02 +00001239 if (len >= maxlen)
Greg Clayton8dd5c172011-10-05 22:19:51 +00001240 return maxlen_value;
1241 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001242 }
1243 return len;
1244}
1245
Enrico Granata2206b482014-10-30 18:27:31 +00001246static bool
1247CopyStringDataToBufferSP(const StreamString& source,
1248 lldb::DataBufferSP& destination)
1249{
1250 destination.reset(new DataBufferHeap(source.GetSize()+1,0));
1251 memcpy(destination->GetBytes(), source.GetString().c_str(), source.GetSize());
1252 return true;
1253}
1254
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001255size_t
Enrico Granata2206b482014-10-30 18:27:31 +00001256ValueObject::ReadPointedString (lldb::DataBufferSP& buffer_sp,
Greg Claytoncc4d0142012-02-17 07:49:44 +00001257 Error& error,
1258 uint32_t max_length,
1259 bool honor_array,
1260 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001261{
Enrico Granata2206b482014-10-30 18:27:31 +00001262 StreamString s;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001263 ExecutionContext exe_ctx (GetExecutionContextRef());
1264 Target* target = exe_ctx.GetTargetPtr();
Enrico Granata2206b482014-10-30 18:27:31 +00001265
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001266 if (!target)
1267 {
1268 s << "<no target to read from>";
1269 error.SetErrorString("no target to read from");
Enrico Granata2206b482014-10-30 18:27:31 +00001270 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001271 return 0;
1272 }
1273
1274 if (max_length == 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001275 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001276
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001277 size_t bytes_read = 0;
1278 size_t total_bytes_read = 0;
1279
Greg Clayton57ee3062013-07-11 22:46:58 +00001280 ClangASTType clang_type = GetClangType();
1281 ClangASTType elem_or_pointee_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001282 const Flags type_flags (GetTypeInfo (&elem_or_pointee_clang_type));
Enrico Granata622be232014-10-21 20:52:14 +00001283 if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Greg Clayton57ee3062013-07-11 22:46:58 +00001284 elem_or_pointee_clang_type.IsCharType ())
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001285 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001286 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1287 AddressType cstr_address_type = eAddressTypeInvalid;
1288
1289 size_t cstr_len = 0;
1290 bool capped_data = false;
Enrico Granata622be232014-10-21 20:52:14 +00001291 if (type_flags.Test (eTypeIsArray))
Greg Claytoncc4d0142012-02-17 07:49:44 +00001292 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001293 // We have an array
Greg Clayton57ee3062013-07-11 22:46:58 +00001294 uint64_t array_size = 0;
1295 if (clang_type.IsArrayType(NULL, &array_size, NULL))
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001296 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001297 cstr_len = array_size;
1298 if (cstr_len > max_length)
1299 {
1300 capped_data = true;
1301 cstr_len = max_length;
1302 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001303 }
1304 cstr_address = GetAddressOf (true, &cstr_address_type);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001305 }
1306 else
1307 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001308 // We have a pointer
1309 cstr_address = GetPointerValue (&cstr_address_type);
1310 }
1311
1312 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1313 {
1314 s << "<invalid address>";
1315 error.SetErrorString("invalid address");
Enrico Granata2206b482014-10-30 18:27:31 +00001316 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001317 return 0;
1318 }
Enrico Granata2206b482014-10-30 18:27:31 +00001319
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001320 Address cstr_so_addr (cstr_address);
1321 DataExtractor data;
1322 if (cstr_len > 0 && honor_array)
1323 {
1324 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1325 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1326 GetPointeeData(data, 0, cstr_len);
Enrico Granata2206b482014-10-30 18:27:31 +00001327
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001328 if ((bytes_read = data.GetByteSize()) > 0)
1329 {
1330 total_bytes_read = bytes_read;
Enrico Granata2206b482014-10-30 18:27:31 +00001331 for (size_t offset = 0; offset < bytes_read; offset++)
1332 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001333 if (capped_data)
1334 s << "...";
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001335 }
1336 }
1337 else
1338 {
1339 cstr_len = max_length;
1340 const size_t k_max_buf_size = 64;
Enrico Granata2206b482014-10-30 18:27:31 +00001341
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001342 size_t offset = 0;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001343
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001344 int cstr_len_displayed = -1;
1345 bool capped_cstr = false;
1346 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1347 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1348 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001349 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001350 total_bytes_read += bytes_read;
1351 const char *cstr = data.PeekCStr(0);
1352 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1353 if (len > k_max_buf_size)
1354 len = k_max_buf_size;
Enrico Granata2206b482014-10-30 18:27:31 +00001355
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001356 if (cstr_len_displayed < 0)
1357 cstr_len_displayed = len;
Enrico Granata2206b482014-10-30 18:27:31 +00001358
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001359 if (len == 0)
1360 break;
1361 cstr_len_displayed += len;
1362 if (len > bytes_read)
1363 len = bytes_read;
1364 if (len > cstr_len)
1365 len = cstr_len;
1366
Enrico Granata2206b482014-10-30 18:27:31 +00001367 for (size_t offset = 0; offset < bytes_read; offset++)
1368 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001369
1370 if (len < k_max_buf_size)
1371 break;
1372
1373 if (len >= cstr_len)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001374 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001375 capped_cstr = true;
1376 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001377 }
Enrico Granata2206b482014-10-30 18:27:31 +00001378
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001379 cstr_len -= len;
1380 offset += len;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001381 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001382
1383 if (cstr_len_displayed >= 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001384 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001385 if (capped_cstr)
1386 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001387 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001388 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001389 }
1390 else
1391 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001392 error.SetErrorString("not a string object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001393 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001394 }
Enrico Granata2206b482014-10-30 18:27:31 +00001395 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001396 return total_bytes_read;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001397}
1398
Enrico Granata744794a2014-09-05 21:46:22 +00001399std::pair<TypeValidatorResult, std::string>
1400ValueObject::GetValidationStatus ()
1401{
1402 if (!UpdateValueIfNeeded(true))
1403 return {TypeValidatorResult::Success,""}; // not the validator's job to discuss update problems
1404
1405 if (m_validation_result.hasValue())
1406 return m_validation_result.getValue();
1407
1408 if (!m_type_validator_sp)
1409 return {TypeValidatorResult::Success,""}; // no validator no failure
1410
1411 auto outcome = m_type_validator_sp->FormatObject(this);
1412
1413 return (m_validation_result = {outcome.m_result,outcome.m_message}).getValue();
1414}
1415
Jim Ingham53c47f12010-09-10 23:12:17 +00001416const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001417ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001418{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001419
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001420 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001421 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001422
1423 if (!m_object_desc_str.empty())
1424 return m_object_desc_str.c_str();
1425
Greg Claytoncc4d0142012-02-17 07:49:44 +00001426 ExecutionContext exe_ctx (GetExecutionContextRef());
1427 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001428 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001429 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001430
Jim Ingham53c47f12010-09-10 23:12:17 +00001431 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001432
Greg Claytonafacd142011-09-02 01:15:17 +00001433 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001434 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1435
Jim Inghama2cf2632010-12-23 02:29:54 +00001436 if (runtime == NULL)
1437 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001438 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Greg Clayton57ee3062013-07-11 22:46:58 +00001439 ClangASTType clang_type = GetClangType();
1440 if (clang_type)
Jim Inghama2cf2632010-12-23 02:29:54 +00001441 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001442 bool is_signed;
Greg Clayton57ee3062013-07-11 22:46:58 +00001443 if (clang_type.IsIntegerType (is_signed) || clang_type.IsPointerType ())
Jim Inghamb7603bb2011-03-18 00:05:18 +00001444 {
Greg Claytonafacd142011-09-02 01:15:17 +00001445 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001446 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001447 }
1448 }
1449
Jim Ingham8d543de2011-03-31 23:01:21 +00001450 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001451 {
1452 m_object_desc_str.append (s.GetData());
1453 }
Sean Callanan672ad942010-10-23 00:18:49 +00001454
1455 if (m_object_desc_str.empty())
1456 return NULL;
1457 else
1458 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001459}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001460
Enrico Granata0c489f52012-03-01 04:24:26 +00001461bool
Enrico Granata4939b982013-12-22 09:24:22 +00001462ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format,
1463 std::string& destination)
1464{
1465 if (UpdateValueIfNeeded(false))
1466 return format.FormatObject(this,destination);
1467 else
1468 return false;
1469}
1470
1471bool
Enrico Granata0c489f52012-03-01 04:24:26 +00001472ValueObject::GetValueAsCString (lldb::Format format,
1473 std::string& destination)
1474{
Enrico Granata30f287f2013-12-28 08:44:02 +00001475 return GetValueAsCString(TypeFormatImpl_Format(format),destination);
Enrico Granata0c489f52012-03-01 04:24:26 +00001476}
1477
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001478const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001479ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001480{
Enrico Granatab294fd22013-05-31 19:18:19 +00001481 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001482 {
Enrico Granata4939b982013-12-22 09:24:22 +00001483 lldb::TypeFormatImplSP format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001484 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001485 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001486 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001487 if (m_type_format_sp)
Enrico Granata4939b982013-12-22 09:24:22 +00001488 format_sp = m_type_format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001489 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001490 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001491 if (m_is_bitfield_for_scalar)
1492 my_format = eFormatUnsigned;
1493 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001494 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001495 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001496 {
1497 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1498 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001499 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001500 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001501 else
1502 {
Enrico Granatad07cfd32014-10-08 18:27:36 +00001503 my_format = GetValue().GetClangType().GetFormat();
Enrico Granata0c489f52012-03-01 04:24:26 +00001504 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001505 }
1506 }
1507 }
Enrico Granatab294fd22013-05-31 19:18:19 +00001508 if (my_format != m_last_format || m_value_str.empty())
Enrico Granata297e69f2012-03-06 23:21:16 +00001509 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001510 m_last_format = my_format;
Enrico Granata4939b982013-12-22 09:24:22 +00001511 if (!format_sp)
Enrico Granata30f287f2013-12-28 08:44:02 +00001512 format_sp.reset(new TypeFormatImpl_Format(my_format));
Enrico Granata4939b982013-12-22 09:24:22 +00001513 if (GetValueAsCString(*format_sp.get(), m_value_str))
Enrico Granata297e69f2012-03-06 23:21:16 +00001514 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001515 if (!m_value_did_change && m_old_value_valid)
1516 {
1517 // The value was gotten successfully, so we consider the
1518 // value as changed if the value string differs
1519 SetValueDidChange (m_old_value_str != m_value_str);
1520 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001521 }
1522 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001523 }
1524 if (m_value_str.empty())
1525 return NULL;
1526 return m_value_str.c_str();
1527}
1528
Enrico Granatac3e320a2011-08-02 17:27:39 +00001529// if > 8bytes, 0 is returned. this method should mostly be used
1530// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001531uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001532ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001533{
1534 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001535 if (CanProvideValue())
Enrico Granatac3e320a2011-08-02 17:27:39 +00001536 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001537 Scalar scalar;
1538 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001539 {
1540 if (success)
1541 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001542 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001543 }
1544 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001545 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001546
1547 if (success)
1548 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001549 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001550}
1551
Enrico Granatad7373f62013-10-31 18:57:50 +00001552int64_t
1553ValueObject::GetValueAsSigned (int64_t fail_value, bool *success)
1554{
1555 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001556 if (CanProvideValue())
Enrico Granatad7373f62013-10-31 18:57:50 +00001557 {
1558 Scalar scalar;
1559 if (ResolveValue (scalar))
1560 {
1561 if (success)
1562 *success = true;
1563 return scalar.SLongLong(fail_value);
1564 }
1565 // fallthrough, otherwise...
1566 }
1567
1568 if (success)
1569 *success = false;
1570 return fail_value;
1571}
1572
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001573// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1574// this call up to date by returning true for your new special cases. We will eventually move
1575// to checking this call result before trying to display special cases
1576bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001577ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1578 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001579{
Greg Clayton57ee3062013-07-11 22:46:58 +00001580 Flags flags(GetTypeInfo());
Enrico Granata622be232014-10-21 20:52:14 +00001581 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001582 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001583 {
1584 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001585 (custom_format == eFormatCString ||
1586 custom_format == eFormatCharArray ||
1587 custom_format == eFormatChar ||
1588 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001589 return true;
1590
Enrico Granata622be232014-10-21 20:52:14 +00001591 if (flags.Test(eTypeIsArray))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001592 {
Greg Claytonafacd142011-09-02 01:15:17 +00001593 if ((custom_format == eFormatBytes) ||
1594 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001595 return true;
1596
Greg Claytonafacd142011-09-02 01:15:17 +00001597 if ((custom_format == eFormatVectorOfChar) ||
1598 (custom_format == eFormatVectorOfFloat32) ||
1599 (custom_format == eFormatVectorOfFloat64) ||
1600 (custom_format == eFormatVectorOfSInt16) ||
1601 (custom_format == eFormatVectorOfSInt32) ||
1602 (custom_format == eFormatVectorOfSInt64) ||
1603 (custom_format == eFormatVectorOfSInt8) ||
1604 (custom_format == eFormatVectorOfUInt128) ||
1605 (custom_format == eFormatVectorOfUInt16) ||
1606 (custom_format == eFormatVectorOfUInt32) ||
1607 (custom_format == eFormatVectorOfUInt64) ||
1608 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001609 return true;
1610 }
1611 }
1612 return false;
1613}
1614
Enrico Granata9fc19442011-07-06 02:13:41 +00001615bool
1616ValueObject::DumpPrintableRepresentation(Stream& s,
1617 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001618 Format custom_format,
Enrico Granata0dba9b32014-01-08 01:36:59 +00001619 PrintableRepresentationSpecialCases special,
1620 bool do_dump_error)
Enrico Granata9fc19442011-07-06 02:13:41 +00001621{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001622
Greg Clayton57ee3062013-07-11 22:46:58 +00001623 Flags flags(GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001624
Enrico Granata86cc9822012-03-19 22:58:49 +00001625 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1626 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1627
1628 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001629 {
Enrico Granata622be232014-10-21 20:52:14 +00001630 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001631 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001632 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001633 // when being asked to get a printable display an array or pointer type directly,
1634 // try to "do the right thing"
1635
1636 if (IsCStringContainer(true) &&
1637 (custom_format == eFormatCString ||
1638 custom_format == eFormatCharArray ||
1639 custom_format == eFormatChar ||
1640 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001641 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001642 Error error;
Enrico Granata2206b482014-10-30 18:27:31 +00001643 lldb::DataBufferSP buffer_sp;
1644 ReadPointedString(buffer_sp,
Enrico Granata86cc9822012-03-19 22:58:49 +00001645 error,
1646 0,
1647 (custom_format == eFormatVectorOfChar) ||
1648 (custom_format == eFormatCharArray));
Enrico Granataebdc1ac2014-11-05 21:20:48 +00001649 lldb_private::formatters::ReadBufferAndDumpToStreamOptions options(*this);
Enrico Granata2206b482014-10-30 18:27:31 +00001650 options.SetData(DataExtractor(buffer_sp, lldb::eByteOrderInvalid, 8)); // none of this matters for a string - pass some defaults
1651 options.SetStream(&s);
1652 options.SetPrefixToken(0);
1653 options.SetQuote('"');
1654 options.SetSourceSize(buffer_sp->GetByteSize());
Enrico Granata2206b482014-10-30 18:27:31 +00001655 lldb_private::formatters::ReadBufferAndDumpToStream<lldb_private::formatters::StringElementType::ASCII>(options);
Enrico Granata86cc9822012-03-19 22:58:49 +00001656 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001657 }
1658
Enrico Granata86cc9822012-03-19 22:58:49 +00001659 if (custom_format == eFormatEnum)
1660 return false;
1661
1662 // this only works for arrays, because I have no way to know when
1663 // the pointed memory ends, and no special \0 end of data marker
Enrico Granata622be232014-10-21 20:52:14 +00001664 if (flags.Test(eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001665 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001666 if ((custom_format == eFormatBytes) ||
1667 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001668 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001669 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001670
1671 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001672 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001673 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001674
1675 if (low)
1676 s << ',';
1677
1678 ValueObjectSP child = GetChildAtIndex(low,true);
1679 if (!child.get())
1680 {
1681 s << "<invalid child>";
1682 continue;
1683 }
1684 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1685 }
1686
1687 s << ']';
1688
1689 return true;
1690 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001691
Enrico Granata86cc9822012-03-19 22:58:49 +00001692 if ((custom_format == eFormatVectorOfChar) ||
1693 (custom_format == eFormatVectorOfFloat32) ||
1694 (custom_format == eFormatVectorOfFloat64) ||
1695 (custom_format == eFormatVectorOfSInt16) ||
1696 (custom_format == eFormatVectorOfSInt32) ||
1697 (custom_format == eFormatVectorOfSInt64) ||
1698 (custom_format == eFormatVectorOfSInt8) ||
1699 (custom_format == eFormatVectorOfUInt128) ||
1700 (custom_format == eFormatVectorOfUInt16) ||
1701 (custom_format == eFormatVectorOfUInt32) ||
1702 (custom_format == eFormatVectorOfUInt64) ||
1703 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1704 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001705 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001706
1707 Format format = FormatManager::GetSingleItemFormat(custom_format);
1708
1709 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001710 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001711 {
1712
1713 if (low)
1714 s << ',';
1715
1716 ValueObjectSP child = GetChildAtIndex(low,true);
1717 if (!child.get())
1718 {
1719 s << "<invalid child>";
1720 continue;
1721 }
1722 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1723 }
1724
1725 s << ']';
1726
1727 return true;
1728 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001729 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001730
1731 if ((custom_format == eFormatBoolean) ||
1732 (custom_format == eFormatBinary) ||
1733 (custom_format == eFormatChar) ||
1734 (custom_format == eFormatCharPrintable) ||
1735 (custom_format == eFormatComplexFloat) ||
1736 (custom_format == eFormatDecimal) ||
1737 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001738 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001739 (custom_format == eFormatFloat) ||
1740 (custom_format == eFormatOctal) ||
1741 (custom_format == eFormatOSType) ||
1742 (custom_format == eFormatUnicode16) ||
1743 (custom_format == eFormatUnicode32) ||
1744 (custom_format == eFormatUnsigned) ||
1745 (custom_format == eFormatPointer) ||
1746 (custom_format == eFormatComplexInteger) ||
1747 (custom_format == eFormatComplex) ||
1748 (custom_format == eFormatDefault)) // use the [] operator
1749 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001750 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001751 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001752
1753 if (only_special)
1754 return false;
1755
Enrico Granata86cc9822012-03-19 22:58:49 +00001756 bool var_success = false;
1757
1758 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001759 const char *cstr = NULL;
Enrico Granata2c75f112013-06-21 00:04:51 +00001760
1761 // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1762 // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1763 // area for cases where our desired output is not backed by some other longer-term storage
Greg Claytonc7bece562013-01-25 18:06:21 +00001764 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001765
Enrico Granata465f4bc2014-02-15 01:24:44 +00001766 if (custom_format != eFormatInvalid)
Enrico Granata86cc9822012-03-19 22:58:49 +00001767 SetFormat(custom_format);
1768
1769 switch(val_obj_display)
1770 {
1771 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001772 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001773 break;
1774
1775 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001776 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001777 break;
1778
1779 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001780 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001781 break;
1782
1783 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001784 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001785 break;
1786
1787 case eValueObjectRepresentationStyleChildrenCount:
Deepak Panickal99fbc072014-03-03 15:39:47 +00001788 strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren());
Greg Claytonc7bece562013-01-25 18:06:21 +00001789 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001790 break;
1791
1792 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001793 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001794 break;
Enrico Granata2c75f112013-06-21 00:04:51 +00001795
1796 case eValueObjectRepresentationStyleName:
1797 cstr = GetName().AsCString();
1798 break;
1799
1800 case eValueObjectRepresentationStyleExpressionPath:
1801 GetExpressionPath(strm, false);
1802 cstr = strm.GetString().c_str();
1803 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001804 }
1805
Greg Claytonc7bece562013-01-25 18:06:21 +00001806 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001807 {
1808 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001809 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001810 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1811 {
Enrico Granatad07cfd32014-10-08 18:27:36 +00001812 if (!CanProvideValue())
Enrico Granata86cc9822012-03-19 22:58:49 +00001813 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001814 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1815 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001816 }
1817 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001818 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001819 }
1820 }
1821
Greg Claytonc7bece562013-01-25 18:06:21 +00001822 if (cstr)
1823 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001824 else
1825 {
1826 if (m_error.Fail())
Enrico Granata0dba9b32014-01-08 01:36:59 +00001827 {
1828 if (do_dump_error)
1829 s.Printf("<%s>", m_error.AsCString());
1830 else
1831 return false;
1832 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001833 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1834 s.PutCString("<no summary available>");
1835 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1836 s.PutCString("<no value available>");
1837 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1838 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1839 else
1840 s.PutCString("<no printable representation>");
1841 }
1842
1843 // we should only return false here if we could not do *anything*
1844 // even if we have an error message as output, that's a success
1845 // from our callers' perspective, so return true
1846 var_success = true;
Enrico Granata465f4bc2014-02-15 01:24:44 +00001847
1848 if (custom_format != eFormatInvalid)
1849 SetFormat(eFormatDefault);
Enrico Granata86cc9822012-03-19 22:58:49 +00001850 }
1851
Enrico Granataf4efecd2011-07-12 22:56:10 +00001852 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001853}
1854
Greg Clayton737b9322010-09-13 03:32:57 +00001855addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001856ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001857{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001858 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001859 return LLDB_INVALID_ADDRESS;
1860
Greg Clayton73b472d2010-10-27 03:32:59 +00001861 switch (m_value.GetValueType())
1862 {
1863 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001864 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001865 if (scalar_is_load_address)
1866 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001867 if(address_type)
1868 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001869 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1870 }
1871 break;
1872
1873 case Value::eValueTypeLoadAddress:
1874 case Value::eValueTypeFileAddress:
1875 case Value::eValueTypeHostAddress:
1876 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001877 if(address_type)
1878 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001879 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1880 }
1881 break;
1882 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001883 if (address_type)
1884 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001885 return LLDB_INVALID_ADDRESS;
1886}
1887
1888addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001889ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001890{
Greg Claytonafacd142011-09-02 01:15:17 +00001891 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001892 if(address_type)
1893 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001894
Enrico Granatac3e320a2011-08-02 17:27:39 +00001895 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001896 return address;
1897
Greg Clayton73b472d2010-10-27 03:32:59 +00001898 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001899 {
1900 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001901 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001902 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001903 break;
1904
Enrico Granata9128ee22011-09-06 19:20:51 +00001905 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001906 case Value::eValueTypeLoadAddress:
1907 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001908 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001909 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001910 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001911 }
1912 break;
1913 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001914
Enrico Granata9128ee22011-09-06 19:20:51 +00001915 if (address_type)
1916 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001917
Greg Clayton737b9322010-09-13 03:32:57 +00001918 return address;
1919}
1920
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001921bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001922ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001923{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001924 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001925 // Make sure our value is up to date first so that our location and location
1926 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001927 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001928 {
1929 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001930 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001931 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001932
Greg Claytonfaac1112013-03-14 18:31:44 +00001933 uint64_t count = 0;
Greg Clayton57ee3062013-07-11 22:46:58 +00001934 const Encoding encoding = GetClangType().GetEncoding (count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001935
Greg Claytonb1320972010-07-14 00:18:15 +00001936 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001937
Jim Ingham16e0c682011-08-12 23:34:31 +00001938 Value::ValueType value_type = m_value.GetValueType();
1939
1940 if (value_type == Value::eValueTypeScalar)
1941 {
1942 // If the value is already a scalar, then let the scalar change itself:
1943 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1944 }
1945 else if (byte_size <= Scalar::GetMaxByteSize())
1946 {
1947 // If the value fits in a scalar, then make a new scalar and again let the
1948 // scalar code do the conversion, then figure out where to put the new value.
1949 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001950 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1951 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001952 {
Jim Ingham4b536182011-08-09 02:12:22 +00001953 switch (value_type)
1954 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001955 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001956 {
1957 // If it is a load address, then the scalar value is the storage location
1958 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001959 ExecutionContext exe_ctx (GetExecutionContextRef());
1960 Process *process = exe_ctx.GetProcessPtr();
1961 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001962 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001963 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001964 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1965 new_scalar,
1966 byte_size,
1967 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001968 if (!error.Success())
1969 return false;
1970 if (bytes_written != byte_size)
1971 {
1972 error.SetErrorString("unable to write value to memory");
1973 return false;
1974 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001975 }
1976 }
Jim Ingham4b536182011-08-09 02:12:22 +00001977 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001978 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001979 {
1980 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1981 DataExtractor new_data;
1982 new_data.SetByteOrder (m_data.GetByteOrder());
1983
1984 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1985 m_data.SetData(buffer_sp, 0);
1986 bool success = new_scalar.GetData(new_data);
1987 if (success)
1988 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001989 new_data.CopyByteOrderedData (0,
1990 byte_size,
1991 const_cast<uint8_t *>(m_data.GetDataStart()),
1992 byte_size,
1993 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001994 }
1995 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1996
1997 }
Jim Ingham4b536182011-08-09 02:12:22 +00001998 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001999 case Value::eValueTypeFileAddress:
2000 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00002001 case Value::eValueTypeVector:
2002 break;
Jim Ingham4b536182011-08-09 02:12:22 +00002003 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002004 }
2005 else
2006 {
Jim Ingham16e0c682011-08-12 23:34:31 +00002007 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002008 }
Jim Ingham16e0c682011-08-12 23:34:31 +00002009 }
2010 else
2011 {
2012 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00002013 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002014 return false;
2015 }
Jim Ingham16e0c682011-08-12 23:34:31 +00002016
2017 // If we have reached this point, then we have successfully changed the value.
2018 SetNeedsUpdate();
2019 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002020}
2021
Greg Clayton81e871e2012-02-04 02:27:34 +00002022bool
2023ValueObject::GetDeclaration (Declaration &decl)
2024{
2025 decl.Clear();
2026 return false;
2027}
2028
Greg Clayton84db9102012-03-26 23:03:23 +00002029ConstString
2030ValueObject::GetTypeName()
2031{
Greg Clayton57ee3062013-07-11 22:46:58 +00002032 return GetClangType().GetConstTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00002033}
2034
2035ConstString
Enrico Granatae8daa2f2014-05-17 19:14:17 +00002036ValueObject::GetDisplayTypeName()
2037{
2038 return GetTypeName();
2039}
2040
2041ConstString
Greg Clayton84db9102012-03-26 23:03:23 +00002042ValueObject::GetQualifiedTypeName()
2043{
Greg Clayton57ee3062013-07-11 22:46:58 +00002044 return GetClangType().GetConstQualifiedTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00002045}
2046
2047
Greg Claytonafacd142011-09-02 01:15:17 +00002048LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00002049ValueObject::GetObjectRuntimeLanguage ()
2050{
Greg Clayton57ee3062013-07-11 22:46:58 +00002051 return GetClangType().GetMinimumLanguage ();
Jim Ingham5a369122010-09-28 01:25:32 +00002052}
2053
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002054void
Jim Ingham58b59f92011-04-22 23:53:53 +00002055ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002056{
Jim Ingham58b59f92011-04-22 23:53:53 +00002057 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002058}
2059
2060ValueObjectSP
2061ValueObject::GetSyntheticChild (const ConstString &key) const
2062{
2063 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00002064 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002065 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00002066 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002067 return synthetic_child_sp;
2068}
2069
Greg Clayton2452ab72013-02-08 22:02:02 +00002070uint32_t
Greg Clayton57ee3062013-07-11 22:46:58 +00002071ValueObject::GetTypeInfo (ClangASTType *pointee_or_element_clang_type)
Greg Clayton2452ab72013-02-08 22:02:02 +00002072{
Greg Clayton57ee3062013-07-11 22:46:58 +00002073 return GetClangType().GetTypeInfo (pointee_or_element_clang_type);
Greg Clayton2452ab72013-02-08 22:02:02 +00002074}
2075
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002076bool
2077ValueObject::IsPointerType ()
2078{
Greg Clayton57ee3062013-07-11 22:46:58 +00002079 return GetClangType().IsPointerType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002080}
2081
Jim Inghamb7603bb2011-03-18 00:05:18 +00002082bool
Greg Claytondaf515f2011-07-09 20:12:33 +00002083ValueObject::IsArrayType ()
2084{
Greg Clayton57ee3062013-07-11 22:46:58 +00002085 return GetClangType().IsArrayType (NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00002086}
2087
2088bool
Enrico Granata9fc19442011-07-06 02:13:41 +00002089ValueObject::IsScalarType ()
2090{
Greg Clayton57ee3062013-07-11 22:46:58 +00002091 return GetClangType().IsScalarType ();
Enrico Granata9fc19442011-07-06 02:13:41 +00002092}
2093
2094bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00002095ValueObject::IsIntegerType (bool &is_signed)
2096{
Greg Clayton57ee3062013-07-11 22:46:58 +00002097 return GetClangType().IsIntegerType (is_signed);
Jim Inghamb7603bb2011-03-18 00:05:18 +00002098}
Greg Clayton73b472d2010-10-27 03:32:59 +00002099
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002100bool
2101ValueObject::IsPointerOrReferenceType ()
2102{
Greg Clayton57ee3062013-07-11 22:46:58 +00002103 return GetClangType().IsPointerOrReferenceType ();
Greg Clayton007d5be2011-05-30 00:49:24 +00002104}
2105
2106bool
Greg Claytondea8cb42011-06-29 22:09:02 +00002107ValueObject::IsPossibleDynamicType ()
2108{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002109 ExecutionContext exe_ctx (GetExecutionContextRef());
2110 Process *process = exe_ctx.GetProcessPtr();
2111 if (process)
2112 return process->IsPossibleDynamicValue(*this);
2113 else
Greg Clayton57ee3062013-07-11 22:46:58 +00002114 return GetClangType().IsPossibleDynamicType (NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00002115}
2116
Enrico Granata9e7b3882012-12-13 23:50:33 +00002117bool
2118ValueObject::IsObjCNil ()
2119{
Enrico Granata622be232014-10-21 20:52:14 +00002120 const uint32_t mask = eTypeIsObjC | eTypeIsPointer;
Greg Clayton57ee3062013-07-11 22:46:58 +00002121 bool isObjCpointer = (((GetClangType().GetTypeInfo(NULL)) & mask) == mask);
Enrico Granata7277d202013-03-15 23:33:15 +00002122 if (!isObjCpointer)
2123 return false;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002124 bool canReadValue = true;
2125 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
Enrico Granata7277d202013-03-15 23:33:15 +00002126 return canReadValue && isZero;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002127}
2128
Greg Claytonafacd142011-09-02 01:15:17 +00002129ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002130ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002131{
Greg Clayton2452ab72013-02-08 22:02:02 +00002132 const uint32_t type_info = GetTypeInfo ();
Enrico Granata622be232014-10-21 20:52:14 +00002133 if (type_info & eTypeIsArray)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002134 return GetSyntheticArrayMemberFromArray(index, can_create);
2135
Enrico Granata622be232014-10-21 20:52:14 +00002136 if (type_info & eTypeIsPointer)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002137 return GetSyntheticArrayMemberFromPointer(index, can_create);
2138
2139 return ValueObjectSP();
2140
2141}
2142
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002143ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002144ValueObject::GetSyntheticArrayMemberFromPointer (size_t index, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002145{
2146 ValueObjectSP synthetic_child_sp;
2147 if (IsPointerType ())
2148 {
2149 char index_str[64];
Deepak Panickal99fbc072014-03-03 15:39:47 +00002150 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002151 ConstString index_const_str(index_str);
2152 // Check if we have already created a synthetic array member in this
2153 // valid object. If we have we will re-use it.
2154 synthetic_child_sp = GetSyntheticChild (index_const_str);
2155 if (!synthetic_child_sp)
2156 {
Jim Ingham58b59f92011-04-22 23:53:53 +00002157 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002158 // We haven't made a synthetic array member for INDEX yet, so
2159 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00002160 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002161
2162 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00002163 if (synthetic_child)
2164 {
2165 AddSyntheticChild(index_const_str, synthetic_child);
2166 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002167 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00002168 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00002169 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002170 }
2171 }
2172 return synthetic_child_sp;
2173}
Jim Ingham22777012010-09-23 02:01:19 +00002174
Greg Claytondaf515f2011-07-09 20:12:33 +00002175// This allows you to create an array member using and index
2176// that doesn't not fall in the normal bounds of the array.
2177// Many times structure can be defined as:
2178// struct Collection
2179// {
2180// uint32_t item_count;
2181// Item item_array[0];
2182// };
2183// The size of the "item_array" is 1, but many times in practice
2184// there are more items in "item_array".
2185
2186ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002187ValueObject::GetSyntheticArrayMemberFromArray (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00002188{
2189 ValueObjectSP synthetic_child_sp;
2190 if (IsArrayType ())
2191 {
2192 char index_str[64];
Deepak Panickal99fbc072014-03-03 15:39:47 +00002193 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
Greg Claytondaf515f2011-07-09 20:12:33 +00002194 ConstString index_const_str(index_str);
2195 // Check if we have already created a synthetic array member in this
2196 // valid object. If we have we will re-use it.
2197 synthetic_child_sp = GetSyntheticChild (index_const_str);
2198 if (!synthetic_child_sp)
2199 {
2200 ValueObject *synthetic_child;
2201 // We haven't made a synthetic array member for INDEX yet, so
2202 // lets make one and cache it for any future reference.
2203 synthetic_child = CreateChildAtIndex(0, true, index);
2204
2205 // Cache the value if we got one back...
2206 if (synthetic_child)
2207 {
2208 AddSyntheticChild(index_const_str, synthetic_child);
2209 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002210 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00002211 synthetic_child_sp->m_is_array_item_for_pointer = true;
2212 }
2213 }
2214 }
2215 return synthetic_child_sp;
2216}
2217
Enrico Granata9fc19442011-07-06 02:13:41 +00002218ValueObjectSP
2219ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2220{
2221 ValueObjectSP synthetic_child_sp;
2222 if (IsScalarType ())
2223 {
2224 char index_str[64];
2225 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2226 ConstString index_const_str(index_str);
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 (index_const_str);
2230 if (!synthetic_child_sp)
2231 {
Enrico Granata9fc19442011-07-06 02:13:41 +00002232 // We haven't made a synthetic array member for INDEX yet, so
2233 // lets make one and cache it for any future reference.
Greg Clayton57ee3062013-07-11 22:46:58 +00002234 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
2235 GetClangType(),
2236 index_const_str,
2237 GetByteSize(),
2238 0,
2239 to-from+1,
2240 from,
2241 false,
2242 false,
2243 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002244
2245 // Cache the value if we got one back...
2246 if (synthetic_child)
2247 {
2248 AddSyntheticChild(index_const_str, synthetic_child);
2249 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002250 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002251 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2252 }
2253 }
2254 }
2255 return synthetic_child_sp;
2256}
2257
Greg Claytonafacd142011-09-02 01:15:17 +00002258ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00002259ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
2260{
2261
2262 ValueObjectSP synthetic_child_sp;
2263
2264 char name_str[64];
2265 snprintf(name_str, sizeof(name_str), "@%i", offset);
2266 ConstString name_const_str(name_str);
2267
2268 // Check if we have already created a synthetic array member in this
2269 // valid object. If we have we will re-use it.
2270 synthetic_child_sp = GetSyntheticChild (name_const_str);
2271
2272 if (synthetic_child_sp.get())
2273 return synthetic_child_sp;
2274
2275 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002276 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002277
2278 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
Greg Clayton57ee3062013-07-11 22:46:58 +00002279 type,
Enrico Granata6f3533f2011-07-29 19:53:35 +00002280 name_const_str,
Greg Clayton57ee3062013-07-11 22:46:58 +00002281 type.GetByteSize(),
Enrico Granata6f3533f2011-07-29 19:53:35 +00002282 offset,
2283 0,
2284 0,
2285 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002286 false,
2287 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002288 if (synthetic_child)
2289 {
2290 AddSyntheticChild(name_const_str, synthetic_child);
2291 synthetic_child_sp = synthetic_child->GetSP();
2292 synthetic_child_sp->SetName(name_const_str);
2293 synthetic_child_sp->m_is_child_at_offset = true;
2294 }
2295 return synthetic_child_sp;
2296}
2297
Enrico Granata32556cd2014-08-26 20:54:04 +00002298ValueObjectSP
Enrico Granata59953f02014-08-26 21:35:30 +00002299ValueObject::GetSyntheticBase (uint32_t offset, const ClangASTType& type, bool can_create)
Enrico Granata32556cd2014-08-26 20:54:04 +00002300{
2301 ValueObjectSP synthetic_child_sp;
2302
2303 char name_str[64];
2304 snprintf(name_str, sizeof(name_str), "%s", type.GetTypeName().AsCString("<unknown>"));
2305 ConstString name_const_str(name_str);
2306
2307 // Check if we have already created a synthetic array member in this
2308 // valid object. If we have we will re-use it.
2309 synthetic_child_sp = GetSyntheticChild (name_const_str);
2310
2311 if (synthetic_child_sp.get())
2312 return synthetic_child_sp;
2313
2314 if (!can_create)
2315 return ValueObjectSP();
2316
Enrico Granata32556cd2014-08-26 20:54:04 +00002317 const bool is_base_class = true;
2318
2319 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2320 type,
2321 name_const_str,
2322 type.GetByteSize(),
2323 offset,
2324 0,
2325 0,
2326 is_base_class,
2327 false,
2328 eAddressTypeInvalid);
2329 if (synthetic_child)
2330 {
2331 AddSyntheticChild(name_const_str, synthetic_child);
2332 synthetic_child_sp = synthetic_child->GetSP();
2333 synthetic_child_sp->SetName(name_const_str);
2334 }
2335 return synthetic_child_sp;
2336}
2337
2338
Enrico Granatad55546b2011-07-22 00:16:08 +00002339// your expression path needs to have a leading . or ->
2340// (unless it somehow "looks like" an array, in which case it has
2341// a leading [ symbol). while the [ is meaningful and should be shown
2342// to the user, . and -> are just parser design, but by no means
2343// added information for the user.. strip them off
2344static const char*
2345SkipLeadingExpressionPathSeparators(const char* expression)
2346{
2347 if (!expression || !expression[0])
2348 return expression;
2349 if (expression[0] == '.')
2350 return expression+1;
2351 if (expression[0] == '-' && expression[1] == '>')
2352 return expression+2;
2353 return expression;
2354}
2355
Greg Claytonafacd142011-09-02 01:15:17 +00002356ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002357ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2358{
2359 ValueObjectSP synthetic_child_sp;
2360 ConstString name_const_string(expression);
2361 // Check if we have already created a synthetic array member in this
2362 // valid object. If we have we will re-use it.
2363 synthetic_child_sp = GetSyntheticChild (name_const_string);
2364 if (!synthetic_child_sp)
2365 {
2366 // We haven't made a synthetic array member for expression yet, so
2367 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002368 synthetic_child_sp = GetValueForExpressionPath(expression,
2369 NULL, NULL, NULL,
2370 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
Enrico Granatad55546b2011-07-22 00:16:08 +00002371
2372 // Cache the value if we got one back...
2373 if (synthetic_child_sp.get())
2374 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002375 // 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 +00002376 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002377 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002378 }
2379 }
2380 return synthetic_child_sp;
2381}
2382
2383void
Enrico Granata86cc9822012-03-19 22:58:49 +00002384ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002385{
Enrico Granata86cc9822012-03-19 22:58:49 +00002386 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002387 return;
2388
Enrico Granatac5bc4122012-03-27 02:35:13 +00002389 TargetSP target_sp(GetTargetSP());
Enrico Granata5d5f60c2013-09-24 22:58:37 +00002390 if (target_sp && target_sp->GetEnableSyntheticValue() == false)
Enrico Granatac5bc4122012-03-27 02:35:13 +00002391 {
2392 m_synthetic_value = NULL;
2393 return;
2394 }
2395
Enrico Granatae3e91512012-10-22 18:18:36 +00002396 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2397
Enrico Granata5548cb52013-01-28 23:47:25 +00002398 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002399 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002400
Enrico Granata0c489f52012-03-01 04:24:26 +00002401 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002402 return;
2403
Enrico Granatae3e91512012-10-22 18:18:36 +00002404 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2405 return;
2406
Enrico Granata86cc9822012-03-19 22:58:49 +00002407 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002408}
2409
Jim Ingham78a685a2011-04-16 00:01:13 +00002410void
Greg Claytonafacd142011-09-02 01:15:17 +00002411ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002412{
Greg Claytonafacd142011-09-02 01:15:17 +00002413 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002414 return;
2415
Jim Ingham58b59f92011-04-22 23:53:53 +00002416 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002417 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002418 ExecutionContext exe_ctx (GetExecutionContextRef());
2419 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002420 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002421 {
2422 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002423 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002424 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002425 }
2426}
2427
Jim Ingham58b59f92011-04-22 23:53:53 +00002428ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002429ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002430{
Greg Claytonafacd142011-09-02 01:15:17 +00002431 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002432 return ValueObjectSP();
2433
2434 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002435 {
Jim Ingham2837b762011-05-04 03:43:18 +00002436 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002437 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002438 if (m_dynamic_value)
2439 return m_dynamic_value->GetSP();
2440 else
2441 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002442}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002443
Jim Ingham60dbabb2011-12-08 19:44:08 +00002444ValueObjectSP
2445ValueObject::GetStaticValue()
2446{
2447 return GetSP();
2448}
2449
Enrico Granata886147f2012-05-08 18:47:08 +00002450lldb::ValueObjectSP
2451ValueObject::GetNonSyntheticValue ()
2452{
2453 return GetSP();
2454}
2455
Enrico Granatad55546b2011-07-22 00:16:08 +00002456ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002457ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002458{
Enrico Granata86cc9822012-03-19 22:58:49 +00002459 if (use_synthetic == false)
2460 return ValueObjectSP();
2461
Enrico Granatad55546b2011-07-22 00:16:08 +00002462 CalculateSyntheticValue(use_synthetic);
2463
2464 if (m_synthetic_value)
2465 return m_synthetic_value->GetSP();
2466 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002467 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002468}
2469
Greg Claytone221f822011-01-21 01:59:00 +00002470bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002471ValueObject::HasSyntheticValue()
2472{
Enrico Granata5548cb52013-01-28 23:47:25 +00002473 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002474
Enrico Granata0c489f52012-03-01 04:24:26 +00002475 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002476 return false;
2477
Enrico Granata86cc9822012-03-19 22:58:49 +00002478 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002479
2480 if (m_synthetic_value)
2481 return true;
2482 else
2483 return false;
2484}
2485
2486bool
Greg Claytone221f822011-01-21 01:59:00 +00002487ValueObject::GetBaseClassPath (Stream &s)
2488{
2489 if (IsBaseClass())
2490 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002491 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Clayton57ee3062013-07-11 22:46:58 +00002492 ClangASTType clang_type = GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002493 std::string cxx_class_name;
Greg Clayton57ee3062013-07-11 22:46:58 +00002494 bool this_had_base_class = clang_type.GetCXXClassName (cxx_class_name);
Greg Claytone221f822011-01-21 01:59:00 +00002495 if (this_had_base_class)
2496 {
2497 if (parent_had_base_class)
2498 s.PutCString("::");
2499 s.PutCString(cxx_class_name.c_str());
2500 }
2501 return parent_had_base_class || this_had_base_class;
2502 }
2503 return false;
2504}
2505
2506
2507ValueObject *
2508ValueObject::GetNonBaseClassParent()
2509{
Jim Ingham78a685a2011-04-16 00:01:13 +00002510 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002511 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002512 if (GetParent()->IsBaseClass())
2513 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002514 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002515 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002516 }
2517 return NULL;
2518}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002519
Enrico Granataa3c8f042014-08-19 22:29:08 +00002520
2521bool
2522ValueObject::IsBaseClass (uint32_t& depth)
2523{
2524 if (!IsBaseClass())
2525 {
2526 depth = 0;
2527 return false;
2528 }
2529 if (GetParent())
2530 {
2531 GetParent()->IsBaseClass(depth);
2532 depth = depth + 1;
2533 return true;
2534 }
2535 // TODO: a base of no parent? weird..
2536 depth = 1;
2537 return true;
2538}
2539
Greg Clayton1d3afba2010-10-05 00:00:42 +00002540void
Enrico Granata4becb372011-06-29 22:27:15 +00002541ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002542{
Enrico Granata986fa5f2014-12-09 21:41:16 +00002543 // synthetic children do not actually "exist" as part of the hierarchy, and sometimes they are consed up in ways
2544 // that don't make sense from an underlying language/API standpoint. So, use a special code path here to return
2545 // something that can hopefully be used in expression
2546 if (m_is_synthetic_children_generated)
2547 {
2548 UpdateValueIfNeeded();
2549
2550 if (m_value.GetValueType() == Value::eValueTypeLoadAddress)
2551 {
2552 if (IsPointerOrReferenceType())
2553 {
2554 s.Printf("((%s)0x%" PRIx64 ")",
2555 GetTypeName().AsCString("void"),
2556 GetValueAsUnsigned(0));
2557 return;
2558 }
2559 else
2560 {
2561 uint64_t load_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
2562 if (load_addr != LLDB_INVALID_ADDRESS)
2563 {
2564 s.Printf("(*( (%s *)0x%" PRIx64 "))",
2565 GetTypeName().AsCString("void"),
2566 load_addr);
2567 return;
2568 }
2569 }
2570 }
2571
2572 if (CanProvideValue())
2573 {
2574 s.Printf("((%s)%s)",
2575 GetTypeName().AsCString("void"),
2576 GetValueAsCString());
2577 return;
2578 }
2579
2580 return;
2581 }
2582
Greg Claytone221f822011-01-21 01:59:00 +00002583 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002584
Enrico Granata86cc9822012-03-19 22:58:49 +00002585 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002586 {
Enrico Granata4becb372011-06-29 22:27:15 +00002587 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2588 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2589 // the eHonorPointers mode is meant to produce strings in this latter format
2590 s.PutCString("*(");
2591 }
Greg Claytone221f822011-01-21 01:59:00 +00002592
Enrico Granata4becb372011-06-29 22:27:15 +00002593 ValueObject* parent = GetParent();
2594
2595 if (parent)
2596 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002597
2598 // if we are a deref_of_parent just because we are synthetic array
2599 // members made up to allow ptr[%d] syntax to work in variable
2600 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002601 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002602 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002603
Greg Claytone221f822011-01-21 01:59:00 +00002604 if (!IsBaseClass())
2605 {
2606 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002607 {
Greg Claytone221f822011-01-21 01:59:00 +00002608 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2609 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002610 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002611 ClangASTType non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002612 if (non_base_class_parent_clang_type)
2613 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002614 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002615 {
2616 s.PutCString("->");
2617 }
Enrico Granata4becb372011-06-29 22:27:15 +00002618 else
2619 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002620 const uint32_t non_base_class_parent_type_info = non_base_class_parent_clang_type.GetTypeInfo();
2621
Enrico Granata622be232014-10-21 20:52:14 +00002622 if (non_base_class_parent_type_info & eTypeIsPointer)
Enrico Granata4becb372011-06-29 22:27:15 +00002623 {
2624 s.PutCString("->");
2625 }
Enrico Granata622be232014-10-21 20:52:14 +00002626 else if ((non_base_class_parent_type_info & eTypeHasChildren) &&
2627 !(non_base_class_parent_type_info & eTypeIsArray))
Enrico Granata4becb372011-06-29 22:27:15 +00002628 {
2629 s.PutChar('.');
2630 }
Greg Claytone221f822011-01-21 01:59:00 +00002631 }
2632 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002633 }
Greg Claytone221f822011-01-21 01:59:00 +00002634
2635 const char *name = GetName().GetCString();
2636 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002637 {
Greg Claytone221f822011-01-21 01:59:00 +00002638 if (qualify_cxx_base_classes)
2639 {
2640 if (GetBaseClassPath (s))
2641 s.PutCString("::");
2642 }
2643 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002644 }
2645 }
2646 }
2647
Enrico Granata86cc9822012-03-19 22:58:49 +00002648 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002649 {
Greg Claytone221f822011-01-21 01:59:00 +00002650 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002651 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002652}
2653
Greg Claytonafacd142011-09-02 01:15:17 +00002654ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002655ValueObject::GetValueForExpressionPath(const char* expression,
2656 const char** first_unparsed,
2657 ExpressionPathScanEndReason* reason_to_stop,
2658 ExpressionPathEndResultType* final_value_type,
2659 const GetValueForExpressionPathOptions& options,
2660 ExpressionPathAftermath* final_task_on_target)
2661{
2662
2663 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002664 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2665 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002666 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002667
2668 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2669 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2670 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2671 final_value_type ? final_value_type : &dummy_final_value_type,
2672 options,
2673 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2674
Enrico Granata86cc9822012-03-19 22:58:49 +00002675 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002676 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002677
Enrico Granata86cc9822012-03-19 22:58:49 +00002678 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 +00002679 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002680 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002681 {
2682 Error error;
2683 ValueObjectSP final_value = ret_val->Dereference(error);
2684 if (error.Fail() || !final_value.get())
2685 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002686 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002687 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002688 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002689 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002690 return ValueObjectSP();
2691 }
2692 else
2693 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002694 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002695 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002696 return final_value;
2697 }
2698 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002699 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002700 {
2701 Error error;
2702 ValueObjectSP final_value = ret_val->AddressOf(error);
2703 if (error.Fail() || !final_value.get())
2704 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002705 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002706 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002707 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002708 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002709 return ValueObjectSP();
2710 }
2711 else
2712 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002713 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002714 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002715 return final_value;
2716 }
2717 }
2718 }
2719 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2720}
2721
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002722int
2723ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002724 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002725 const char** first_unparsed,
2726 ExpressionPathScanEndReason* reason_to_stop,
2727 ExpressionPathEndResultType* final_value_type,
2728 const GetValueForExpressionPathOptions& options,
2729 ExpressionPathAftermath* final_task_on_target)
2730{
2731 const char* dummy_first_unparsed;
2732 ExpressionPathScanEndReason dummy_reason_to_stop;
2733 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002734 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002735
2736 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2737 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2738 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2739 final_value_type ? final_value_type : &dummy_final_value_type,
2740 options,
2741 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2742
2743 if (!ret_val.get()) // if there are errors, I add nothing to the list
2744 return 0;
2745
Enrico Granata86ea8d82012-03-29 01:34:34 +00002746 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002747 {
2748 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002749 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002750 {
2751 list->Append(ret_val);
2752 return 1;
2753 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002754 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 +00002755 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002756 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002757 {
2758 Error error;
2759 ValueObjectSP final_value = ret_val->Dereference(error);
2760 if (error.Fail() || !final_value.get())
2761 {
Greg Clayton23f59502012-07-17 03:23:13 +00002762 if (reason_to_stop)
2763 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2764 if (final_value_type)
2765 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002766 return 0;
2767 }
2768 else
2769 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002770 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002771 list->Append(final_value);
2772 return 1;
2773 }
2774 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002775 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002776 {
2777 Error error;
2778 ValueObjectSP final_value = ret_val->AddressOf(error);
2779 if (error.Fail() || !final_value.get())
2780 {
Greg Clayton23f59502012-07-17 03:23:13 +00002781 if (reason_to_stop)
2782 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2783 if (final_value_type)
2784 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002785 return 0;
2786 }
2787 else
2788 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002789 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002790 list->Append(final_value);
2791 return 1;
2792 }
2793 }
2794 }
2795 }
2796 else
2797 {
2798 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2799 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2800 ret_val,
2801 list,
2802 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2803 final_value_type ? final_value_type : &dummy_final_value_type,
2804 options,
2805 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2806 }
2807 // in any non-covered case, just do the obviously right thing
2808 list->Append(ret_val);
2809 return 1;
2810}
2811
Greg Claytonafacd142011-09-02 01:15:17 +00002812ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002813ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2814 const char** first_unparsed,
2815 ExpressionPathScanEndReason* reason_to_stop,
2816 ExpressionPathEndResultType* final_result,
2817 const GetValueForExpressionPathOptions& options,
2818 ExpressionPathAftermath* what_next)
2819{
2820 ValueObjectSP root = GetSP();
2821
2822 if (!root.get())
2823 return ValueObjectSP();
2824
2825 *first_unparsed = expression_cstr;
2826
2827 while (true)
2828 {
2829
2830 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2831
Greg Clayton57ee3062013-07-11 22:46:58 +00002832 ClangASTType root_clang_type = root->GetClangType();
2833 ClangASTType pointee_clang_type;
2834 Flags pointee_clang_type_info;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002835
Greg Clayton57ee3062013-07-11 22:46:58 +00002836 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002837 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00002838 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002839
2840 if (!expression_cstr || *expression_cstr == '\0')
2841 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002842 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002843 return root;
2844 }
2845
2846 switch (*expression_cstr)
2847 {
2848 case '-':
2849 {
2850 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granata622be232014-10-21 20:52:14 +00002851 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 +00002852 {
2853 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002854 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2855 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002856 return ValueObjectSP();
2857 }
Enrico Granata622be232014-10-21 20:52:14 +00002858 if (root_clang_type_info.Test(eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2859 root_clang_type_info.Test(eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002860 options.m_no_fragile_ivar)
2861 {
2862 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002863 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2864 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002865 return ValueObjectSP();
2866 }
2867 if (expression_cstr[1] != '>')
2868 {
2869 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002870 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2871 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002872 return ValueObjectSP();
2873 }
2874 expression_cstr++; // skip the -
2875 }
2876 case '.': // or fallthrough from ->
2877 {
2878 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granata622be232014-10-21 20:52:14 +00002879 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 +00002880 {
2881 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002882 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2883 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002884 return ValueObjectSP();
2885 }
2886 expression_cstr++; // skip .
2887 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2888 ConstString child_name;
2889 if (!next_separator) // if no other separator just expand this last layer
2890 {
2891 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002892 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2893
2894 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002895 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002896 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002897 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2898 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002899 return child_valobj_sp;
2900 }
2901 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2902 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002903 if (root->IsSynthetic())
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002904 {
2905 *first_unparsed = expression_cstr;
Enrico Granatad07cfd32014-10-08 18:27:36 +00002906 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchSyntheticChild;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002907 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2908 return ValueObjectSP();
2909 }
2910
2911 child_valobj_sp = root->GetSyntheticValue();
Enrico Granata86cc9822012-03-19 22:58:49 +00002912 if (child_valobj_sp.get())
2913 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002914 }
2915
2916 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2917 // so we hit the "else" branch, and return an error
2918 if(child_valobj_sp.get()) // if it worked, just return
2919 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002920 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002921 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2922 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002923 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002924 }
2925 else
2926 {
2927 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002928 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2929 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002930 return ValueObjectSP();
2931 }
2932 }
2933 else // other layers do expand
2934 {
2935 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002936 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2937 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002938 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002939 root = child_valobj_sp;
2940 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002941 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002942 continue;
2943 }
2944 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2945 {
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002946 if (root->IsSynthetic())
2947 {
2948 *first_unparsed = expression_cstr;
2949 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2950 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2951 return ValueObjectSP();
2952 }
2953
Enrico Granata86cc9822012-03-19 22:58:49 +00002954 child_valobj_sp = root->GetSyntheticValue(true);
2955 if (child_valobj_sp)
2956 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002957 }
2958
2959 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2960 // so we hit the "else" branch, and return an error
2961 if(child_valobj_sp.get()) // if it worked, move on
2962 {
2963 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002964 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002965 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002966 continue;
2967 }
2968 else
2969 {
2970 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002971 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2972 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002973 return ValueObjectSP();
2974 }
2975 }
2976 break;
2977 }
2978 case '[':
2979 {
Enrico Granata622be232014-10-21 20:52:14 +00002980 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 +00002981 {
Enrico Granata622be232014-10-21 20:52:14 +00002982 if (!root_clang_type_info.Test(eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002983 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002984 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2985 {
2986 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002987 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2988 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002989 return ValueObjectSP();
2990 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002991 }
2992 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2993 {
2994 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002995 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2996 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002997 return ValueObjectSP();
2998 }
2999 }
3000 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3001 {
Enrico Granata622be232014-10-21 20:52:14 +00003002 if (!root_clang_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003003 {
3004 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003005 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3006 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003007 return ValueObjectSP();
3008 }
3009 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
3010 {
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 }
3017 const char *separator_position = ::strchr(expression_cstr+1,'-');
3018 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3019 if (!close_bracket_position) // if there is no ], this is a syntax error
3020 {
3021 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003022 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3023 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003024 return ValueObjectSP();
3025 }
3026 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3027 {
3028 char *end = NULL;
3029 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3030 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3031 {
3032 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003033 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3034 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003035 return ValueObjectSP();
3036 }
3037 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3038 {
Enrico Granata622be232014-10-21 20:52:14 +00003039 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003040 {
3041 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003042 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3043 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003044 return root;
3045 }
3046 else
3047 {
3048 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003049 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3050 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003051 return ValueObjectSP();
3052 }
3053 }
3054 // from here on we do have a valid index
Enrico Granata622be232014-10-21 20:52:14 +00003055 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003056 {
Greg Claytondaf515f2011-07-09 20:12:33 +00003057 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
3058 if (!child_valobj_sp)
3059 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003060 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00003061 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
3062 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00003063 if (child_valobj_sp)
3064 {
3065 root = child_valobj_sp;
3066 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003067 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00003068 continue;
3069 }
3070 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003071 {
3072 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003073 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3074 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003075 return ValueObjectSP();
3076 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003077 }
Enrico Granata622be232014-10-21 20:52:14 +00003078 else if (root_clang_type_info.Test(eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003079 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003080 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 +00003081 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003082 {
3083 Error error;
3084 root = root->Dereference(error);
3085 if (error.Fail() || !root.get())
3086 {
3087 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003088 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3089 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003090 return ValueObjectSP();
3091 }
3092 else
3093 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003094 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003095 continue;
3096 }
3097 }
3098 else
3099 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003100 if (root->GetClangType().GetMinimumLanguage() == eLanguageTypeObjC
Enrico Granata622be232014-10-21 20:52:14 +00003101 && pointee_clang_type_info.AllClear(eTypeIsPointer)
Greg Clayton84db9102012-03-26 23:03:23 +00003102 && root->HasSyntheticValue()
3103 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00003104 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003105 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003106 }
3107 else
3108 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003109 if (!root.get())
3110 {
3111 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003112 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3113 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003114 return ValueObjectSP();
3115 }
3116 else
3117 {
3118 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003119 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003120 continue;
3121 }
3122 }
3123 }
Enrico Granata622be232014-10-21 20:52:14 +00003124 else if (root_clang_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003125 {
3126 root = root->GetSyntheticBitFieldChild(index, index, true);
3127 if (!root.get())
3128 {
3129 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003130 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3131 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003132 return ValueObjectSP();
3133 }
3134 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3135 {
3136 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003137 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3138 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003139 return root;
3140 }
3141 }
Enrico Granata622be232014-10-21 20:52:14 +00003142 else if (root_clang_type_info.Test(eTypeIsVector))
Enrico Granata08a1bb82013-06-19 00:00:45 +00003143 {
3144 root = root->GetChildAtIndex(index, true);
3145 if (!root.get())
3146 {
3147 *first_unparsed = expression_cstr;
3148 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3149 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3150 return ValueObjectSP();
3151 }
3152 else
3153 {
3154 *first_unparsed = end+1; // skip ]
3155 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3156 continue;
3157 }
3158 }
Enrico Granata86cc9822012-03-19 22:58:49 +00003159 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00003160 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003161 if (root->HasSyntheticValue())
3162 root = root->GetSyntheticValue();
3163 else if (!root->IsSynthetic())
3164 {
3165 *first_unparsed = expression_cstr;
3166 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3167 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3168 return ValueObjectSP();
3169 }
3170 // if we are here, then root itself is a synthetic VO.. should be good to go
3171
Enrico Granata27b625e2011-08-09 01:04:56 +00003172 if (!root.get())
3173 {
3174 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003175 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3176 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3177 return ValueObjectSP();
3178 }
3179 root = root->GetChildAtIndex(index, true);
3180 if (!root.get())
3181 {
3182 *first_unparsed = expression_cstr;
3183 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3184 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003185 return ValueObjectSP();
3186 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00003187 else
3188 {
3189 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003190 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00003191 continue;
3192 }
Enrico Granata27b625e2011-08-09 01:04:56 +00003193 }
3194 else
3195 {
3196 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003197 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3198 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003199 return ValueObjectSP();
3200 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003201 }
3202 else // we have a low and a high index
3203 {
3204 char *end = NULL;
3205 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3206 if (!end || end != separator_position) // if something weird is in our way return an error
3207 {
3208 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003209 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3210 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003211 return ValueObjectSP();
3212 }
3213 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3214 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3215 {
3216 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003217 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3218 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003219 return ValueObjectSP();
3220 }
3221 if (index_lower > index_higher) // swap indices if required
3222 {
3223 unsigned long temp = index_lower;
3224 index_lower = index_higher;
3225 index_higher = temp;
3226 }
Enrico Granata622be232014-10-21 20:52:14 +00003227 if (root_clang_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003228 {
3229 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3230 if (!root.get())
3231 {
3232 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003233 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3234 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003235 return ValueObjectSP();
3236 }
3237 else
3238 {
3239 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003240 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3241 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003242 return root;
3243 }
3244 }
Enrico Granata622be232014-10-21 20:52:14 +00003245 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 +00003246 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granata622be232014-10-21 20:52:14 +00003247 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003248 {
3249 Error error;
3250 root = root->Dereference(error);
3251 if (error.Fail() || !root.get())
3252 {
3253 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003254 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3255 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003256 return ValueObjectSP();
3257 }
3258 else
3259 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003260 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003261 continue;
3262 }
3263 }
3264 else
3265 {
3266 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003267 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3268 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003269 return root;
3270 }
3271 }
3272 break;
3273 }
3274 default: // some non-separator is in the way
3275 {
3276 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003277 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3278 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003279 return ValueObjectSP();
3280 break;
3281 }
3282 }
3283 }
3284}
3285
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003286int
3287ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3288 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00003289 ValueObjectSP root,
3290 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003291 ExpressionPathScanEndReason* reason_to_stop,
3292 ExpressionPathEndResultType* final_result,
3293 const GetValueForExpressionPathOptions& options,
3294 ExpressionPathAftermath* what_next)
3295{
3296 if (!root.get())
3297 return 0;
3298
3299 *first_unparsed = expression_cstr;
3300
3301 while (true)
3302 {
3303
3304 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3305
Greg Clayton57ee3062013-07-11 22:46:58 +00003306 ClangASTType root_clang_type = root->GetClangType();
3307 ClangASTType pointee_clang_type;
3308 Flags pointee_clang_type_info;
3309 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003310 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00003311 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003312
3313 if (!expression_cstr || *expression_cstr == '\0')
3314 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003315 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003316 list->Append(root);
3317 return 1;
3318 }
3319
3320 switch (*expression_cstr)
3321 {
3322 case '[':
3323 {
Enrico Granata622be232014-10-21 20:52:14 +00003324 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 +00003325 {
Enrico Granata622be232014-10-21 20:52:14 +00003326 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 +00003327 {
3328 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003329 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3330 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003331 return 0;
3332 }
3333 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3334 {
3335 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003336 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3337 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003338 return 0;
3339 }
3340 }
3341 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3342 {
Enrico Granata622be232014-10-21 20:52:14 +00003343 if (!root_clang_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003344 {
3345 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003346 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3347 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003348 return 0;
3349 }
3350 else // expand this into list
3351 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003352 const size_t max_index = root->GetNumChildren() - 1;
3353 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003354 {
3355 ValueObjectSP child =
3356 root->GetChildAtIndex(index, true);
3357 list->Append(child);
3358 }
3359 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003360 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3361 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003362 return max_index; // tell me number of items I added to the VOList
3363 }
3364 }
3365 const char *separator_position = ::strchr(expression_cstr+1,'-');
3366 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3367 if (!close_bracket_position) // if there is no ], this is a syntax error
3368 {
3369 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003370 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3371 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003372 return 0;
3373 }
3374 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3375 {
3376 char *end = NULL;
3377 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3378 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3379 {
3380 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003381 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3382 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003383 return 0;
3384 }
3385 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3386 {
Enrico Granata622be232014-10-21 20:52:14 +00003387 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003388 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003389 const size_t max_index = root->GetNumChildren() - 1;
3390 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003391 {
3392 ValueObjectSP child =
3393 root->GetChildAtIndex(index, true);
3394 list->Append(child);
3395 }
3396 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003397 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3398 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003399 return max_index; // tell me number of items I added to the VOList
3400 }
3401 else
3402 {
3403 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003404 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3405 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003406 return 0;
3407 }
3408 }
3409 // from here on we do have a valid index
Enrico Granata622be232014-10-21 20:52:14 +00003410 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003411 {
3412 root = root->GetChildAtIndex(index, true);
3413 if (!root.get())
3414 {
3415 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003416 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3417 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003418 return 0;
3419 }
3420 else
3421 {
3422 list->Append(root);
3423 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003424 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3425 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003426 return 1;
3427 }
3428 }
Enrico Granata622be232014-10-21 20:52:14 +00003429 else if (root_clang_type_info.Test(eTypeIsPointer))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003430 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003431 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 +00003432 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003433 {
3434 Error error;
3435 root = root->Dereference(error);
3436 if (error.Fail() || !root.get())
3437 {
3438 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003439 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3440 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003441 return 0;
3442 }
3443 else
3444 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003445 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003446 continue;
3447 }
3448 }
3449 else
3450 {
3451 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3452 if (!root.get())
3453 {
3454 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003455 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3456 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003457 return 0;
3458 }
3459 else
3460 {
3461 list->Append(root);
3462 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003463 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3464 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003465 return 1;
3466 }
3467 }
3468 }
3469 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3470 {
3471 root = root->GetSyntheticBitFieldChild(index, index, true);
3472 if (!root.get())
3473 {
3474 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003475 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3476 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003477 return 0;
3478 }
3479 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3480 {
3481 list->Append(root);
3482 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003483 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3484 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003485 return 1;
3486 }
3487 }
3488 }
3489 else // we have a low and a high index
3490 {
3491 char *end = NULL;
3492 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3493 if (!end || end != separator_position) // if something weird is in our way return an error
3494 {
3495 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003496 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3497 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003498 return 0;
3499 }
3500 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3501 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3502 {
3503 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003504 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3505 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003506 return 0;
3507 }
3508 if (index_lower > index_higher) // swap indices if required
3509 {
3510 unsigned long temp = index_lower;
3511 index_lower = index_higher;
3512 index_higher = temp;
3513 }
Enrico Granata622be232014-10-21 20:52:14 +00003514 if (root_clang_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003515 {
3516 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3517 if (!root.get())
3518 {
3519 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003520 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3521 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003522 return 0;
3523 }
3524 else
3525 {
3526 list->Append(root);
3527 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003528 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3529 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003530 return 1;
3531 }
3532 }
Enrico Granata622be232014-10-21 20:52:14 +00003533 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 +00003534 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granata622be232014-10-21 20:52:14 +00003535 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003536 {
3537 Error error;
3538 root = root->Dereference(error);
3539 if (error.Fail() || !root.get())
3540 {
3541 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003542 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3543 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003544 return 0;
3545 }
3546 else
3547 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003548 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003549 continue;
3550 }
3551 }
3552 else
3553 {
Johnny Chen44805302011-07-19 19:48:13 +00003554 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003555 index <= index_higher; index++)
3556 {
3557 ValueObjectSP child =
3558 root->GetChildAtIndex(index, true);
3559 list->Append(child);
3560 }
3561 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003562 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3563 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003564 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3565 }
3566 }
3567 break;
3568 }
3569 default: // some non-[ separator, or something entirely wrong, is in the way
3570 {
3571 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003572 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3573 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003574 return 0;
3575 break;
3576 }
3577 }
3578 }
3579}
3580
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003581void
3582ValueObject::LogValueObject (Log *log)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003583{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003584 if (log)
3585 return LogValueObject (log, DumpValueObjectOptions::DefaultOptions());
Greg Clayton1d3afba2010-10-05 00:00:42 +00003586}
3587
Enrico Granata0c489f52012-03-01 04:24:26 +00003588void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003589ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003590{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003591 if (log)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003592 {
3593 StreamString s;
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003594 Dump (s, options);
Greg Claytonf830dbb2012-03-22 18:15:37 +00003595 if (s.GetSize())
3596 log->PutCString(s.GetData());
3597 }
3598}
3599
3600void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003601ValueObject::Dump (Stream &s)
Enrico Granata0c489f52012-03-01 04:24:26 +00003602{
3603
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003604 ValueObjectPrinter printer(this,&s,DumpValueObjectOptions::DefaultOptions());
3605 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003606}
3607
3608void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003609ValueObject::Dump (Stream &s,
3610 const DumpValueObjectOptions& options)
Enrico Granata0c489f52012-03-01 04:24:26 +00003611{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003612 ValueObjectPrinter printer(this,&s,options);
3613 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003614}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003615
3616ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003617ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003618{
3619 ValueObjectSP valobj_sp;
3620
Enrico Granatac3e320a2011-08-02 17:27:39 +00003621 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003622 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003623 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003624
3625 DataExtractor data;
3626 data.SetByteOrder (m_data.GetByteOrder());
3627 data.SetAddressByteSize(m_data.GetAddressByteSize());
3628
Enrico Granata9f1e2042012-04-24 22:15:37 +00003629 if (IsBitfield())
3630 {
3631 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
Greg Clayton57ee3062013-07-11 22:46:58 +00003632 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Enrico Granata9f1e2042012-04-24 22:15:37 +00003633 }
3634 else
Greg Clayton57ee3062013-07-11 22:46:58 +00003635 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003636
3637 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003638 GetClangType(),
3639 name,
3640 data,
3641 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003642 }
Jim Ingham6035b672011-03-31 00:19:25 +00003643
3644 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003645 {
Greg Claytoneeb15652013-12-10 23:16:40 +00003646 ExecutionContext exe_ctx (GetExecutionContextRef());
3647 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003648 }
3649 return valobj_sp;
3650}
3651
Enrico Granata538a88a2014-10-09 18:24:30 +00003652ValueObjectSP
3653ValueObject::GetQualifiedRepresentationIfAvailable (lldb::DynamicValueType dynValue,
3654 bool synthValue)
3655{
3656 ValueObjectSP result_sp(GetSP());
3657
3658 switch (dynValue)
3659 {
3660 case lldb::eDynamicCanRunTarget:
3661 case lldb::eDynamicDontRunTarget:
3662 {
3663 if (!result_sp->IsDynamic())
3664 {
3665 if (result_sp->GetDynamicValue(dynValue))
3666 result_sp = result_sp->GetDynamicValue(dynValue);
3667 }
3668 }
3669 break;
3670 case lldb::eNoDynamicValues:
Enrico Granata538a88a2014-10-09 18:24:30 +00003671 {
3672 if (result_sp->IsDynamic())
3673 {
3674 if (result_sp->GetStaticValue())
3675 result_sp = result_sp->GetStaticValue();
3676 }
3677 }
3678 break;
3679 }
3680
3681 if (synthValue)
3682 {
3683 if (!result_sp->IsSynthetic())
3684 {
3685 if (result_sp->GetSyntheticValue())
3686 result_sp = result_sp->GetSyntheticValue();
3687 }
3688 }
3689 else
3690 {
3691 if (result_sp->IsSynthetic())
3692 {
3693 if (result_sp->GetNonSyntheticValue())
3694 result_sp = result_sp->GetNonSyntheticValue();
3695 }
3696 }
3697
3698 return result_sp;
3699}
3700
Greg Clayton759e7442014-07-19 00:12:57 +00003701lldb::addr_t
3702ValueObject::GetCPPVTableAddress (AddressType &address_type)
3703{
3704 ClangASTType pointee_type;
3705 ClangASTType this_type(GetClangType());
3706 uint32_t type_info = this_type.GetTypeInfo(&pointee_type);
3707 if (type_info)
3708 {
3709 bool ptr_or_ref = false;
Enrico Granata622be232014-10-21 20:52:14 +00003710 if (type_info & (eTypeIsPointer | eTypeIsReference))
Greg Clayton759e7442014-07-19 00:12:57 +00003711 {
3712 ptr_or_ref = true;
3713 type_info = pointee_type.GetTypeInfo();
3714 }
3715
Enrico Granata622be232014-10-21 20:52:14 +00003716 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus;
Greg Clayton759e7442014-07-19 00:12:57 +00003717 if ((type_info & cpp_class) == cpp_class)
3718 {
3719 if (ptr_or_ref)
3720 {
3721 address_type = GetAddressTypeOfChildren();
3722 return GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
3723 }
3724 else
3725 return GetAddressOf (false, &address_type);
3726 }
3727 }
3728
3729 address_type = eAddressTypeInvalid;
3730 return LLDB_INVALID_ADDRESS;
3731}
3732
Greg Claytonafacd142011-09-02 01:15:17 +00003733ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003734ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003735{
Jim Ingham58b59f92011-04-22 23:53:53 +00003736 if (m_deref_valobj)
3737 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003738
Greg Clayton54979cd2010-12-15 05:08:08 +00003739 const bool is_pointer_type = IsPointerType();
3740 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003741 {
3742 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003743 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003744
3745 std::string child_name_str;
3746 uint32_t child_byte_size = 0;
3747 int32_t child_byte_offset = 0;
3748 uint32_t child_bitfield_bit_size = 0;
3749 uint32_t child_bitfield_bit_offset = 0;
3750 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003751 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003752 const bool transparent_pointers = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00003753 ClangASTType clang_type = GetClangType();
3754 ClangASTType child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003755
Greg Claytoncc4d0142012-02-17 07:49:44 +00003756 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003757
Greg Clayton57ee3062013-07-11 22:46:58 +00003758 child_clang_type = clang_type.GetChildClangTypeAtIndex (&exe_ctx,
Greg Clayton57ee3062013-07-11 22:46:58 +00003759 0,
3760 transparent_pointers,
3761 omit_empty_base_classes,
3762 ignore_array_bounds,
3763 child_name_str,
3764 child_byte_size,
3765 child_byte_offset,
3766 child_bitfield_bit_size,
3767 child_bitfield_bit_offset,
3768 child_is_base_class,
Greg Clayton759e7442014-07-19 00:12:57 +00003769 child_is_deref_of_parent,
3770 this);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003771 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003772 {
3773 ConstString child_name;
3774 if (!child_name_str.empty())
3775 child_name.SetCString (child_name_str.c_str());
3776
Jim Ingham58b59f92011-04-22 23:53:53 +00003777 m_deref_valobj = new ValueObjectChild (*this,
Jim Ingham58b59f92011-04-22 23:53:53 +00003778 child_clang_type,
3779 child_name,
3780 child_byte_size,
3781 child_byte_offset,
3782 child_bitfield_bit_size,
3783 child_bitfield_bit_offset,
3784 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003785 child_is_deref_of_parent,
3786 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003787 }
3788 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003789
Jim Ingham58b59f92011-04-22 23:53:53 +00003790 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003791 {
3792 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003793 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003794 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003795 else
3796 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003797 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003798 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003799
3800 if (is_pointer_type)
3801 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3802 else
3803 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003804 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003805 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003806}
3807
Greg Claytonafacd142011-09-02 01:15:17 +00003808ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003809ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003810{
Jim Ingham78a685a2011-04-16 00:01:13 +00003811 if (m_addr_of_valobj_sp)
3812 return m_addr_of_valobj_sp;
3813
Greg Claytone0d378b2011-03-24 21:19:54 +00003814 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003815 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003816 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003817 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003818 if (addr != LLDB_INVALID_ADDRESS)
3819 {
3820 switch (address_type)
3821 {
3822 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003823 {
3824 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003825 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003826 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3827 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003828 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003829
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003830 case eAddressTypeFile:
3831 case eAddressTypeLoad:
3832 case eAddressTypeHost:
3833 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003834 ClangASTType clang_type = GetClangType();
3835 if (clang_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003836 {
3837 std::string name (1, '&');
3838 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003839 ExecutionContext exe_ctx (GetExecutionContextRef());
3840 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00003841 clang_type.GetPointerType(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003842 ConstString (name.c_str()),
3843 addr,
3844 eAddressTypeInvalid,
3845 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003846 }
3847 }
3848 break;
3849 }
3850 }
Sean Callananed185ab2013-04-19 19:47:32 +00003851 else
3852 {
3853 StreamString expr_path_strm;
3854 GetExpressionPath(expr_path_strm, true);
3855 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3856 }
3857
Jim Ingham78a685a2011-04-16 00:01:13 +00003858 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003859}
3860
Greg Clayton9a142cf2012-02-03 05:34:10 +00003861ValueObjectSP
3862ValueObject::Cast (const ClangASTType &clang_ast_type)
3863{
Greg Clayton81e871e2012-02-04 02:27:34 +00003864 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003865}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003866
Greg Claytonafacd142011-09-02 01:15:17 +00003867ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003868ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3869{
Greg Claytonafacd142011-09-02 01:15:17 +00003870 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003871 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003872 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003873
3874 if (ptr_value != LLDB_INVALID_ADDRESS)
3875 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003876 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003877 ExecutionContext exe_ctx (GetExecutionContextRef());
3878 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003879 name,
3880 ptr_addr,
3881 clang_ast_type);
3882 }
3883 return valobj_sp;
3884}
3885
Greg Claytonafacd142011-09-02 01:15:17 +00003886ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003887ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3888{
Greg Claytonafacd142011-09-02 01:15:17 +00003889 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003890 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003891 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003892
3893 if (ptr_value != LLDB_INVALID_ADDRESS)
3894 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003895 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003896 ExecutionContext exe_ctx (GetExecutionContextRef());
3897 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003898 name,
3899 ptr_addr,
3900 type_sp);
3901 }
3902 return valobj_sp;
3903}
3904
Jim Ingham6035b672011-03-31 00:19:25 +00003905ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003906 m_mod_id(),
3907 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003908 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003909{
3910}
3911
3912ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003913 m_mod_id(),
3914 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003915 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003916{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003917 ExecutionContext exe_ctx(exe_scope);
3918 TargetSP target_sp (exe_ctx.GetTargetSP());
3919 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003920 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003921 m_exe_ctx_ref.SetTargetSP (target_sp);
3922 ProcessSP process_sp (exe_ctx.GetProcessSP());
3923 if (!process_sp)
3924 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003925
Greg Claytoncc4d0142012-02-17 07:49:44 +00003926 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003927 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003928 m_mod_id = process_sp->GetModID();
3929 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003930
Greg Claytoncc4d0142012-02-17 07:49:44 +00003931 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003932
Greg Claytoncc4d0142012-02-17 07:49:44 +00003933 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003934 {
3935 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003936 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003937 }
Jim Ingham6035b672011-03-31 00:19:25 +00003938
Greg Claytoncc4d0142012-02-17 07:49:44 +00003939 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003940 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003941 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003942
Jason Molendab57e4a12013-11-04 09:33:30 +00003943 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003944 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003945 {
3946 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003947 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003948 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003949 if (frame_sp)
3950 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003951 }
3952 }
3953 }
Jim Ingham6035b672011-03-31 00:19:25 +00003954}
3955
3956ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003957 m_mod_id(),
3958 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003959 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003960{
3961}
3962
3963ValueObject::EvaluationPoint::~EvaluationPoint ()
3964{
3965}
3966
Jim Ingham6035b672011-03-31 00:19:25 +00003967// This function checks the EvaluationPoint against the current process state. If the current
3968// state matches the evaluation point, or the evaluation point is already invalid, then we return
3969// false, meaning "no change". If the current state is different, we update our state, and return
3970// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3971// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003972// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003973
3974bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003975ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003976{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003977
3978 // 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 +00003979 const bool thread_and_frame_only_if_stopped = true;
3980 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
Jim Ingham73ca05a2011-12-17 01:35:57 +00003981
Greg Claytoncc4d0142012-02-17 07:49:44 +00003982 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003983 return false;
3984
Jim Ingham6035b672011-03-31 00:19:25 +00003985 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003986 Process *process = exe_ctx.GetProcessPtr();
3987 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003988 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003989
Jim Ingham6035b672011-03-31 00:19:25 +00003990 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003991 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003992
Jim Ingham78a685a2011-04-16 00:01:13 +00003993 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3994 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003995 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003996 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003997
Greg Clayton23f59502012-07-17 03:23:13 +00003998 bool changed = false;
3999 const bool was_valid = m_mod_id.IsValid();
4000 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004001 {
4002 if (m_mod_id == current_mod_id)
4003 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00004004 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004005 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00004006 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004007 }
Jim Ingham9ee01152011-12-10 01:49:43 +00004008 else
4009 {
4010 m_mod_id = current_mod_id;
4011 m_needs_update = true;
4012 changed = true;
4013 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004014 }
Jim Ingham6035b672011-03-31 00:19:25 +00004015
Jim Ingham73ca05a2011-12-17 01:35:57 +00004016 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
4017 // That way we'll be sure to return a valid exe_scope.
4018 // 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 +00004019
Greg Claytoncc4d0142012-02-17 07:49:44 +00004020 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00004021 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00004022 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
4023 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00004024 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00004025 if (m_exe_ctx_ref.HasFrameRef())
4026 {
Jason Molendab57e4a12013-11-04 09:33:30 +00004027 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00004028 if (!frame_sp)
4029 {
4030 // We used to have a frame, but now it is gone
4031 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00004032 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00004033 }
4034 }
Greg Clayton262f80d2011-07-06 16:49:27 +00004035 }
Jim Ingham6035b672011-03-31 00:19:25 +00004036 else
4037 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00004038 // We used to have a thread, but now it is gone
4039 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00004040 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00004041 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00004042
Jim Ingham6035b672011-03-31 00:19:25 +00004043 }
Jim Ingham9ee01152011-12-10 01:49:43 +00004044 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00004045}
4046
Jim Ingham61be0902011-05-02 18:13:59 +00004047void
4048ValueObject::EvaluationPoint::SetUpdated ()
4049{
Greg Claytoncc4d0142012-02-17 07:49:44 +00004050 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
4051 if (process_sp)
4052 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00004053 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00004054}
4055
4056
Enrico Granataf2bbf712011-07-15 02:26:42 +00004057
4058void
Enrico Granata86cc9822012-03-19 22:58:49 +00004059ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004060{
Enrico Granata86cc9822012-03-19 22:58:49 +00004061 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4062 m_value_str.clear();
4063
4064 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4065 m_location_str.clear();
4066
4067 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
Enrico Granata86cc9822012-03-19 22:58:49 +00004068 m_summary_str.clear();
Enrico Granata86cc9822012-03-19 22:58:49 +00004069
4070 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4071 m_object_desc_str.clear();
4072
4073 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4074 {
4075 if (m_synthetic_value)
4076 m_synthetic_value = NULL;
4077 }
Enrico Granata744794a2014-09-05 21:46:22 +00004078
4079 if ((clear_mask & eClearUserVisibleDataItemsValidator) == eClearUserVisibleDataItemsValidator)
4080 m_validation_result.reset();
Johnny Chen44805302011-07-19 19:48:13 +00004081}
Enrico Granata9128ee22011-09-06 19:20:51 +00004082
4083SymbolContextScope *
4084ValueObject::GetSymbolContextScope()
4085{
4086 if (m_parent)
4087 {
4088 if (!m_parent->IsPointerOrReferenceType())
4089 return m_parent->GetSymbolContextScope();
4090 }
4091 return NULL;
4092}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004093
4094lldb::ValueObjectSP
4095ValueObject::CreateValueObjectFromExpression (const char* name,
4096 const char* expression,
4097 const ExecutionContext& exe_ctx)
4098{
4099 lldb::ValueObjectSP retval_sp;
4100 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4101 if (!target_sp)
4102 return retval_sp;
4103 if (!expression || !*expression)
4104 return retval_sp;
4105 target_sp->EvaluateExpression (expression,
4106 exe_ctx.GetFrameSP().get(),
4107 retval_sp);
4108 if (retval_sp && name && *name)
4109 retval_sp->SetName(ConstString(name));
4110 return retval_sp;
4111}
4112
4113lldb::ValueObjectSP
4114ValueObject::CreateValueObjectFromAddress (const char* name,
4115 uint64_t address,
4116 const ExecutionContext& exe_ctx,
4117 ClangASTType type)
4118{
Greg Clayton57ee3062013-07-11 22:46:58 +00004119 if (type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004120 {
Greg Clayton57ee3062013-07-11 22:46:58 +00004121 ClangASTType pointer_type(type.GetPointerType());
4122 if (pointer_type)
4123 {
4124 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4125 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4126 pointer_type,
4127 ConstString(name),
4128 buffer,
4129 lldb::endian::InlHostByteOrder(),
4130 exe_ctx.GetAddressByteSize()));
4131 if (ptr_result_valobj_sp)
4132 {
4133 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4134 Error err;
4135 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4136 if (ptr_result_valobj_sp && name && *name)
4137 ptr_result_valobj_sp->SetName(ConstString(name));
4138 }
4139 return ptr_result_valobj_sp;
4140 }
Enrico Granatab2698cd2012-09-13 18:27:09 +00004141 }
Greg Clayton57ee3062013-07-11 22:46:58 +00004142 return lldb::ValueObjectSP();
Enrico Granatab2698cd2012-09-13 18:27:09 +00004143}
4144
4145lldb::ValueObjectSP
4146ValueObject::CreateValueObjectFromData (const char* name,
Enrico Granata7ca1c762014-03-31 23:02:25 +00004147 const DataExtractor& data,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004148 const ExecutionContext& exe_ctx,
4149 ClangASTType type)
4150{
4151 lldb::ValueObjectSP new_value_sp;
4152 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004153 type,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004154 ConstString(name),
4155 data,
4156 LLDB_INVALID_ADDRESS);
4157 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4158 if (new_value_sp && name && *name)
4159 new_value_sp->SetName(ConstString(name));
4160 return new_value_sp;
4161}
Enrico Granata4873e522013-04-11 22:48:58 +00004162
4163ModuleSP
4164ValueObject::GetModule ()
4165{
4166 ValueObject* root(GetRoot());
4167 if (root != this)
4168 return root->GetModule();
4169 return lldb::ModuleSP();
4170}
4171
4172ValueObject*
4173ValueObject::GetRoot ()
4174{
4175 if (m_root)
4176 return m_root;
4177 ValueObject* parent = m_parent;
4178 if (!parent)
4179 return (m_root = this);
4180 while (parent->m_parent)
4181 {
4182 if (parent->m_root)
4183 return (m_root = parent->m_root);
4184 parent = parent->m_parent;
4185 }
4186 return (m_root = parent);
4187}
4188
4189AddressType
4190ValueObject::GetAddressTypeOfChildren()
4191{
4192 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
4193 {
4194 ValueObject* root(GetRoot());
4195 if (root != this)
4196 return root->GetAddressTypeOfChildren();
4197 }
4198 return m_address_type_of_ptr_or_ref_children;
4199}
4200
4201lldb::DynamicValueType
4202ValueObject::GetDynamicValueType ()
4203{
4204 ValueObject* with_dv_info = this;
4205 while (with_dv_info)
4206 {
4207 if (with_dv_info->HasDynamicValueTypeInfo())
4208 return with_dv_info->GetDynamicValueTypeImpl();
4209 with_dv_info = with_dv_info->m_parent;
4210 }
4211 return lldb::eNoDynamicValues;
4212}
Enrico Granata39d51412013-05-31 17:43:40 +00004213
Enrico Granata4873e522013-04-11 22:48:58 +00004214lldb::Format
4215ValueObject::GetFormat () const
4216{
4217 const ValueObject* with_fmt_info = this;
4218 while (with_fmt_info)
4219 {
4220 if (with_fmt_info->m_format != lldb::eFormatDefault)
4221 return with_fmt_info->m_format;
4222 with_fmt_info = with_fmt_info->m_parent;
4223 }
4224 return m_format;
4225}
Enrico Granatad07cfd32014-10-08 18:27:36 +00004226
Enrico Granatac1247f52014-11-06 21:23:20 +00004227lldb::LanguageType
4228ValueObject::GetPreferredDisplayLanguage ()
4229{
4230 lldb::LanguageType type = lldb::eLanguageTypeUnknown;
4231 if (GetRoot())
4232 {
4233 if (GetRoot() == this)
4234 {
4235 if (StackFrameSP frame_sp = GetFrameSP())
4236 {
4237 const SymbolContext& sc(frame_sp->GetSymbolContext(eSymbolContextCompUnit));
4238 if (CompileUnit* cu = sc.comp_unit)
4239 type = cu->GetLanguage();
4240 }
4241 }
4242 else
4243 {
4244 type = GetRoot()->GetPreferredDisplayLanguage();
4245 }
4246 }
4247 return type;
4248}
4249
Enrico Granatad07cfd32014-10-08 18:27:36 +00004250bool
4251ValueObject::CanProvideValue ()
4252{
Sean Callanan7375f3e2014-12-09 21:18:59 +00004253 // we need to support invalid types as providers of values because some bare-board
4254 // debugging scenarios have no notion of types, but still manage to have raw numeric
4255 // values for things like registers. sigh.
4256 const ClangASTType &type(GetClangType());
4257 return (false == type.IsValid()) || (0 != (type.GetTypeInfo() & eTypeHasValue));
4258}
4259
4260bool
4261ValueObject::IsChecksumEmpty ()
4262{
4263 return m_value_checksum.empty();
Enrico Granatad07cfd32014-10-08 18:27:36 +00004264}
Enrico Granata0c10a852014-12-08 23:13:56 +00004265
4266ValueObjectSP
4267ValueObject::Persist ()
4268{
4269 if (!UpdateValueIfNeeded())
4270 return nullptr;
4271
4272 TargetSP target_sp(GetTargetSP());
4273 if (!target_sp)
4274 return nullptr;
4275
4276 ConstString name(target_sp->GetPersistentVariables().GetNextPersistentVariableName());
4277
4278 ClangExpressionVariableSP clang_var_sp(new ClangExpressionVariable(target_sp.get(), GetValue(), name));
4279 if (clang_var_sp)
4280 {
4281 clang_var_sp->m_live_sp = clang_var_sp->m_frozen_sp;
4282 clang_var_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
4283 target_sp->GetPersistentVariables().AddVariable(clang_var_sp);
4284 }
4285
4286 return clang_var_sp->GetValueObject();
4287}
Enrico Granatae29df232014-12-09 19:51:20 +00004288
4289bool
4290ValueObject::IsSyntheticChildrenGenerated ()
4291{
4292 return m_is_synthetic_children_generated;
4293}
4294
4295void
4296ValueObject::SetSyntheticChildrenGenerated (bool b)
4297{
4298 m_is_synthetic_children_generated = b;
4299}