blob: 5487b601655505dc0e7f5d2631373600a3f38901 [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{
Greg Claytone221f822011-01-21 01:59:00 +00002543 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002544
Enrico Granata86cc9822012-03-19 22:58:49 +00002545 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002546 {
Enrico Granata4becb372011-06-29 22:27:15 +00002547 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2548 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2549 // the eHonorPointers mode is meant to produce strings in this latter format
2550 s.PutCString("*(");
2551 }
Greg Claytone221f822011-01-21 01:59:00 +00002552
Enrico Granata4becb372011-06-29 22:27:15 +00002553 ValueObject* parent = GetParent();
2554
2555 if (parent)
2556 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002557
2558 // if we are a deref_of_parent just because we are synthetic array
2559 // members made up to allow ptr[%d] syntax to work in variable
2560 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002561 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002562 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002563
Greg Claytone221f822011-01-21 01:59:00 +00002564 if (!IsBaseClass())
2565 {
2566 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002567 {
Greg Claytone221f822011-01-21 01:59:00 +00002568 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2569 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002570 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002571 ClangASTType non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002572 if (non_base_class_parent_clang_type)
2573 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002574 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002575 {
2576 s.PutCString("->");
2577 }
Enrico Granata4becb372011-06-29 22:27:15 +00002578 else
2579 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002580 const uint32_t non_base_class_parent_type_info = non_base_class_parent_clang_type.GetTypeInfo();
2581
Enrico Granata622be232014-10-21 20:52:14 +00002582 if (non_base_class_parent_type_info & eTypeIsPointer)
Enrico Granata4becb372011-06-29 22:27:15 +00002583 {
2584 s.PutCString("->");
2585 }
Enrico Granata622be232014-10-21 20:52:14 +00002586 else if ((non_base_class_parent_type_info & eTypeHasChildren) &&
2587 !(non_base_class_parent_type_info & eTypeIsArray))
Enrico Granata4becb372011-06-29 22:27:15 +00002588 {
2589 s.PutChar('.');
2590 }
Greg Claytone221f822011-01-21 01:59:00 +00002591 }
2592 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002593 }
Greg Claytone221f822011-01-21 01:59:00 +00002594
2595 const char *name = GetName().GetCString();
2596 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002597 {
Greg Claytone221f822011-01-21 01:59:00 +00002598 if (qualify_cxx_base_classes)
2599 {
2600 if (GetBaseClassPath (s))
2601 s.PutCString("::");
2602 }
2603 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002604 }
2605 }
2606 }
2607
Enrico Granata86cc9822012-03-19 22:58:49 +00002608 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002609 {
Greg Claytone221f822011-01-21 01:59:00 +00002610 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002611 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002612}
2613
Greg Claytonafacd142011-09-02 01:15:17 +00002614ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002615ValueObject::GetValueForExpressionPath(const char* expression,
2616 const char** first_unparsed,
2617 ExpressionPathScanEndReason* reason_to_stop,
2618 ExpressionPathEndResultType* final_value_type,
2619 const GetValueForExpressionPathOptions& options,
2620 ExpressionPathAftermath* final_task_on_target)
2621{
2622
2623 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002624 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2625 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002626 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002627
2628 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2629 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2630 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2631 final_value_type ? final_value_type : &dummy_final_value_type,
2632 options,
2633 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2634
Enrico Granata86cc9822012-03-19 22:58:49 +00002635 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002636 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002637
Enrico Granata86cc9822012-03-19 22:58:49 +00002638 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 +00002639 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002640 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002641 {
2642 Error error;
2643 ValueObjectSP final_value = ret_val->Dereference(error);
2644 if (error.Fail() || !final_value.get())
2645 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002646 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002647 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002648 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002649 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002650 return ValueObjectSP();
2651 }
2652 else
2653 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002654 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002655 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002656 return final_value;
2657 }
2658 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002659 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002660 {
2661 Error error;
2662 ValueObjectSP final_value = ret_val->AddressOf(error);
2663 if (error.Fail() || !final_value.get())
2664 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002665 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002666 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002667 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002668 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002669 return ValueObjectSP();
2670 }
2671 else
2672 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002673 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002674 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002675 return final_value;
2676 }
2677 }
2678 }
2679 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2680}
2681
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002682int
2683ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002684 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002685 const char** first_unparsed,
2686 ExpressionPathScanEndReason* reason_to_stop,
2687 ExpressionPathEndResultType* final_value_type,
2688 const GetValueForExpressionPathOptions& options,
2689 ExpressionPathAftermath* final_task_on_target)
2690{
2691 const char* dummy_first_unparsed;
2692 ExpressionPathScanEndReason dummy_reason_to_stop;
2693 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002694 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002695
2696 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2697 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2698 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2699 final_value_type ? final_value_type : &dummy_final_value_type,
2700 options,
2701 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2702
2703 if (!ret_val.get()) // if there are errors, I add nothing to the list
2704 return 0;
2705
Enrico Granata86ea8d82012-03-29 01:34:34 +00002706 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002707 {
2708 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002709 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002710 {
2711 list->Append(ret_val);
2712 return 1;
2713 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002714 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 +00002715 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002716 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002717 {
2718 Error error;
2719 ValueObjectSP final_value = ret_val->Dereference(error);
2720 if (error.Fail() || !final_value.get())
2721 {
Greg Clayton23f59502012-07-17 03:23:13 +00002722 if (reason_to_stop)
2723 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2724 if (final_value_type)
2725 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002726 return 0;
2727 }
2728 else
2729 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002730 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002731 list->Append(final_value);
2732 return 1;
2733 }
2734 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002735 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002736 {
2737 Error error;
2738 ValueObjectSP final_value = ret_val->AddressOf(error);
2739 if (error.Fail() || !final_value.get())
2740 {
Greg Clayton23f59502012-07-17 03:23:13 +00002741 if (reason_to_stop)
2742 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2743 if (final_value_type)
2744 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002745 return 0;
2746 }
2747 else
2748 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002749 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002750 list->Append(final_value);
2751 return 1;
2752 }
2753 }
2754 }
2755 }
2756 else
2757 {
2758 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2759 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2760 ret_val,
2761 list,
2762 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2763 final_value_type ? final_value_type : &dummy_final_value_type,
2764 options,
2765 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2766 }
2767 // in any non-covered case, just do the obviously right thing
2768 list->Append(ret_val);
2769 return 1;
2770}
2771
Greg Claytonafacd142011-09-02 01:15:17 +00002772ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002773ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2774 const char** first_unparsed,
2775 ExpressionPathScanEndReason* reason_to_stop,
2776 ExpressionPathEndResultType* final_result,
2777 const GetValueForExpressionPathOptions& options,
2778 ExpressionPathAftermath* what_next)
2779{
2780 ValueObjectSP root = GetSP();
2781
2782 if (!root.get())
2783 return ValueObjectSP();
2784
2785 *first_unparsed = expression_cstr;
2786
2787 while (true)
2788 {
2789
2790 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2791
Greg Clayton57ee3062013-07-11 22:46:58 +00002792 ClangASTType root_clang_type = root->GetClangType();
2793 ClangASTType pointee_clang_type;
2794 Flags pointee_clang_type_info;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002795
Greg Clayton57ee3062013-07-11 22:46:58 +00002796 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002797 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00002798 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002799
2800 if (!expression_cstr || *expression_cstr == '\0')
2801 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002802 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002803 return root;
2804 }
2805
2806 switch (*expression_cstr)
2807 {
2808 case '-':
2809 {
2810 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granata622be232014-10-21 20:52:14 +00002811 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 +00002812 {
2813 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002814 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2815 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002816 return ValueObjectSP();
2817 }
Enrico Granata622be232014-10-21 20:52:14 +00002818 if (root_clang_type_info.Test(eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2819 root_clang_type_info.Test(eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002820 options.m_no_fragile_ivar)
2821 {
2822 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002823 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2824 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002825 return ValueObjectSP();
2826 }
2827 if (expression_cstr[1] != '>')
2828 {
2829 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002830 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2831 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002832 return ValueObjectSP();
2833 }
2834 expression_cstr++; // skip the -
2835 }
2836 case '.': // or fallthrough from ->
2837 {
2838 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granata622be232014-10-21 20:52:14 +00002839 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 +00002840 {
2841 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002842 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2843 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002844 return ValueObjectSP();
2845 }
2846 expression_cstr++; // skip .
2847 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2848 ConstString child_name;
2849 if (!next_separator) // if no other separator just expand this last layer
2850 {
2851 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002852 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2853
2854 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002855 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002856 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002857 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2858 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002859 return child_valobj_sp;
2860 }
2861 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2862 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002863 if (root->IsSynthetic())
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002864 {
2865 *first_unparsed = expression_cstr;
Enrico Granatad07cfd32014-10-08 18:27:36 +00002866 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchSyntheticChild;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002867 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2868 return ValueObjectSP();
2869 }
2870
2871 child_valobj_sp = root->GetSyntheticValue();
Enrico Granata86cc9822012-03-19 22:58:49 +00002872 if (child_valobj_sp.get())
2873 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002874 }
2875
2876 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2877 // so we hit the "else" branch, and return an error
2878 if(child_valobj_sp.get()) // if it worked, just return
2879 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002880 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002881 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2882 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002883 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002884 }
2885 else
2886 {
2887 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002888 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2889 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002890 return ValueObjectSP();
2891 }
2892 }
2893 else // other layers do expand
2894 {
2895 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002896 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2897 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002898 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002899 root = child_valobj_sp;
2900 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002901 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002902 continue;
2903 }
2904 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2905 {
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002906 if (root->IsSynthetic())
2907 {
2908 *first_unparsed = expression_cstr;
2909 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2910 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2911 return ValueObjectSP();
2912 }
2913
Enrico Granata86cc9822012-03-19 22:58:49 +00002914 child_valobj_sp = root->GetSyntheticValue(true);
2915 if (child_valobj_sp)
2916 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002917 }
2918
2919 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2920 // so we hit the "else" branch, and return an error
2921 if(child_valobj_sp.get()) // if it worked, move on
2922 {
2923 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002924 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002925 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002926 continue;
2927 }
2928 else
2929 {
2930 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002931 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2932 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002933 return ValueObjectSP();
2934 }
2935 }
2936 break;
2937 }
2938 case '[':
2939 {
Enrico Granata622be232014-10-21 20:52:14 +00002940 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 +00002941 {
Enrico Granata622be232014-10-21 20:52:14 +00002942 if (!root_clang_type_info.Test(eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002943 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002944 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2945 {
2946 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002947 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2948 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002949 return ValueObjectSP();
2950 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002951 }
2952 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2953 {
2954 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002955 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2956 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002957 return ValueObjectSP();
2958 }
2959 }
2960 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2961 {
Enrico Granata622be232014-10-21 20:52:14 +00002962 if (!root_clang_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002963 {
2964 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002965 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2966 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002967 return ValueObjectSP();
2968 }
2969 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2970 {
2971 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002972 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2973 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002974 return root;
2975 }
2976 }
2977 const char *separator_position = ::strchr(expression_cstr+1,'-');
2978 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2979 if (!close_bracket_position) // if there is no ], this is a syntax error
2980 {
2981 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002982 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2983 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002984 return ValueObjectSP();
2985 }
2986 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2987 {
2988 char *end = NULL;
2989 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2990 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2991 {
2992 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002993 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2994 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002995 return ValueObjectSP();
2996 }
2997 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2998 {
Enrico Granata622be232014-10-21 20:52:14 +00002999 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003000 {
3001 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003002 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3003 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003004 return root;
3005 }
3006 else
3007 {
3008 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003009 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3010 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003011 return ValueObjectSP();
3012 }
3013 }
3014 // from here on we do have a valid index
Enrico Granata622be232014-10-21 20:52:14 +00003015 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003016 {
Greg Claytondaf515f2011-07-09 20:12:33 +00003017 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
3018 if (!child_valobj_sp)
3019 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003020 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00003021 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
3022 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00003023 if (child_valobj_sp)
3024 {
3025 root = child_valobj_sp;
3026 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003027 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00003028 continue;
3029 }
3030 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003031 {
3032 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003033 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3034 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003035 return ValueObjectSP();
3036 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003037 }
Enrico Granata622be232014-10-21 20:52:14 +00003038 else if (root_clang_type_info.Test(eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003039 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003040 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 +00003041 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003042 {
3043 Error error;
3044 root = root->Dereference(error);
3045 if (error.Fail() || !root.get())
3046 {
3047 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003048 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3049 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003050 return ValueObjectSP();
3051 }
3052 else
3053 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003054 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003055 continue;
3056 }
3057 }
3058 else
3059 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003060 if (root->GetClangType().GetMinimumLanguage() == eLanguageTypeObjC
Enrico Granata622be232014-10-21 20:52:14 +00003061 && pointee_clang_type_info.AllClear(eTypeIsPointer)
Greg Clayton84db9102012-03-26 23:03:23 +00003062 && root->HasSyntheticValue()
3063 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00003064 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003065 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003066 }
3067 else
3068 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003069 if (!root.get())
3070 {
3071 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003072 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3073 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003074 return ValueObjectSP();
3075 }
3076 else
3077 {
3078 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003079 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003080 continue;
3081 }
3082 }
3083 }
Enrico Granata622be232014-10-21 20:52:14 +00003084 else if (root_clang_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003085 {
3086 root = root->GetSyntheticBitFieldChild(index, index, true);
3087 if (!root.get())
3088 {
3089 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003090 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3091 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003092 return ValueObjectSP();
3093 }
3094 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3095 {
3096 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003097 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3098 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003099 return root;
3100 }
3101 }
Enrico Granata622be232014-10-21 20:52:14 +00003102 else if (root_clang_type_info.Test(eTypeIsVector))
Enrico Granata08a1bb82013-06-19 00:00:45 +00003103 {
3104 root = root->GetChildAtIndex(index, true);
3105 if (!root.get())
3106 {
3107 *first_unparsed = expression_cstr;
3108 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3109 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3110 return ValueObjectSP();
3111 }
3112 else
3113 {
3114 *first_unparsed = end+1; // skip ]
3115 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3116 continue;
3117 }
3118 }
Enrico Granata86cc9822012-03-19 22:58:49 +00003119 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00003120 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003121 if (root->HasSyntheticValue())
3122 root = root->GetSyntheticValue();
3123 else if (!root->IsSynthetic())
3124 {
3125 *first_unparsed = expression_cstr;
3126 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3127 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3128 return ValueObjectSP();
3129 }
3130 // if we are here, then root itself is a synthetic VO.. should be good to go
3131
Enrico Granata27b625e2011-08-09 01:04:56 +00003132 if (!root.get())
3133 {
3134 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003135 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3136 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3137 return ValueObjectSP();
3138 }
3139 root = root->GetChildAtIndex(index, true);
3140 if (!root.get())
3141 {
3142 *first_unparsed = expression_cstr;
3143 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3144 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003145 return ValueObjectSP();
3146 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00003147 else
3148 {
3149 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003150 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00003151 continue;
3152 }
Enrico Granata27b625e2011-08-09 01:04:56 +00003153 }
3154 else
3155 {
3156 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003157 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3158 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003159 return ValueObjectSP();
3160 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003161 }
3162 else // we have a low and a high index
3163 {
3164 char *end = NULL;
3165 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3166 if (!end || end != separator_position) // if something weird is in our way return an error
3167 {
3168 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003169 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3170 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003171 return ValueObjectSP();
3172 }
3173 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3174 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3175 {
3176 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003177 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3178 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003179 return ValueObjectSP();
3180 }
3181 if (index_lower > index_higher) // swap indices if required
3182 {
3183 unsigned long temp = index_lower;
3184 index_lower = index_higher;
3185 index_higher = temp;
3186 }
Enrico Granata622be232014-10-21 20:52:14 +00003187 if (root_clang_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003188 {
3189 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3190 if (!root.get())
3191 {
3192 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003193 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3194 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003195 return ValueObjectSP();
3196 }
3197 else
3198 {
3199 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003200 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3201 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003202 return root;
3203 }
3204 }
Enrico Granata622be232014-10-21 20:52:14 +00003205 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 +00003206 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granata622be232014-10-21 20:52:14 +00003207 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003208 {
3209 Error error;
3210 root = root->Dereference(error);
3211 if (error.Fail() || !root.get())
3212 {
3213 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003214 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3215 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003216 return ValueObjectSP();
3217 }
3218 else
3219 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003220 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003221 continue;
3222 }
3223 }
3224 else
3225 {
3226 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003227 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3228 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003229 return root;
3230 }
3231 }
3232 break;
3233 }
3234 default: // some non-separator is in the way
3235 {
3236 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003237 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3238 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003239 return ValueObjectSP();
3240 break;
3241 }
3242 }
3243 }
3244}
3245
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003246int
3247ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3248 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00003249 ValueObjectSP root,
3250 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003251 ExpressionPathScanEndReason* reason_to_stop,
3252 ExpressionPathEndResultType* final_result,
3253 const GetValueForExpressionPathOptions& options,
3254 ExpressionPathAftermath* what_next)
3255{
3256 if (!root.get())
3257 return 0;
3258
3259 *first_unparsed = expression_cstr;
3260
3261 while (true)
3262 {
3263
3264 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3265
Greg Clayton57ee3062013-07-11 22:46:58 +00003266 ClangASTType root_clang_type = root->GetClangType();
3267 ClangASTType pointee_clang_type;
3268 Flags pointee_clang_type_info;
3269 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003270 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00003271 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003272
3273 if (!expression_cstr || *expression_cstr == '\0')
3274 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003275 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003276 list->Append(root);
3277 return 1;
3278 }
3279
3280 switch (*expression_cstr)
3281 {
3282 case '[':
3283 {
Enrico Granata622be232014-10-21 20:52:14 +00003284 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 +00003285 {
Enrico Granata622be232014-10-21 20:52:14 +00003286 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 +00003287 {
3288 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003289 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3290 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003291 return 0;
3292 }
3293 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3294 {
3295 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003296 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3297 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003298 return 0;
3299 }
3300 }
3301 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3302 {
Enrico Granata622be232014-10-21 20:52:14 +00003303 if (!root_clang_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003304 {
3305 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003306 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3307 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003308 return 0;
3309 }
3310 else // expand this into list
3311 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003312 const size_t max_index = root->GetNumChildren() - 1;
3313 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003314 {
3315 ValueObjectSP child =
3316 root->GetChildAtIndex(index, true);
3317 list->Append(child);
3318 }
3319 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003320 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3321 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003322 return max_index; // tell me number of items I added to the VOList
3323 }
3324 }
3325 const char *separator_position = ::strchr(expression_cstr+1,'-');
3326 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3327 if (!close_bracket_position) // if there is no ], this is a syntax error
3328 {
3329 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003330 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3331 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003332 return 0;
3333 }
3334 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3335 {
3336 char *end = NULL;
3337 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3338 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3339 {
3340 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003341 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3342 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003343 return 0;
3344 }
3345 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3346 {
Enrico Granata622be232014-10-21 20:52:14 +00003347 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003348 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003349 const size_t max_index = root->GetNumChildren() - 1;
3350 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003351 {
3352 ValueObjectSP child =
3353 root->GetChildAtIndex(index, true);
3354 list->Append(child);
3355 }
3356 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003357 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3358 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003359 return max_index; // tell me number of items I added to the VOList
3360 }
3361 else
3362 {
3363 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003364 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3365 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003366 return 0;
3367 }
3368 }
3369 // from here on we do have a valid index
Enrico Granata622be232014-10-21 20:52:14 +00003370 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003371 {
3372 root = root->GetChildAtIndex(index, true);
3373 if (!root.get())
3374 {
3375 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003376 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3377 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003378 return 0;
3379 }
3380 else
3381 {
3382 list->Append(root);
3383 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003384 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3385 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003386 return 1;
3387 }
3388 }
Enrico Granata622be232014-10-21 20:52:14 +00003389 else if (root_clang_type_info.Test(eTypeIsPointer))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003390 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003391 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 +00003392 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003393 {
3394 Error error;
3395 root = root->Dereference(error);
3396 if (error.Fail() || !root.get())
3397 {
3398 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003399 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3400 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003401 return 0;
3402 }
3403 else
3404 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003405 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003406 continue;
3407 }
3408 }
3409 else
3410 {
3411 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3412 if (!root.get())
3413 {
3414 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003415 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3416 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003417 return 0;
3418 }
3419 else
3420 {
3421 list->Append(root);
3422 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003423 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3424 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003425 return 1;
3426 }
3427 }
3428 }
3429 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3430 {
3431 root = root->GetSyntheticBitFieldChild(index, index, true);
3432 if (!root.get())
3433 {
3434 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003435 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3436 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003437 return 0;
3438 }
3439 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3440 {
3441 list->Append(root);
3442 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003443 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3444 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003445 return 1;
3446 }
3447 }
3448 }
3449 else // we have a low and a high index
3450 {
3451 char *end = NULL;
3452 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3453 if (!end || end != separator_position) // if something weird is in our way return an error
3454 {
3455 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003456 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3457 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003458 return 0;
3459 }
3460 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3461 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3462 {
3463 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003464 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3465 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003466 return 0;
3467 }
3468 if (index_lower > index_higher) // swap indices if required
3469 {
3470 unsigned long temp = index_lower;
3471 index_lower = index_higher;
3472 index_higher = temp;
3473 }
Enrico Granata622be232014-10-21 20:52:14 +00003474 if (root_clang_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003475 {
3476 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3477 if (!root.get())
3478 {
3479 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003480 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3481 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003482 return 0;
3483 }
3484 else
3485 {
3486 list->Append(root);
3487 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003488 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3489 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003490 return 1;
3491 }
3492 }
Enrico Granata622be232014-10-21 20:52:14 +00003493 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 +00003494 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granata622be232014-10-21 20:52:14 +00003495 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003496 {
3497 Error error;
3498 root = root->Dereference(error);
3499 if (error.Fail() || !root.get())
3500 {
3501 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003502 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3503 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003504 return 0;
3505 }
3506 else
3507 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003508 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003509 continue;
3510 }
3511 }
3512 else
3513 {
Johnny Chen44805302011-07-19 19:48:13 +00003514 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003515 index <= index_higher; index++)
3516 {
3517 ValueObjectSP child =
3518 root->GetChildAtIndex(index, true);
3519 list->Append(child);
3520 }
3521 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003522 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3523 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003524 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3525 }
3526 }
3527 break;
3528 }
3529 default: // some non-[ separator, or something entirely wrong, is in the way
3530 {
3531 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003532 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3533 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003534 return 0;
3535 break;
3536 }
3537 }
3538 }
3539}
3540
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003541void
3542ValueObject::LogValueObject (Log *log)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003543{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003544 if (log)
3545 return LogValueObject (log, DumpValueObjectOptions::DefaultOptions());
Greg Clayton1d3afba2010-10-05 00:00:42 +00003546}
3547
Enrico Granata0c489f52012-03-01 04:24:26 +00003548void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003549ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003550{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003551 if (log)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003552 {
3553 StreamString s;
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003554 Dump (s, options);
Greg Claytonf830dbb2012-03-22 18:15:37 +00003555 if (s.GetSize())
3556 log->PutCString(s.GetData());
3557 }
3558}
3559
3560void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003561ValueObject::Dump (Stream &s)
Enrico Granata0c489f52012-03-01 04:24:26 +00003562{
3563
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003564 ValueObjectPrinter printer(this,&s,DumpValueObjectOptions::DefaultOptions());
3565 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003566}
3567
3568void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003569ValueObject::Dump (Stream &s,
3570 const DumpValueObjectOptions& options)
Enrico Granata0c489f52012-03-01 04:24:26 +00003571{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003572 ValueObjectPrinter printer(this,&s,options);
3573 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003574}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003575
3576ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003577ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003578{
3579 ValueObjectSP valobj_sp;
3580
Enrico Granatac3e320a2011-08-02 17:27:39 +00003581 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003582 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003583 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003584
3585 DataExtractor data;
3586 data.SetByteOrder (m_data.GetByteOrder());
3587 data.SetAddressByteSize(m_data.GetAddressByteSize());
3588
Enrico Granata9f1e2042012-04-24 22:15:37 +00003589 if (IsBitfield())
3590 {
3591 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
Greg Clayton57ee3062013-07-11 22:46:58 +00003592 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Enrico Granata9f1e2042012-04-24 22:15:37 +00003593 }
3594 else
Greg Clayton57ee3062013-07-11 22:46:58 +00003595 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003596
3597 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003598 GetClangType(),
3599 name,
3600 data,
3601 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003602 }
Jim Ingham6035b672011-03-31 00:19:25 +00003603
3604 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003605 {
Greg Claytoneeb15652013-12-10 23:16:40 +00003606 ExecutionContext exe_ctx (GetExecutionContextRef());
3607 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003608 }
3609 return valobj_sp;
3610}
3611
Enrico Granata538a88a2014-10-09 18:24:30 +00003612ValueObjectSP
3613ValueObject::GetQualifiedRepresentationIfAvailable (lldb::DynamicValueType dynValue,
3614 bool synthValue)
3615{
3616 ValueObjectSP result_sp(GetSP());
3617
3618 switch (dynValue)
3619 {
3620 case lldb::eDynamicCanRunTarget:
3621 case lldb::eDynamicDontRunTarget:
3622 {
3623 if (!result_sp->IsDynamic())
3624 {
3625 if (result_sp->GetDynamicValue(dynValue))
3626 result_sp = result_sp->GetDynamicValue(dynValue);
3627 }
3628 }
3629 break;
3630 case lldb::eNoDynamicValues:
Enrico Granata538a88a2014-10-09 18:24:30 +00003631 {
3632 if (result_sp->IsDynamic())
3633 {
3634 if (result_sp->GetStaticValue())
3635 result_sp = result_sp->GetStaticValue();
3636 }
3637 }
3638 break;
3639 }
3640
3641 if (synthValue)
3642 {
3643 if (!result_sp->IsSynthetic())
3644 {
3645 if (result_sp->GetSyntheticValue())
3646 result_sp = result_sp->GetSyntheticValue();
3647 }
3648 }
3649 else
3650 {
3651 if (result_sp->IsSynthetic())
3652 {
3653 if (result_sp->GetNonSyntheticValue())
3654 result_sp = result_sp->GetNonSyntheticValue();
3655 }
3656 }
3657
3658 return result_sp;
3659}
3660
Greg Clayton759e7442014-07-19 00:12:57 +00003661lldb::addr_t
3662ValueObject::GetCPPVTableAddress (AddressType &address_type)
3663{
3664 ClangASTType pointee_type;
3665 ClangASTType this_type(GetClangType());
3666 uint32_t type_info = this_type.GetTypeInfo(&pointee_type);
3667 if (type_info)
3668 {
3669 bool ptr_or_ref = false;
Enrico Granata622be232014-10-21 20:52:14 +00003670 if (type_info & (eTypeIsPointer | eTypeIsReference))
Greg Clayton759e7442014-07-19 00:12:57 +00003671 {
3672 ptr_or_ref = true;
3673 type_info = pointee_type.GetTypeInfo();
3674 }
3675
Enrico Granata622be232014-10-21 20:52:14 +00003676 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus;
Greg Clayton759e7442014-07-19 00:12:57 +00003677 if ((type_info & cpp_class) == cpp_class)
3678 {
3679 if (ptr_or_ref)
3680 {
3681 address_type = GetAddressTypeOfChildren();
3682 return GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
3683 }
3684 else
3685 return GetAddressOf (false, &address_type);
3686 }
3687 }
3688
3689 address_type = eAddressTypeInvalid;
3690 return LLDB_INVALID_ADDRESS;
3691}
3692
Greg Claytonafacd142011-09-02 01:15:17 +00003693ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003694ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003695{
Jim Ingham58b59f92011-04-22 23:53:53 +00003696 if (m_deref_valobj)
3697 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003698
Greg Clayton54979cd2010-12-15 05:08:08 +00003699 const bool is_pointer_type = IsPointerType();
3700 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003701 {
3702 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003703 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003704
3705 std::string child_name_str;
3706 uint32_t child_byte_size = 0;
3707 int32_t child_byte_offset = 0;
3708 uint32_t child_bitfield_bit_size = 0;
3709 uint32_t child_bitfield_bit_offset = 0;
3710 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003711 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003712 const bool transparent_pointers = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00003713 ClangASTType clang_type = GetClangType();
3714 ClangASTType child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003715
Greg Claytoncc4d0142012-02-17 07:49:44 +00003716 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003717
Greg Clayton57ee3062013-07-11 22:46:58 +00003718 child_clang_type = clang_type.GetChildClangTypeAtIndex (&exe_ctx,
Greg Clayton57ee3062013-07-11 22:46:58 +00003719 0,
3720 transparent_pointers,
3721 omit_empty_base_classes,
3722 ignore_array_bounds,
3723 child_name_str,
3724 child_byte_size,
3725 child_byte_offset,
3726 child_bitfield_bit_size,
3727 child_bitfield_bit_offset,
3728 child_is_base_class,
Greg Clayton759e7442014-07-19 00:12:57 +00003729 child_is_deref_of_parent,
3730 this);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003731 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003732 {
3733 ConstString child_name;
3734 if (!child_name_str.empty())
3735 child_name.SetCString (child_name_str.c_str());
3736
Jim Ingham58b59f92011-04-22 23:53:53 +00003737 m_deref_valobj = new ValueObjectChild (*this,
Jim Ingham58b59f92011-04-22 23:53:53 +00003738 child_clang_type,
3739 child_name,
3740 child_byte_size,
3741 child_byte_offset,
3742 child_bitfield_bit_size,
3743 child_bitfield_bit_offset,
3744 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003745 child_is_deref_of_parent,
3746 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003747 }
3748 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003749
Jim Ingham58b59f92011-04-22 23:53:53 +00003750 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003751 {
3752 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003753 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003754 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003755 else
3756 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003757 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003758 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003759
3760 if (is_pointer_type)
3761 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3762 else
3763 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003764 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003765 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003766}
3767
Greg Claytonafacd142011-09-02 01:15:17 +00003768ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003769ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003770{
Jim Ingham78a685a2011-04-16 00:01:13 +00003771 if (m_addr_of_valobj_sp)
3772 return m_addr_of_valobj_sp;
3773
Greg Claytone0d378b2011-03-24 21:19:54 +00003774 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003775 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003776 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003777 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003778 if (addr != LLDB_INVALID_ADDRESS)
3779 {
3780 switch (address_type)
3781 {
3782 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003783 {
3784 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003785 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003786 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3787 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003788 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003789
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003790 case eAddressTypeFile:
3791 case eAddressTypeLoad:
3792 case eAddressTypeHost:
3793 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003794 ClangASTType clang_type = GetClangType();
3795 if (clang_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003796 {
3797 std::string name (1, '&');
3798 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003799 ExecutionContext exe_ctx (GetExecutionContextRef());
3800 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00003801 clang_type.GetPointerType(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003802 ConstString (name.c_str()),
3803 addr,
3804 eAddressTypeInvalid,
3805 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003806 }
3807 }
3808 break;
3809 }
3810 }
Sean Callananed185ab2013-04-19 19:47:32 +00003811 else
3812 {
3813 StreamString expr_path_strm;
3814 GetExpressionPath(expr_path_strm, true);
3815 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3816 }
3817
Jim Ingham78a685a2011-04-16 00:01:13 +00003818 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003819}
3820
Greg Clayton9a142cf2012-02-03 05:34:10 +00003821ValueObjectSP
3822ValueObject::Cast (const ClangASTType &clang_ast_type)
3823{
Greg Clayton81e871e2012-02-04 02:27:34 +00003824 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003825}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003826
Greg Claytonafacd142011-09-02 01:15:17 +00003827ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003828ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3829{
Greg Claytonafacd142011-09-02 01:15:17 +00003830 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003831 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003832 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003833
3834 if (ptr_value != LLDB_INVALID_ADDRESS)
3835 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003836 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003837 ExecutionContext exe_ctx (GetExecutionContextRef());
3838 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003839 name,
3840 ptr_addr,
3841 clang_ast_type);
3842 }
3843 return valobj_sp;
3844}
3845
Greg Claytonafacd142011-09-02 01:15:17 +00003846ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003847ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3848{
Greg Claytonafacd142011-09-02 01:15:17 +00003849 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003850 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003851 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003852
3853 if (ptr_value != LLDB_INVALID_ADDRESS)
3854 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003855 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003856 ExecutionContext exe_ctx (GetExecutionContextRef());
3857 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003858 name,
3859 ptr_addr,
3860 type_sp);
3861 }
3862 return valobj_sp;
3863}
3864
Jim Ingham6035b672011-03-31 00:19:25 +00003865ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003866 m_mod_id(),
3867 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003868 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003869{
3870}
3871
3872ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003873 m_mod_id(),
3874 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003875 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003876{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003877 ExecutionContext exe_ctx(exe_scope);
3878 TargetSP target_sp (exe_ctx.GetTargetSP());
3879 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003880 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003881 m_exe_ctx_ref.SetTargetSP (target_sp);
3882 ProcessSP process_sp (exe_ctx.GetProcessSP());
3883 if (!process_sp)
3884 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003885
Greg Claytoncc4d0142012-02-17 07:49:44 +00003886 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003887 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003888 m_mod_id = process_sp->GetModID();
3889 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003890
Greg Claytoncc4d0142012-02-17 07:49:44 +00003891 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003892
Greg Claytoncc4d0142012-02-17 07:49:44 +00003893 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003894 {
3895 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003896 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003897 }
Jim Ingham6035b672011-03-31 00:19:25 +00003898
Greg Claytoncc4d0142012-02-17 07:49:44 +00003899 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003900 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003901 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003902
Jason Molendab57e4a12013-11-04 09:33:30 +00003903 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003904 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003905 {
3906 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003907 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003908 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003909 if (frame_sp)
3910 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003911 }
3912 }
3913 }
Jim Ingham6035b672011-03-31 00:19:25 +00003914}
3915
3916ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003917 m_mod_id(),
3918 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003919 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003920{
3921}
3922
3923ValueObject::EvaluationPoint::~EvaluationPoint ()
3924{
3925}
3926
Jim Ingham6035b672011-03-31 00:19:25 +00003927// This function checks the EvaluationPoint against the current process state. If the current
3928// state matches the evaluation point, or the evaluation point is already invalid, then we return
3929// false, meaning "no change". If the current state is different, we update our state, and return
3930// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3931// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003932// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003933
3934bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003935ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003936{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003937
3938 // 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 +00003939 const bool thread_and_frame_only_if_stopped = true;
3940 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
Jim Ingham73ca05a2011-12-17 01:35:57 +00003941
Greg Claytoncc4d0142012-02-17 07:49:44 +00003942 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003943 return false;
3944
Jim Ingham6035b672011-03-31 00:19:25 +00003945 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003946 Process *process = exe_ctx.GetProcessPtr();
3947 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003948 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003949
Jim Ingham6035b672011-03-31 00:19:25 +00003950 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003951 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003952
Jim Ingham78a685a2011-04-16 00:01:13 +00003953 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3954 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003955 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003956 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003957
Greg Clayton23f59502012-07-17 03:23:13 +00003958 bool changed = false;
3959 const bool was_valid = m_mod_id.IsValid();
3960 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003961 {
3962 if (m_mod_id == current_mod_id)
3963 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003964 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003965 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003966 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003967 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003968 else
3969 {
3970 m_mod_id = current_mod_id;
3971 m_needs_update = true;
3972 changed = true;
3973 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003974 }
Jim Ingham6035b672011-03-31 00:19:25 +00003975
Jim Ingham73ca05a2011-12-17 01:35:57 +00003976 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3977 // That way we'll be sure to return a valid exe_scope.
3978 // 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 +00003979
Greg Claytoncc4d0142012-02-17 07:49:44 +00003980 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003981 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003982 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3983 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003984 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003985 if (m_exe_ctx_ref.HasFrameRef())
3986 {
Jason Molendab57e4a12013-11-04 09:33:30 +00003987 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003988 if (!frame_sp)
3989 {
3990 // We used to have a frame, but now it is gone
3991 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003992 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00003993 }
3994 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003995 }
Jim Ingham6035b672011-03-31 00:19:25 +00003996 else
3997 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003998 // We used to have a thread, but now it is gone
3999 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00004000 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00004001 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00004002
Jim Ingham6035b672011-03-31 00:19:25 +00004003 }
Jim Ingham9ee01152011-12-10 01:49:43 +00004004 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00004005}
4006
Jim Ingham61be0902011-05-02 18:13:59 +00004007void
4008ValueObject::EvaluationPoint::SetUpdated ()
4009{
Greg Claytoncc4d0142012-02-17 07:49:44 +00004010 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
4011 if (process_sp)
4012 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00004013 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00004014}
4015
4016
Enrico Granataf2bbf712011-07-15 02:26:42 +00004017
4018void
Enrico Granata86cc9822012-03-19 22:58:49 +00004019ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004020{
Enrico Granata86cc9822012-03-19 22:58:49 +00004021 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4022 m_value_str.clear();
4023
4024 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4025 m_location_str.clear();
4026
4027 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
Enrico Granata86cc9822012-03-19 22:58:49 +00004028 m_summary_str.clear();
Enrico Granata86cc9822012-03-19 22:58:49 +00004029
4030 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4031 m_object_desc_str.clear();
4032
4033 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4034 {
4035 if (m_synthetic_value)
4036 m_synthetic_value = NULL;
4037 }
Enrico Granata744794a2014-09-05 21:46:22 +00004038
4039 if ((clear_mask & eClearUserVisibleDataItemsValidator) == eClearUserVisibleDataItemsValidator)
4040 m_validation_result.reset();
Johnny Chen44805302011-07-19 19:48:13 +00004041}
Enrico Granata9128ee22011-09-06 19:20:51 +00004042
4043SymbolContextScope *
4044ValueObject::GetSymbolContextScope()
4045{
4046 if (m_parent)
4047 {
4048 if (!m_parent->IsPointerOrReferenceType())
4049 return m_parent->GetSymbolContextScope();
4050 }
4051 return NULL;
4052}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004053
4054lldb::ValueObjectSP
4055ValueObject::CreateValueObjectFromExpression (const char* name,
4056 const char* expression,
4057 const ExecutionContext& exe_ctx)
4058{
4059 lldb::ValueObjectSP retval_sp;
4060 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4061 if (!target_sp)
4062 return retval_sp;
4063 if (!expression || !*expression)
4064 return retval_sp;
4065 target_sp->EvaluateExpression (expression,
4066 exe_ctx.GetFrameSP().get(),
4067 retval_sp);
4068 if (retval_sp && name && *name)
4069 retval_sp->SetName(ConstString(name));
4070 return retval_sp;
4071}
4072
4073lldb::ValueObjectSP
4074ValueObject::CreateValueObjectFromAddress (const char* name,
4075 uint64_t address,
4076 const ExecutionContext& exe_ctx,
4077 ClangASTType type)
4078{
Greg Clayton57ee3062013-07-11 22:46:58 +00004079 if (type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004080 {
Greg Clayton57ee3062013-07-11 22:46:58 +00004081 ClangASTType pointer_type(type.GetPointerType());
4082 if (pointer_type)
4083 {
4084 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4085 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4086 pointer_type,
4087 ConstString(name),
4088 buffer,
4089 lldb::endian::InlHostByteOrder(),
4090 exe_ctx.GetAddressByteSize()));
4091 if (ptr_result_valobj_sp)
4092 {
4093 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4094 Error err;
4095 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4096 if (ptr_result_valobj_sp && name && *name)
4097 ptr_result_valobj_sp->SetName(ConstString(name));
4098 }
4099 return ptr_result_valobj_sp;
4100 }
Enrico Granatab2698cd2012-09-13 18:27:09 +00004101 }
Greg Clayton57ee3062013-07-11 22:46:58 +00004102 return lldb::ValueObjectSP();
Enrico Granatab2698cd2012-09-13 18:27:09 +00004103}
4104
4105lldb::ValueObjectSP
4106ValueObject::CreateValueObjectFromData (const char* name,
Enrico Granata7ca1c762014-03-31 23:02:25 +00004107 const DataExtractor& data,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004108 const ExecutionContext& exe_ctx,
4109 ClangASTType type)
4110{
4111 lldb::ValueObjectSP new_value_sp;
4112 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004113 type,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004114 ConstString(name),
4115 data,
4116 LLDB_INVALID_ADDRESS);
4117 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4118 if (new_value_sp && name && *name)
4119 new_value_sp->SetName(ConstString(name));
4120 return new_value_sp;
4121}
Enrico Granata4873e522013-04-11 22:48:58 +00004122
4123ModuleSP
4124ValueObject::GetModule ()
4125{
4126 ValueObject* root(GetRoot());
4127 if (root != this)
4128 return root->GetModule();
4129 return lldb::ModuleSP();
4130}
4131
4132ValueObject*
4133ValueObject::GetRoot ()
4134{
4135 if (m_root)
4136 return m_root;
4137 ValueObject* parent = m_parent;
4138 if (!parent)
4139 return (m_root = this);
4140 while (parent->m_parent)
4141 {
4142 if (parent->m_root)
4143 return (m_root = parent->m_root);
4144 parent = parent->m_parent;
4145 }
4146 return (m_root = parent);
4147}
4148
4149AddressType
4150ValueObject::GetAddressTypeOfChildren()
4151{
4152 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
4153 {
4154 ValueObject* root(GetRoot());
4155 if (root != this)
4156 return root->GetAddressTypeOfChildren();
4157 }
4158 return m_address_type_of_ptr_or_ref_children;
4159}
4160
4161lldb::DynamicValueType
4162ValueObject::GetDynamicValueType ()
4163{
4164 ValueObject* with_dv_info = this;
4165 while (with_dv_info)
4166 {
4167 if (with_dv_info->HasDynamicValueTypeInfo())
4168 return with_dv_info->GetDynamicValueTypeImpl();
4169 with_dv_info = with_dv_info->m_parent;
4170 }
4171 return lldb::eNoDynamicValues;
4172}
Enrico Granata39d51412013-05-31 17:43:40 +00004173
Enrico Granata4873e522013-04-11 22:48:58 +00004174lldb::Format
4175ValueObject::GetFormat () const
4176{
4177 const ValueObject* with_fmt_info = this;
4178 while (with_fmt_info)
4179 {
4180 if (with_fmt_info->m_format != lldb::eFormatDefault)
4181 return with_fmt_info->m_format;
4182 with_fmt_info = with_fmt_info->m_parent;
4183 }
4184 return m_format;
4185}
Enrico Granatad07cfd32014-10-08 18:27:36 +00004186
Enrico Granatac1247f52014-11-06 21:23:20 +00004187lldb::LanguageType
4188ValueObject::GetPreferredDisplayLanguage ()
4189{
4190 lldb::LanguageType type = lldb::eLanguageTypeUnknown;
4191 if (GetRoot())
4192 {
4193 if (GetRoot() == this)
4194 {
4195 if (StackFrameSP frame_sp = GetFrameSP())
4196 {
4197 const SymbolContext& sc(frame_sp->GetSymbolContext(eSymbolContextCompUnit));
4198 if (CompileUnit* cu = sc.comp_unit)
4199 type = cu->GetLanguage();
4200 }
4201 }
4202 else
4203 {
4204 type = GetRoot()->GetPreferredDisplayLanguage();
4205 }
4206 }
4207 return type;
4208}
4209
Enrico Granatad07cfd32014-10-08 18:27:36 +00004210bool
4211ValueObject::CanProvideValue ()
4212{
Sean Callanan7375f3e2014-12-09 21:18:59 +00004213 // we need to support invalid types as providers of values because some bare-board
4214 // debugging scenarios have no notion of types, but still manage to have raw numeric
4215 // values for things like registers. sigh.
4216 const ClangASTType &type(GetClangType());
4217 return (false == type.IsValid()) || (0 != (type.GetTypeInfo() & eTypeHasValue));
4218}
4219
4220bool
4221ValueObject::IsChecksumEmpty ()
4222{
4223 return m_value_checksum.empty();
Enrico Granatad07cfd32014-10-08 18:27:36 +00004224}
Enrico Granata0c10a852014-12-08 23:13:56 +00004225
4226ValueObjectSP
4227ValueObject::Persist ()
4228{
4229 if (!UpdateValueIfNeeded())
4230 return nullptr;
4231
4232 TargetSP target_sp(GetTargetSP());
4233 if (!target_sp)
4234 return nullptr;
4235
4236 ConstString name(target_sp->GetPersistentVariables().GetNextPersistentVariableName());
4237
4238 ClangExpressionVariableSP clang_var_sp(new ClangExpressionVariable(target_sp.get(), GetValue(), name));
4239 if (clang_var_sp)
4240 {
4241 clang_var_sp->m_live_sp = clang_var_sp->m_frozen_sp;
4242 clang_var_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
4243 target_sp->GetPersistentVariables().AddVariable(clang_var_sp);
4244 }
4245
4246 return clang_var_sp->GetValueObject();
4247}
Enrico Granatae29df232014-12-09 19:51:20 +00004248
4249bool
4250ValueObject::IsSyntheticChildrenGenerated ()
4251{
4252 return m_is_synthetic_children_generated;
4253}
4254
4255void
4256ValueObject::SetSyntheticChildrenGenerated (bool b)
4257{
4258 m_is_synthetic_children_generated = b;
4259}