blob: 1d40eab25a0dc490d49f9ef10eb9133eda9c2ffb [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- ValueObject.cpp -----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "lldb/Core/ValueObject.h"
13
14// C Includes
Greg Claytonf5e56de2010-09-14 23:36:40 +000015#include <stdlib.h>
16
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017// C++ Includes
18// Other libraries and framework includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "llvm/Support/raw_ostream.h"
Jim Ingham5a369122010-09-28 01:25:32 +000020#include "clang/AST/Type.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021
22// Project includes
23#include "lldb/Core/DataBufferHeap.h"
Enrico Granata4becb372011-06-29 22:27:15 +000024#include "lldb/Core/Debugger.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000025#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000026#include "lldb/Core/Module.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Core/StreamString.h"
Enrico Granata21fd13f2012-10-27 02:05:48 +000028#include "lldb/Core/ValueObjectCast.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Core/ValueObjectChild.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000030#include "lldb/Core/ValueObjectConstResult.h"
Jim Ingham78a685a2011-04-16 00:01:13 +000031#include "lldb/Core/ValueObjectDynamicValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032#include "lldb/Core/ValueObjectList.h"
Greg Claytonb2dcc362011-05-05 23:32:56 +000033#include "lldb/Core/ValueObjectMemory.h"
Enrico Granatad55546b2011-07-22 00:16:08 +000034#include "lldb/Core/ValueObjectSyntheticFilter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035
Enrico Granata5548cb52013-01-28 23:47:25 +000036#include "lldb/DataFormatters/DataVisualization.h"
Enrico Granata2206b482014-10-30 18:27:31 +000037#include "lldb/DataFormatters/StringPrinter.h"
Enrico Granata4d93b8c2013-09-30 19:11:51 +000038#include "lldb/DataFormatters/ValueObjectPrinter.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000039
Enrico Granata0c10a852014-12-08 23:13:56 +000040#include "lldb/Expression/ClangExpressionVariable.h"
41#include "lldb/Expression/ClangPersistentVariables.h"
42
Greg Clayton7fb56d02011-02-01 01:31:41 +000043#include "lldb/Host/Endian.h"
44
Enrico Granata61a80ba2011-08-12 16:42:31 +000045#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granataf2bbf712011-07-15 02:26:42 +000046#include "lldb/Interpreter/ScriptInterpreterPython.h"
47
Greg Claytone1a916a2010-07-21 22:12:05 +000048#include "lldb/Symbol/ClangASTType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049#include "lldb/Symbol/ClangASTContext.h"
Enrico Granatac1247f52014-11-06 21:23:20 +000050#include "lldb/Symbol/CompileUnit.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051#include "lldb/Symbol/Type.h"
52
Jim Ingham53c47f12010-09-10 23:12:17 +000053#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000054#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000055#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056#include "lldb/Target/Process.h"
57#include "lldb/Target/RegisterContext.h"
Greg Claytond5944cd2013-12-06 01:12:00 +000058#include "lldb/Target/SectionLoadList.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000059#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061
62using namespace lldb;
63using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000064using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065
Greg Claytonafacd142011-09-02 01:15:17 +000066static user_id_t g_value_obj_uid = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000067
68//----------------------------------------------------------------------
69// ValueObject constructor
70//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000071ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000072 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000073 m_parent (&parent),
Enrico Granata4873e522013-04-11 22:48:58 +000074 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +000075 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000076 m_name (),
77 m_data (),
78 m_value (),
79 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000080 m_value_str (),
81 m_old_value_str (),
82 m_location_str (),
83 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000084 m_object_desc_str (),
Enrico Granata744794a2014-09-05 21:46:22 +000085 m_validation_result(),
Jim Ingham58b59f92011-04-22 23:53:53 +000086 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000087 m_children (),
88 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000089 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000090 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000091 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000092 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +000093 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000094 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +000095 m_type_summary_sp(),
96 m_type_format_sp(),
97 m_synthetic_children_sp(),
Enrico Granata744794a2014-09-05 21:46:22 +000098 m_type_validator_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +000099 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000100 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
Sean Callanan7375f3e2014-12-09 21:18:59 +0000101 m_value_checksum(),
Enrico Granataed3228a2015-01-21 01:47:13 +0000102 m_preferred_display_language(lldb::eLanguageTypeUnknown),
Greg Clayton288bdf92010-09-02 02:59:18 +0000103 m_value_is_valid (false),
104 m_value_did_change (false),
105 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000106 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000107 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000108 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000109 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000110 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000111 m_is_getting_summary(false),
Enrico Granatae29df232014-12-09 19:51:20 +0000112 m_did_calculate_complete_objc_class_type(false),
113 m_is_synthetic_children_generated(parent.m_is_synthetic_children_generated)
Jim Ingham6035b672011-03-31 00:19:25 +0000114{
Jim Ingham58b59f92011-04-22 23:53:53 +0000115 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000116}
117
118//----------------------------------------------------------------------
119// ValueObject constructor
120//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000121ValueObject::ValueObject (ExecutionContextScope *exe_scope,
122 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000123 UserID (++g_value_obj_uid), // Unique identifier for every value object
124 m_parent (NULL),
Enrico Granata4873e522013-04-11 22:48:58 +0000125 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000126 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000127 m_name (),
128 m_data (),
129 m_value (),
130 m_error (),
131 m_value_str (),
132 m_old_value_str (),
133 m_location_str (),
134 m_summary_str (),
135 m_object_desc_str (),
Enrico Granata744794a2014-09-05 21:46:22 +0000136 m_validation_result(),
Jim Ingham58b59f92011-04-22 23:53:53 +0000137 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000138 m_children (),
139 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000140 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000141 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000142 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000143 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +0000144 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000145 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +0000146 m_type_summary_sp(),
147 m_type_format_sp(),
148 m_synthetic_children_sp(),
Enrico Granata744794a2014-09-05 21:46:22 +0000149 m_type_validator_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000150 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000151 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Sean Callanan7375f3e2014-12-09 21:18:59 +0000152 m_value_checksum(),
Enrico Granataed3228a2015-01-21 01:47:13 +0000153 m_preferred_display_language(lldb::eLanguageTypeUnknown),
Jim Ingham6035b672011-03-31 00:19:25 +0000154 m_value_is_valid (false),
155 m_value_did_change (false),
156 m_children_count_valid (false),
157 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000158 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000159 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000160 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000161 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000162 m_is_getting_summary(false),
Enrico Granatae29df232014-12-09 19:51:20 +0000163 m_did_calculate_complete_objc_class_type(false),
164 m_is_synthetic_children_generated(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000165{
Jim Ingham58b59f92011-04-22 23:53:53 +0000166 m_manager = new ValueObjectManager();
167 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000168}
169
170//----------------------------------------------------------------------
171// Destructor
172//----------------------------------------------------------------------
173ValueObject::~ValueObject ()
174{
175}
176
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000177bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000178ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000179{
Enrico Granata4becb372011-06-29 22:27:15 +0000180
Enrico Granata9128ee22011-09-06 19:20:51 +0000181 bool did_change_formats = false;
182
Enrico Granata0a3958e2011-07-02 00:25:22 +0000183 if (update_format)
Enrico Granata5548cb52013-01-28 23:47:25 +0000184 did_change_formats = UpdateFormatsIfNeeded();
Enrico Granata4becb372011-06-29 22:27:15 +0000185
Greg Claytonb71f3842010-10-05 03:13:51 +0000186 // If this is a constant value, then our success is predicated on whether
187 // we have an error or not
188 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000189 {
Enrico Granatab1c6c482013-10-09 00:33:55 +0000190 // if you are constant, things might still have changed behind your back
191 // (e.g. you are a frozen object and things have changed deeper than you cared to freeze-dry yourself)
192 // in this case, your value has not changed, but "computed" entries might have, so you might now have
193 // a different summary, or a different object description. clear these so we will recompute them
Enrico Granata9128ee22011-09-06 19:20:51 +0000194 if (update_format && !did_change_formats)
Enrico Granatab1c6c482013-10-09 00:33:55 +0000195 ClearUserVisibleData(eClearUserVisibleDataItemsSummary | eClearUserVisibleDataItemsDescription);
Greg Claytonb71f3842010-10-05 03:13:51 +0000196 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000197 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000198
Sean Callanan7375f3e2014-12-09 21:18:59 +0000199 bool first_update = IsChecksumEmpty();
Jim Ingham6035b672011-03-31 00:19:25 +0000200
Enrico Granatabb642e52015-05-16 01:27:00 +0000201 if (NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000202 {
Jim Ingham6035b672011-03-31 00:19:25 +0000203 m_update_point.SetUpdated();
204
205 // Save the old value using swap to avoid a string copy which
206 // also will clear our m_value_str
207 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000208 {
Jim Ingham6035b672011-03-31 00:19:25 +0000209 m_old_value_valid = false;
210 }
211 else
212 {
213 m_old_value_valid = true;
214 m_old_value_str.swap (m_value_str);
Enrico Granata86cc9822012-03-19 22:58:49 +0000215 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham6035b672011-03-31 00:19:25 +0000216 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000217
Enrico Granataf2bbf712011-07-15 02:26:42 +0000218 ClearUserVisibleData();
219
Greg Claytonefbc7d22012-03-09 04:23:44 +0000220 if (IsInScope())
Jim Ingham6035b672011-03-31 00:19:25 +0000221 {
Greg Claytonefbc7d22012-03-09 04:23:44 +0000222 const bool value_was_valid = GetValueIsValid();
223 SetValueDidChange (false);
224
225 m_error.Clear();
226
227 // Call the pure virtual function to update the value
Sean Callanan7375f3e2014-12-09 21:18:59 +0000228
229 bool need_compare_checksums = false;
230 llvm::SmallVector<uint8_t, 16> old_checksum;
231
232 if (!first_update && CanProvideValue())
233 {
234 need_compare_checksums = true;
235 old_checksum.resize(m_value_checksum.size());
236 std::copy(m_value_checksum.begin(), m_value_checksum.end(), old_checksum.begin());
237 }
238
Greg Claytonefbc7d22012-03-09 04:23:44 +0000239 bool success = UpdateValue ();
240
241 SetValueIsValid (success);
242
Sean Callanan7375f3e2014-12-09 21:18:59 +0000243 if (success)
244 {
245 const uint64_t max_checksum_size = 128;
246 m_data.Checksum(m_value_checksum,
247 max_checksum_size);
248 }
249 else
250 {
251 need_compare_checksums = false;
252 m_value_checksum.clear();
253 }
254
Enrico Granata20c321c2015-01-08 19:11:43 +0000255 assert (!need_compare_checksums || (!old_checksum.empty() && !m_value_checksum.empty()));
256
Greg Claytonefbc7d22012-03-09 04:23:44 +0000257 if (first_update)
258 SetValueDidChange (false);
259 else if (!m_value_did_change && success == false)
260 {
261 // The value wasn't gotten successfully, so we mark this
262 // as changed if the value used to be valid and now isn't
263 SetValueDidChange (value_was_valid);
264 }
Sean Callanan7375f3e2014-12-09 21:18:59 +0000265 else if (need_compare_checksums)
266 {
267 SetValueDidChange(memcmp(&old_checksum[0], &m_value_checksum[0], m_value_checksum.size()));
268 }
269
Greg Claytonefbc7d22012-03-09 04:23:44 +0000270 }
271 else
272 {
273 m_error.SetErrorString("out of scope");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000274 }
275 }
276 return m_error.Success();
277}
278
Enrico Granata9128ee22011-09-06 19:20:51 +0000279bool
Enrico Granata5548cb52013-01-28 23:47:25 +0000280ValueObject::UpdateFormatsIfNeeded()
Enrico Granata4becb372011-06-29 22:27:15 +0000281{
Greg Clayton5160ce52013-03-27 23:08:40 +0000282 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000283 if (log)
Enrico Granatad2284832012-10-17 22:23:56 +0000284 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000285 GetName().GetCString(), static_cast<void*>(this),
286 m_last_format_mgr_revision,
287 DataVisualization::GetCurrentRevision());
288
Enrico Granata9128ee22011-09-06 19:20:51 +0000289 bool any_change = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000290
Enrico Granata5548cb52013-01-28 23:47:25 +0000291 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()))
Enrico Granata4becb372011-06-29 22:27:15 +0000292 {
Enrico Granataa0db6ed2014-04-09 21:06:11 +0000293 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
294 any_change = true;
295
Enrico Granata852cc952013-10-08 19:03:22 +0000296 SetValueFormat(DataVisualization::GetFormat (*this, eNoDynamicValues));
Enrico Granata5548cb52013-01-28 23:47:25 +0000297 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000298#ifndef LLDB_DISABLE_PYTHON
Enrico Granata5548cb52013-01-28 23:47:25 +0000299 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000300#endif
Enrico Granata744794a2014-09-05 21:46:22 +0000301 SetValidator(DataVisualization::GetValidator(*this, GetDynamicValueType()));
Enrico Granata4becb372011-06-29 22:27:15 +0000302 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000303
Enrico Granata9128ee22011-09-06 19:20:51 +0000304 return any_change;
Enrico Granata4becb372011-06-29 22:27:15 +0000305}
306
Jim Ingham16e0c682011-08-12 23:34:31 +0000307void
308ValueObject::SetNeedsUpdate ()
309{
310 m_update_point.SetNeedsUpdate();
311 // We have to clear the value string here so ConstResult children will notice if their values are
312 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000313 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000314}
315
Enrico Granata13ac0e22012-10-17 19:03:34 +0000316void
Enrico Granatae3e91512012-10-22 18:18:36 +0000317ValueObject::ClearDynamicTypeInformation ()
Enrico Granata13ac0e22012-10-17 19:03:34 +0000318{
Enrico Granata38c54632013-10-30 00:04:29 +0000319 m_children_count_valid = false;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000320 m_did_calculate_complete_objc_class_type = false;
Enrico Granatae3e91512012-10-22 18:18:36 +0000321 m_last_format_mgr_revision = 0;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000322 m_override_type = ClangASTType();
Enrico Granatae3e91512012-10-22 18:18:36 +0000323 SetValueFormat(lldb::TypeFormatImplSP());
324 SetSummaryFormat(lldb::TypeSummaryImplSP());
325 SetSyntheticChildren(lldb::SyntheticChildrenSP());
Enrico Granata13ac0e22012-10-17 19:03:34 +0000326}
327
Sean Callanan72772842012-02-22 23:57:45 +0000328ClangASTType
329ValueObject::MaybeCalculateCompleteType ()
330{
Greg Clayton57ee3062013-07-11 22:46:58 +0000331 ClangASTType clang_type(GetClangTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000332
Sean Callanan72772842012-02-22 23:57:45 +0000333 if (m_did_calculate_complete_objc_class_type)
334 {
335 if (m_override_type.IsValid())
336 return m_override_type;
337 else
Greg Clayton57ee3062013-07-11 22:46:58 +0000338 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000339 }
340
Greg Clayton57ee3062013-07-11 22:46:58 +0000341 ClangASTType class_type;
342 bool is_pointer_type = false;
Sean Callanan72772842012-02-22 23:57:45 +0000343
Greg Clayton57ee3062013-07-11 22:46:58 +0000344 if (clang_type.IsObjCObjectPointerType(&class_type))
Sean Callanan72772842012-02-22 23:57:45 +0000345 {
346 is_pointer_type = true;
347 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000348 else if (clang_type.IsObjCObjectOrInterfaceType())
Sean Callanan72772842012-02-22 23:57:45 +0000349 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000350 class_type = clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000351 }
352 else
353 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000354 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000355 }
356
357 m_did_calculate_complete_objc_class_type = true;
358
Greg Clayton57ee3062013-07-11 22:46:58 +0000359 if (class_type)
Sean Callanan72772842012-02-22 23:57:45 +0000360 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000361 ConstString class_name (class_type.GetConstTypeName());
Sean Callanan72772842012-02-22 23:57:45 +0000362
Greg Clayton57ee3062013-07-11 22:46:58 +0000363 if (class_name)
364 {
365 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
366
367 if (process_sp)
368 {
369 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
370
371 if (objc_language_runtime)
372 {
373 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name);
374
375 if (complete_objc_class_type_sp)
376 {
377 ClangASTType complete_class(complete_objc_class_type_sp->GetClangFullType());
378
379 if (complete_class.GetCompleteType())
380 {
381 if (is_pointer_type)
382 {
383 m_override_type = complete_class.GetPointerType();
384 }
385 else
386 {
387 m_override_type = complete_class;
388 }
389
390 if (m_override_type.IsValid())
391 return m_override_type;
392 }
393 }
394 }
395 }
396 }
Sean Callanan72772842012-02-22 23:57:45 +0000397 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000398 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000399}
400
Greg Clayton57ee3062013-07-11 22:46:58 +0000401ClangASTType
Sean Callanan72772842012-02-22 23:57:45 +0000402ValueObject::GetClangType ()
403{
Greg Clayton57ee3062013-07-11 22:46:58 +0000404 return MaybeCalculateCompleteType();
Sean Callanan72772842012-02-22 23:57:45 +0000405}
406
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000407TypeImpl
408ValueObject::GetTypeImpl ()
409{
410 return TypeImpl(GetClangType());
411}
412
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000413DataExtractor &
414ValueObject::GetDataExtractor ()
415{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000416 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000417 return m_data;
418}
419
420const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000421ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000422{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000423 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000424 return m_error;
425}
426
427const ConstString &
428ValueObject::GetName() const
429{
430 return m_name;
431}
432
433const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000434ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000435{
Enrico Granata82fabf82013-04-30 20:45:04 +0000436 return GetLocationAsCStringImpl(m_value,
437 m_data);
438}
439
440const char *
441ValueObject::GetLocationAsCStringImpl (const Value& value,
442 const DataExtractor& data)
443{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000444 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000445 {
446 if (m_location_str.empty())
447 {
448 StreamString sstr;
Enrico Granata82fabf82013-04-30 20:45:04 +0000449
450 Value::ValueType value_type = value.GetValueType();
451
452 switch (value_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000453 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000454 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +0000455 case Value::eValueTypeVector:
Enrico Granata82fabf82013-04-30 20:45:04 +0000456 if (value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000457 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000458 RegisterInfo *reg_info = value.GetRegisterInfo();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000459 if (reg_info)
460 {
461 if (reg_info->name)
462 m_location_str = reg_info->name;
463 else if (reg_info->alt_name)
464 m_location_str = reg_info->alt_name;
Enrico Granata82fabf82013-04-30 20:45:04 +0000465 if (m_location_str.empty())
466 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000467 }
468 }
Enrico Granata82fabf82013-04-30 20:45:04 +0000469 if (m_location_str.empty())
470 m_location_str = (value_type == Value::eValueTypeVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000471 break;
472
473 case Value::eValueTypeLoadAddress:
474 case Value::eValueTypeFileAddress:
475 case Value::eValueTypeHostAddress:
476 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000477 uint32_t addr_nibble_size = data.GetAddressByteSize() * 2;
478 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000479 m_location_str.swap(sstr.GetString());
480 }
481 break;
482 }
483 }
484 }
485 return m_location_str.c_str();
486}
487
488Value &
489ValueObject::GetValue()
490{
491 return m_value;
492}
493
494const Value &
495ValueObject::GetValue() const
496{
497 return m_value;
498}
499
500bool
Jim Ingham6035b672011-03-31 00:19:25 +0000501ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000502{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000503 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
504 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000505 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000506 Value tmp_value(m_value);
Greg Clayton57ee3062013-07-11 22:46:58 +0000507 scalar = tmp_value.ResolveValue(&exe_ctx);
Greg Claytondcad5022011-12-29 01:26:56 +0000508 if (scalar.IsValid())
509 {
510 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
511 if (bitfield_bit_size)
512 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
513 return true;
514 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000515 }
Greg Claytondcad5022011-12-29 01:26:56 +0000516 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000517}
518
519bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000520ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000521{
Greg Clayton288bdf92010-09-02 02:59:18 +0000522 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000523}
524
525
526void
527ValueObject::SetValueIsValid (bool b)
528{
Greg Clayton288bdf92010-09-02 02:59:18 +0000529 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000530}
531
532bool
Jim Ingham6035b672011-03-31 00:19:25 +0000533ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000534{
Greg Clayton288bdf92010-09-02 02:59:18 +0000535 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000536}
537
538void
539ValueObject::SetValueDidChange (bool value_changed)
540{
Greg Clayton288bdf92010-09-02 02:59:18 +0000541 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000542}
543
544ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000545ValueObject::GetChildAtIndex (size_t idx, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000546{
547 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000548 // We may need to update our value if we are dynamic
549 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000550 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000551 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000552 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000553 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000554 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000555 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000556 // No we haven't created the child at this index, so lets have our
557 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000558 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000559 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000560
Enrico Granata9d60f602012-03-09 03:09:58 +0000561 ValueObject* child = m_children.GetChildAtIndex(idx);
562 if (child != NULL)
563 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000564 }
565 return child_sp;
566}
567
Enrico Granata3309d882013-01-12 01:00:22 +0000568ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000569ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
570 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000571{
572 if (idxs.size() == 0)
573 return GetSP();
574 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000575 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000576 {
577 root = root->GetChildAtIndex(idx, true);
578 if (!root)
579 {
580 if (index_of_error)
581 *index_of_error = idx;
582 return root;
583 }
584 }
585 return root;
586}
587
588ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000589ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
590 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000591{
592 if (idxs.size() == 0)
593 return GetSP();
594 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000595 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000596 {
597 root = root->GetChildAtIndex(idx.first, idx.second);
598 if (!root)
599 {
600 if (index_of_error)
601 *index_of_error = idx.first;
602 return root;
603 }
604 }
605 return root;
606}
607
608lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000609ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
610 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000611{
612 if (idxs.size() == 0)
613 return GetSP();
614 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000615 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000616 {
617 root = root->GetChildAtIndex(idx, true);
618 if (!root)
619 {
620 if (index_of_error)
621 *index_of_error = idx;
622 return root;
623 }
624 }
625 return root;
626}
627
628lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000629ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
630 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000631{
632 if (idxs.size() == 0)
633 return GetSP();
634 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000635 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000636 {
637 root = root->GetChildAtIndex(idx.first, idx.second);
638 if (!root)
639 {
640 if (index_of_error)
641 *index_of_error = idx.first;
642 return root;
643 }
644 }
645 return root;
646}
647
Enrico Granatae2e220a2013-09-12 00:48:47 +0000648lldb::ValueObjectSP
649ValueObject::GetChildAtNamePath (const std::initializer_list<ConstString> &names,
650 ConstString* name_of_error)
651{
652 if (names.size() == 0)
653 return GetSP();
654 ValueObjectSP root(GetSP());
655 for (ConstString name : names)
656 {
657 root = root->GetChildMemberWithName(name, true);
658 if (!root)
659 {
660 if (name_of_error)
661 *name_of_error = name;
662 return root;
663 }
664 }
665 return root;
666}
667
668lldb::ValueObjectSP
669ValueObject::GetChildAtNamePath (const std::vector<ConstString> &names,
670 ConstString* name_of_error)
671{
672 if (names.size() == 0)
673 return GetSP();
674 ValueObjectSP root(GetSP());
675 for (ConstString name : names)
676 {
677 root = root->GetChildMemberWithName(name, true);
678 if (!root)
679 {
680 if (name_of_error)
681 *name_of_error = name;
682 return root;
683 }
684 }
685 return root;
686}
687
688lldb::ValueObjectSP
689ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names,
690 ConstString* name_of_error)
691{
692 if (names.size() == 0)
693 return GetSP();
694 ValueObjectSP root(GetSP());
695 for (std::pair<ConstString, bool> name : names)
696 {
697 root = root->GetChildMemberWithName(name.first, name.second);
698 if (!root)
699 {
700 if (name_of_error)
701 *name_of_error = name.first;
702 return root;
703 }
704 }
705 return root;
706}
707
708lldb::ValueObjectSP
709ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names,
710 ConstString* name_of_error)
711{
712 if (names.size() == 0)
713 return GetSP();
714 ValueObjectSP root(GetSP());
715 for (std::pair<ConstString, bool> name : names)
716 {
717 root = root->GetChildMemberWithName(name.first, name.second);
718 if (!root)
719 {
720 if (name_of_error)
721 *name_of_error = name.first;
722 return root;
723 }
724 }
725 return root;
726}
727
Greg Claytonc7bece562013-01-25 18:06:21 +0000728size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000729ValueObject::GetIndexOfChildWithName (const ConstString &name)
730{
731 bool omit_empty_base_classes = true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000732 return GetClangType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000733}
734
735ValueObjectSP
736ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
737{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000738 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000739 // classes (which really aren't part of the expression path), so we
740 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000741 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000742
Greg Claytondea8cb42011-06-29 22:09:02 +0000743 // We may need to update our value if we are dynamic
744 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000745 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000746
747 std::vector<uint32_t> child_indexes;
Greg Claytondea8cb42011-06-29 22:09:02 +0000748 bool omit_empty_base_classes = true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000749 const size_t num_child_indexes = GetClangType().GetIndexOfChildMemberWithName (name.GetCString(),
750 omit_empty_base_classes,
751 child_indexes);
Greg Claytondea8cb42011-06-29 22:09:02 +0000752 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000753 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000754 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
755 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
756
757 child_sp = GetChildAtIndex(*pos, can_create);
758 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000759 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000760 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000761 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000762 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
763 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000764 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000765 else
766 {
767 child_sp.reset();
768 }
769
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000770 }
771 }
772 return child_sp;
773}
774
775
Greg Claytonc7bece562013-01-25 18:06:21 +0000776size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000777ValueObject::GetNumChildren ()
778{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000779 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000780 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000781 {
782 SetNumChildren (CalculateNumChildren());
783 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000784 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000785}
Greg Clayton4a792072012-10-23 01:50:10 +0000786
787bool
788ValueObject::MightHaveChildren()
789{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000790 bool has_children = false;
Greg Clayton2452ab72013-02-08 22:02:02 +0000791 const uint32_t type_info = GetTypeInfo();
792 if (type_info)
Greg Clayton4a792072012-10-23 01:50:10 +0000793 {
Enrico Granata622be232014-10-21 20:52:14 +0000794 if (type_info & (eTypeHasChildren |
795 eTypeIsPointer |
796 eTypeIsReference))
Greg Clayton4a792072012-10-23 01:50:10 +0000797 has_children = true;
798 }
799 else
800 {
801 has_children = GetNumChildren () > 0;
802 }
803 return has_children;
804}
805
806// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000807void
Greg Claytonc7bece562013-01-25 18:06:21 +0000808ValueObject::SetNumChildren (size_t num_children)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000809{
Greg Clayton288bdf92010-09-02 02:59:18 +0000810 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000811 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000812}
813
814void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000815ValueObject::SetName (const ConstString &name)
816{
817 m_name = name;
818}
819
Jim Ingham58b59f92011-04-22 23:53:53 +0000820ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000821ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000822{
Jim Ingham2eec4872011-05-07 00:10:58 +0000823 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000824
Greg Claytondea8cb42011-06-29 22:09:02 +0000825 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000826 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000827 std::string child_name_str;
828 uint32_t child_byte_size = 0;
829 int32_t child_byte_offset = 0;
830 uint32_t child_bitfield_bit_size = 0;
831 uint32_t child_bitfield_bit_offset = 0;
832 bool child_is_base_class = false;
833 bool child_is_deref_of_parent = false;
834
835 const bool transparent_pointers = synthetic_array_member == false;
Greg Clayton57ee3062013-07-11 22:46:58 +0000836 ClangASTType child_clang_type;
Greg Claytondea8cb42011-06-29 22:09:02 +0000837
Greg Claytoncc4d0142012-02-17 07:49:44 +0000838 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000839
Greg Clayton57ee3062013-07-11 22:46:58 +0000840 child_clang_type = GetClangType().GetChildClangTypeAtIndex (&exe_ctx,
Greg Clayton57ee3062013-07-11 22:46:58 +0000841 idx,
842 transparent_pointers,
843 omit_empty_base_classes,
844 ignore_array_bounds,
845 child_name_str,
846 child_byte_size,
847 child_byte_offset,
848 child_bitfield_bit_size,
849 child_bitfield_bit_offset,
850 child_is_base_class,
Greg Clayton759e7442014-07-19 00:12:57 +0000851 child_is_deref_of_parent,
852 this);
Greg Clayton4ef877f2012-12-06 02:33:54 +0000853 if (child_clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000854 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000855 if (synthetic_index)
856 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000857
Greg Claytondea8cb42011-06-29 22:09:02 +0000858 ConstString child_name;
859 if (!child_name_str.empty())
860 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000861
Greg Claytondea8cb42011-06-29 22:09:02 +0000862 valobj = new ValueObjectChild (*this,
Greg Claytondea8cb42011-06-29 22:09:02 +0000863 child_clang_type,
864 child_name,
865 child_byte_size,
866 child_byte_offset,
867 child_bitfield_bit_size,
868 child_bitfield_bit_offset,
869 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000870 child_is_deref_of_parent,
871 eAddressTypeInvalid);
872 //if (valobj)
873 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
874 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000875
Jim Ingham58b59f92011-04-22 23:53:53 +0000876 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000877}
878
Enrico Granata0c489f52012-03-01 04:24:26 +0000879bool
880ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
881 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000882{
Enrico Granatac1247f52014-11-06 21:23:20 +0000883 return GetSummaryAsCString(summary_ptr, destination, TypeSummaryOptions());
884}
885
886bool
887ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
888 std::string& destination,
889 const TypeSummaryOptions& options)
890{
Enrico Granata0c489f52012-03-01 04:24:26 +0000891 destination.clear();
892
893 // ideally we would like to bail out if passing NULL, but if we do so
894 // we end up not providing the summary for function pointers anymore
895 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
896 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000897
898 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000899
900 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
901 // information that we might care to see in a crash log. might be useful in very specific situations though.
902 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
903 GetTypeName().GetCString(),
904 GetName().GetCString(),
905 summary_ptr->GetDescription().c_str());*/
906
Enrico Granataff0f23d2014-12-10 02:00:45 +0000907 if (UpdateValueIfNeeded (false) && summary_ptr)
Enrico Granata0c489f52012-03-01 04:24:26 +0000908 {
Enrico Granataff0f23d2014-12-10 02:00:45 +0000909 if (HasSyntheticValue())
910 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
911 summary_ptr->FormatObject(this, destination, options);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000912 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000913 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000914 return !destination.empty();
915}
916
917const char *
918ValueObject::GetSummaryAsCString ()
919{
920 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
921 {
922 GetSummaryAsCString(GetSummaryFormat().get(),
Enrico Granatac1247f52014-11-06 21:23:20 +0000923 m_summary_str,
Enrico Granata49bfafb2014-11-18 23:36:25 +0000924 TypeSummaryOptions());
Enrico Granata0c489f52012-03-01 04:24:26 +0000925 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000926 if (m_summary_str.empty())
927 return NULL;
928 return m_summary_str.c_str();
929}
930
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000931bool
Enrico Granata49bfafb2014-11-18 23:36:25 +0000932ValueObject::GetSummaryAsCString (std::string& destination,
933 const TypeSummaryOptions& options)
934{
935 return GetSummaryAsCString(GetSummaryFormat().get(),
936 destination,
937 options);
938}
939
940bool
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000941ValueObject::IsCStringContainer(bool check_pointer)
942{
Greg Clayton57ee3062013-07-11 22:46:58 +0000943 ClangASTType pointee_or_element_clang_type;
944 const Flags type_flags (GetTypeInfo (&pointee_or_element_clang_type));
Enrico Granata622be232014-10-21 20:52:14 +0000945 bool is_char_arr_ptr (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Greg Clayton57ee3062013-07-11 22:46:58 +0000946 pointee_or_element_clang_type.IsCharType ());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000947 if (!is_char_arr_ptr)
948 return false;
949 if (!check_pointer)
950 return true;
Enrico Granata622be232014-10-21 20:52:14 +0000951 if (type_flags.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000952 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000953 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000954 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000955 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000956 return (cstr_address != LLDB_INVALID_ADDRESS);
957}
958
Enrico Granata9128ee22011-09-06 19:20:51 +0000959size_t
960ValueObject::GetPointeeData (DataExtractor& data,
961 uint32_t item_idx,
962 uint32_t item_count)
963{
Greg Clayton57ee3062013-07-11 22:46:58 +0000964 ClangASTType pointee_or_element_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +0000965 const uint32_t type_info = GetTypeInfo (&pointee_or_element_clang_type);
Enrico Granata622be232014-10-21 20:52:14 +0000966 const bool is_pointer_type = type_info & eTypeIsPointer;
967 const bool is_array_type = type_info & eTypeIsArray;
Greg Clayton2452ab72013-02-08 22:02:02 +0000968 if (!(is_pointer_type || is_array_type))
Enrico Granata9128ee22011-09-06 19:20:51 +0000969 return 0;
970
971 if (item_count == 0)
972 return 0;
973
Enrico Granata951bdd52015-01-28 01:09:45 +0000974 ExecutionContext exe_ctx (GetExecutionContextRef());
975
Greg Clayton526ae042015-02-12 00:34:25 +0000976 const uint64_t item_type_size = pointee_or_element_clang_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
Enrico Granata9128ee22011-09-06 19:20:51 +0000977 const uint64_t bytes = item_count * item_type_size;
Enrico Granata9128ee22011-09-06 19:20:51 +0000978 const uint64_t offset = item_idx * item_type_size;
979
980 if (item_idx == 0 && item_count == 1) // simply a deref
981 {
Greg Clayton2452ab72013-02-08 22:02:02 +0000982 if (is_pointer_type)
Enrico Granata9128ee22011-09-06 19:20:51 +0000983 {
984 Error error;
985 ValueObjectSP pointee_sp = Dereference(error);
986 if (error.Fail() || pointee_sp.get() == NULL)
987 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +0000988 return pointee_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +0000989 }
990 else
991 {
992 ValueObjectSP child_sp = GetChildAtIndex(0, true);
993 if (child_sp.get() == NULL)
994 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +0000995 Error error;
996 return child_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +0000997 }
998 return true;
999 }
1000 else /* (items > 1) */
1001 {
1002 Error error;
1003 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
1004 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
1005
1006 AddressType addr_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001007 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001008
Enrico Granata9128ee22011-09-06 19:20:51 +00001009 switch (addr_type)
1010 {
1011 case eAddressTypeFile:
1012 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001013 ModuleSP module_sp (GetModule());
1014 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001015 {
Enrico Granata9c2efe32012-08-07 01:49:34 +00001016 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +00001017 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001018 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001019 ExecutionContext exe_ctx (GetExecutionContextRef());
1020 Target* target = exe_ctx.GetTargetPtr();
1021 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +00001022 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001023 heap_buf_ptr->SetByteSize(bytes);
1024 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
1025 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +00001026 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001027 data.SetData(data_sp);
1028 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +00001029 }
1030 }
1031 }
1032 }
1033 break;
1034 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +00001035 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001036 ExecutionContext exe_ctx (GetExecutionContextRef());
1037 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +00001038 if (process)
1039 {
1040 heap_buf_ptr->SetByteSize(bytes);
1041 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
Enrico Granata5e1480c2013-10-30 17:52:44 +00001042 if (error.Success() || bytes_read > 0)
Enrico Granata9128ee22011-09-06 19:20:51 +00001043 {
1044 data.SetData(data_sp);
1045 return bytes_read;
1046 }
1047 }
1048 }
1049 break;
1050 case eAddressTypeHost:
1051 {
Greg Clayton526ae042015-02-12 00:34:25 +00001052 const uint64_t max_bytes = GetClangType().GetByteSize(exe_ctx.GetBestExecutionContextScope());
Greg Clayton2452ab72013-02-08 22:02:02 +00001053 if (max_bytes > offset)
1054 {
1055 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
Siva Chandrae32f2b52015-05-05 00:41:35 +00001056 addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1057 if (addr == LLDB_INVALID_ADDRESS)
1058 break;
Greg Clayton2452ab72013-02-08 22:02:02 +00001059 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
1060 data.SetData(data_sp);
1061 return bytes_read;
1062 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001063 }
1064 break;
1065 case eAddressTypeInvalid:
Enrico Granata9128ee22011-09-06 19:20:51 +00001066 break;
1067 }
1068 }
1069 return 0;
1070}
1071
Greg Claytonfaac1112013-03-14 18:31:44 +00001072uint64_t
Sean Callanan866e91c2014-02-28 22:27:53 +00001073ValueObject::GetData (DataExtractor& data, Error &error)
Enrico Granata9128ee22011-09-06 19:20:51 +00001074{
1075 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001076 ExecutionContext exe_ctx (GetExecutionContextRef());
Sean Callanan866e91c2014-02-28 22:27:53 +00001077 error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001078 if (error.Fail())
Sean Callananed185ab2013-04-19 19:47:32 +00001079 {
1080 if (m_data.GetByteSize())
1081 {
1082 data = m_data;
1083 return data.GetByteSize();
1084 }
1085 else
1086 {
1087 return 0;
1088 }
1089 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001090 data.SetAddressByteSize(m_data.GetAddressByteSize());
1091 data.SetByteOrder(m_data.GetByteOrder());
1092 return data.GetByteSize();
1093}
1094
Sean Callanan389823e2013-04-13 01:21:23 +00001095bool
1096ValueObject::SetData (DataExtractor &data, Error &error)
1097{
1098 error.Clear();
1099 // Make sure our value is up to date first so that our location and location
1100 // type is valid.
1101 if (!UpdateValueIfNeeded(false))
1102 {
1103 error.SetErrorString("unable to read value");
1104 return false;
1105 }
1106
1107 uint64_t count = 0;
Greg Clayton57ee3062013-07-11 22:46:58 +00001108 const Encoding encoding = GetClangType().GetEncoding(count);
Sean Callanan389823e2013-04-13 01:21:23 +00001109
1110 const size_t byte_size = GetByteSize();
1111
1112 Value::ValueType value_type = m_value.GetValueType();
1113
1114 switch (value_type)
1115 {
1116 case Value::eValueTypeScalar:
1117 {
1118 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1119
1120 if (!set_error.Success())
1121 {
1122 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1123 return false;
1124 }
1125 }
1126 break;
1127 case Value::eValueTypeLoadAddress:
1128 {
1129 // If it is a load address, then the scalar value is the storage location
1130 // of the data, and we have to shove this value down to that load location.
1131 ExecutionContext exe_ctx (GetExecutionContextRef());
1132 Process *process = exe_ctx.GetProcessPtr();
1133 if (process)
1134 {
1135 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1136 size_t bytes_written = process->WriteMemory(target_addr,
1137 data.GetDataStart(),
1138 byte_size,
1139 error);
1140 if (!error.Success())
1141 return false;
1142 if (bytes_written != byte_size)
1143 {
1144 error.SetErrorString("unable to write value to memory");
1145 return false;
1146 }
1147 }
1148 }
1149 break;
1150 case Value::eValueTypeHostAddress:
1151 {
1152 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1153 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1154 m_data.SetData(buffer_sp, 0);
1155 data.CopyByteOrderedData (0,
1156 byte_size,
1157 const_cast<uint8_t *>(m_data.GetDataStart()),
1158 byte_size,
1159 m_data.GetByteOrder());
1160 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1161 }
1162 break;
1163 case Value::eValueTypeFileAddress:
1164 case Value::eValueTypeVector:
1165 break;
1166 }
1167
1168 // If we have reached this point, then we have successfully changed the value.
1169 SetNeedsUpdate();
1170 return true;
1171}
1172
Enrico Granata9128ee22011-09-06 19:20:51 +00001173// will compute strlen(str), but without consuming more than
1174// maxlen bytes out of str (this serves the purpose of reading
1175// chunks of a string without having to worry about
1176// missing NULL terminators in the chunk)
1177// of course, if strlen(str) > maxlen, the function will return
1178// maxlen_value (which should be != maxlen, because that allows you
1179// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1180static uint32_t
1181strlen_or_inf (const char* str,
1182 uint32_t maxlen,
1183 uint32_t maxlen_value)
1184{
1185 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +00001186 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +00001187 {
Greg Clayton8dd5c172011-10-05 22:19:51 +00001188 while(*str)
1189 {
1190 len++;str++;
Greg Clayton2452ab72013-02-08 22:02:02 +00001191 if (len >= maxlen)
Greg Clayton8dd5c172011-10-05 22:19:51 +00001192 return maxlen_value;
1193 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001194 }
1195 return len;
1196}
1197
Enrico Granata2206b482014-10-30 18:27:31 +00001198static bool
1199CopyStringDataToBufferSP(const StreamString& source,
1200 lldb::DataBufferSP& destination)
1201{
1202 destination.reset(new DataBufferHeap(source.GetSize()+1,0));
1203 memcpy(destination->GetBytes(), source.GetString().c_str(), source.GetSize());
1204 return true;
1205}
1206
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001207size_t
Enrico Granata2206b482014-10-30 18:27:31 +00001208ValueObject::ReadPointedString (lldb::DataBufferSP& buffer_sp,
Greg Claytoncc4d0142012-02-17 07:49:44 +00001209 Error& error,
1210 uint32_t max_length,
1211 bool honor_array,
1212 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001213{
Enrico Granata2206b482014-10-30 18:27:31 +00001214 StreamString s;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001215 ExecutionContext exe_ctx (GetExecutionContextRef());
1216 Target* target = exe_ctx.GetTargetPtr();
Enrico Granata2206b482014-10-30 18:27:31 +00001217
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001218 if (!target)
1219 {
1220 s << "<no target to read from>";
1221 error.SetErrorString("no target to read from");
Enrico Granata2206b482014-10-30 18:27:31 +00001222 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001223 return 0;
1224 }
1225
1226 if (max_length == 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001227 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001228
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001229 size_t bytes_read = 0;
1230 size_t total_bytes_read = 0;
1231
Greg Clayton57ee3062013-07-11 22:46:58 +00001232 ClangASTType clang_type = GetClangType();
1233 ClangASTType elem_or_pointee_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001234 const Flags type_flags (GetTypeInfo (&elem_or_pointee_clang_type));
Enrico Granata622be232014-10-21 20:52:14 +00001235 if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Greg Clayton57ee3062013-07-11 22:46:58 +00001236 elem_or_pointee_clang_type.IsCharType ())
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001237 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001238 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1239 AddressType cstr_address_type = eAddressTypeInvalid;
1240
1241 size_t cstr_len = 0;
1242 bool capped_data = false;
Enrico Granata622be232014-10-21 20:52:14 +00001243 if (type_flags.Test (eTypeIsArray))
Greg Claytoncc4d0142012-02-17 07:49:44 +00001244 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001245 // We have an array
Greg Clayton57ee3062013-07-11 22:46:58 +00001246 uint64_t array_size = 0;
1247 if (clang_type.IsArrayType(NULL, &array_size, NULL))
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001248 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001249 cstr_len = array_size;
1250 if (cstr_len > max_length)
1251 {
1252 capped_data = true;
1253 cstr_len = max_length;
1254 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001255 }
1256 cstr_address = GetAddressOf (true, &cstr_address_type);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001257 }
1258 else
1259 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001260 // We have a pointer
1261 cstr_address = GetPointerValue (&cstr_address_type);
1262 }
1263
1264 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1265 {
1266 s << "<invalid address>";
1267 error.SetErrorString("invalid address");
Enrico Granata2206b482014-10-30 18:27:31 +00001268 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001269 return 0;
1270 }
Enrico Granata2206b482014-10-30 18:27:31 +00001271
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001272 Address cstr_so_addr (cstr_address);
1273 DataExtractor data;
1274 if (cstr_len > 0 && honor_array)
1275 {
1276 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1277 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1278 GetPointeeData(data, 0, cstr_len);
Enrico Granata2206b482014-10-30 18:27:31 +00001279
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001280 if ((bytes_read = data.GetByteSize()) > 0)
1281 {
1282 total_bytes_read = bytes_read;
Enrico Granata2206b482014-10-30 18:27:31 +00001283 for (size_t offset = 0; offset < bytes_read; offset++)
1284 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001285 if (capped_data)
1286 s << "...";
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001287 }
1288 }
1289 else
1290 {
1291 cstr_len = max_length;
1292 const size_t k_max_buf_size = 64;
Enrico Granata2206b482014-10-30 18:27:31 +00001293
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001294 size_t offset = 0;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001295
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001296 int cstr_len_displayed = -1;
1297 bool capped_cstr = false;
1298 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1299 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1300 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001301 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001302 total_bytes_read += bytes_read;
1303 const char *cstr = data.PeekCStr(0);
1304 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1305 if (len > k_max_buf_size)
1306 len = k_max_buf_size;
Enrico Granata2206b482014-10-30 18:27:31 +00001307
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001308 if (cstr_len_displayed < 0)
1309 cstr_len_displayed = len;
Enrico Granata2206b482014-10-30 18:27:31 +00001310
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001311 if (len == 0)
1312 break;
1313 cstr_len_displayed += len;
1314 if (len > bytes_read)
1315 len = bytes_read;
1316 if (len > cstr_len)
1317 len = cstr_len;
1318
Enrico Granata2206b482014-10-30 18:27:31 +00001319 for (size_t offset = 0; offset < bytes_read; offset++)
1320 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001321
1322 if (len < k_max_buf_size)
1323 break;
1324
1325 if (len >= cstr_len)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001326 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001327 capped_cstr = true;
1328 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001329 }
Enrico Granata2206b482014-10-30 18:27:31 +00001330
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001331 cstr_len -= len;
1332 offset += len;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001333 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001334
1335 if (cstr_len_displayed >= 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001336 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001337 if (capped_cstr)
1338 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001339 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001340 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001341 }
1342 else
1343 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001344 error.SetErrorString("not a string object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001345 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001346 }
Enrico Granata2206b482014-10-30 18:27:31 +00001347 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001348 return total_bytes_read;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001349}
1350
Enrico Granata744794a2014-09-05 21:46:22 +00001351std::pair<TypeValidatorResult, std::string>
1352ValueObject::GetValidationStatus ()
1353{
1354 if (!UpdateValueIfNeeded(true))
1355 return {TypeValidatorResult::Success,""}; // not the validator's job to discuss update problems
1356
1357 if (m_validation_result.hasValue())
1358 return m_validation_result.getValue();
1359
1360 if (!m_type_validator_sp)
1361 return {TypeValidatorResult::Success,""}; // no validator no failure
1362
1363 auto outcome = m_type_validator_sp->FormatObject(this);
1364
1365 return (m_validation_result = {outcome.m_result,outcome.m_message}).getValue();
1366}
1367
Jim Ingham53c47f12010-09-10 23:12:17 +00001368const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001369ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001370{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001371
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001372 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001373 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001374
1375 if (!m_object_desc_str.empty())
1376 return m_object_desc_str.c_str();
1377
Greg Claytoncc4d0142012-02-17 07:49:44 +00001378 ExecutionContext exe_ctx (GetExecutionContextRef());
1379 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001380 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001381 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001382
Jim Ingham53c47f12010-09-10 23:12:17 +00001383 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001384
Greg Claytonafacd142011-09-02 01:15:17 +00001385 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001386 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1387
Jim Inghama2cf2632010-12-23 02:29:54 +00001388 if (runtime == NULL)
1389 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001390 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Greg Clayton57ee3062013-07-11 22:46:58 +00001391 ClangASTType clang_type = GetClangType();
1392 if (clang_type)
Jim Inghama2cf2632010-12-23 02:29:54 +00001393 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001394 bool is_signed;
Greg Clayton57ee3062013-07-11 22:46:58 +00001395 if (clang_type.IsIntegerType (is_signed) || clang_type.IsPointerType ())
Jim Inghamb7603bb2011-03-18 00:05:18 +00001396 {
Greg Claytonafacd142011-09-02 01:15:17 +00001397 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001398 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001399 }
1400 }
1401
Jim Ingham8d543de2011-03-31 23:01:21 +00001402 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001403 {
1404 m_object_desc_str.append (s.GetData());
1405 }
Sean Callanan672ad942010-10-23 00:18:49 +00001406
1407 if (m_object_desc_str.empty())
1408 return NULL;
1409 else
1410 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001411}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001412
Enrico Granata0c489f52012-03-01 04:24:26 +00001413bool
Enrico Granata4939b982013-12-22 09:24:22 +00001414ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format,
1415 std::string& destination)
1416{
1417 if (UpdateValueIfNeeded(false))
1418 return format.FormatObject(this,destination);
1419 else
1420 return false;
1421}
1422
1423bool
Enrico Granata0c489f52012-03-01 04:24:26 +00001424ValueObject::GetValueAsCString (lldb::Format format,
1425 std::string& destination)
1426{
Enrico Granata30f287f2013-12-28 08:44:02 +00001427 return GetValueAsCString(TypeFormatImpl_Format(format),destination);
Enrico Granata0c489f52012-03-01 04:24:26 +00001428}
1429
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001430const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001431ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001432{
Enrico Granatab294fd22013-05-31 19:18:19 +00001433 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001434 {
Enrico Granata4939b982013-12-22 09:24:22 +00001435 lldb::TypeFormatImplSP format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001436 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001437 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001438 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001439 if (m_type_format_sp)
Enrico Granata4939b982013-12-22 09:24:22 +00001440 format_sp = m_type_format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001441 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001442 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001443 if (m_is_bitfield_for_scalar)
1444 my_format = eFormatUnsigned;
1445 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001446 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001447 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001448 {
1449 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1450 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001451 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001452 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001453 else
1454 {
Enrico Granatad07cfd32014-10-08 18:27:36 +00001455 my_format = GetValue().GetClangType().GetFormat();
Enrico Granata0c489f52012-03-01 04:24:26 +00001456 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001457 }
1458 }
1459 }
Enrico Granatab294fd22013-05-31 19:18:19 +00001460 if (my_format != m_last_format || m_value_str.empty())
Enrico Granata297e69f2012-03-06 23:21:16 +00001461 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001462 m_last_format = my_format;
Enrico Granata4939b982013-12-22 09:24:22 +00001463 if (!format_sp)
Enrico Granata30f287f2013-12-28 08:44:02 +00001464 format_sp.reset(new TypeFormatImpl_Format(my_format));
Enrico Granata4939b982013-12-22 09:24:22 +00001465 if (GetValueAsCString(*format_sp.get(), m_value_str))
Enrico Granata297e69f2012-03-06 23:21:16 +00001466 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001467 if (!m_value_did_change && m_old_value_valid)
1468 {
1469 // The value was gotten successfully, so we consider the
1470 // value as changed if the value string differs
1471 SetValueDidChange (m_old_value_str != m_value_str);
1472 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001473 }
1474 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001475 }
1476 if (m_value_str.empty())
1477 return NULL;
1478 return m_value_str.c_str();
1479}
1480
Enrico Granatac3e320a2011-08-02 17:27:39 +00001481// if > 8bytes, 0 is returned. this method should mostly be used
1482// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001483uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001484ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001485{
1486 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001487 if (CanProvideValue())
Enrico Granatac3e320a2011-08-02 17:27:39 +00001488 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001489 Scalar scalar;
1490 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001491 {
1492 if (success)
1493 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001494 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001495 }
1496 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001497 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001498
1499 if (success)
1500 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001501 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001502}
1503
Enrico Granatad7373f62013-10-31 18:57:50 +00001504int64_t
1505ValueObject::GetValueAsSigned (int64_t fail_value, bool *success)
1506{
1507 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001508 if (CanProvideValue())
Enrico Granatad7373f62013-10-31 18:57:50 +00001509 {
1510 Scalar scalar;
1511 if (ResolveValue (scalar))
1512 {
1513 if (success)
1514 *success = true;
Tamas Berghammer5a9919f2015-01-23 10:54:21 +00001515 return scalar.SLongLong(fail_value);
Enrico Granatad7373f62013-10-31 18:57:50 +00001516 }
1517 // fallthrough, otherwise...
1518 }
1519
1520 if (success)
1521 *success = false;
Tamas Berghammer5a9919f2015-01-23 10:54:21 +00001522 return fail_value;
Enrico Granatad7373f62013-10-31 18:57:50 +00001523}
1524
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001525// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1526// this call up to date by returning true for your new special cases. We will eventually move
1527// to checking this call result before trying to display special cases
1528bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001529ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1530 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001531{
Greg Clayton57ee3062013-07-11 22:46:58 +00001532 Flags flags(GetTypeInfo());
Enrico Granata622be232014-10-21 20:52:14 +00001533 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001534 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001535 {
1536 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001537 (custom_format == eFormatCString ||
1538 custom_format == eFormatCharArray ||
1539 custom_format == eFormatChar ||
1540 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001541 return true;
1542
Enrico Granata622be232014-10-21 20:52:14 +00001543 if (flags.Test(eTypeIsArray))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001544 {
Greg Claytonafacd142011-09-02 01:15:17 +00001545 if ((custom_format == eFormatBytes) ||
1546 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001547 return true;
1548
Greg Claytonafacd142011-09-02 01:15:17 +00001549 if ((custom_format == eFormatVectorOfChar) ||
1550 (custom_format == eFormatVectorOfFloat32) ||
1551 (custom_format == eFormatVectorOfFloat64) ||
1552 (custom_format == eFormatVectorOfSInt16) ||
1553 (custom_format == eFormatVectorOfSInt32) ||
1554 (custom_format == eFormatVectorOfSInt64) ||
1555 (custom_format == eFormatVectorOfSInt8) ||
1556 (custom_format == eFormatVectorOfUInt128) ||
1557 (custom_format == eFormatVectorOfUInt16) ||
1558 (custom_format == eFormatVectorOfUInt32) ||
1559 (custom_format == eFormatVectorOfUInt64) ||
1560 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001561 return true;
1562 }
1563 }
1564 return false;
1565}
1566
Enrico Granata9fc19442011-07-06 02:13:41 +00001567bool
1568ValueObject::DumpPrintableRepresentation(Stream& s,
1569 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001570 Format custom_format,
Enrico Granata0dba9b32014-01-08 01:36:59 +00001571 PrintableRepresentationSpecialCases special,
1572 bool do_dump_error)
Enrico Granata9fc19442011-07-06 02:13:41 +00001573{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001574
Greg Clayton57ee3062013-07-11 22:46:58 +00001575 Flags flags(GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001576
Enrico Granata86cc9822012-03-19 22:58:49 +00001577 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1578 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1579
1580 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001581 {
Enrico Granata622be232014-10-21 20:52:14 +00001582 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001583 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001584 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001585 // when being asked to get a printable display an array or pointer type directly,
1586 // try to "do the right thing"
1587
1588 if (IsCStringContainer(true) &&
1589 (custom_format == eFormatCString ||
1590 custom_format == eFormatCharArray ||
1591 custom_format == eFormatChar ||
1592 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001593 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001594 Error error;
Enrico Granata2206b482014-10-30 18:27:31 +00001595 lldb::DataBufferSP buffer_sp;
1596 ReadPointedString(buffer_sp,
Enrico Granata86cc9822012-03-19 22:58:49 +00001597 error,
1598 0,
1599 (custom_format == eFormatVectorOfChar) ||
1600 (custom_format == eFormatCharArray));
Enrico Granataebdc1ac2014-11-05 21:20:48 +00001601 lldb_private::formatters::ReadBufferAndDumpToStreamOptions options(*this);
Enrico Granata2206b482014-10-30 18:27:31 +00001602 options.SetData(DataExtractor(buffer_sp, lldb::eByteOrderInvalid, 8)); // none of this matters for a string - pass some defaults
1603 options.SetStream(&s);
1604 options.SetPrefixToken(0);
1605 options.SetQuote('"');
1606 options.SetSourceSize(buffer_sp->GetByteSize());
Enrico Granata2206b482014-10-30 18:27:31 +00001607 lldb_private::formatters::ReadBufferAndDumpToStream<lldb_private::formatters::StringElementType::ASCII>(options);
Enrico Granata86cc9822012-03-19 22:58:49 +00001608 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001609 }
1610
Enrico Granata86cc9822012-03-19 22:58:49 +00001611 if (custom_format == eFormatEnum)
1612 return false;
1613
1614 // this only works for arrays, because I have no way to know when
1615 // the pointed memory ends, and no special \0 end of data marker
Enrico Granata622be232014-10-21 20:52:14 +00001616 if (flags.Test(eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001617 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001618 if ((custom_format == eFormatBytes) ||
1619 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001620 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001621 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001622
1623 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001624 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001625 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001626
1627 if (low)
1628 s << ',';
1629
1630 ValueObjectSP child = GetChildAtIndex(low,true);
1631 if (!child.get())
1632 {
1633 s << "<invalid child>";
1634 continue;
1635 }
1636 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1637 }
1638
1639 s << ']';
1640
1641 return true;
1642 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001643
Enrico Granata86cc9822012-03-19 22:58:49 +00001644 if ((custom_format == eFormatVectorOfChar) ||
1645 (custom_format == eFormatVectorOfFloat32) ||
1646 (custom_format == eFormatVectorOfFloat64) ||
1647 (custom_format == eFormatVectorOfSInt16) ||
1648 (custom_format == eFormatVectorOfSInt32) ||
1649 (custom_format == eFormatVectorOfSInt64) ||
1650 (custom_format == eFormatVectorOfSInt8) ||
1651 (custom_format == eFormatVectorOfUInt128) ||
1652 (custom_format == eFormatVectorOfUInt16) ||
1653 (custom_format == eFormatVectorOfUInt32) ||
1654 (custom_format == eFormatVectorOfUInt64) ||
1655 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1656 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001657 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001658
1659 Format format = FormatManager::GetSingleItemFormat(custom_format);
1660
1661 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001662 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001663 {
1664
1665 if (low)
1666 s << ',';
1667
1668 ValueObjectSP child = GetChildAtIndex(low,true);
1669 if (!child.get())
1670 {
1671 s << "<invalid child>";
1672 continue;
1673 }
1674 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1675 }
1676
1677 s << ']';
1678
1679 return true;
1680 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001681 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001682
1683 if ((custom_format == eFormatBoolean) ||
1684 (custom_format == eFormatBinary) ||
1685 (custom_format == eFormatChar) ||
1686 (custom_format == eFormatCharPrintable) ||
1687 (custom_format == eFormatComplexFloat) ||
1688 (custom_format == eFormatDecimal) ||
1689 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001690 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001691 (custom_format == eFormatFloat) ||
1692 (custom_format == eFormatOctal) ||
1693 (custom_format == eFormatOSType) ||
1694 (custom_format == eFormatUnicode16) ||
1695 (custom_format == eFormatUnicode32) ||
1696 (custom_format == eFormatUnsigned) ||
1697 (custom_format == eFormatPointer) ||
1698 (custom_format == eFormatComplexInteger) ||
1699 (custom_format == eFormatComplex) ||
1700 (custom_format == eFormatDefault)) // use the [] operator
1701 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001702 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001703 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001704
1705 if (only_special)
1706 return false;
1707
Enrico Granata86cc9822012-03-19 22:58:49 +00001708 bool var_success = false;
1709
1710 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001711 const char *cstr = NULL;
Enrico Granata2c75f112013-06-21 00:04:51 +00001712
1713 // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1714 // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1715 // area for cases where our desired output is not backed by some other longer-term storage
Greg Claytonc7bece562013-01-25 18:06:21 +00001716 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001717
Enrico Granata465f4bc2014-02-15 01:24:44 +00001718 if (custom_format != eFormatInvalid)
Enrico Granata86cc9822012-03-19 22:58:49 +00001719 SetFormat(custom_format);
1720
1721 switch(val_obj_display)
1722 {
1723 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001724 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001725 break;
1726
1727 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001728 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001729 break;
1730
1731 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001732 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001733 break;
1734
1735 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001736 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001737 break;
1738
1739 case eValueObjectRepresentationStyleChildrenCount:
Deepak Panickal99fbc072014-03-03 15:39:47 +00001740 strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren());
Greg Claytonc7bece562013-01-25 18:06:21 +00001741 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001742 break;
1743
1744 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001745 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001746 break;
Enrico Granata2c75f112013-06-21 00:04:51 +00001747
1748 case eValueObjectRepresentationStyleName:
1749 cstr = GetName().AsCString();
1750 break;
1751
1752 case eValueObjectRepresentationStyleExpressionPath:
1753 GetExpressionPath(strm, false);
1754 cstr = strm.GetString().c_str();
1755 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001756 }
1757
Greg Claytonc7bece562013-01-25 18:06:21 +00001758 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001759 {
1760 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001761 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001762 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1763 {
Enrico Granatad07cfd32014-10-08 18:27:36 +00001764 if (!CanProvideValue())
Enrico Granata86cc9822012-03-19 22:58:49 +00001765 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001766 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1767 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001768 }
1769 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001770 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001771 }
1772 }
1773
Greg Claytonc7bece562013-01-25 18:06:21 +00001774 if (cstr)
1775 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001776 else
1777 {
1778 if (m_error.Fail())
Enrico Granata0dba9b32014-01-08 01:36:59 +00001779 {
1780 if (do_dump_error)
1781 s.Printf("<%s>", m_error.AsCString());
1782 else
1783 return false;
1784 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001785 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1786 s.PutCString("<no summary available>");
1787 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1788 s.PutCString("<no value available>");
1789 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1790 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1791 else
1792 s.PutCString("<no printable representation>");
1793 }
1794
1795 // we should only return false here if we could not do *anything*
1796 // even if we have an error message as output, that's a success
1797 // from our callers' perspective, so return true
1798 var_success = true;
Enrico Granata465f4bc2014-02-15 01:24:44 +00001799
1800 if (custom_format != eFormatInvalid)
1801 SetFormat(eFormatDefault);
Enrico Granata86cc9822012-03-19 22:58:49 +00001802 }
1803
Enrico Granataf4efecd2011-07-12 22:56:10 +00001804 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001805}
1806
Greg Clayton737b9322010-09-13 03:32:57 +00001807addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001808ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001809{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001810 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001811 return LLDB_INVALID_ADDRESS;
1812
Greg Clayton73b472d2010-10-27 03:32:59 +00001813 switch (m_value.GetValueType())
1814 {
1815 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001816 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001817 if (scalar_is_load_address)
1818 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001819 if(address_type)
1820 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001821 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1822 }
1823 break;
1824
1825 case Value::eValueTypeLoadAddress:
1826 case Value::eValueTypeFileAddress:
Greg Clayton73b472d2010-10-27 03:32:59 +00001827 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001828 if(address_type)
1829 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001830 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1831 }
1832 break;
Siva Chandraa3747a92015-05-04 19:43:34 +00001833 case Value::eValueTypeHostAddress:
Siva Chandrae32f2b52015-05-05 00:41:35 +00001834 {
1835 if(address_type)
1836 *address_type = m_value.GetValueAddressType ();
1837 return LLDB_INVALID_ADDRESS;
1838 }
Siva Chandraa3747a92015-05-04 19:43:34 +00001839 break;
Greg Clayton73b472d2010-10-27 03:32:59 +00001840 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001841 if (address_type)
1842 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001843 return LLDB_INVALID_ADDRESS;
1844}
1845
1846addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001847ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001848{
Greg Claytonafacd142011-09-02 01:15:17 +00001849 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001850 if(address_type)
1851 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001852
Enrico Granatac3e320a2011-08-02 17:27:39 +00001853 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001854 return address;
1855
Greg Clayton73b472d2010-10-27 03:32:59 +00001856 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001857 {
1858 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001859 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001860 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001861 break;
1862
Enrico Granata9128ee22011-09-06 19:20:51 +00001863 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001864 case Value::eValueTypeLoadAddress:
1865 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001866 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001867 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001868 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001869 }
1870 break;
1871 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001872
Enrico Granata9128ee22011-09-06 19:20:51 +00001873 if (address_type)
1874 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001875
Greg Clayton737b9322010-09-13 03:32:57 +00001876 return address;
1877}
1878
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001879bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001880ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001881{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001882 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001883 // Make sure our value is up to date first so that our location and location
1884 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001885 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001886 {
1887 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001888 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001889 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001890
Greg Claytonfaac1112013-03-14 18:31:44 +00001891 uint64_t count = 0;
Greg Clayton57ee3062013-07-11 22:46:58 +00001892 const Encoding encoding = GetClangType().GetEncoding (count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001893
Greg Claytonb1320972010-07-14 00:18:15 +00001894 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001895
Jim Ingham16e0c682011-08-12 23:34:31 +00001896 Value::ValueType value_type = m_value.GetValueType();
1897
1898 if (value_type == Value::eValueTypeScalar)
1899 {
1900 // If the value is already a scalar, then let the scalar change itself:
1901 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1902 }
1903 else if (byte_size <= Scalar::GetMaxByteSize())
1904 {
1905 // If the value fits in a scalar, then make a new scalar and again let the
1906 // scalar code do the conversion, then figure out where to put the new value.
1907 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001908 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1909 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001910 {
Jim Ingham4b536182011-08-09 02:12:22 +00001911 switch (value_type)
1912 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001913 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001914 {
1915 // If it is a load address, then the scalar value is the storage location
1916 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001917 ExecutionContext exe_ctx (GetExecutionContextRef());
1918 Process *process = exe_ctx.GetProcessPtr();
1919 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001920 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001921 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001922 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1923 new_scalar,
1924 byte_size,
1925 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001926 if (!error.Success())
1927 return false;
1928 if (bytes_written != byte_size)
1929 {
1930 error.SetErrorString("unable to write value to memory");
1931 return false;
1932 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001933 }
1934 }
Jim Ingham4b536182011-08-09 02:12:22 +00001935 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001936 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001937 {
1938 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1939 DataExtractor new_data;
1940 new_data.SetByteOrder (m_data.GetByteOrder());
1941
1942 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1943 m_data.SetData(buffer_sp, 0);
1944 bool success = new_scalar.GetData(new_data);
1945 if (success)
1946 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001947 new_data.CopyByteOrderedData (0,
1948 byte_size,
1949 const_cast<uint8_t *>(m_data.GetDataStart()),
1950 byte_size,
1951 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001952 }
1953 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1954
1955 }
Jim Ingham4b536182011-08-09 02:12:22 +00001956 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001957 case Value::eValueTypeFileAddress:
1958 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001959 case Value::eValueTypeVector:
1960 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001961 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001962 }
1963 else
1964 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001965 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001966 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001967 }
1968 else
1969 {
1970 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001971 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001972 return false;
1973 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001974
1975 // If we have reached this point, then we have successfully changed the value.
1976 SetNeedsUpdate();
1977 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001978}
1979
Greg Clayton81e871e2012-02-04 02:27:34 +00001980bool
1981ValueObject::GetDeclaration (Declaration &decl)
1982{
1983 decl.Clear();
1984 return false;
1985}
1986
Greg Clayton84db9102012-03-26 23:03:23 +00001987ConstString
1988ValueObject::GetTypeName()
1989{
Greg Clayton57ee3062013-07-11 22:46:58 +00001990 return GetClangType().GetConstTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00001991}
1992
1993ConstString
Enrico Granatae8daa2f2014-05-17 19:14:17 +00001994ValueObject::GetDisplayTypeName()
1995{
1996 return GetTypeName();
1997}
1998
1999ConstString
Greg Clayton84db9102012-03-26 23:03:23 +00002000ValueObject::GetQualifiedTypeName()
2001{
Greg Clayton57ee3062013-07-11 22:46:58 +00002002 return GetClangType().GetConstQualifiedTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00002003}
2004
2005
Greg Claytonafacd142011-09-02 01:15:17 +00002006LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00002007ValueObject::GetObjectRuntimeLanguage ()
2008{
Greg Clayton57ee3062013-07-11 22:46:58 +00002009 return GetClangType().GetMinimumLanguage ();
Jim Ingham5a369122010-09-28 01:25:32 +00002010}
2011
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002012void
Jim Ingham58b59f92011-04-22 23:53:53 +00002013ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002014{
Jim Ingham58b59f92011-04-22 23:53:53 +00002015 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002016}
2017
2018ValueObjectSP
2019ValueObject::GetSyntheticChild (const ConstString &key) const
2020{
2021 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00002022 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002023 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00002024 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002025 return synthetic_child_sp;
2026}
2027
Greg Clayton2452ab72013-02-08 22:02:02 +00002028uint32_t
Greg Clayton57ee3062013-07-11 22:46:58 +00002029ValueObject::GetTypeInfo (ClangASTType *pointee_or_element_clang_type)
Greg Clayton2452ab72013-02-08 22:02:02 +00002030{
Greg Clayton57ee3062013-07-11 22:46:58 +00002031 return GetClangType().GetTypeInfo (pointee_or_element_clang_type);
Greg Clayton2452ab72013-02-08 22:02:02 +00002032}
2033
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002034bool
2035ValueObject::IsPointerType ()
2036{
Greg Clayton57ee3062013-07-11 22:46:58 +00002037 return GetClangType().IsPointerType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002038}
2039
Jim Inghamb7603bb2011-03-18 00:05:18 +00002040bool
Greg Claytondaf515f2011-07-09 20:12:33 +00002041ValueObject::IsArrayType ()
2042{
Greg Clayton57ee3062013-07-11 22:46:58 +00002043 return GetClangType().IsArrayType (NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00002044}
2045
2046bool
Enrico Granata9fc19442011-07-06 02:13:41 +00002047ValueObject::IsScalarType ()
2048{
Greg Clayton57ee3062013-07-11 22:46:58 +00002049 return GetClangType().IsScalarType ();
Enrico Granata9fc19442011-07-06 02:13:41 +00002050}
2051
2052bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00002053ValueObject::IsIntegerType (bool &is_signed)
2054{
Greg Clayton57ee3062013-07-11 22:46:58 +00002055 return GetClangType().IsIntegerType (is_signed);
Jim Inghamb7603bb2011-03-18 00:05:18 +00002056}
Greg Clayton73b472d2010-10-27 03:32:59 +00002057
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002058bool
2059ValueObject::IsPointerOrReferenceType ()
2060{
Greg Clayton57ee3062013-07-11 22:46:58 +00002061 return GetClangType().IsPointerOrReferenceType ();
Greg Clayton007d5be2011-05-30 00:49:24 +00002062}
2063
2064bool
Greg Claytondea8cb42011-06-29 22:09:02 +00002065ValueObject::IsPossibleDynamicType ()
2066{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002067 ExecutionContext exe_ctx (GetExecutionContextRef());
2068 Process *process = exe_ctx.GetProcessPtr();
2069 if (process)
2070 return process->IsPossibleDynamicValue(*this);
2071 else
Greg Clayton57ee3062013-07-11 22:46:58 +00002072 return GetClangType().IsPossibleDynamicType (NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00002073}
2074
Enrico Granata9e7b3882012-12-13 23:50:33 +00002075bool
Enrico Granata560558e2015-02-11 02:35:39 +00002076ValueObject::IsRuntimeSupportValue ()
2077{
2078 Process *process(GetProcessSP().get());
2079 if (process)
2080 {
2081 LanguageRuntime *runtime = process->GetLanguageRuntime(GetObjectRuntimeLanguage());
2082 if (!runtime)
2083 runtime = process->GetObjCLanguageRuntime();
2084 if (runtime)
2085 return runtime->IsRuntimeSupportValue(*this);
2086 }
2087 return false;
2088}
2089
2090bool
Enrico Granata9e7b3882012-12-13 23:50:33 +00002091ValueObject::IsObjCNil ()
2092{
Enrico Granata622be232014-10-21 20:52:14 +00002093 const uint32_t mask = eTypeIsObjC | eTypeIsPointer;
Greg Clayton57ee3062013-07-11 22:46:58 +00002094 bool isObjCpointer = (((GetClangType().GetTypeInfo(NULL)) & mask) == mask);
Enrico Granata7277d202013-03-15 23:33:15 +00002095 if (!isObjCpointer)
2096 return false;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002097 bool canReadValue = true;
2098 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
Enrico Granata7277d202013-03-15 23:33:15 +00002099 return canReadValue && isZero;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002100}
2101
Greg Claytondaf515f2011-07-09 20:12:33 +00002102// This allows you to create an array member using and index
2103// that doesn't not fall in the normal bounds of the array.
2104// Many times structure can be defined as:
2105// struct Collection
2106// {
2107// uint32_t item_count;
2108// Item item_array[0];
2109// };
2110// The size of the "item_array" is 1, but many times in practice
2111// there are more items in "item_array".
2112
2113ValueObjectSP
Bruce Mitchener11d86362015-02-26 23:55:39 +00002114ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00002115{
2116 ValueObjectSP synthetic_child_sp;
Bruce Mitchener11d86362015-02-26 23:55:39 +00002117 if (IsPointerType () || IsArrayType())
Greg Claytondaf515f2011-07-09 20:12:33 +00002118 {
2119 char index_str[64];
Deepak Panickal99fbc072014-03-03 15:39:47 +00002120 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
Greg Claytondaf515f2011-07-09 20:12:33 +00002121 ConstString index_const_str(index_str);
2122 // Check if we have already created a synthetic array member in this
2123 // valid object. If we have we will re-use it.
2124 synthetic_child_sp = GetSyntheticChild (index_const_str);
2125 if (!synthetic_child_sp)
2126 {
2127 ValueObject *synthetic_child;
2128 // We haven't made a synthetic array member for INDEX yet, so
2129 // lets make one and cache it for any future reference.
2130 synthetic_child = CreateChildAtIndex(0, true, index);
Bruce Mitchener11d86362015-02-26 23:55:39 +00002131
Greg Claytondaf515f2011-07-09 20:12:33 +00002132 // Cache the value if we got one back...
2133 if (synthetic_child)
2134 {
2135 AddSyntheticChild(index_const_str, synthetic_child);
2136 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002137 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00002138 synthetic_child_sp->m_is_array_item_for_pointer = true;
2139 }
2140 }
2141 }
2142 return synthetic_child_sp;
2143}
2144
Enrico Granata9fc19442011-07-06 02:13:41 +00002145ValueObjectSP
2146ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2147{
2148 ValueObjectSP synthetic_child_sp;
2149 if (IsScalarType ())
2150 {
2151 char index_str[64];
2152 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2153 ConstString index_const_str(index_str);
2154 // Check if we have already created a synthetic array member in this
2155 // valid object. If we have we will re-use it.
2156 synthetic_child_sp = GetSyntheticChild (index_const_str);
2157 if (!synthetic_child_sp)
2158 {
Enrico Granata9fc19442011-07-06 02:13:41 +00002159 // We haven't made a synthetic array member for INDEX yet, so
2160 // lets make one and cache it for any future reference.
Greg Clayton57ee3062013-07-11 22:46:58 +00002161 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
2162 GetClangType(),
2163 index_const_str,
2164 GetByteSize(),
2165 0,
2166 to-from+1,
2167 from,
2168 false,
2169 false,
2170 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002171
2172 // Cache the value if we got one back...
2173 if (synthetic_child)
2174 {
2175 AddSyntheticChild(index_const_str, synthetic_child);
2176 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002177 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002178 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2179 }
2180 }
2181 }
2182 return synthetic_child_sp;
2183}
2184
Greg Claytonafacd142011-09-02 01:15:17 +00002185ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00002186ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
2187{
2188
2189 ValueObjectSP synthetic_child_sp;
2190
2191 char name_str[64];
2192 snprintf(name_str, sizeof(name_str), "@%i", offset);
2193 ConstString name_const_str(name_str);
2194
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 (name_const_str);
2198
2199 if (synthetic_child_sp.get())
2200 return synthetic_child_sp;
2201
2202 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002203 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002204
Enrico Granata951bdd52015-01-28 01:09:45 +00002205 ExecutionContext exe_ctx (GetExecutionContextRef());
2206
Enrico Granata6f3533f2011-07-29 19:53:35 +00002207 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
Greg Clayton57ee3062013-07-11 22:46:58 +00002208 type,
Enrico Granata6f3533f2011-07-29 19:53:35 +00002209 name_const_str,
Greg Clayton526ae042015-02-12 00:34:25 +00002210 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
Enrico Granata6f3533f2011-07-29 19:53:35 +00002211 offset,
2212 0,
2213 0,
2214 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002215 false,
2216 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002217 if (synthetic_child)
2218 {
2219 AddSyntheticChild(name_const_str, synthetic_child);
2220 synthetic_child_sp = synthetic_child->GetSP();
2221 synthetic_child_sp->SetName(name_const_str);
2222 synthetic_child_sp->m_is_child_at_offset = true;
2223 }
2224 return synthetic_child_sp;
2225}
2226
Enrico Granata32556cd2014-08-26 20:54:04 +00002227ValueObjectSP
Enrico Granata59953f02014-08-26 21:35:30 +00002228ValueObject::GetSyntheticBase (uint32_t offset, const ClangASTType& type, bool can_create)
Enrico Granata32556cd2014-08-26 20:54:04 +00002229{
2230 ValueObjectSP synthetic_child_sp;
2231
2232 char name_str[64];
2233 snprintf(name_str, sizeof(name_str), "%s", type.GetTypeName().AsCString("<unknown>"));
2234 ConstString name_const_str(name_str);
2235
2236 // Check if we have already created a synthetic array member in this
2237 // valid object. If we have we will re-use it.
2238 synthetic_child_sp = GetSyntheticChild (name_const_str);
2239
2240 if (synthetic_child_sp.get())
2241 return synthetic_child_sp;
2242
2243 if (!can_create)
2244 return ValueObjectSP();
2245
Enrico Granata32556cd2014-08-26 20:54:04 +00002246 const bool is_base_class = true;
2247
Enrico Granata951bdd52015-01-28 01:09:45 +00002248 ExecutionContext exe_ctx (GetExecutionContextRef());
2249
Enrico Granata32556cd2014-08-26 20:54:04 +00002250 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2251 type,
2252 name_const_str,
Greg Clayton526ae042015-02-12 00:34:25 +00002253 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
Enrico Granata32556cd2014-08-26 20:54:04 +00002254 offset,
2255 0,
2256 0,
2257 is_base_class,
2258 false,
2259 eAddressTypeInvalid);
2260 if (synthetic_child)
2261 {
2262 AddSyntheticChild(name_const_str, synthetic_child);
2263 synthetic_child_sp = synthetic_child->GetSP();
2264 synthetic_child_sp->SetName(name_const_str);
2265 }
2266 return synthetic_child_sp;
2267}
2268
2269
Enrico Granatad55546b2011-07-22 00:16:08 +00002270// your expression path needs to have a leading . or ->
2271// (unless it somehow "looks like" an array, in which case it has
2272// a leading [ symbol). while the [ is meaningful and should be shown
2273// to the user, . and -> are just parser design, but by no means
2274// added information for the user.. strip them off
2275static const char*
2276SkipLeadingExpressionPathSeparators(const char* expression)
2277{
2278 if (!expression || !expression[0])
2279 return expression;
2280 if (expression[0] == '.')
2281 return expression+1;
2282 if (expression[0] == '-' && expression[1] == '>')
2283 return expression+2;
2284 return expression;
2285}
2286
Greg Claytonafacd142011-09-02 01:15:17 +00002287ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002288ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2289{
2290 ValueObjectSP synthetic_child_sp;
2291 ConstString name_const_string(expression);
2292 // Check if we have already created a synthetic array member in this
2293 // valid object. If we have we will re-use it.
2294 synthetic_child_sp = GetSyntheticChild (name_const_string);
2295 if (!synthetic_child_sp)
2296 {
2297 // We haven't made a synthetic array member for expression yet, so
2298 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002299 synthetic_child_sp = GetValueForExpressionPath(expression,
2300 NULL, NULL, NULL,
Enrico Granataef238c12015-03-12 22:30:58 +00002301 GetValueForExpressionPathOptions().SetSyntheticChildrenTraversal(GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None));
Enrico Granatad55546b2011-07-22 00:16:08 +00002302
2303 // Cache the value if we got one back...
2304 if (synthetic_child_sp.get())
2305 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002306 // 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 +00002307 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002308 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002309 }
2310 }
2311 return synthetic_child_sp;
2312}
2313
2314void
Enrico Granata86cc9822012-03-19 22:58:49 +00002315ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002316{
Enrico Granata86cc9822012-03-19 22:58:49 +00002317 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002318 return;
2319
Enrico Granatac5bc4122012-03-27 02:35:13 +00002320 TargetSP target_sp(GetTargetSP());
Enrico Granata5d5f60c2013-09-24 22:58:37 +00002321 if (target_sp && target_sp->GetEnableSyntheticValue() == false)
Enrico Granatac5bc4122012-03-27 02:35:13 +00002322 {
2323 m_synthetic_value = NULL;
2324 return;
2325 }
2326
Enrico Granatae3e91512012-10-22 18:18:36 +00002327 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2328
Enrico Granata5548cb52013-01-28 23:47:25 +00002329 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002330 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002331
Enrico Granata0c489f52012-03-01 04:24:26 +00002332 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002333 return;
2334
Enrico Granatae3e91512012-10-22 18:18:36 +00002335 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2336 return;
2337
Enrico Granata86cc9822012-03-19 22:58:49 +00002338 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002339}
2340
Jim Ingham78a685a2011-04-16 00:01:13 +00002341void
Greg Claytonafacd142011-09-02 01:15:17 +00002342ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002343{
Greg Claytonafacd142011-09-02 01:15:17 +00002344 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002345 return;
2346
Jim Ingham58b59f92011-04-22 23:53:53 +00002347 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002348 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002349 ExecutionContext exe_ctx (GetExecutionContextRef());
2350 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002351 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002352 {
2353 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002354 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002355 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002356 }
2357}
2358
Jim Ingham58b59f92011-04-22 23:53:53 +00002359ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002360ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002361{
Greg Claytonafacd142011-09-02 01:15:17 +00002362 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002363 return ValueObjectSP();
2364
2365 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002366 {
Jim Ingham2837b762011-05-04 03:43:18 +00002367 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002368 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002369 if (m_dynamic_value)
2370 return m_dynamic_value->GetSP();
2371 else
2372 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002373}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002374
Jim Ingham60dbabb2011-12-08 19:44:08 +00002375ValueObjectSP
2376ValueObject::GetStaticValue()
2377{
2378 return GetSP();
2379}
2380
Enrico Granata886147f2012-05-08 18:47:08 +00002381lldb::ValueObjectSP
2382ValueObject::GetNonSyntheticValue ()
2383{
2384 return GetSP();
2385}
2386
Enrico Granatad55546b2011-07-22 00:16:08 +00002387ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002388ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002389{
Enrico Granata86cc9822012-03-19 22:58:49 +00002390 if (use_synthetic == false)
2391 return ValueObjectSP();
2392
Enrico Granatad55546b2011-07-22 00:16:08 +00002393 CalculateSyntheticValue(use_synthetic);
2394
2395 if (m_synthetic_value)
2396 return m_synthetic_value->GetSP();
2397 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002398 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002399}
2400
Greg Claytone221f822011-01-21 01:59:00 +00002401bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002402ValueObject::HasSyntheticValue()
2403{
Enrico Granata5548cb52013-01-28 23:47:25 +00002404 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002405
Enrico Granata0c489f52012-03-01 04:24:26 +00002406 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002407 return false;
2408
Enrico Granata86cc9822012-03-19 22:58:49 +00002409 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002410
2411 if (m_synthetic_value)
2412 return true;
2413 else
2414 return false;
2415}
2416
2417bool
Greg Claytone221f822011-01-21 01:59:00 +00002418ValueObject::GetBaseClassPath (Stream &s)
2419{
2420 if (IsBaseClass())
2421 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002422 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Clayton57ee3062013-07-11 22:46:58 +00002423 ClangASTType clang_type = GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002424 std::string cxx_class_name;
Greg Clayton57ee3062013-07-11 22:46:58 +00002425 bool this_had_base_class = clang_type.GetCXXClassName (cxx_class_name);
Greg Claytone221f822011-01-21 01:59:00 +00002426 if (this_had_base_class)
2427 {
2428 if (parent_had_base_class)
2429 s.PutCString("::");
2430 s.PutCString(cxx_class_name.c_str());
2431 }
2432 return parent_had_base_class || this_had_base_class;
2433 }
2434 return false;
2435}
2436
2437
2438ValueObject *
2439ValueObject::GetNonBaseClassParent()
2440{
Jim Ingham78a685a2011-04-16 00:01:13 +00002441 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002442 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002443 if (GetParent()->IsBaseClass())
2444 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002445 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002446 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002447 }
2448 return NULL;
2449}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002450
Enrico Granataa3c8f042014-08-19 22:29:08 +00002451
2452bool
2453ValueObject::IsBaseClass (uint32_t& depth)
2454{
2455 if (!IsBaseClass())
2456 {
2457 depth = 0;
2458 return false;
2459 }
2460 if (GetParent())
2461 {
2462 GetParent()->IsBaseClass(depth);
2463 depth = depth + 1;
2464 return true;
2465 }
2466 // TODO: a base of no parent? weird..
2467 depth = 1;
2468 return true;
2469}
2470
Greg Clayton1d3afba2010-10-05 00:00:42 +00002471void
Enrico Granata4becb372011-06-29 22:27:15 +00002472ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002473{
Enrico Granata986fa5f2014-12-09 21:41:16 +00002474 // synthetic children do not actually "exist" as part of the hierarchy, and sometimes they are consed up in ways
2475 // that don't make sense from an underlying language/API standpoint. So, use a special code path here to return
2476 // something that can hopefully be used in expression
2477 if (m_is_synthetic_children_generated)
2478 {
2479 UpdateValueIfNeeded();
2480
2481 if (m_value.GetValueType() == Value::eValueTypeLoadAddress)
2482 {
2483 if (IsPointerOrReferenceType())
2484 {
2485 s.Printf("((%s)0x%" PRIx64 ")",
2486 GetTypeName().AsCString("void"),
2487 GetValueAsUnsigned(0));
2488 return;
2489 }
2490 else
2491 {
2492 uint64_t load_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
2493 if (load_addr != LLDB_INVALID_ADDRESS)
2494 {
2495 s.Printf("(*( (%s *)0x%" PRIx64 "))",
2496 GetTypeName().AsCString("void"),
2497 load_addr);
2498 return;
2499 }
2500 }
2501 }
2502
2503 if (CanProvideValue())
2504 {
2505 s.Printf("((%s)%s)",
2506 GetTypeName().AsCString("void"),
2507 GetValueAsCString());
2508 return;
2509 }
2510
2511 return;
2512 }
2513
Greg Claytone221f822011-01-21 01:59:00 +00002514 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002515
Enrico Granata86cc9822012-03-19 22:58:49 +00002516 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002517 {
Enrico Granata4becb372011-06-29 22:27:15 +00002518 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2519 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2520 // the eHonorPointers mode is meant to produce strings in this latter format
2521 s.PutCString("*(");
2522 }
Greg Claytone221f822011-01-21 01:59:00 +00002523
Enrico Granata4becb372011-06-29 22:27:15 +00002524 ValueObject* parent = GetParent();
2525
2526 if (parent)
2527 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002528
2529 // if we are a deref_of_parent just because we are synthetic array
2530 // members made up to allow ptr[%d] syntax to work in variable
2531 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002532 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002533 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002534
Greg Claytone221f822011-01-21 01:59:00 +00002535 if (!IsBaseClass())
2536 {
2537 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002538 {
Greg Claytone221f822011-01-21 01:59:00 +00002539 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2540 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002541 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002542 ClangASTType non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002543 if (non_base_class_parent_clang_type)
2544 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002545 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002546 {
2547 s.PutCString("->");
2548 }
Enrico Granata4becb372011-06-29 22:27:15 +00002549 else
2550 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002551 const uint32_t non_base_class_parent_type_info = non_base_class_parent_clang_type.GetTypeInfo();
2552
Enrico Granata622be232014-10-21 20:52:14 +00002553 if (non_base_class_parent_type_info & eTypeIsPointer)
Enrico Granata4becb372011-06-29 22:27:15 +00002554 {
2555 s.PutCString("->");
2556 }
Enrico Granata622be232014-10-21 20:52:14 +00002557 else if ((non_base_class_parent_type_info & eTypeHasChildren) &&
2558 !(non_base_class_parent_type_info & eTypeIsArray))
Enrico Granata4becb372011-06-29 22:27:15 +00002559 {
2560 s.PutChar('.');
2561 }
Greg Claytone221f822011-01-21 01:59:00 +00002562 }
2563 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002564 }
Greg Claytone221f822011-01-21 01:59:00 +00002565
2566 const char *name = GetName().GetCString();
2567 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002568 {
Greg Claytone221f822011-01-21 01:59:00 +00002569 if (qualify_cxx_base_classes)
2570 {
2571 if (GetBaseClassPath (s))
2572 s.PutCString("::");
2573 }
2574 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002575 }
2576 }
2577 }
2578
Enrico Granata86cc9822012-03-19 22:58:49 +00002579 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002580 {
Greg Claytone221f822011-01-21 01:59:00 +00002581 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002582 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002583}
2584
Greg Claytonafacd142011-09-02 01:15:17 +00002585ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002586ValueObject::GetValueForExpressionPath(const char* expression,
2587 const char** first_unparsed,
2588 ExpressionPathScanEndReason* reason_to_stop,
2589 ExpressionPathEndResultType* final_value_type,
2590 const GetValueForExpressionPathOptions& options,
2591 ExpressionPathAftermath* final_task_on_target)
2592{
2593
2594 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002595 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2596 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002597 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002598
2599 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2600 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2601 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2602 final_value_type ? final_value_type : &dummy_final_value_type,
2603 options,
2604 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2605
Enrico Granata86cc9822012-03-19 22:58:49 +00002606 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002607 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002608
Enrico Granata86cc9822012-03-19 22:58:49 +00002609 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 +00002610 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002611 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002612 {
2613 Error error;
2614 ValueObjectSP final_value = ret_val->Dereference(error);
2615 if (error.Fail() || !final_value.get())
2616 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002617 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002618 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002619 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002620 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002621 return ValueObjectSP();
2622 }
2623 else
2624 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002625 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002626 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002627 return final_value;
2628 }
2629 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002630 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002631 {
2632 Error error;
2633 ValueObjectSP final_value = ret_val->AddressOf(error);
2634 if (error.Fail() || !final_value.get())
2635 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002636 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002637 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002638 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002639 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002640 return ValueObjectSP();
2641 }
2642 else
2643 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002644 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002645 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002646 return final_value;
2647 }
2648 }
2649 }
2650 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2651}
2652
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002653int
2654ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002655 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002656 const char** first_unparsed,
2657 ExpressionPathScanEndReason* reason_to_stop,
2658 ExpressionPathEndResultType* final_value_type,
2659 const GetValueForExpressionPathOptions& options,
2660 ExpressionPathAftermath* final_task_on_target)
2661{
2662 const char* dummy_first_unparsed;
2663 ExpressionPathScanEndReason dummy_reason_to_stop;
2664 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002665 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002666
2667 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2668 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2669 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2670 final_value_type ? final_value_type : &dummy_final_value_type,
2671 options,
2672 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2673
2674 if (!ret_val.get()) // if there are errors, I add nothing to the list
2675 return 0;
2676
Enrico Granata86ea8d82012-03-29 01:34:34 +00002677 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002678 {
2679 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002680 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002681 {
2682 list->Append(ret_val);
2683 return 1;
2684 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002685 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 +00002686 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002687 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002688 {
2689 Error error;
2690 ValueObjectSP final_value = ret_val->Dereference(error);
2691 if (error.Fail() || !final_value.get())
2692 {
Greg Clayton23f59502012-07-17 03:23:13 +00002693 if (reason_to_stop)
2694 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2695 if (final_value_type)
2696 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002697 return 0;
2698 }
2699 else
2700 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002701 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002702 list->Append(final_value);
2703 return 1;
2704 }
2705 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002706 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002707 {
2708 Error error;
2709 ValueObjectSP final_value = ret_val->AddressOf(error);
2710 if (error.Fail() || !final_value.get())
2711 {
Greg Clayton23f59502012-07-17 03:23:13 +00002712 if (reason_to_stop)
2713 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2714 if (final_value_type)
2715 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002716 return 0;
2717 }
2718 else
2719 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002720 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002721 list->Append(final_value);
2722 return 1;
2723 }
2724 }
2725 }
2726 }
2727 else
2728 {
2729 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2730 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2731 ret_val,
2732 list,
2733 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2734 final_value_type ? final_value_type : &dummy_final_value_type,
2735 options,
2736 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2737 }
2738 // in any non-covered case, just do the obviously right thing
2739 list->Append(ret_val);
2740 return 1;
2741}
2742
Greg Claytonafacd142011-09-02 01:15:17 +00002743ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002744ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2745 const char** first_unparsed,
2746 ExpressionPathScanEndReason* reason_to_stop,
2747 ExpressionPathEndResultType* final_result,
2748 const GetValueForExpressionPathOptions& options,
2749 ExpressionPathAftermath* what_next)
2750{
2751 ValueObjectSP root = GetSP();
2752
2753 if (!root.get())
2754 return ValueObjectSP();
2755
2756 *first_unparsed = expression_cstr;
2757
2758 while (true)
2759 {
2760
2761 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2762
Greg Clayton57ee3062013-07-11 22:46:58 +00002763 ClangASTType root_clang_type = root->GetClangType();
2764 ClangASTType pointee_clang_type;
2765 Flags pointee_clang_type_info;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002766
Greg Clayton57ee3062013-07-11 22:46:58 +00002767 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002768 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00002769 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002770
2771 if (!expression_cstr || *expression_cstr == '\0')
2772 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002773 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002774 return root;
2775 }
2776
2777 switch (*expression_cstr)
2778 {
2779 case '-':
2780 {
2781 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granata622be232014-10-21 20:52:14 +00002782 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 +00002783 {
2784 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002785 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2786 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002787 return ValueObjectSP();
2788 }
Enrico Granata622be232014-10-21 20:52:14 +00002789 if (root_clang_type_info.Test(eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2790 root_clang_type_info.Test(eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002791 options.m_no_fragile_ivar)
2792 {
2793 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002794 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2795 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002796 return ValueObjectSP();
2797 }
2798 if (expression_cstr[1] != '>')
2799 {
2800 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002801 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2802 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002803 return ValueObjectSP();
2804 }
2805 expression_cstr++; // skip the -
2806 }
2807 case '.': // or fallthrough from ->
2808 {
2809 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granata622be232014-10-21 20:52:14 +00002810 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 +00002811 {
2812 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002813 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2814 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002815 return ValueObjectSP();
2816 }
2817 expression_cstr++; // skip .
2818 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2819 ConstString child_name;
2820 if (!next_separator) // if no other separator just expand this last layer
2821 {
2822 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002823 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2824
2825 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002826 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002827 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002828 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2829 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002830 return child_valobj_sp;
2831 }
Enrico Granataef238c12015-03-12 22:30:58 +00002832 else
Enrico Granata8c9d3562011-08-11 17:08:01 +00002833 {
Enrico Granataef238c12015-03-12 22:30:58 +00002834 switch (options.m_synthetic_children_traversal)
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002835 {
Enrico Granataef238c12015-03-12 22:30:58 +00002836 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None:
2837 break;
2838 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic:
2839 if (root->IsSynthetic())
2840 {
2841 child_valobj_sp = root->GetNonSyntheticValue();
2842 if (child_valobj_sp.get())
2843 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2844 }
2845 break;
2846 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic:
2847 if (!root->IsSynthetic())
2848 {
2849 child_valobj_sp = root->GetSyntheticValue();
2850 if (child_valobj_sp.get())
2851 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2852 }
2853 break;
2854 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both:
2855 if (root->IsSynthetic())
2856 {
2857 child_valobj_sp = root->GetNonSyntheticValue();
2858 if (child_valobj_sp.get())
2859 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2860 }
2861 else
2862 {
2863 child_valobj_sp = root->GetSyntheticValue();
2864 if (child_valobj_sp.get())
2865 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2866 }
2867 break;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002868 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002869 }
2870
2871 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2872 // so we hit the "else" branch, and return an error
2873 if(child_valobj_sp.get()) // if it worked, just return
2874 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002875 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002876 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2877 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002878 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002879 }
2880 else
2881 {
2882 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002883 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2884 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002885 return ValueObjectSP();
2886 }
2887 }
2888 else // other layers do expand
2889 {
2890 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002891 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2892 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002893 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002894 root = child_valobj_sp;
2895 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002896 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002897 continue;
2898 }
Enrico Granataef238c12015-03-12 22:30:58 +00002899 else
Enrico Granata8c9d3562011-08-11 17:08:01 +00002900 {
Enrico Granataef238c12015-03-12 22:30:58 +00002901 switch (options.m_synthetic_children_traversal)
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002902 {
Enrico Granataef238c12015-03-12 22:30:58 +00002903 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None:
2904 break;
2905 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic:
2906 if (root->IsSynthetic())
2907 {
2908 child_valobj_sp = root->GetNonSyntheticValue();
2909 if (child_valobj_sp.get())
2910 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2911 }
2912 break;
2913 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic:
2914 if (!root->IsSynthetic())
2915 {
2916 child_valobj_sp = root->GetSyntheticValue();
2917 if (child_valobj_sp.get())
2918 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2919 }
2920 break;
2921 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both:
2922 if (root->IsSynthetic())
2923 {
2924 child_valobj_sp = root->GetNonSyntheticValue();
2925 if (child_valobj_sp.get())
2926 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2927 }
2928 else
2929 {
2930 child_valobj_sp = root->GetSyntheticValue();
2931 if (child_valobj_sp.get())
2932 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2933 }
2934 break;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002935 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002936 }
2937
2938 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2939 // so we hit the "else" branch, and return an error
2940 if(child_valobj_sp.get()) // if it worked, move on
2941 {
2942 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002943 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002944 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002945 continue;
2946 }
2947 else
2948 {
2949 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002950 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2951 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002952 return ValueObjectSP();
2953 }
2954 }
2955 break;
2956 }
2957 case '[':
2958 {
Enrico Granata622be232014-10-21 20:52:14 +00002959 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 +00002960 {
Enrico Granata622be232014-10-21 20:52:14 +00002961 if (!root_clang_type_info.Test(eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002962 {
Enrico Granataef238c12015-03-12 22:30:58 +00002963 if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None) // ...only chance left is synthetic
Enrico Granata27b625e2011-08-09 01:04:56 +00002964 {
2965 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002966 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2967 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002968 return ValueObjectSP();
2969 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002970 }
2971 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2972 {
2973 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002974 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2975 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002976 return ValueObjectSP();
2977 }
2978 }
2979 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2980 {
Enrico Granata622be232014-10-21 20:52:14 +00002981 if (!root_clang_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002982 {
2983 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002984 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2985 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002986 return ValueObjectSP();
2987 }
2988 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2989 {
2990 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002991 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2992 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002993 return root;
2994 }
2995 }
2996 const char *separator_position = ::strchr(expression_cstr+1,'-');
2997 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2998 if (!close_bracket_position) // if there is no ], this is a syntax error
2999 {
3000 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003001 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3002 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003003 return ValueObjectSP();
3004 }
3005 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3006 {
3007 char *end = NULL;
3008 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3009 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3010 {
3011 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003012 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3013 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003014 return ValueObjectSP();
3015 }
3016 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3017 {
Enrico Granata622be232014-10-21 20:52:14 +00003018 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003019 {
3020 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003021 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3022 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003023 return root;
3024 }
3025 else
3026 {
3027 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003028 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3029 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003030 return ValueObjectSP();
3031 }
3032 }
3033 // from here on we do have a valid index
Enrico Granata622be232014-10-21 20:52:14 +00003034 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003035 {
Greg Claytondaf515f2011-07-09 20:12:33 +00003036 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
3037 if (!child_valobj_sp)
Bruce Mitchener11d86362015-02-26 23:55:39 +00003038 child_valobj_sp = root->GetSyntheticArrayMember(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003039 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00003040 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
3041 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00003042 if (child_valobj_sp)
3043 {
3044 root = child_valobj_sp;
3045 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003046 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00003047 continue;
3048 }
3049 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003050 {
3051 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003052 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3053 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003054 return ValueObjectSP();
3055 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003056 }
Enrico Granata622be232014-10-21 20:52:14 +00003057 else if (root_clang_type_info.Test(eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003058 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003059 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 +00003060 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003061 {
3062 Error error;
3063 root = root->Dereference(error);
3064 if (error.Fail() || !root.get())
3065 {
3066 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003067 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3068 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003069 return ValueObjectSP();
3070 }
3071 else
3072 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003073 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003074 continue;
3075 }
3076 }
3077 else
3078 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003079 if (root->GetClangType().GetMinimumLanguage() == eLanguageTypeObjC
Enrico Granata622be232014-10-21 20:52:14 +00003080 && pointee_clang_type_info.AllClear(eTypeIsPointer)
Greg Clayton84db9102012-03-26 23:03:23 +00003081 && root->HasSyntheticValue()
Enrico Granataef238c12015-03-12 22:30:58 +00003082 && (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic ||
3083 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both))
Enrico Granata27b625e2011-08-09 01:04:56 +00003084 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003085 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003086 }
3087 else
Bruce Mitchener11d86362015-02-26 23:55:39 +00003088 root = root->GetSyntheticArrayMember(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003089 if (!root.get())
3090 {
3091 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003092 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3093 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003094 return ValueObjectSP();
3095 }
3096 else
3097 {
3098 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003099 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003100 continue;
3101 }
3102 }
3103 }
Enrico Granata622be232014-10-21 20:52:14 +00003104 else if (root_clang_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003105 {
3106 root = root->GetSyntheticBitFieldChild(index, index, true);
3107 if (!root.get())
3108 {
3109 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003110 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3111 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003112 return ValueObjectSP();
3113 }
3114 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3115 {
3116 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003117 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3118 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003119 return root;
3120 }
3121 }
Enrico Granata622be232014-10-21 20:52:14 +00003122 else if (root_clang_type_info.Test(eTypeIsVector))
Enrico Granata08a1bb82013-06-19 00:00:45 +00003123 {
3124 root = root->GetChildAtIndex(index, true);
3125 if (!root.get())
3126 {
3127 *first_unparsed = expression_cstr;
3128 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3129 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3130 return ValueObjectSP();
3131 }
3132 else
3133 {
3134 *first_unparsed = end+1; // skip ]
3135 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3136 continue;
3137 }
3138 }
Enrico Granataef238c12015-03-12 22:30:58 +00003139 else if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic ||
3140 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both)
Enrico Granata27b625e2011-08-09 01:04:56 +00003141 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003142 if (root->HasSyntheticValue())
3143 root = root->GetSyntheticValue();
3144 else if (!root->IsSynthetic())
3145 {
3146 *first_unparsed = expression_cstr;
3147 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3148 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3149 return ValueObjectSP();
3150 }
3151 // if we are here, then root itself is a synthetic VO.. should be good to go
3152
Enrico Granata27b625e2011-08-09 01:04:56 +00003153 if (!root.get())
3154 {
3155 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003156 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3157 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3158 return ValueObjectSP();
3159 }
3160 root = root->GetChildAtIndex(index, true);
3161 if (!root.get())
3162 {
3163 *first_unparsed = expression_cstr;
3164 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3165 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003166 return ValueObjectSP();
3167 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00003168 else
3169 {
3170 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003171 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00003172 continue;
3173 }
Enrico Granata27b625e2011-08-09 01:04:56 +00003174 }
3175 else
3176 {
3177 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003178 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3179 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003180 return ValueObjectSP();
3181 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003182 }
3183 else // we have a low and a high index
3184 {
3185 char *end = NULL;
3186 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3187 if (!end || end != separator_position) // if something weird is in our way return an error
3188 {
3189 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003190 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3191 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003192 return ValueObjectSP();
3193 }
3194 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3195 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3196 {
3197 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003198 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3199 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003200 return ValueObjectSP();
3201 }
3202 if (index_lower > index_higher) // swap indices if required
3203 {
3204 unsigned long temp = index_lower;
3205 index_lower = index_higher;
3206 index_higher = temp;
3207 }
Enrico Granata622be232014-10-21 20:52:14 +00003208 if (root_clang_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003209 {
3210 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3211 if (!root.get())
3212 {
3213 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003214 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3215 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003216 return ValueObjectSP();
3217 }
3218 else
3219 {
3220 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003221 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3222 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003223 return root;
3224 }
3225 }
Enrico Granata622be232014-10-21 20:52:14 +00003226 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 +00003227 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granata622be232014-10-21 20:52:14 +00003228 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003229 {
3230 Error error;
3231 root = root->Dereference(error);
3232 if (error.Fail() || !root.get())
3233 {
3234 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003235 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3236 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003237 return ValueObjectSP();
3238 }
3239 else
3240 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003241 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003242 continue;
3243 }
3244 }
3245 else
3246 {
3247 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003248 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3249 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003250 return root;
3251 }
3252 }
3253 break;
3254 }
3255 default: // some non-separator is in the way
3256 {
3257 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003258 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3259 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003260 return ValueObjectSP();
3261 break;
3262 }
3263 }
3264 }
3265}
3266
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003267int
3268ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3269 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00003270 ValueObjectSP root,
3271 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003272 ExpressionPathScanEndReason* reason_to_stop,
3273 ExpressionPathEndResultType* final_result,
3274 const GetValueForExpressionPathOptions& options,
3275 ExpressionPathAftermath* what_next)
3276{
3277 if (!root.get())
3278 return 0;
3279
3280 *first_unparsed = expression_cstr;
3281
3282 while (true)
3283 {
3284
3285 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3286
Greg Clayton57ee3062013-07-11 22:46:58 +00003287 ClangASTType root_clang_type = root->GetClangType();
3288 ClangASTType pointee_clang_type;
3289 Flags pointee_clang_type_info;
3290 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003291 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00003292 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003293
3294 if (!expression_cstr || *expression_cstr == '\0')
3295 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003296 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003297 list->Append(root);
3298 return 1;
3299 }
3300
3301 switch (*expression_cstr)
3302 {
3303 case '[':
3304 {
Enrico Granata622be232014-10-21 20:52:14 +00003305 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 +00003306 {
Enrico Granata622be232014-10-21 20:52:14 +00003307 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 +00003308 {
3309 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003310 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3311 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003312 return 0;
3313 }
3314 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3315 {
3316 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003317 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3318 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003319 return 0;
3320 }
3321 }
3322 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3323 {
Enrico Granata622be232014-10-21 20:52:14 +00003324 if (!root_clang_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003325 {
3326 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003327 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3328 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003329 return 0;
3330 }
3331 else // expand this into list
3332 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003333 const size_t max_index = root->GetNumChildren() - 1;
3334 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003335 {
3336 ValueObjectSP child =
3337 root->GetChildAtIndex(index, true);
3338 list->Append(child);
3339 }
3340 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003341 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3342 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003343 return max_index; // tell me number of items I added to the VOList
3344 }
3345 }
3346 const char *separator_position = ::strchr(expression_cstr+1,'-');
3347 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3348 if (!close_bracket_position) // if there is no ], this is a syntax error
3349 {
3350 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003351 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3352 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003353 return 0;
3354 }
3355 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3356 {
3357 char *end = NULL;
3358 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3359 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3360 {
3361 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003362 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3363 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003364 return 0;
3365 }
3366 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3367 {
Enrico Granata622be232014-10-21 20:52:14 +00003368 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003369 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003370 const size_t max_index = root->GetNumChildren() - 1;
3371 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003372 {
3373 ValueObjectSP child =
3374 root->GetChildAtIndex(index, true);
3375 list->Append(child);
3376 }
3377 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003378 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3379 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003380 return max_index; // tell me number of items I added to the VOList
3381 }
3382 else
3383 {
3384 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003385 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3386 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003387 return 0;
3388 }
3389 }
3390 // from here on we do have a valid index
Enrico Granata622be232014-10-21 20:52:14 +00003391 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003392 {
3393 root = root->GetChildAtIndex(index, true);
3394 if (!root.get())
3395 {
3396 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003397 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3398 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003399 return 0;
3400 }
3401 else
3402 {
3403 list->Append(root);
3404 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003405 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3406 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003407 return 1;
3408 }
3409 }
Enrico Granata622be232014-10-21 20:52:14 +00003410 else if (root_clang_type_info.Test(eTypeIsPointer))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003411 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003412 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 +00003413 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003414 {
3415 Error error;
3416 root = root->Dereference(error);
3417 if (error.Fail() || !root.get())
3418 {
3419 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003420 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3421 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003422 return 0;
3423 }
3424 else
3425 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003426 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003427 continue;
3428 }
3429 }
3430 else
3431 {
Bruce Mitchener11d86362015-02-26 23:55:39 +00003432 root = root->GetSyntheticArrayMember(index, true);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003433 if (!root.get())
3434 {
3435 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003436 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3437 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003438 return 0;
3439 }
3440 else
3441 {
3442 list->Append(root);
3443 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003444 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3445 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003446 return 1;
3447 }
3448 }
3449 }
3450 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3451 {
3452 root = root->GetSyntheticBitFieldChild(index, index, true);
3453 if (!root.get())
3454 {
3455 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003456 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3457 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003458 return 0;
3459 }
3460 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3461 {
3462 list->Append(root);
3463 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003464 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3465 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003466 return 1;
3467 }
3468 }
3469 }
3470 else // we have a low and a high index
3471 {
3472 char *end = NULL;
3473 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3474 if (!end || end != separator_position) // if something weird is in our way return an error
3475 {
3476 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003477 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3478 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003479 return 0;
3480 }
3481 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3482 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3483 {
3484 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003485 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3486 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003487 return 0;
3488 }
3489 if (index_lower > index_higher) // swap indices if required
3490 {
3491 unsigned long temp = index_lower;
3492 index_lower = index_higher;
3493 index_higher = temp;
3494 }
Enrico Granata622be232014-10-21 20:52:14 +00003495 if (root_clang_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003496 {
3497 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3498 if (!root.get())
3499 {
3500 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003501 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3502 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003503 return 0;
3504 }
3505 else
3506 {
3507 list->Append(root);
3508 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003509 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3510 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003511 return 1;
3512 }
3513 }
Enrico Granata622be232014-10-21 20:52:14 +00003514 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 +00003515 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granata622be232014-10-21 20:52:14 +00003516 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003517 {
3518 Error error;
3519 root = root->Dereference(error);
3520 if (error.Fail() || !root.get())
3521 {
3522 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003523 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3524 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003525 return 0;
3526 }
3527 else
3528 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003529 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003530 continue;
3531 }
3532 }
3533 else
3534 {
Johnny Chen44805302011-07-19 19:48:13 +00003535 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003536 index <= index_higher; index++)
3537 {
3538 ValueObjectSP child =
3539 root->GetChildAtIndex(index, true);
3540 list->Append(child);
3541 }
3542 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003543 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3544 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003545 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3546 }
3547 }
3548 break;
3549 }
3550 default: // some non-[ separator, or something entirely wrong, is in the way
3551 {
3552 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003553 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3554 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003555 return 0;
3556 break;
3557 }
3558 }
3559 }
3560}
3561
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003562void
3563ValueObject::LogValueObject (Log *log)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003564{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003565 if (log)
3566 return LogValueObject (log, DumpValueObjectOptions::DefaultOptions());
Greg Clayton1d3afba2010-10-05 00:00:42 +00003567}
3568
Enrico Granata0c489f52012-03-01 04:24:26 +00003569void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003570ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003571{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003572 if (log)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003573 {
3574 StreamString s;
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003575 Dump (s, options);
Greg Claytonf830dbb2012-03-22 18:15:37 +00003576 if (s.GetSize())
3577 log->PutCString(s.GetData());
3578 }
3579}
3580
3581void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003582ValueObject::Dump (Stream &s)
Enrico Granata0c489f52012-03-01 04:24:26 +00003583{
Enrico Granata78639912014-12-20 01:41:27 +00003584 Dump (s, DumpValueObjectOptions::DefaultOptions());
Enrico Granata0c489f52012-03-01 04:24:26 +00003585}
3586
3587void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003588ValueObject::Dump (Stream &s,
3589 const DumpValueObjectOptions& options)
Enrico Granata0c489f52012-03-01 04:24:26 +00003590{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003591 ValueObjectPrinter printer(this,&s,options);
3592 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003593}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003594
3595ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003596ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003597{
3598 ValueObjectSP valobj_sp;
3599
Enrico Granatac3e320a2011-08-02 17:27:39 +00003600 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003601 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003602 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003603
3604 DataExtractor data;
3605 data.SetByteOrder (m_data.GetByteOrder());
3606 data.SetAddressByteSize(m_data.GetAddressByteSize());
3607
Enrico Granata9f1e2042012-04-24 22:15:37 +00003608 if (IsBitfield())
3609 {
3610 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
Greg Clayton57ee3062013-07-11 22:46:58 +00003611 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Enrico Granata9f1e2042012-04-24 22:15:37 +00003612 }
3613 else
Greg Clayton57ee3062013-07-11 22:46:58 +00003614 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003615
3616 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003617 GetClangType(),
3618 name,
3619 data,
3620 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003621 }
Jim Ingham6035b672011-03-31 00:19:25 +00003622
3623 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003624 {
Greg Claytoneeb15652013-12-10 23:16:40 +00003625 ExecutionContext exe_ctx (GetExecutionContextRef());
3626 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003627 }
3628 return valobj_sp;
3629}
3630
Enrico Granata538a88a2014-10-09 18:24:30 +00003631ValueObjectSP
3632ValueObject::GetQualifiedRepresentationIfAvailable (lldb::DynamicValueType dynValue,
3633 bool synthValue)
3634{
3635 ValueObjectSP result_sp(GetSP());
3636
3637 switch (dynValue)
3638 {
3639 case lldb::eDynamicCanRunTarget:
3640 case lldb::eDynamicDontRunTarget:
3641 {
3642 if (!result_sp->IsDynamic())
3643 {
3644 if (result_sp->GetDynamicValue(dynValue))
3645 result_sp = result_sp->GetDynamicValue(dynValue);
3646 }
3647 }
3648 break;
3649 case lldb::eNoDynamicValues:
Enrico Granata538a88a2014-10-09 18:24:30 +00003650 {
3651 if (result_sp->IsDynamic())
3652 {
3653 if (result_sp->GetStaticValue())
3654 result_sp = result_sp->GetStaticValue();
3655 }
3656 }
3657 break;
3658 }
3659
3660 if (synthValue)
3661 {
3662 if (!result_sp->IsSynthetic())
3663 {
3664 if (result_sp->GetSyntheticValue())
3665 result_sp = result_sp->GetSyntheticValue();
3666 }
3667 }
3668 else
3669 {
3670 if (result_sp->IsSynthetic())
3671 {
3672 if (result_sp->GetNonSyntheticValue())
3673 result_sp = result_sp->GetNonSyntheticValue();
3674 }
3675 }
3676
3677 return result_sp;
3678}
3679
Greg Clayton759e7442014-07-19 00:12:57 +00003680lldb::addr_t
3681ValueObject::GetCPPVTableAddress (AddressType &address_type)
3682{
3683 ClangASTType pointee_type;
3684 ClangASTType this_type(GetClangType());
3685 uint32_t type_info = this_type.GetTypeInfo(&pointee_type);
3686 if (type_info)
3687 {
3688 bool ptr_or_ref = false;
Enrico Granata622be232014-10-21 20:52:14 +00003689 if (type_info & (eTypeIsPointer | eTypeIsReference))
Greg Clayton759e7442014-07-19 00:12:57 +00003690 {
3691 ptr_or_ref = true;
3692 type_info = pointee_type.GetTypeInfo();
3693 }
3694
Enrico Granata622be232014-10-21 20:52:14 +00003695 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus;
Greg Clayton759e7442014-07-19 00:12:57 +00003696 if ((type_info & cpp_class) == cpp_class)
3697 {
3698 if (ptr_or_ref)
3699 {
3700 address_type = GetAddressTypeOfChildren();
3701 return GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
3702 }
3703 else
3704 return GetAddressOf (false, &address_type);
3705 }
3706 }
3707
3708 address_type = eAddressTypeInvalid;
3709 return LLDB_INVALID_ADDRESS;
3710}
3711
Greg Claytonafacd142011-09-02 01:15:17 +00003712ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003713ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003714{
Jim Ingham58b59f92011-04-22 23:53:53 +00003715 if (m_deref_valobj)
3716 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003717
Greg Clayton54979cd2010-12-15 05:08:08 +00003718 const bool is_pointer_type = IsPointerType();
3719 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003720 {
3721 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003722 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003723
3724 std::string child_name_str;
3725 uint32_t child_byte_size = 0;
3726 int32_t child_byte_offset = 0;
3727 uint32_t child_bitfield_bit_size = 0;
3728 uint32_t child_bitfield_bit_offset = 0;
3729 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003730 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003731 const bool transparent_pointers = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00003732 ClangASTType clang_type = GetClangType();
3733 ClangASTType child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003734
Greg Claytoncc4d0142012-02-17 07:49:44 +00003735 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003736
Greg Clayton57ee3062013-07-11 22:46:58 +00003737 child_clang_type = clang_type.GetChildClangTypeAtIndex (&exe_ctx,
Greg Clayton57ee3062013-07-11 22:46:58 +00003738 0,
3739 transparent_pointers,
3740 omit_empty_base_classes,
3741 ignore_array_bounds,
3742 child_name_str,
3743 child_byte_size,
3744 child_byte_offset,
3745 child_bitfield_bit_size,
3746 child_bitfield_bit_offset,
3747 child_is_base_class,
Greg Clayton759e7442014-07-19 00:12:57 +00003748 child_is_deref_of_parent,
3749 this);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003750 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003751 {
3752 ConstString child_name;
3753 if (!child_name_str.empty())
3754 child_name.SetCString (child_name_str.c_str());
3755
Jim Ingham58b59f92011-04-22 23:53:53 +00003756 m_deref_valobj = new ValueObjectChild (*this,
Jim Ingham58b59f92011-04-22 23:53:53 +00003757 child_clang_type,
3758 child_name,
3759 child_byte_size,
3760 child_byte_offset,
3761 child_bitfield_bit_size,
3762 child_bitfield_bit_offset,
3763 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003764 child_is_deref_of_parent,
3765 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003766 }
3767 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003768
Jim Ingham58b59f92011-04-22 23:53:53 +00003769 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003770 {
3771 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003772 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003773 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003774 else
3775 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003776 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003777 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003778
3779 if (is_pointer_type)
3780 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3781 else
3782 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003783 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003784 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003785}
3786
Greg Claytonafacd142011-09-02 01:15:17 +00003787ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003788ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003789{
Jim Ingham78a685a2011-04-16 00:01:13 +00003790 if (m_addr_of_valobj_sp)
3791 return m_addr_of_valobj_sp;
3792
Greg Claytone0d378b2011-03-24 21:19:54 +00003793 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003794 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003795 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003796 error.Clear();
Siva Chandraa3747a92015-05-04 19:43:34 +00003797 if (addr != LLDB_INVALID_ADDRESS && address_type != eAddressTypeHost)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003798 {
3799 switch (address_type)
3800 {
3801 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003802 {
3803 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003804 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003805 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3806 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003807 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003808
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003809 case eAddressTypeFile:
3810 case eAddressTypeLoad:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003811 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003812 ClangASTType clang_type = GetClangType();
3813 if (clang_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003814 {
3815 std::string name (1, '&');
3816 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003817 ExecutionContext exe_ctx (GetExecutionContextRef());
3818 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00003819 clang_type.GetPointerType(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003820 ConstString (name.c_str()),
3821 addr,
3822 eAddressTypeInvalid,
3823 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003824 }
3825 }
3826 break;
Siva Chandraa3747a92015-05-04 19:43:34 +00003827 default:
3828 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003829 }
3830 }
Sean Callananed185ab2013-04-19 19:47:32 +00003831 else
3832 {
3833 StreamString expr_path_strm;
3834 GetExpressionPath(expr_path_strm, true);
3835 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3836 }
3837
Jim Ingham78a685a2011-04-16 00:01:13 +00003838 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003839}
3840
Greg Clayton9a142cf2012-02-03 05:34:10 +00003841ValueObjectSP
3842ValueObject::Cast (const ClangASTType &clang_ast_type)
3843{
Greg Clayton81e871e2012-02-04 02:27:34 +00003844 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003845}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003846
Greg Claytonafacd142011-09-02 01:15:17 +00003847ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003848ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3849{
Greg Claytonafacd142011-09-02 01:15:17 +00003850 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003851 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003852 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003853
3854 if (ptr_value != LLDB_INVALID_ADDRESS)
3855 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003856 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003857 ExecutionContext exe_ctx (GetExecutionContextRef());
3858 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003859 name,
3860 ptr_addr,
3861 clang_ast_type);
3862 }
3863 return valobj_sp;
3864}
3865
Greg Claytonafacd142011-09-02 01:15:17 +00003866ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003867ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3868{
Greg Claytonafacd142011-09-02 01:15:17 +00003869 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003870 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003871 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003872
3873 if (ptr_value != LLDB_INVALID_ADDRESS)
3874 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003875 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003876 ExecutionContext exe_ctx (GetExecutionContextRef());
3877 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003878 name,
3879 ptr_addr,
3880 type_sp);
3881 }
3882 return valobj_sp;
3883}
3884
Jim Ingham6035b672011-03-31 00:19:25 +00003885ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003886 m_mod_id(),
3887 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003888 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003889{
3890}
3891
3892ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003893 m_mod_id(),
3894 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003895 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003896{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003897 ExecutionContext exe_ctx(exe_scope);
3898 TargetSP target_sp (exe_ctx.GetTargetSP());
3899 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003900 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003901 m_exe_ctx_ref.SetTargetSP (target_sp);
3902 ProcessSP process_sp (exe_ctx.GetProcessSP());
3903 if (!process_sp)
3904 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003905
Greg Claytoncc4d0142012-02-17 07:49:44 +00003906 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003907 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003908 m_mod_id = process_sp->GetModID();
3909 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003910
Greg Claytoncc4d0142012-02-17 07:49:44 +00003911 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003912
Greg Claytoncc4d0142012-02-17 07:49:44 +00003913 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003914 {
3915 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003916 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003917 }
Jim Ingham6035b672011-03-31 00:19:25 +00003918
Greg Claytoncc4d0142012-02-17 07:49:44 +00003919 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003920 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003921 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003922
Jason Molendab57e4a12013-11-04 09:33:30 +00003923 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003924 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003925 {
3926 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003927 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003928 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003929 if (frame_sp)
3930 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003931 }
3932 }
3933 }
Jim Ingham6035b672011-03-31 00:19:25 +00003934}
3935
3936ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003937 m_mod_id(),
3938 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003939 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003940{
3941}
3942
3943ValueObject::EvaluationPoint::~EvaluationPoint ()
3944{
3945}
3946
Jim Ingham6035b672011-03-31 00:19:25 +00003947// This function checks the EvaluationPoint against the current process state. If the current
3948// state matches the evaluation point, or the evaluation point is already invalid, then we return
3949// false, meaning "no change". If the current state is different, we update our state, and return
3950// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3951// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003952// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003953
3954bool
Enrico Granatabb642e52015-05-16 01:27:00 +00003955ValueObject::EvaluationPoint::SyncWithProcessState(bool accept_invalid_exe_ctx)
Jim Ingham6035b672011-03-31 00:19:25 +00003956{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003957 // 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 +00003958 const bool thread_and_frame_only_if_stopped = true;
3959 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
Jim Ingham73ca05a2011-12-17 01:35:57 +00003960
Greg Claytoncc4d0142012-02-17 07:49:44 +00003961 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003962 return false;
3963
Jim Ingham6035b672011-03-31 00:19:25 +00003964 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003965 Process *process = exe_ctx.GetProcessPtr();
3966 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003967 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003968
Jim Ingham6035b672011-03-31 00:19:25 +00003969 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003970 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003971
Jim Ingham78a685a2011-04-16 00:01:13 +00003972 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3973 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003974 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003975 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003976
Greg Clayton23f59502012-07-17 03:23:13 +00003977 bool changed = false;
3978 const bool was_valid = m_mod_id.IsValid();
3979 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003980 {
3981 if (m_mod_id == current_mod_id)
3982 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003983 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003984 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003985 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003986 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003987 else
3988 {
3989 m_mod_id = current_mod_id;
3990 m_needs_update = true;
3991 changed = true;
3992 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003993 }
Jim Ingham6035b672011-03-31 00:19:25 +00003994
Jim Ingham73ca05a2011-12-17 01:35:57 +00003995 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3996 // That way we'll be sure to return a valid exe_scope.
3997 // 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 +00003998
Enrico Granatabb642e52015-05-16 01:27:00 +00003999 if (!accept_invalid_exe_ctx)
Jim Ingham6035b672011-03-31 00:19:25 +00004000 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004001 if (m_exe_ctx_ref.HasThreadRef())
Greg Clayton262f80d2011-07-06 16:49:27 +00004002 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004003 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
4004 if (thread_sp)
Greg Claytoncc4d0142012-02-17 07:49:44 +00004005 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004006 if (m_exe_ctx_ref.HasFrameRef())
Greg Claytoncc4d0142012-02-17 07:49:44 +00004007 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004008 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
4009 if (!frame_sp)
4010 {
4011 // We used to have a frame, but now it is gone
4012 SetInvalid();
4013 changed = was_valid;
4014 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00004015 }
4016 }
Enrico Granatabb642e52015-05-16 01:27:00 +00004017 else
4018 {
4019 // We used to have a thread, but now it is gone
4020 SetInvalid();
4021 changed = was_valid;
4022 }
Greg Clayton262f80d2011-07-06 16:49:27 +00004023 }
Jim Ingham6035b672011-03-31 00:19:25 +00004024 }
Enrico Granatabb642e52015-05-16 01:27:00 +00004025
Jim Ingham9ee01152011-12-10 01:49:43 +00004026 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00004027}
4028
Jim Ingham61be0902011-05-02 18:13:59 +00004029void
4030ValueObject::EvaluationPoint::SetUpdated ()
4031{
Greg Claytoncc4d0142012-02-17 07:49:44 +00004032 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
4033 if (process_sp)
4034 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00004035 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00004036}
4037
4038
Enrico Granataf2bbf712011-07-15 02:26:42 +00004039
4040void
Enrico Granata86cc9822012-03-19 22:58:49 +00004041ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004042{
Enrico Granata86cc9822012-03-19 22:58:49 +00004043 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4044 m_value_str.clear();
4045
4046 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4047 m_location_str.clear();
4048
4049 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
Enrico Granata86cc9822012-03-19 22:58:49 +00004050 m_summary_str.clear();
Enrico Granata86cc9822012-03-19 22:58:49 +00004051
4052 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4053 m_object_desc_str.clear();
4054
4055 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4056 {
4057 if (m_synthetic_value)
4058 m_synthetic_value = NULL;
4059 }
Enrico Granata744794a2014-09-05 21:46:22 +00004060
4061 if ((clear_mask & eClearUserVisibleDataItemsValidator) == eClearUserVisibleDataItemsValidator)
4062 m_validation_result.reset();
Johnny Chen44805302011-07-19 19:48:13 +00004063}
Enrico Granata9128ee22011-09-06 19:20:51 +00004064
4065SymbolContextScope *
4066ValueObject::GetSymbolContextScope()
4067{
4068 if (m_parent)
4069 {
4070 if (!m_parent->IsPointerOrReferenceType())
4071 return m_parent->GetSymbolContextScope();
4072 }
4073 return NULL;
4074}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004075
4076lldb::ValueObjectSP
4077ValueObject::CreateValueObjectFromExpression (const char* name,
4078 const char* expression,
4079 const ExecutionContext& exe_ctx)
4080{
Enrico Granata972be532014-12-17 21:18:43 +00004081 return CreateValueObjectFromExpression(name, expression, exe_ctx, EvaluateExpressionOptions());
4082}
4083
4084
4085lldb::ValueObjectSP
4086ValueObject::CreateValueObjectFromExpression (const char* name,
4087 const char* expression,
4088 const ExecutionContext& exe_ctx,
4089 const EvaluateExpressionOptions& options)
4090{
Enrico Granatab2698cd2012-09-13 18:27:09 +00004091 lldb::ValueObjectSP retval_sp;
4092 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4093 if (!target_sp)
4094 return retval_sp;
4095 if (!expression || !*expression)
4096 return retval_sp;
4097 target_sp->EvaluateExpression (expression,
4098 exe_ctx.GetFrameSP().get(),
Enrico Granata972be532014-12-17 21:18:43 +00004099 retval_sp,
4100 options);
Enrico Granatab2698cd2012-09-13 18:27:09 +00004101 if (retval_sp && name && *name)
4102 retval_sp->SetName(ConstString(name));
4103 return retval_sp;
4104}
4105
4106lldb::ValueObjectSP
4107ValueObject::CreateValueObjectFromAddress (const char* name,
4108 uint64_t address,
4109 const ExecutionContext& exe_ctx,
4110 ClangASTType type)
4111{
Greg Clayton57ee3062013-07-11 22:46:58 +00004112 if (type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004113 {
Greg Clayton57ee3062013-07-11 22:46:58 +00004114 ClangASTType pointer_type(type.GetPointerType());
4115 if (pointer_type)
4116 {
4117 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4118 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4119 pointer_type,
4120 ConstString(name),
4121 buffer,
Enrico Granata972be532014-12-17 21:18:43 +00004122 exe_ctx.GetByteOrder(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004123 exe_ctx.GetAddressByteSize()));
4124 if (ptr_result_valobj_sp)
4125 {
4126 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4127 Error err;
4128 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4129 if (ptr_result_valobj_sp && name && *name)
4130 ptr_result_valobj_sp->SetName(ConstString(name));
4131 }
4132 return ptr_result_valobj_sp;
4133 }
Enrico Granatab2698cd2012-09-13 18:27:09 +00004134 }
Greg Clayton57ee3062013-07-11 22:46:58 +00004135 return lldb::ValueObjectSP();
Enrico Granatab2698cd2012-09-13 18:27:09 +00004136}
4137
4138lldb::ValueObjectSP
4139ValueObject::CreateValueObjectFromData (const char* name,
Enrico Granata7ca1c762014-03-31 23:02:25 +00004140 const DataExtractor& data,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004141 const ExecutionContext& exe_ctx,
4142 ClangASTType type)
4143{
4144 lldb::ValueObjectSP new_value_sp;
4145 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004146 type,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004147 ConstString(name),
4148 data,
4149 LLDB_INVALID_ADDRESS);
4150 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4151 if (new_value_sp && name && *name)
4152 new_value_sp->SetName(ConstString(name));
4153 return new_value_sp;
4154}
Enrico Granata4873e522013-04-11 22:48:58 +00004155
4156ModuleSP
4157ValueObject::GetModule ()
4158{
4159 ValueObject* root(GetRoot());
4160 if (root != this)
4161 return root->GetModule();
4162 return lldb::ModuleSP();
4163}
4164
4165ValueObject*
4166ValueObject::GetRoot ()
4167{
4168 if (m_root)
4169 return m_root;
Enrico Granatade61eba2015-01-22 03:07:34 +00004170 return (m_root = FollowParentChain( [] (ValueObject* vo) -> bool {
4171 return (vo->m_parent != nullptr);
4172 }));
4173}
4174
4175ValueObject*
4176ValueObject::FollowParentChain (std::function<bool(ValueObject*)> f)
4177{
4178 ValueObject* vo = this;
4179 while (vo)
Enrico Granata4873e522013-04-11 22:48:58 +00004180 {
Enrico Granatade61eba2015-01-22 03:07:34 +00004181 if (f(vo) == false)
4182 break;
4183 vo = vo->m_parent;
Enrico Granata4873e522013-04-11 22:48:58 +00004184 }
Enrico Granatade61eba2015-01-22 03:07:34 +00004185 return vo;
Enrico Granata4873e522013-04-11 22:48:58 +00004186}
4187
4188AddressType
4189ValueObject::GetAddressTypeOfChildren()
4190{
4191 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
4192 {
4193 ValueObject* root(GetRoot());
4194 if (root != this)
4195 return root->GetAddressTypeOfChildren();
4196 }
4197 return m_address_type_of_ptr_or_ref_children;
4198}
4199
4200lldb::DynamicValueType
4201ValueObject::GetDynamicValueType ()
4202{
4203 ValueObject* with_dv_info = this;
4204 while (with_dv_info)
4205 {
4206 if (with_dv_info->HasDynamicValueTypeInfo())
4207 return with_dv_info->GetDynamicValueTypeImpl();
4208 with_dv_info = with_dv_info->m_parent;
4209 }
4210 return lldb::eNoDynamicValues;
4211}
Enrico Granata39d51412013-05-31 17:43:40 +00004212
Enrico Granata4873e522013-04-11 22:48:58 +00004213lldb::Format
4214ValueObject::GetFormat () const
4215{
4216 const ValueObject* with_fmt_info = this;
4217 while (with_fmt_info)
4218 {
4219 if (with_fmt_info->m_format != lldb::eFormatDefault)
4220 return with_fmt_info->m_format;
4221 with_fmt_info = with_fmt_info->m_parent;
4222 }
4223 return m_format;
4224}
Enrico Granatad07cfd32014-10-08 18:27:36 +00004225
Enrico Granatac1247f52014-11-06 21:23:20 +00004226lldb::LanguageType
4227ValueObject::GetPreferredDisplayLanguage ()
4228{
Enrico Granataed3228a2015-01-21 01:47:13 +00004229 lldb::LanguageType type = m_preferred_display_language;
4230 if (m_preferred_display_language == lldb::eLanguageTypeUnknown)
Enrico Granatac1247f52014-11-06 21:23:20 +00004231 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004232 if (GetRoot())
Enrico Granatac1247f52014-11-06 21:23:20 +00004233 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004234 if (GetRoot() == this)
Enrico Granatac1247f52014-11-06 21:23:20 +00004235 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004236 if (StackFrameSP frame_sp = GetFrameSP())
4237 {
4238 const SymbolContext& sc(frame_sp->GetSymbolContext(eSymbolContextCompUnit));
4239 if (CompileUnit* cu = sc.comp_unit)
4240 type = cu->GetLanguage();
4241 }
4242 }
4243 else
4244 {
4245 type = GetRoot()->GetPreferredDisplayLanguage();
Enrico Granatac1247f52014-11-06 21:23:20 +00004246 }
4247 }
Enrico Granatac1247f52014-11-06 21:23:20 +00004248 }
Enrico Granataed3228a2015-01-21 01:47:13 +00004249 return (m_preferred_display_language = type); // only compute it once
4250}
4251
4252void
4253ValueObject::SetPreferredDisplayLanguage (lldb::LanguageType lt)
4254{
4255 m_preferred_display_language = lt;
Enrico Granatac1247f52014-11-06 21:23:20 +00004256}
4257
Enrico Granatad07cfd32014-10-08 18:27:36 +00004258bool
4259ValueObject::CanProvideValue ()
4260{
Sean Callanan7375f3e2014-12-09 21:18:59 +00004261 // we need to support invalid types as providers of values because some bare-board
4262 // debugging scenarios have no notion of types, but still manage to have raw numeric
4263 // values for things like registers. sigh.
4264 const ClangASTType &type(GetClangType());
4265 return (false == type.IsValid()) || (0 != (type.GetTypeInfo() & eTypeHasValue));
4266}
4267
4268bool
4269ValueObject::IsChecksumEmpty ()
4270{
4271 return m_value_checksum.empty();
Enrico Granatad07cfd32014-10-08 18:27:36 +00004272}
Enrico Granata0c10a852014-12-08 23:13:56 +00004273
4274ValueObjectSP
4275ValueObject::Persist ()
4276{
4277 if (!UpdateValueIfNeeded())
4278 return nullptr;
4279
4280 TargetSP target_sp(GetTargetSP());
4281 if (!target_sp)
4282 return nullptr;
4283
4284 ConstString name(target_sp->GetPersistentVariables().GetNextPersistentVariableName());
4285
4286 ClangExpressionVariableSP clang_var_sp(new ClangExpressionVariable(target_sp.get(), GetValue(), name));
4287 if (clang_var_sp)
4288 {
4289 clang_var_sp->m_live_sp = clang_var_sp->m_frozen_sp;
4290 clang_var_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
4291 target_sp->GetPersistentVariables().AddVariable(clang_var_sp);
4292 }
4293
4294 return clang_var_sp->GetValueObject();
4295}
Enrico Granatae29df232014-12-09 19:51:20 +00004296
4297bool
4298ValueObject::IsSyntheticChildrenGenerated ()
4299{
4300 return m_is_synthetic_children_generated;
4301}
4302
4303void
4304ValueObject::SetSyntheticChildrenGenerated (bool b)
4305{
4306 m_is_synthetic_children_generated = b;
4307}