blob: 7231f0187ee59ce3d36d1fd604e1b88008347382 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- ValueObject.cpp -----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "lldb/Core/ValueObject.h"
13
14// C Includes
Greg Claytonf5e56de2010-09-14 23:36:40 +000015#include <stdlib.h>
16
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017// C++ Includes
18// Other libraries and framework includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "llvm/Support/raw_ostream.h"
Jim Ingham5a369122010-09-28 01:25:32 +000020#include "clang/AST/Type.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021
22// Project includes
23#include "lldb/Core/DataBufferHeap.h"
Enrico Granata4becb372011-06-29 22:27:15 +000024#include "lldb/Core/Debugger.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000025#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000026#include "lldb/Core/Module.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Core/StreamString.h"
Enrico Granata21fd13f2012-10-27 02:05:48 +000028#include "lldb/Core/ValueObjectCast.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Core/ValueObjectChild.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000030#include "lldb/Core/ValueObjectConstResult.h"
Jim Ingham78a685a2011-04-16 00:01:13 +000031#include "lldb/Core/ValueObjectDynamicValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032#include "lldb/Core/ValueObjectList.h"
Greg Claytonb2dcc362011-05-05 23:32:56 +000033#include "lldb/Core/ValueObjectMemory.h"
Enrico Granatad55546b2011-07-22 00:16:08 +000034#include "lldb/Core/ValueObjectSyntheticFilter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035
Enrico Granata5548cb52013-01-28 23:47:25 +000036#include "lldb/DataFormatters/DataVisualization.h"
Enrico Granata2206b482014-10-30 18:27:31 +000037#include "lldb/DataFormatters/StringPrinter.h"
Enrico Granata4d93b8c2013-09-30 19:11:51 +000038#include "lldb/DataFormatters/ValueObjectPrinter.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000039
Enrico Granata0c10a852014-12-08 23:13:56 +000040#include "lldb/Expression/ClangExpressionVariable.h"
41#include "lldb/Expression/ClangPersistentVariables.h"
42
Greg Clayton7fb56d02011-02-01 01:31:41 +000043#include "lldb/Host/Endian.h"
44
Enrico Granata61a80ba2011-08-12 16:42:31 +000045#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granataf2bbf712011-07-15 02:26:42 +000046#include "lldb/Interpreter/ScriptInterpreterPython.h"
47
Greg Claytone1a916a2010-07-21 22:12:05 +000048#include "lldb/Symbol/ClangASTType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049#include "lldb/Symbol/ClangASTContext.h"
Enrico Granatac1247f52014-11-06 21:23:20 +000050#include "lldb/Symbol/CompileUnit.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051#include "lldb/Symbol/Type.h"
52
Jim Ingham53c47f12010-09-10 23:12:17 +000053#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000054#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000055#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056#include "lldb/Target/Process.h"
57#include "lldb/Target/RegisterContext.h"
Greg Claytond5944cd2013-12-06 01:12:00 +000058#include "lldb/Target/SectionLoadList.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000059#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061
62using namespace lldb;
63using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000064using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065
Greg Claytonafacd142011-09-02 01:15:17 +000066static user_id_t g_value_obj_uid = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000067
68//----------------------------------------------------------------------
69// ValueObject constructor
70//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000071ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000072 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000073 m_parent (&parent),
Enrico Granata4873e522013-04-11 22:48:58 +000074 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +000075 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000076 m_name (),
77 m_data (),
78 m_value (),
79 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000080 m_value_str (),
81 m_old_value_str (),
82 m_location_str (),
83 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000084 m_object_desc_str (),
Enrico Granata744794a2014-09-05 21:46:22 +000085 m_validation_result(),
Jim Ingham58b59f92011-04-22 23:53:53 +000086 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000087 m_children (),
88 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000089 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000090 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000091 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000092 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +000093 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000094 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +000095 m_type_summary_sp(),
96 m_type_format_sp(),
97 m_synthetic_children_sp(),
Enrico Granata744794a2014-09-05 21:46:22 +000098 m_type_validator_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +000099 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000100 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
Sean Callanan7375f3e2014-12-09 21:18:59 +0000101 m_value_checksum(),
Enrico Granataed3228a2015-01-21 01:47:13 +0000102 m_preferred_display_language(lldb::eLanguageTypeUnknown),
Greg Clayton288bdf92010-09-02 02:59:18 +0000103 m_value_is_valid (false),
104 m_value_did_change (false),
105 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000106 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000107 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000108 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000109 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000110 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000111 m_is_getting_summary(false),
Enrico Granatae29df232014-12-09 19:51:20 +0000112 m_did_calculate_complete_objc_class_type(false),
113 m_is_synthetic_children_generated(parent.m_is_synthetic_children_generated)
Jim Ingham6035b672011-03-31 00:19:25 +0000114{
Jim Ingham58b59f92011-04-22 23:53:53 +0000115 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000116}
117
118//----------------------------------------------------------------------
119// ValueObject constructor
120//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000121ValueObject::ValueObject (ExecutionContextScope *exe_scope,
122 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000123 UserID (++g_value_obj_uid), // Unique identifier for every value object
124 m_parent (NULL),
Enrico Granata4873e522013-04-11 22:48:58 +0000125 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000126 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000127 m_name (),
128 m_data (),
129 m_value (),
130 m_error (),
131 m_value_str (),
132 m_old_value_str (),
133 m_location_str (),
134 m_summary_str (),
135 m_object_desc_str (),
Enrico Granata744794a2014-09-05 21:46:22 +0000136 m_validation_result(),
Jim Ingham58b59f92011-04-22 23:53:53 +0000137 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000138 m_children (),
139 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000140 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000141 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000142 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000143 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +0000144 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000145 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +0000146 m_type_summary_sp(),
147 m_type_format_sp(),
148 m_synthetic_children_sp(),
Enrico Granata744794a2014-09-05 21:46:22 +0000149 m_type_validator_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000150 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000151 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Sean Callanan7375f3e2014-12-09 21:18:59 +0000152 m_value_checksum(),
Enrico Granataed3228a2015-01-21 01:47:13 +0000153 m_preferred_display_language(lldb::eLanguageTypeUnknown),
Jim Ingham6035b672011-03-31 00:19:25 +0000154 m_value_is_valid (false),
155 m_value_did_change (false),
156 m_children_count_valid (false),
157 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000158 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000159 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000160 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000161 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000162 m_is_getting_summary(false),
Enrico Granatae29df232014-12-09 19:51:20 +0000163 m_did_calculate_complete_objc_class_type(false),
164 m_is_synthetic_children_generated(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000165{
Jim Ingham58b59f92011-04-22 23:53:53 +0000166 m_manager = new ValueObjectManager();
167 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000168}
169
170//----------------------------------------------------------------------
171// Destructor
172//----------------------------------------------------------------------
173ValueObject::~ValueObject ()
174{
175}
176
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000177bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000178ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000179{
Enrico Granata4becb372011-06-29 22:27:15 +0000180
Enrico Granata9128ee22011-09-06 19:20:51 +0000181 bool did_change_formats = false;
182
Enrico Granata0a3958e2011-07-02 00:25:22 +0000183 if (update_format)
Enrico Granata5548cb52013-01-28 23:47:25 +0000184 did_change_formats = UpdateFormatsIfNeeded();
Enrico Granata4becb372011-06-29 22:27:15 +0000185
Greg Claytonb71f3842010-10-05 03:13:51 +0000186 // If this is a constant value, then our success is predicated on whether
187 // we have an error or not
188 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000189 {
Enrico Granatab1c6c482013-10-09 00:33:55 +0000190 // if you are constant, things might still have changed behind your back
191 // (e.g. you are a frozen object and things have changed deeper than you cared to freeze-dry yourself)
192 // in this case, your value has not changed, but "computed" entries might have, so you might now have
193 // a different summary, or a different object description. clear these so we will recompute them
Enrico Granata9128ee22011-09-06 19:20:51 +0000194 if (update_format && !did_change_formats)
Enrico Granatab1c6c482013-10-09 00:33:55 +0000195 ClearUserVisibleData(eClearUserVisibleDataItemsSummary | eClearUserVisibleDataItemsDescription);
Greg Claytonb71f3842010-10-05 03:13:51 +0000196 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000197 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000198
Sean Callanan7375f3e2014-12-09 21:18:59 +0000199 bool first_update = IsChecksumEmpty();
Jim Ingham6035b672011-03-31 00:19:25 +0000200
201 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000202 {
Jim Ingham6035b672011-03-31 00:19:25 +0000203 m_update_point.SetUpdated();
204
205 // Save the old value using swap to avoid a string copy which
206 // also will clear our m_value_str
207 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000208 {
Jim Ingham6035b672011-03-31 00:19:25 +0000209 m_old_value_valid = false;
210 }
211 else
212 {
213 m_old_value_valid = true;
214 m_old_value_str.swap (m_value_str);
Enrico Granata86cc9822012-03-19 22:58:49 +0000215 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham6035b672011-03-31 00:19:25 +0000216 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000217
Enrico Granataf2bbf712011-07-15 02:26:42 +0000218 ClearUserVisibleData();
219
Greg Claytonefbc7d22012-03-09 04:23:44 +0000220 if (IsInScope())
Jim Ingham6035b672011-03-31 00:19:25 +0000221 {
Greg Claytonefbc7d22012-03-09 04:23:44 +0000222 const bool value_was_valid = GetValueIsValid();
223 SetValueDidChange (false);
224
225 m_error.Clear();
226
227 // Call the pure virtual function to update the value
Sean Callanan7375f3e2014-12-09 21:18:59 +0000228
229 bool need_compare_checksums = false;
230 llvm::SmallVector<uint8_t, 16> old_checksum;
231
232 if (!first_update && CanProvideValue())
233 {
234 need_compare_checksums = true;
235 old_checksum.resize(m_value_checksum.size());
236 std::copy(m_value_checksum.begin(), m_value_checksum.end(), old_checksum.begin());
237 }
238
Greg Claytonefbc7d22012-03-09 04:23:44 +0000239 bool success = UpdateValue ();
240
241 SetValueIsValid (success);
242
Sean Callanan7375f3e2014-12-09 21:18:59 +0000243 if (success)
244 {
245 const uint64_t max_checksum_size = 128;
246 m_data.Checksum(m_value_checksum,
247 max_checksum_size);
248 }
249 else
250 {
251 need_compare_checksums = false;
252 m_value_checksum.clear();
253 }
254
Enrico Granata20c321c2015-01-08 19:11:43 +0000255 assert (!need_compare_checksums || (!old_checksum.empty() && !m_value_checksum.empty()));
256
Greg Claytonefbc7d22012-03-09 04:23:44 +0000257 if (first_update)
258 SetValueDidChange (false);
259 else if (!m_value_did_change && success == false)
260 {
261 // The value wasn't gotten successfully, so we mark this
262 // as changed if the value used to be valid and now isn't
263 SetValueDidChange (value_was_valid);
264 }
Sean Callanan7375f3e2014-12-09 21:18:59 +0000265 else if (need_compare_checksums)
266 {
267 SetValueDidChange(memcmp(&old_checksum[0], &m_value_checksum[0], m_value_checksum.size()));
268 }
269
Greg Claytonefbc7d22012-03-09 04:23:44 +0000270 }
271 else
272 {
273 m_error.SetErrorString("out of scope");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000274 }
275 }
276 return m_error.Success();
277}
278
Enrico Granata9128ee22011-09-06 19:20:51 +0000279bool
Enrico Granata5548cb52013-01-28 23:47:25 +0000280ValueObject::UpdateFormatsIfNeeded()
Enrico Granata4becb372011-06-29 22:27:15 +0000281{
Greg Clayton5160ce52013-03-27 23:08:40 +0000282 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000283 if (log)
Enrico Granatad2284832012-10-17 22:23:56 +0000284 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000285 GetName().GetCString(), static_cast<void*>(this),
286 m_last_format_mgr_revision,
287 DataVisualization::GetCurrentRevision());
288
Enrico Granata9128ee22011-09-06 19:20:51 +0000289 bool any_change = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000290
Enrico Granata5548cb52013-01-28 23:47:25 +0000291 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()))
Enrico Granata4becb372011-06-29 22:27:15 +0000292 {
Enrico Granataa0db6ed2014-04-09 21:06:11 +0000293 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
294 any_change = true;
295
Enrico Granata852cc952013-10-08 19:03:22 +0000296 SetValueFormat(DataVisualization::GetFormat (*this, eNoDynamicValues));
Enrico Granata5548cb52013-01-28 23:47:25 +0000297 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000298#ifndef LLDB_DISABLE_PYTHON
Enrico Granata5548cb52013-01-28 23:47:25 +0000299 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000300#endif
Enrico Granata744794a2014-09-05 21:46:22 +0000301 SetValidator(DataVisualization::GetValidator(*this, GetDynamicValueType()));
Enrico Granata4becb372011-06-29 22:27:15 +0000302 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000303
Enrico Granata9128ee22011-09-06 19:20:51 +0000304 return any_change;
Enrico Granata4becb372011-06-29 22:27:15 +0000305}
306
Jim Ingham16e0c682011-08-12 23:34:31 +0000307void
308ValueObject::SetNeedsUpdate ()
309{
310 m_update_point.SetNeedsUpdate();
311 // We have to clear the value string here so ConstResult children will notice if their values are
312 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000313 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000314}
315
Enrico Granata13ac0e22012-10-17 19:03:34 +0000316void
Enrico Granatae3e91512012-10-22 18:18:36 +0000317ValueObject::ClearDynamicTypeInformation ()
Enrico Granata13ac0e22012-10-17 19:03:34 +0000318{
Enrico Granata38c54632013-10-30 00:04:29 +0000319 m_children_count_valid = false;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000320 m_did_calculate_complete_objc_class_type = false;
Enrico Granatae3e91512012-10-22 18:18:36 +0000321 m_last_format_mgr_revision = 0;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000322 m_override_type = ClangASTType();
Enrico Granatae3e91512012-10-22 18:18:36 +0000323 SetValueFormat(lldb::TypeFormatImplSP());
324 SetSummaryFormat(lldb::TypeSummaryImplSP());
325 SetSyntheticChildren(lldb::SyntheticChildrenSP());
Enrico Granata13ac0e22012-10-17 19:03:34 +0000326}
327
Sean Callanan72772842012-02-22 23:57:45 +0000328ClangASTType
329ValueObject::MaybeCalculateCompleteType ()
330{
Greg Clayton57ee3062013-07-11 22:46:58 +0000331 ClangASTType clang_type(GetClangTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000332
Sean Callanan72772842012-02-22 23:57:45 +0000333 if (m_did_calculate_complete_objc_class_type)
334 {
335 if (m_override_type.IsValid())
336 return m_override_type;
337 else
Greg Clayton57ee3062013-07-11 22:46:58 +0000338 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000339 }
340
Greg Clayton57ee3062013-07-11 22:46:58 +0000341 ClangASTType class_type;
342 bool is_pointer_type = false;
Sean Callanan72772842012-02-22 23:57:45 +0000343
Greg Clayton57ee3062013-07-11 22:46:58 +0000344 if (clang_type.IsObjCObjectPointerType(&class_type))
Sean Callanan72772842012-02-22 23:57:45 +0000345 {
346 is_pointer_type = true;
347 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000348 else if (clang_type.IsObjCObjectOrInterfaceType())
Sean Callanan72772842012-02-22 23:57:45 +0000349 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000350 class_type = clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000351 }
352 else
353 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000354 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000355 }
356
357 m_did_calculate_complete_objc_class_type = true;
358
Greg Clayton57ee3062013-07-11 22:46:58 +0000359 if (class_type)
Sean Callanan72772842012-02-22 23:57:45 +0000360 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000361 ConstString class_name (class_type.GetConstTypeName());
Sean Callanan72772842012-02-22 23:57:45 +0000362
Greg Clayton57ee3062013-07-11 22:46:58 +0000363 if (class_name)
364 {
365 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
366
367 if (process_sp)
368 {
369 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
370
371 if (objc_language_runtime)
372 {
373 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name);
374
375 if (complete_objc_class_type_sp)
376 {
377 ClangASTType complete_class(complete_objc_class_type_sp->GetClangFullType());
378
379 if (complete_class.GetCompleteType())
380 {
381 if (is_pointer_type)
382 {
383 m_override_type = complete_class.GetPointerType();
384 }
385 else
386 {
387 m_override_type = complete_class;
388 }
389
390 if (m_override_type.IsValid())
391 return m_override_type;
392 }
393 }
394 }
395 }
396 }
Sean Callanan72772842012-02-22 23:57:45 +0000397 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000398 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000399}
400
Greg Clayton57ee3062013-07-11 22:46:58 +0000401ClangASTType
Sean Callanan72772842012-02-22 23:57:45 +0000402ValueObject::GetClangType ()
403{
Greg Clayton57ee3062013-07-11 22:46:58 +0000404 return MaybeCalculateCompleteType();
Sean Callanan72772842012-02-22 23:57:45 +0000405}
406
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000407TypeImpl
408ValueObject::GetTypeImpl ()
409{
410 return TypeImpl(GetClangType());
411}
412
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000413DataExtractor &
414ValueObject::GetDataExtractor ()
415{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000416 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000417 return m_data;
418}
419
420const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000421ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000422{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000423 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000424 return m_error;
425}
426
427const ConstString &
428ValueObject::GetName() const
429{
430 return m_name;
431}
432
433const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000434ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000435{
Enrico Granata82fabf82013-04-30 20:45:04 +0000436 return GetLocationAsCStringImpl(m_value,
437 m_data);
438}
439
440const char *
441ValueObject::GetLocationAsCStringImpl (const Value& value,
442 const DataExtractor& data)
443{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000444 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000445 {
446 if (m_location_str.empty())
447 {
448 StreamString sstr;
Enrico Granata82fabf82013-04-30 20:45:04 +0000449
450 Value::ValueType value_type = value.GetValueType();
451
452 switch (value_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000453 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000454 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +0000455 case Value::eValueTypeVector:
Enrico Granata82fabf82013-04-30 20:45:04 +0000456 if (value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000457 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000458 RegisterInfo *reg_info = value.GetRegisterInfo();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000459 if (reg_info)
460 {
461 if (reg_info->name)
462 m_location_str = reg_info->name;
463 else if (reg_info->alt_name)
464 m_location_str = reg_info->alt_name;
Enrico Granata82fabf82013-04-30 20:45:04 +0000465 if (m_location_str.empty())
466 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000467 }
468 }
Enrico Granata82fabf82013-04-30 20:45:04 +0000469 if (m_location_str.empty())
470 m_location_str = (value_type == Value::eValueTypeVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000471 break;
472
473 case Value::eValueTypeLoadAddress:
474 case Value::eValueTypeFileAddress:
475 case Value::eValueTypeHostAddress:
476 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000477 uint32_t addr_nibble_size = data.GetAddressByteSize() * 2;
478 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000479 m_location_str.swap(sstr.GetString());
480 }
481 break;
482 }
483 }
484 }
485 return m_location_str.c_str();
486}
487
488Value &
489ValueObject::GetValue()
490{
491 return m_value;
492}
493
494const Value &
495ValueObject::GetValue() const
496{
497 return m_value;
498}
499
500bool
Jim Ingham6035b672011-03-31 00:19:25 +0000501ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000502{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000503 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
504 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000505 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000506 Value tmp_value(m_value);
Greg Clayton57ee3062013-07-11 22:46:58 +0000507 scalar = tmp_value.ResolveValue(&exe_ctx);
Greg Claytondcad5022011-12-29 01:26:56 +0000508 if (scalar.IsValid())
509 {
510 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
511 if (bitfield_bit_size)
512 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
513 return true;
514 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000515 }
Greg Claytondcad5022011-12-29 01:26:56 +0000516 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000517}
518
519bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000520ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000521{
Greg Clayton288bdf92010-09-02 02:59:18 +0000522 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000523}
524
525
526void
527ValueObject::SetValueIsValid (bool b)
528{
Greg Clayton288bdf92010-09-02 02:59:18 +0000529 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000530}
531
532bool
Jim Ingham6035b672011-03-31 00:19:25 +0000533ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000534{
Greg Clayton288bdf92010-09-02 02:59:18 +0000535 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000536}
537
538void
539ValueObject::SetValueDidChange (bool value_changed)
540{
Greg Clayton288bdf92010-09-02 02:59:18 +0000541 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000542}
543
544ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000545ValueObject::GetChildAtIndex (size_t idx, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000546{
547 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000548 // We may need to update our value if we are dynamic
549 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000550 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000551 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000552 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000553 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000554 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000555 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000556 // No we haven't created the child at this index, so lets have our
557 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000558 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000559 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000560
Enrico Granata9d60f602012-03-09 03:09:58 +0000561 ValueObject* child = m_children.GetChildAtIndex(idx);
562 if (child != NULL)
563 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000564 }
565 return child_sp;
566}
567
Enrico Granata3309d882013-01-12 01:00:22 +0000568ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000569ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
570 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000571{
572 if (idxs.size() == 0)
573 return GetSP();
574 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000575 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000576 {
577 root = root->GetChildAtIndex(idx, true);
578 if (!root)
579 {
580 if (index_of_error)
581 *index_of_error = idx;
582 return root;
583 }
584 }
585 return root;
586}
587
588ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000589ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
590 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000591{
592 if (idxs.size() == 0)
593 return GetSP();
594 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000595 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000596 {
597 root = root->GetChildAtIndex(idx.first, idx.second);
598 if (!root)
599 {
600 if (index_of_error)
601 *index_of_error = idx.first;
602 return root;
603 }
604 }
605 return root;
606}
607
608lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000609ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
610 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000611{
612 if (idxs.size() == 0)
613 return GetSP();
614 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000615 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000616 {
617 root = root->GetChildAtIndex(idx, true);
618 if (!root)
619 {
620 if (index_of_error)
621 *index_of_error = idx;
622 return root;
623 }
624 }
625 return root;
626}
627
628lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000629ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
630 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000631{
632 if (idxs.size() == 0)
633 return GetSP();
634 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000635 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000636 {
637 root = root->GetChildAtIndex(idx.first, idx.second);
638 if (!root)
639 {
640 if (index_of_error)
641 *index_of_error = idx.first;
642 return root;
643 }
644 }
645 return root;
646}
647
Enrico Granatae2e220a2013-09-12 00:48:47 +0000648lldb::ValueObjectSP
649ValueObject::GetChildAtNamePath (const std::initializer_list<ConstString> &names,
650 ConstString* name_of_error)
651{
652 if (names.size() == 0)
653 return GetSP();
654 ValueObjectSP root(GetSP());
655 for (ConstString name : names)
656 {
657 root = root->GetChildMemberWithName(name, true);
658 if (!root)
659 {
660 if (name_of_error)
661 *name_of_error = name;
662 return root;
663 }
664 }
665 return root;
666}
667
668lldb::ValueObjectSP
669ValueObject::GetChildAtNamePath (const std::vector<ConstString> &names,
670 ConstString* name_of_error)
671{
672 if (names.size() == 0)
673 return GetSP();
674 ValueObjectSP root(GetSP());
675 for (ConstString name : names)
676 {
677 root = root->GetChildMemberWithName(name, true);
678 if (!root)
679 {
680 if (name_of_error)
681 *name_of_error = name;
682 return root;
683 }
684 }
685 return root;
686}
687
688lldb::ValueObjectSP
689ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names,
690 ConstString* name_of_error)
691{
692 if (names.size() == 0)
693 return GetSP();
694 ValueObjectSP root(GetSP());
695 for (std::pair<ConstString, bool> name : names)
696 {
697 root = root->GetChildMemberWithName(name.first, name.second);
698 if (!root)
699 {
700 if (name_of_error)
701 *name_of_error = name.first;
702 return root;
703 }
704 }
705 return root;
706}
707
708lldb::ValueObjectSP
709ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names,
710 ConstString* name_of_error)
711{
712 if (names.size() == 0)
713 return GetSP();
714 ValueObjectSP root(GetSP());
715 for (std::pair<ConstString, bool> name : names)
716 {
717 root = root->GetChildMemberWithName(name.first, name.second);
718 if (!root)
719 {
720 if (name_of_error)
721 *name_of_error = name.first;
722 return root;
723 }
724 }
725 return root;
726}
727
Greg Claytonc7bece562013-01-25 18:06:21 +0000728size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000729ValueObject::GetIndexOfChildWithName (const ConstString &name)
730{
731 bool omit_empty_base_classes = true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000732 return GetClangType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000733}
734
735ValueObjectSP
736ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
737{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000738 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000739 // classes (which really aren't part of the expression path), so we
740 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000741 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000742
Greg Claytondea8cb42011-06-29 22:09:02 +0000743 // We may need to update our value if we are dynamic
744 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000745 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000746
747 std::vector<uint32_t> child_indexes;
Greg Claytondea8cb42011-06-29 22:09:02 +0000748 bool omit_empty_base_classes = true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000749 const size_t num_child_indexes = GetClangType().GetIndexOfChildMemberWithName (name.GetCString(),
750 omit_empty_base_classes,
751 child_indexes);
Greg Claytondea8cb42011-06-29 22:09:02 +0000752 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000753 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000754 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
755 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
756
757 child_sp = GetChildAtIndex(*pos, can_create);
758 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000759 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000760 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000761 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000762 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
763 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000764 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000765 else
766 {
767 child_sp.reset();
768 }
769
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000770 }
771 }
772 return child_sp;
773}
774
775
Greg Claytonc7bece562013-01-25 18:06:21 +0000776size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000777ValueObject::GetNumChildren ()
778{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000779 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000780 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000781 {
782 SetNumChildren (CalculateNumChildren());
783 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000784 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000785}
Greg Clayton4a792072012-10-23 01:50:10 +0000786
787bool
788ValueObject::MightHaveChildren()
789{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000790 bool has_children = false;
Greg Clayton2452ab72013-02-08 22:02:02 +0000791 const uint32_t type_info = GetTypeInfo();
792 if (type_info)
Greg Clayton4a792072012-10-23 01:50:10 +0000793 {
Enrico Granata622be232014-10-21 20:52:14 +0000794 if (type_info & (eTypeHasChildren |
795 eTypeIsPointer |
796 eTypeIsReference))
Greg Clayton4a792072012-10-23 01:50:10 +0000797 has_children = true;
798 }
799 else
800 {
801 has_children = GetNumChildren () > 0;
802 }
803 return has_children;
804}
805
806// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000807void
Greg Claytonc7bece562013-01-25 18:06:21 +0000808ValueObject::SetNumChildren (size_t num_children)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000809{
Greg Clayton288bdf92010-09-02 02:59:18 +0000810 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000811 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000812}
813
814void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000815ValueObject::SetName (const ConstString &name)
816{
817 m_name = name;
818}
819
Jim Ingham58b59f92011-04-22 23:53:53 +0000820ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000821ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000822{
Jim Ingham2eec4872011-05-07 00:10:58 +0000823 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000824
Greg Claytondea8cb42011-06-29 22:09:02 +0000825 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000826 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000827 std::string child_name_str;
828 uint32_t child_byte_size = 0;
829 int32_t child_byte_offset = 0;
830 uint32_t child_bitfield_bit_size = 0;
831 uint32_t child_bitfield_bit_offset = 0;
832 bool child_is_base_class = false;
833 bool child_is_deref_of_parent = false;
834
835 const bool transparent_pointers = synthetic_array_member == false;
Greg Clayton57ee3062013-07-11 22:46:58 +0000836 ClangASTType child_clang_type;
Greg Claytondea8cb42011-06-29 22:09:02 +0000837
Greg Claytoncc4d0142012-02-17 07:49:44 +0000838 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000839
Greg Clayton57ee3062013-07-11 22:46:58 +0000840 child_clang_type = GetClangType().GetChildClangTypeAtIndex (&exe_ctx,
Greg Clayton57ee3062013-07-11 22:46:58 +0000841 idx,
842 transparent_pointers,
843 omit_empty_base_classes,
844 ignore_array_bounds,
845 child_name_str,
846 child_byte_size,
847 child_byte_offset,
848 child_bitfield_bit_size,
849 child_bitfield_bit_offset,
850 child_is_base_class,
Greg Clayton759e7442014-07-19 00:12:57 +0000851 child_is_deref_of_parent,
852 this);
Greg Clayton4ef877f2012-12-06 02:33:54 +0000853 if (child_clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000854 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000855 if (synthetic_index)
856 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000857
Greg Claytondea8cb42011-06-29 22:09:02 +0000858 ConstString child_name;
859 if (!child_name_str.empty())
860 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000861
Greg Claytondea8cb42011-06-29 22:09:02 +0000862 valobj = new ValueObjectChild (*this,
Greg Claytondea8cb42011-06-29 22:09:02 +0000863 child_clang_type,
864 child_name,
865 child_byte_size,
866 child_byte_offset,
867 child_bitfield_bit_size,
868 child_bitfield_bit_offset,
869 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000870 child_is_deref_of_parent,
871 eAddressTypeInvalid);
872 //if (valobj)
873 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
874 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000875
Jim Ingham58b59f92011-04-22 23:53:53 +0000876 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000877}
878
Enrico Granata0c489f52012-03-01 04:24:26 +0000879bool
880ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
881 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000882{
Enrico Granatac1247f52014-11-06 21:23:20 +0000883 return GetSummaryAsCString(summary_ptr, destination, TypeSummaryOptions());
884}
885
886bool
887ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
888 std::string& destination,
889 const TypeSummaryOptions& options)
890{
Enrico Granata0c489f52012-03-01 04:24:26 +0000891 destination.clear();
892
893 // ideally we would like to bail out if passing NULL, but if we do so
894 // we end up not providing the summary for function pointers anymore
895 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
896 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000897
898 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000899
900 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
901 // information that we might care to see in a crash log. might be useful in very specific situations though.
902 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
903 GetTypeName().GetCString(),
904 GetName().GetCString(),
905 summary_ptr->GetDescription().c_str());*/
906
Enrico Granataff0f23d2014-12-10 02:00:45 +0000907 if (UpdateValueIfNeeded (false) && summary_ptr)
Enrico Granata0c489f52012-03-01 04:24:26 +0000908 {
Enrico Granataff0f23d2014-12-10 02:00:45 +0000909 if (HasSyntheticValue())
910 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
911 summary_ptr->FormatObject(this, destination, options);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000912 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000913 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000914 return !destination.empty();
915}
916
917const char *
918ValueObject::GetSummaryAsCString ()
919{
920 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
921 {
922 GetSummaryAsCString(GetSummaryFormat().get(),
Enrico Granatac1247f52014-11-06 21:23:20 +0000923 m_summary_str,
Enrico Granata49bfafb2014-11-18 23:36:25 +0000924 TypeSummaryOptions());
Enrico Granata0c489f52012-03-01 04:24:26 +0000925 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000926 if (m_summary_str.empty())
927 return NULL;
928 return m_summary_str.c_str();
929}
930
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000931bool
Enrico Granata49bfafb2014-11-18 23:36:25 +0000932ValueObject::GetSummaryAsCString (std::string& destination,
933 const TypeSummaryOptions& options)
934{
935 return GetSummaryAsCString(GetSummaryFormat().get(),
936 destination,
937 options);
938}
939
940bool
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000941ValueObject::IsCStringContainer(bool check_pointer)
942{
Greg Clayton57ee3062013-07-11 22:46:58 +0000943 ClangASTType pointee_or_element_clang_type;
944 const Flags type_flags (GetTypeInfo (&pointee_or_element_clang_type));
Enrico Granata622be232014-10-21 20:52:14 +0000945 bool is_char_arr_ptr (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Greg Clayton57ee3062013-07-11 22:46:58 +0000946 pointee_or_element_clang_type.IsCharType ());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000947 if (!is_char_arr_ptr)
948 return false;
949 if (!check_pointer)
950 return true;
Enrico Granata622be232014-10-21 20:52:14 +0000951 if (type_flags.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000952 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000953 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000954 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000955 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000956 return (cstr_address != LLDB_INVALID_ADDRESS);
957}
958
Enrico Granata9128ee22011-09-06 19:20:51 +0000959size_t
960ValueObject::GetPointeeData (DataExtractor& data,
961 uint32_t item_idx,
962 uint32_t item_count)
963{
Greg Clayton57ee3062013-07-11 22:46:58 +0000964 ClangASTType pointee_or_element_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +0000965 const uint32_t type_info = GetTypeInfo (&pointee_or_element_clang_type);
Enrico Granata622be232014-10-21 20:52:14 +0000966 const bool is_pointer_type = type_info & eTypeIsPointer;
967 const bool is_array_type = type_info & eTypeIsArray;
Greg Clayton2452ab72013-02-08 22:02:02 +0000968 if (!(is_pointer_type || is_array_type))
Enrico Granata9128ee22011-09-06 19:20:51 +0000969 return 0;
970
971 if (item_count == 0)
972 return 0;
973
Greg Clayton57ee3062013-07-11 22:46:58 +0000974 const uint64_t item_type_size = pointee_or_element_clang_type.GetByteSize();
Enrico Granata9128ee22011-09-06 19:20:51 +0000975 const uint64_t bytes = item_count * item_type_size;
Enrico Granata9128ee22011-09-06 19:20:51 +0000976 const uint64_t offset = item_idx * item_type_size;
977
978 if (item_idx == 0 && item_count == 1) // simply a deref
979 {
Greg Clayton2452ab72013-02-08 22:02:02 +0000980 if (is_pointer_type)
Enrico Granata9128ee22011-09-06 19:20:51 +0000981 {
982 Error error;
983 ValueObjectSP pointee_sp = Dereference(error);
984 if (error.Fail() || pointee_sp.get() == NULL)
985 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +0000986 return pointee_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +0000987 }
988 else
989 {
990 ValueObjectSP child_sp = GetChildAtIndex(0, true);
991 if (child_sp.get() == NULL)
992 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +0000993 Error error;
994 return child_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +0000995 }
996 return true;
997 }
998 else /* (items > 1) */
999 {
1000 Error error;
1001 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
1002 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
1003
1004 AddressType addr_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001005 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001006
Enrico Granata9128ee22011-09-06 19:20:51 +00001007 switch (addr_type)
1008 {
1009 case eAddressTypeFile:
1010 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001011 ModuleSP module_sp (GetModule());
1012 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001013 {
Enrico Granata9c2efe32012-08-07 01:49:34 +00001014 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +00001015 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001016 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001017 ExecutionContext exe_ctx (GetExecutionContextRef());
1018 Target* target = exe_ctx.GetTargetPtr();
1019 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +00001020 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001021 heap_buf_ptr->SetByteSize(bytes);
1022 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
1023 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +00001024 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001025 data.SetData(data_sp);
1026 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +00001027 }
1028 }
1029 }
1030 }
1031 break;
1032 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +00001033 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001034 ExecutionContext exe_ctx (GetExecutionContextRef());
1035 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +00001036 if (process)
1037 {
1038 heap_buf_ptr->SetByteSize(bytes);
1039 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
Enrico Granata5e1480c2013-10-30 17:52:44 +00001040 if (error.Success() || bytes_read > 0)
Enrico Granata9128ee22011-09-06 19:20:51 +00001041 {
1042 data.SetData(data_sp);
1043 return bytes_read;
1044 }
1045 }
1046 }
1047 break;
1048 case eAddressTypeHost:
1049 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001050 const uint64_t max_bytes = GetClangType().GetByteSize();
Greg Clayton2452ab72013-02-08 22:02:02 +00001051 if (max_bytes > offset)
1052 {
1053 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
1054 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
1055 data.SetData(data_sp);
1056 return bytes_read;
1057 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001058 }
1059 break;
1060 case eAddressTypeInvalid:
Enrico Granata9128ee22011-09-06 19:20:51 +00001061 break;
1062 }
1063 }
1064 return 0;
1065}
1066
Greg Claytonfaac1112013-03-14 18:31:44 +00001067uint64_t
Sean Callanan866e91c2014-02-28 22:27:53 +00001068ValueObject::GetData (DataExtractor& data, Error &error)
Enrico Granata9128ee22011-09-06 19:20:51 +00001069{
1070 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001071 ExecutionContext exe_ctx (GetExecutionContextRef());
Sean Callanan866e91c2014-02-28 22:27:53 +00001072 error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001073 if (error.Fail())
Sean Callananed185ab2013-04-19 19:47:32 +00001074 {
1075 if (m_data.GetByteSize())
1076 {
1077 data = m_data;
1078 return data.GetByteSize();
1079 }
1080 else
1081 {
1082 return 0;
1083 }
1084 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001085 data.SetAddressByteSize(m_data.GetAddressByteSize());
1086 data.SetByteOrder(m_data.GetByteOrder());
1087 return data.GetByteSize();
1088}
1089
Sean Callanan389823e2013-04-13 01:21:23 +00001090bool
1091ValueObject::SetData (DataExtractor &data, Error &error)
1092{
1093 error.Clear();
1094 // Make sure our value is up to date first so that our location and location
1095 // type is valid.
1096 if (!UpdateValueIfNeeded(false))
1097 {
1098 error.SetErrorString("unable to read value");
1099 return false;
1100 }
1101
1102 uint64_t count = 0;
Greg Clayton57ee3062013-07-11 22:46:58 +00001103 const Encoding encoding = GetClangType().GetEncoding(count);
Sean Callanan389823e2013-04-13 01:21:23 +00001104
1105 const size_t byte_size = GetByteSize();
1106
1107 Value::ValueType value_type = m_value.GetValueType();
1108
1109 switch (value_type)
1110 {
1111 case Value::eValueTypeScalar:
1112 {
1113 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1114
1115 if (!set_error.Success())
1116 {
1117 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1118 return false;
1119 }
1120 }
1121 break;
1122 case Value::eValueTypeLoadAddress:
1123 {
1124 // If it is a load address, then the scalar value is the storage location
1125 // of the data, and we have to shove this value down to that load location.
1126 ExecutionContext exe_ctx (GetExecutionContextRef());
1127 Process *process = exe_ctx.GetProcessPtr();
1128 if (process)
1129 {
1130 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1131 size_t bytes_written = process->WriteMemory(target_addr,
1132 data.GetDataStart(),
1133 byte_size,
1134 error);
1135 if (!error.Success())
1136 return false;
1137 if (bytes_written != byte_size)
1138 {
1139 error.SetErrorString("unable to write value to memory");
1140 return false;
1141 }
1142 }
1143 }
1144 break;
1145 case Value::eValueTypeHostAddress:
1146 {
1147 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1148 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1149 m_data.SetData(buffer_sp, 0);
1150 data.CopyByteOrderedData (0,
1151 byte_size,
1152 const_cast<uint8_t *>(m_data.GetDataStart()),
1153 byte_size,
1154 m_data.GetByteOrder());
1155 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1156 }
1157 break;
1158 case Value::eValueTypeFileAddress:
1159 case Value::eValueTypeVector:
1160 break;
1161 }
1162
1163 // If we have reached this point, then we have successfully changed the value.
1164 SetNeedsUpdate();
1165 return true;
1166}
1167
Enrico Granata9128ee22011-09-06 19:20:51 +00001168// will compute strlen(str), but without consuming more than
1169// maxlen bytes out of str (this serves the purpose of reading
1170// chunks of a string without having to worry about
1171// missing NULL terminators in the chunk)
1172// of course, if strlen(str) > maxlen, the function will return
1173// maxlen_value (which should be != maxlen, because that allows you
1174// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1175static uint32_t
1176strlen_or_inf (const char* str,
1177 uint32_t maxlen,
1178 uint32_t maxlen_value)
1179{
1180 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +00001181 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +00001182 {
Greg Clayton8dd5c172011-10-05 22:19:51 +00001183 while(*str)
1184 {
1185 len++;str++;
Greg Clayton2452ab72013-02-08 22:02:02 +00001186 if (len >= maxlen)
Greg Clayton8dd5c172011-10-05 22:19:51 +00001187 return maxlen_value;
1188 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001189 }
1190 return len;
1191}
1192
Enrico Granata2206b482014-10-30 18:27:31 +00001193static bool
1194CopyStringDataToBufferSP(const StreamString& source,
1195 lldb::DataBufferSP& destination)
1196{
1197 destination.reset(new DataBufferHeap(source.GetSize()+1,0));
1198 memcpy(destination->GetBytes(), source.GetString().c_str(), source.GetSize());
1199 return true;
1200}
1201
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001202size_t
Enrico Granata2206b482014-10-30 18:27:31 +00001203ValueObject::ReadPointedString (lldb::DataBufferSP& buffer_sp,
Greg Claytoncc4d0142012-02-17 07:49:44 +00001204 Error& error,
1205 uint32_t max_length,
1206 bool honor_array,
1207 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001208{
Enrico Granata2206b482014-10-30 18:27:31 +00001209 StreamString s;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001210 ExecutionContext exe_ctx (GetExecutionContextRef());
1211 Target* target = exe_ctx.GetTargetPtr();
Enrico Granata2206b482014-10-30 18:27:31 +00001212
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001213 if (!target)
1214 {
1215 s << "<no target to read from>";
1216 error.SetErrorString("no target to read from");
Enrico Granata2206b482014-10-30 18:27:31 +00001217 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001218 return 0;
1219 }
1220
1221 if (max_length == 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001222 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001223
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001224 size_t bytes_read = 0;
1225 size_t total_bytes_read = 0;
1226
Greg Clayton57ee3062013-07-11 22:46:58 +00001227 ClangASTType clang_type = GetClangType();
1228 ClangASTType elem_or_pointee_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001229 const Flags type_flags (GetTypeInfo (&elem_or_pointee_clang_type));
Enrico Granata622be232014-10-21 20:52:14 +00001230 if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Greg Clayton57ee3062013-07-11 22:46:58 +00001231 elem_or_pointee_clang_type.IsCharType ())
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001232 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001233 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1234 AddressType cstr_address_type = eAddressTypeInvalid;
1235
1236 size_t cstr_len = 0;
1237 bool capped_data = false;
Enrico Granata622be232014-10-21 20:52:14 +00001238 if (type_flags.Test (eTypeIsArray))
Greg Claytoncc4d0142012-02-17 07:49:44 +00001239 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001240 // We have an array
Greg Clayton57ee3062013-07-11 22:46:58 +00001241 uint64_t array_size = 0;
1242 if (clang_type.IsArrayType(NULL, &array_size, NULL))
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001243 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001244 cstr_len = array_size;
1245 if (cstr_len > max_length)
1246 {
1247 capped_data = true;
1248 cstr_len = max_length;
1249 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001250 }
1251 cstr_address = GetAddressOf (true, &cstr_address_type);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001252 }
1253 else
1254 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001255 // We have a pointer
1256 cstr_address = GetPointerValue (&cstr_address_type);
1257 }
1258
1259 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1260 {
1261 s << "<invalid address>";
1262 error.SetErrorString("invalid address");
Enrico Granata2206b482014-10-30 18:27:31 +00001263 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001264 return 0;
1265 }
Enrico Granata2206b482014-10-30 18:27:31 +00001266
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001267 Address cstr_so_addr (cstr_address);
1268 DataExtractor data;
1269 if (cstr_len > 0 && honor_array)
1270 {
1271 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1272 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1273 GetPointeeData(data, 0, cstr_len);
Enrico Granata2206b482014-10-30 18:27:31 +00001274
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001275 if ((bytes_read = data.GetByteSize()) > 0)
1276 {
1277 total_bytes_read = bytes_read;
Enrico Granata2206b482014-10-30 18:27:31 +00001278 for (size_t offset = 0; offset < bytes_read; offset++)
1279 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001280 if (capped_data)
1281 s << "...";
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001282 }
1283 }
1284 else
1285 {
1286 cstr_len = max_length;
1287 const size_t k_max_buf_size = 64;
Enrico Granata2206b482014-10-30 18:27:31 +00001288
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001289 size_t offset = 0;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001290
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001291 int cstr_len_displayed = -1;
1292 bool capped_cstr = false;
1293 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1294 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1295 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001296 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001297 total_bytes_read += bytes_read;
1298 const char *cstr = data.PeekCStr(0);
1299 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1300 if (len > k_max_buf_size)
1301 len = k_max_buf_size;
Enrico Granata2206b482014-10-30 18:27:31 +00001302
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001303 if (cstr_len_displayed < 0)
1304 cstr_len_displayed = len;
Enrico Granata2206b482014-10-30 18:27:31 +00001305
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001306 if (len == 0)
1307 break;
1308 cstr_len_displayed += len;
1309 if (len > bytes_read)
1310 len = bytes_read;
1311 if (len > cstr_len)
1312 len = cstr_len;
1313
Enrico Granata2206b482014-10-30 18:27:31 +00001314 for (size_t offset = 0; offset < bytes_read; offset++)
1315 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001316
1317 if (len < k_max_buf_size)
1318 break;
1319
1320 if (len >= cstr_len)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001321 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001322 capped_cstr = true;
1323 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001324 }
Enrico Granata2206b482014-10-30 18:27:31 +00001325
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001326 cstr_len -= len;
1327 offset += len;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001328 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001329
1330 if (cstr_len_displayed >= 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001331 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001332 if (capped_cstr)
1333 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001334 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001335 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001336 }
1337 else
1338 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001339 error.SetErrorString("not a string object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001340 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001341 }
Enrico Granata2206b482014-10-30 18:27:31 +00001342 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001343 return total_bytes_read;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001344}
1345
Enrico Granata744794a2014-09-05 21:46:22 +00001346std::pair<TypeValidatorResult, std::string>
1347ValueObject::GetValidationStatus ()
1348{
1349 if (!UpdateValueIfNeeded(true))
1350 return {TypeValidatorResult::Success,""}; // not the validator's job to discuss update problems
1351
1352 if (m_validation_result.hasValue())
1353 return m_validation_result.getValue();
1354
1355 if (!m_type_validator_sp)
1356 return {TypeValidatorResult::Success,""}; // no validator no failure
1357
1358 auto outcome = m_type_validator_sp->FormatObject(this);
1359
1360 return (m_validation_result = {outcome.m_result,outcome.m_message}).getValue();
1361}
1362
Jim Ingham53c47f12010-09-10 23:12:17 +00001363const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001364ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001365{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001366
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001367 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001368 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001369
1370 if (!m_object_desc_str.empty())
1371 return m_object_desc_str.c_str();
1372
Greg Claytoncc4d0142012-02-17 07:49:44 +00001373 ExecutionContext exe_ctx (GetExecutionContextRef());
1374 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001375 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001376 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001377
Jim Ingham53c47f12010-09-10 23:12:17 +00001378 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001379
Greg Claytonafacd142011-09-02 01:15:17 +00001380 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001381 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1382
Jim Inghama2cf2632010-12-23 02:29:54 +00001383 if (runtime == NULL)
1384 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001385 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Greg Clayton57ee3062013-07-11 22:46:58 +00001386 ClangASTType clang_type = GetClangType();
1387 if (clang_type)
Jim Inghama2cf2632010-12-23 02:29:54 +00001388 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001389 bool is_signed;
Greg Clayton57ee3062013-07-11 22:46:58 +00001390 if (clang_type.IsIntegerType (is_signed) || clang_type.IsPointerType ())
Jim Inghamb7603bb2011-03-18 00:05:18 +00001391 {
Greg Claytonafacd142011-09-02 01:15:17 +00001392 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001393 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001394 }
1395 }
1396
Jim Ingham8d543de2011-03-31 23:01:21 +00001397 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001398 {
1399 m_object_desc_str.append (s.GetData());
1400 }
Sean Callanan672ad942010-10-23 00:18:49 +00001401
1402 if (m_object_desc_str.empty())
1403 return NULL;
1404 else
1405 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001406}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001407
Enrico Granata0c489f52012-03-01 04:24:26 +00001408bool
Enrico Granata4939b982013-12-22 09:24:22 +00001409ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format,
1410 std::string& destination)
1411{
1412 if (UpdateValueIfNeeded(false))
1413 return format.FormatObject(this,destination);
1414 else
1415 return false;
1416}
1417
1418bool
Enrico Granata0c489f52012-03-01 04:24:26 +00001419ValueObject::GetValueAsCString (lldb::Format format,
1420 std::string& destination)
1421{
Enrico Granata30f287f2013-12-28 08:44:02 +00001422 return GetValueAsCString(TypeFormatImpl_Format(format),destination);
Enrico Granata0c489f52012-03-01 04:24:26 +00001423}
1424
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001425const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001426ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001427{
Enrico Granatab294fd22013-05-31 19:18:19 +00001428 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001429 {
Enrico Granata4939b982013-12-22 09:24:22 +00001430 lldb::TypeFormatImplSP format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001431 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001432 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001433 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001434 if (m_type_format_sp)
Enrico Granata4939b982013-12-22 09:24:22 +00001435 format_sp = m_type_format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001436 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001437 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001438 if (m_is_bitfield_for_scalar)
1439 my_format = eFormatUnsigned;
1440 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001441 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001442 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001443 {
1444 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1445 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001446 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001447 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001448 else
1449 {
Enrico Granatad07cfd32014-10-08 18:27:36 +00001450 my_format = GetValue().GetClangType().GetFormat();
Enrico Granata0c489f52012-03-01 04:24:26 +00001451 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001452 }
1453 }
1454 }
Enrico Granatab294fd22013-05-31 19:18:19 +00001455 if (my_format != m_last_format || m_value_str.empty())
Enrico Granata297e69f2012-03-06 23:21:16 +00001456 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001457 m_last_format = my_format;
Enrico Granata4939b982013-12-22 09:24:22 +00001458 if (!format_sp)
Enrico Granata30f287f2013-12-28 08:44:02 +00001459 format_sp.reset(new TypeFormatImpl_Format(my_format));
Enrico Granata4939b982013-12-22 09:24:22 +00001460 if (GetValueAsCString(*format_sp.get(), m_value_str))
Enrico Granata297e69f2012-03-06 23:21:16 +00001461 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001462 if (!m_value_did_change && m_old_value_valid)
1463 {
1464 // The value was gotten successfully, so we consider the
1465 // value as changed if the value string differs
1466 SetValueDidChange (m_old_value_str != m_value_str);
1467 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001468 }
1469 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001470 }
1471 if (m_value_str.empty())
1472 return NULL;
1473 return m_value_str.c_str();
1474}
1475
Enrico Granatac3e320a2011-08-02 17:27:39 +00001476// if > 8bytes, 0 is returned. this method should mostly be used
1477// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001478uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001479ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001480{
1481 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001482 if (CanProvideValue())
Enrico Granatac3e320a2011-08-02 17:27:39 +00001483 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001484 Scalar scalar;
1485 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001486 {
1487 if (success)
1488 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001489 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001490 }
1491 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001492 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001493
1494 if (success)
1495 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001496 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001497}
1498
Enrico Granatad7373f62013-10-31 18:57:50 +00001499int64_t
1500ValueObject::GetValueAsSigned (int64_t fail_value, bool *success)
1501{
1502 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001503 if (CanProvideValue())
Enrico Granatad7373f62013-10-31 18:57:50 +00001504 {
1505 Scalar scalar;
1506 if (ResolveValue (scalar))
1507 {
1508 if (success)
1509 *success = true;
1510 return scalar.SLongLong(fail_value);
1511 }
1512 // fallthrough, otherwise...
1513 }
1514
1515 if (success)
1516 *success = false;
1517 return fail_value;
1518}
1519
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001520// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1521// this call up to date by returning true for your new special cases. We will eventually move
1522// to checking this call result before trying to display special cases
1523bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001524ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1525 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001526{
Greg Clayton57ee3062013-07-11 22:46:58 +00001527 Flags flags(GetTypeInfo());
Enrico Granata622be232014-10-21 20:52:14 +00001528 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001529 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001530 {
1531 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001532 (custom_format == eFormatCString ||
1533 custom_format == eFormatCharArray ||
1534 custom_format == eFormatChar ||
1535 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001536 return true;
1537
Enrico Granata622be232014-10-21 20:52:14 +00001538 if (flags.Test(eTypeIsArray))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001539 {
Greg Claytonafacd142011-09-02 01:15:17 +00001540 if ((custom_format == eFormatBytes) ||
1541 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001542 return true;
1543
Greg Claytonafacd142011-09-02 01:15:17 +00001544 if ((custom_format == eFormatVectorOfChar) ||
1545 (custom_format == eFormatVectorOfFloat32) ||
1546 (custom_format == eFormatVectorOfFloat64) ||
1547 (custom_format == eFormatVectorOfSInt16) ||
1548 (custom_format == eFormatVectorOfSInt32) ||
1549 (custom_format == eFormatVectorOfSInt64) ||
1550 (custom_format == eFormatVectorOfSInt8) ||
1551 (custom_format == eFormatVectorOfUInt128) ||
1552 (custom_format == eFormatVectorOfUInt16) ||
1553 (custom_format == eFormatVectorOfUInt32) ||
1554 (custom_format == eFormatVectorOfUInt64) ||
1555 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001556 return true;
1557 }
1558 }
1559 return false;
1560}
1561
Enrico Granata9fc19442011-07-06 02:13:41 +00001562bool
1563ValueObject::DumpPrintableRepresentation(Stream& s,
1564 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001565 Format custom_format,
Enrico Granata0dba9b32014-01-08 01:36:59 +00001566 PrintableRepresentationSpecialCases special,
1567 bool do_dump_error)
Enrico Granata9fc19442011-07-06 02:13:41 +00001568{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001569
Greg Clayton57ee3062013-07-11 22:46:58 +00001570 Flags flags(GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001571
Enrico Granata86cc9822012-03-19 22:58:49 +00001572 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1573 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1574
1575 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001576 {
Enrico Granata622be232014-10-21 20:52:14 +00001577 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001578 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001579 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001580 // when being asked to get a printable display an array or pointer type directly,
1581 // try to "do the right thing"
1582
1583 if (IsCStringContainer(true) &&
1584 (custom_format == eFormatCString ||
1585 custom_format == eFormatCharArray ||
1586 custom_format == eFormatChar ||
1587 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001588 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001589 Error error;
Enrico Granata2206b482014-10-30 18:27:31 +00001590 lldb::DataBufferSP buffer_sp;
1591 ReadPointedString(buffer_sp,
Enrico Granata86cc9822012-03-19 22:58:49 +00001592 error,
1593 0,
1594 (custom_format == eFormatVectorOfChar) ||
1595 (custom_format == eFormatCharArray));
Enrico Granataebdc1ac2014-11-05 21:20:48 +00001596 lldb_private::formatters::ReadBufferAndDumpToStreamOptions options(*this);
Enrico Granata2206b482014-10-30 18:27:31 +00001597 options.SetData(DataExtractor(buffer_sp, lldb::eByteOrderInvalid, 8)); // none of this matters for a string - pass some defaults
1598 options.SetStream(&s);
1599 options.SetPrefixToken(0);
1600 options.SetQuote('"');
1601 options.SetSourceSize(buffer_sp->GetByteSize());
Enrico Granata2206b482014-10-30 18:27:31 +00001602 lldb_private::formatters::ReadBufferAndDumpToStream<lldb_private::formatters::StringElementType::ASCII>(options);
Enrico Granata86cc9822012-03-19 22:58:49 +00001603 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001604 }
1605
Enrico Granata86cc9822012-03-19 22:58:49 +00001606 if (custom_format == eFormatEnum)
1607 return false;
1608
1609 // this only works for arrays, because I have no way to know when
1610 // the pointed memory ends, and no special \0 end of data marker
Enrico Granata622be232014-10-21 20:52:14 +00001611 if (flags.Test(eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001612 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001613 if ((custom_format == eFormatBytes) ||
1614 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001615 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001616 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001617
1618 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001619 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001620 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001621
1622 if (low)
1623 s << ',';
1624
1625 ValueObjectSP child = GetChildAtIndex(low,true);
1626 if (!child.get())
1627 {
1628 s << "<invalid child>";
1629 continue;
1630 }
1631 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1632 }
1633
1634 s << ']';
1635
1636 return true;
1637 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001638
Enrico Granata86cc9822012-03-19 22:58:49 +00001639 if ((custom_format == eFormatVectorOfChar) ||
1640 (custom_format == eFormatVectorOfFloat32) ||
1641 (custom_format == eFormatVectorOfFloat64) ||
1642 (custom_format == eFormatVectorOfSInt16) ||
1643 (custom_format == eFormatVectorOfSInt32) ||
1644 (custom_format == eFormatVectorOfSInt64) ||
1645 (custom_format == eFormatVectorOfSInt8) ||
1646 (custom_format == eFormatVectorOfUInt128) ||
1647 (custom_format == eFormatVectorOfUInt16) ||
1648 (custom_format == eFormatVectorOfUInt32) ||
1649 (custom_format == eFormatVectorOfUInt64) ||
1650 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1651 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001652 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001653
1654 Format format = FormatManager::GetSingleItemFormat(custom_format);
1655
1656 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001657 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001658 {
1659
1660 if (low)
1661 s << ',';
1662
1663 ValueObjectSP child = GetChildAtIndex(low,true);
1664 if (!child.get())
1665 {
1666 s << "<invalid child>";
1667 continue;
1668 }
1669 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1670 }
1671
1672 s << ']';
1673
1674 return true;
1675 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001676 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001677
1678 if ((custom_format == eFormatBoolean) ||
1679 (custom_format == eFormatBinary) ||
1680 (custom_format == eFormatChar) ||
1681 (custom_format == eFormatCharPrintable) ||
1682 (custom_format == eFormatComplexFloat) ||
1683 (custom_format == eFormatDecimal) ||
1684 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001685 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001686 (custom_format == eFormatFloat) ||
1687 (custom_format == eFormatOctal) ||
1688 (custom_format == eFormatOSType) ||
1689 (custom_format == eFormatUnicode16) ||
1690 (custom_format == eFormatUnicode32) ||
1691 (custom_format == eFormatUnsigned) ||
1692 (custom_format == eFormatPointer) ||
1693 (custom_format == eFormatComplexInteger) ||
1694 (custom_format == eFormatComplex) ||
1695 (custom_format == eFormatDefault)) // use the [] operator
1696 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001697 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001698 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001699
1700 if (only_special)
1701 return false;
1702
Enrico Granata86cc9822012-03-19 22:58:49 +00001703 bool var_success = false;
1704
1705 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001706 const char *cstr = NULL;
Enrico Granata2c75f112013-06-21 00:04:51 +00001707
1708 // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1709 // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1710 // area for cases where our desired output is not backed by some other longer-term storage
Greg Claytonc7bece562013-01-25 18:06:21 +00001711 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001712
Enrico Granata465f4bc2014-02-15 01:24:44 +00001713 if (custom_format != eFormatInvalid)
Enrico Granata86cc9822012-03-19 22:58:49 +00001714 SetFormat(custom_format);
1715
1716 switch(val_obj_display)
1717 {
1718 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001719 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001720 break;
1721
1722 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001723 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001724 break;
1725
1726 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001727 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001728 break;
1729
1730 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001731 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001732 break;
1733
1734 case eValueObjectRepresentationStyleChildrenCount:
Deepak Panickal99fbc072014-03-03 15:39:47 +00001735 strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren());
Greg Claytonc7bece562013-01-25 18:06:21 +00001736 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001737 break;
1738
1739 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001740 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001741 break;
Enrico Granata2c75f112013-06-21 00:04:51 +00001742
1743 case eValueObjectRepresentationStyleName:
1744 cstr = GetName().AsCString();
1745 break;
1746
1747 case eValueObjectRepresentationStyleExpressionPath:
1748 GetExpressionPath(strm, false);
1749 cstr = strm.GetString().c_str();
1750 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001751 }
1752
Greg Claytonc7bece562013-01-25 18:06:21 +00001753 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001754 {
1755 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001756 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001757 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1758 {
Enrico Granatad07cfd32014-10-08 18:27:36 +00001759 if (!CanProvideValue())
Enrico Granata86cc9822012-03-19 22:58:49 +00001760 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001761 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1762 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001763 }
1764 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001765 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001766 }
1767 }
1768
Greg Claytonc7bece562013-01-25 18:06:21 +00001769 if (cstr)
1770 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001771 else
1772 {
1773 if (m_error.Fail())
Enrico Granata0dba9b32014-01-08 01:36:59 +00001774 {
1775 if (do_dump_error)
1776 s.Printf("<%s>", m_error.AsCString());
1777 else
1778 return false;
1779 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001780 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1781 s.PutCString("<no summary available>");
1782 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1783 s.PutCString("<no value available>");
1784 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1785 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1786 else
1787 s.PutCString("<no printable representation>");
1788 }
1789
1790 // we should only return false here if we could not do *anything*
1791 // even if we have an error message as output, that's a success
1792 // from our callers' perspective, so return true
1793 var_success = true;
Enrico Granata465f4bc2014-02-15 01:24:44 +00001794
1795 if (custom_format != eFormatInvalid)
1796 SetFormat(eFormatDefault);
Enrico Granata86cc9822012-03-19 22:58:49 +00001797 }
1798
Enrico Granataf4efecd2011-07-12 22:56:10 +00001799 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001800}
1801
Greg Clayton737b9322010-09-13 03:32:57 +00001802addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001803ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001804{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001805 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001806 return LLDB_INVALID_ADDRESS;
1807
Greg Clayton73b472d2010-10-27 03:32:59 +00001808 switch (m_value.GetValueType())
1809 {
1810 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001811 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001812 if (scalar_is_load_address)
1813 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001814 if(address_type)
1815 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001816 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1817 }
1818 break;
1819
1820 case Value::eValueTypeLoadAddress:
1821 case Value::eValueTypeFileAddress:
1822 case Value::eValueTypeHostAddress:
1823 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001824 if(address_type)
1825 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001826 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1827 }
1828 break;
1829 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001830 if (address_type)
1831 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001832 return LLDB_INVALID_ADDRESS;
1833}
1834
1835addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001836ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001837{
Greg Claytonafacd142011-09-02 01:15:17 +00001838 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001839 if(address_type)
1840 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001841
Enrico Granatac3e320a2011-08-02 17:27:39 +00001842 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001843 return address;
1844
Greg Clayton73b472d2010-10-27 03:32:59 +00001845 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001846 {
1847 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001848 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001849 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001850 break;
1851
Enrico Granata9128ee22011-09-06 19:20:51 +00001852 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001853 case Value::eValueTypeLoadAddress:
1854 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001855 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001856 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001857 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001858 }
1859 break;
1860 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001861
Enrico Granata9128ee22011-09-06 19:20:51 +00001862 if (address_type)
1863 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001864
Greg Clayton737b9322010-09-13 03:32:57 +00001865 return address;
1866}
1867
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001868bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001869ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001870{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001871 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001872 // Make sure our value is up to date first so that our location and location
1873 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001874 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001875 {
1876 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001877 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001878 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001879
Greg Claytonfaac1112013-03-14 18:31:44 +00001880 uint64_t count = 0;
Greg Clayton57ee3062013-07-11 22:46:58 +00001881 const Encoding encoding = GetClangType().GetEncoding (count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001882
Greg Claytonb1320972010-07-14 00:18:15 +00001883 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001884
Jim Ingham16e0c682011-08-12 23:34:31 +00001885 Value::ValueType value_type = m_value.GetValueType();
1886
1887 if (value_type == Value::eValueTypeScalar)
1888 {
1889 // If the value is already a scalar, then let the scalar change itself:
1890 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1891 }
1892 else if (byte_size <= Scalar::GetMaxByteSize())
1893 {
1894 // If the value fits in a scalar, then make a new scalar and again let the
1895 // scalar code do the conversion, then figure out where to put the new value.
1896 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001897 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1898 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001899 {
Jim Ingham4b536182011-08-09 02:12:22 +00001900 switch (value_type)
1901 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001902 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001903 {
1904 // If it is a load address, then the scalar value is the storage location
1905 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001906 ExecutionContext exe_ctx (GetExecutionContextRef());
1907 Process *process = exe_ctx.GetProcessPtr();
1908 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001909 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001910 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001911 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1912 new_scalar,
1913 byte_size,
1914 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001915 if (!error.Success())
1916 return false;
1917 if (bytes_written != byte_size)
1918 {
1919 error.SetErrorString("unable to write value to memory");
1920 return false;
1921 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001922 }
1923 }
Jim Ingham4b536182011-08-09 02:12:22 +00001924 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001925 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001926 {
1927 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1928 DataExtractor new_data;
1929 new_data.SetByteOrder (m_data.GetByteOrder());
1930
1931 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1932 m_data.SetData(buffer_sp, 0);
1933 bool success = new_scalar.GetData(new_data);
1934 if (success)
1935 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001936 new_data.CopyByteOrderedData (0,
1937 byte_size,
1938 const_cast<uint8_t *>(m_data.GetDataStart()),
1939 byte_size,
1940 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001941 }
1942 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1943
1944 }
Jim Ingham4b536182011-08-09 02:12:22 +00001945 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001946 case Value::eValueTypeFileAddress:
1947 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001948 case Value::eValueTypeVector:
1949 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001950 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001951 }
1952 else
1953 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001954 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001955 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001956 }
1957 else
1958 {
1959 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001960 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001961 return false;
1962 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001963
1964 // If we have reached this point, then we have successfully changed the value.
1965 SetNeedsUpdate();
1966 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001967}
1968
Greg Clayton81e871e2012-02-04 02:27:34 +00001969bool
1970ValueObject::GetDeclaration (Declaration &decl)
1971{
1972 decl.Clear();
1973 return false;
1974}
1975
Greg Clayton84db9102012-03-26 23:03:23 +00001976ConstString
1977ValueObject::GetTypeName()
1978{
Greg Clayton57ee3062013-07-11 22:46:58 +00001979 return GetClangType().GetConstTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00001980}
1981
1982ConstString
Enrico Granatae8daa2f2014-05-17 19:14:17 +00001983ValueObject::GetDisplayTypeName()
1984{
1985 return GetTypeName();
1986}
1987
1988ConstString
Greg Clayton84db9102012-03-26 23:03:23 +00001989ValueObject::GetQualifiedTypeName()
1990{
Greg Clayton57ee3062013-07-11 22:46:58 +00001991 return GetClangType().GetConstQualifiedTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00001992}
1993
1994
Greg Claytonafacd142011-09-02 01:15:17 +00001995LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001996ValueObject::GetObjectRuntimeLanguage ()
1997{
Greg Clayton57ee3062013-07-11 22:46:58 +00001998 return GetClangType().GetMinimumLanguage ();
Jim Ingham5a369122010-09-28 01:25:32 +00001999}
2000
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002001void
Jim Ingham58b59f92011-04-22 23:53:53 +00002002ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002003{
Jim Ingham58b59f92011-04-22 23:53:53 +00002004 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002005}
2006
2007ValueObjectSP
2008ValueObject::GetSyntheticChild (const ConstString &key) const
2009{
2010 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00002011 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002012 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00002013 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002014 return synthetic_child_sp;
2015}
2016
Greg Clayton2452ab72013-02-08 22:02:02 +00002017uint32_t
Greg Clayton57ee3062013-07-11 22:46:58 +00002018ValueObject::GetTypeInfo (ClangASTType *pointee_or_element_clang_type)
Greg Clayton2452ab72013-02-08 22:02:02 +00002019{
Greg Clayton57ee3062013-07-11 22:46:58 +00002020 return GetClangType().GetTypeInfo (pointee_or_element_clang_type);
Greg Clayton2452ab72013-02-08 22:02:02 +00002021}
2022
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002023bool
2024ValueObject::IsPointerType ()
2025{
Greg Clayton57ee3062013-07-11 22:46:58 +00002026 return GetClangType().IsPointerType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002027}
2028
Jim Inghamb7603bb2011-03-18 00:05:18 +00002029bool
Greg Claytondaf515f2011-07-09 20:12:33 +00002030ValueObject::IsArrayType ()
2031{
Greg Clayton57ee3062013-07-11 22:46:58 +00002032 return GetClangType().IsArrayType (NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00002033}
2034
2035bool
Enrico Granata9fc19442011-07-06 02:13:41 +00002036ValueObject::IsScalarType ()
2037{
Greg Clayton57ee3062013-07-11 22:46:58 +00002038 return GetClangType().IsScalarType ();
Enrico Granata9fc19442011-07-06 02:13:41 +00002039}
2040
2041bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00002042ValueObject::IsIntegerType (bool &is_signed)
2043{
Greg Clayton57ee3062013-07-11 22:46:58 +00002044 return GetClangType().IsIntegerType (is_signed);
Jim Inghamb7603bb2011-03-18 00:05:18 +00002045}
Greg Clayton73b472d2010-10-27 03:32:59 +00002046
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002047bool
2048ValueObject::IsPointerOrReferenceType ()
2049{
Greg Clayton57ee3062013-07-11 22:46:58 +00002050 return GetClangType().IsPointerOrReferenceType ();
Greg Clayton007d5be2011-05-30 00:49:24 +00002051}
2052
2053bool
Greg Claytondea8cb42011-06-29 22:09:02 +00002054ValueObject::IsPossibleDynamicType ()
2055{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002056 ExecutionContext exe_ctx (GetExecutionContextRef());
2057 Process *process = exe_ctx.GetProcessPtr();
2058 if (process)
2059 return process->IsPossibleDynamicValue(*this);
2060 else
Greg Clayton57ee3062013-07-11 22:46:58 +00002061 return GetClangType().IsPossibleDynamicType (NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00002062}
2063
Enrico Granata9e7b3882012-12-13 23:50:33 +00002064bool
2065ValueObject::IsObjCNil ()
2066{
Enrico Granata622be232014-10-21 20:52:14 +00002067 const uint32_t mask = eTypeIsObjC | eTypeIsPointer;
Greg Clayton57ee3062013-07-11 22:46:58 +00002068 bool isObjCpointer = (((GetClangType().GetTypeInfo(NULL)) & mask) == mask);
Enrico Granata7277d202013-03-15 23:33:15 +00002069 if (!isObjCpointer)
2070 return false;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002071 bool canReadValue = true;
2072 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
Enrico Granata7277d202013-03-15 23:33:15 +00002073 return canReadValue && isZero;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002074}
2075
Greg Claytonafacd142011-09-02 01:15:17 +00002076ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002077ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002078{
Greg Clayton2452ab72013-02-08 22:02:02 +00002079 const uint32_t type_info = GetTypeInfo ();
Enrico Granata622be232014-10-21 20:52:14 +00002080 if (type_info & eTypeIsArray)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002081 return GetSyntheticArrayMemberFromArray(index, can_create);
2082
Enrico Granata622be232014-10-21 20:52:14 +00002083 if (type_info & eTypeIsPointer)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002084 return GetSyntheticArrayMemberFromPointer(index, can_create);
2085
2086 return ValueObjectSP();
2087
2088}
2089
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002090ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002091ValueObject::GetSyntheticArrayMemberFromPointer (size_t index, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002092{
2093 ValueObjectSP synthetic_child_sp;
2094 if (IsPointerType ())
2095 {
2096 char index_str[64];
Deepak Panickal99fbc072014-03-03 15:39:47 +00002097 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002098 ConstString index_const_str(index_str);
2099 // Check if we have already created a synthetic array member in this
2100 // valid object. If we have we will re-use it.
2101 synthetic_child_sp = GetSyntheticChild (index_const_str);
2102 if (!synthetic_child_sp)
2103 {
Jim Ingham58b59f92011-04-22 23:53:53 +00002104 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002105 // We haven't made a synthetic array member for INDEX yet, so
2106 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00002107 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002108
2109 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00002110 if (synthetic_child)
2111 {
2112 AddSyntheticChild(index_const_str, synthetic_child);
2113 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002114 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00002115 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00002116 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002117 }
2118 }
2119 return synthetic_child_sp;
2120}
Jim Ingham22777012010-09-23 02:01:19 +00002121
Greg Claytondaf515f2011-07-09 20:12:33 +00002122// This allows you to create an array member using and index
2123// that doesn't not fall in the normal bounds of the array.
2124// Many times structure can be defined as:
2125// struct Collection
2126// {
2127// uint32_t item_count;
2128// Item item_array[0];
2129// };
2130// The size of the "item_array" is 1, but many times in practice
2131// there are more items in "item_array".
2132
2133ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002134ValueObject::GetSyntheticArrayMemberFromArray (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00002135{
2136 ValueObjectSP synthetic_child_sp;
2137 if (IsArrayType ())
2138 {
2139 char index_str[64];
Deepak Panickal99fbc072014-03-03 15:39:47 +00002140 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
Greg Claytondaf515f2011-07-09 20:12:33 +00002141 ConstString index_const_str(index_str);
2142 // Check if we have already created a synthetic array member in this
2143 // valid object. If we have we will re-use it.
2144 synthetic_child_sp = GetSyntheticChild (index_const_str);
2145 if (!synthetic_child_sp)
2146 {
2147 ValueObject *synthetic_child;
2148 // We haven't made a synthetic array member for INDEX yet, so
2149 // lets make one and cache it for any future reference.
2150 synthetic_child = CreateChildAtIndex(0, true, index);
2151
2152 // Cache the value if we got one back...
2153 if (synthetic_child)
2154 {
2155 AddSyntheticChild(index_const_str, synthetic_child);
2156 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002157 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00002158 synthetic_child_sp->m_is_array_item_for_pointer = true;
2159 }
2160 }
2161 }
2162 return synthetic_child_sp;
2163}
2164
Enrico Granata9fc19442011-07-06 02:13:41 +00002165ValueObjectSP
2166ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2167{
2168 ValueObjectSP synthetic_child_sp;
2169 if (IsScalarType ())
2170 {
2171 char index_str[64];
2172 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2173 ConstString index_const_str(index_str);
2174 // Check if we have already created a synthetic array member in this
2175 // valid object. If we have we will re-use it.
2176 synthetic_child_sp = GetSyntheticChild (index_const_str);
2177 if (!synthetic_child_sp)
2178 {
Enrico Granata9fc19442011-07-06 02:13:41 +00002179 // We haven't made a synthetic array member for INDEX yet, so
2180 // lets make one and cache it for any future reference.
Greg Clayton57ee3062013-07-11 22:46:58 +00002181 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
2182 GetClangType(),
2183 index_const_str,
2184 GetByteSize(),
2185 0,
2186 to-from+1,
2187 from,
2188 false,
2189 false,
2190 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002191
2192 // Cache the value if we got one back...
2193 if (synthetic_child)
2194 {
2195 AddSyntheticChild(index_const_str, synthetic_child);
2196 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002197 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002198 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2199 }
2200 }
2201 }
2202 return synthetic_child_sp;
2203}
2204
Greg Claytonafacd142011-09-02 01:15:17 +00002205ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00002206ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
2207{
2208
2209 ValueObjectSP synthetic_child_sp;
2210
2211 char name_str[64];
2212 snprintf(name_str, sizeof(name_str), "@%i", offset);
2213 ConstString name_const_str(name_str);
2214
2215 // Check if we have already created a synthetic array member in this
2216 // valid object. If we have we will re-use it.
2217 synthetic_child_sp = GetSyntheticChild (name_const_str);
2218
2219 if (synthetic_child_sp.get())
2220 return synthetic_child_sp;
2221
2222 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002223 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002224
2225 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
Greg Clayton57ee3062013-07-11 22:46:58 +00002226 type,
Enrico Granata6f3533f2011-07-29 19:53:35 +00002227 name_const_str,
Greg Clayton57ee3062013-07-11 22:46:58 +00002228 type.GetByteSize(),
Enrico Granata6f3533f2011-07-29 19:53:35 +00002229 offset,
2230 0,
2231 0,
2232 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002233 false,
2234 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002235 if (synthetic_child)
2236 {
2237 AddSyntheticChild(name_const_str, synthetic_child);
2238 synthetic_child_sp = synthetic_child->GetSP();
2239 synthetic_child_sp->SetName(name_const_str);
2240 synthetic_child_sp->m_is_child_at_offset = true;
2241 }
2242 return synthetic_child_sp;
2243}
2244
Enrico Granata32556cd2014-08-26 20:54:04 +00002245ValueObjectSP
Enrico Granata59953f02014-08-26 21:35:30 +00002246ValueObject::GetSyntheticBase (uint32_t offset, const ClangASTType& type, bool can_create)
Enrico Granata32556cd2014-08-26 20:54:04 +00002247{
2248 ValueObjectSP synthetic_child_sp;
2249
2250 char name_str[64];
2251 snprintf(name_str, sizeof(name_str), "%s", type.GetTypeName().AsCString("<unknown>"));
2252 ConstString name_const_str(name_str);
2253
2254 // Check if we have already created a synthetic array member in this
2255 // valid object. If we have we will re-use it.
2256 synthetic_child_sp = GetSyntheticChild (name_const_str);
2257
2258 if (synthetic_child_sp.get())
2259 return synthetic_child_sp;
2260
2261 if (!can_create)
2262 return ValueObjectSP();
2263
Enrico Granata32556cd2014-08-26 20:54:04 +00002264 const bool is_base_class = true;
2265
2266 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2267 type,
2268 name_const_str,
2269 type.GetByteSize(),
2270 offset,
2271 0,
2272 0,
2273 is_base_class,
2274 false,
2275 eAddressTypeInvalid);
2276 if (synthetic_child)
2277 {
2278 AddSyntheticChild(name_const_str, synthetic_child);
2279 synthetic_child_sp = synthetic_child->GetSP();
2280 synthetic_child_sp->SetName(name_const_str);
2281 }
2282 return synthetic_child_sp;
2283}
2284
2285
Enrico Granatad55546b2011-07-22 00:16:08 +00002286// your expression path needs to have a leading . or ->
2287// (unless it somehow "looks like" an array, in which case it has
2288// a leading [ symbol). while the [ is meaningful and should be shown
2289// to the user, . and -> are just parser design, but by no means
2290// added information for the user.. strip them off
2291static const char*
2292SkipLeadingExpressionPathSeparators(const char* expression)
2293{
2294 if (!expression || !expression[0])
2295 return expression;
2296 if (expression[0] == '.')
2297 return expression+1;
2298 if (expression[0] == '-' && expression[1] == '>')
2299 return expression+2;
2300 return expression;
2301}
2302
Greg Claytonafacd142011-09-02 01:15:17 +00002303ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002304ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2305{
2306 ValueObjectSP synthetic_child_sp;
2307 ConstString name_const_string(expression);
2308 // Check if we have already created a synthetic array member in this
2309 // valid object. If we have we will re-use it.
2310 synthetic_child_sp = GetSyntheticChild (name_const_string);
2311 if (!synthetic_child_sp)
2312 {
2313 // We haven't made a synthetic array member for expression yet, so
2314 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002315 synthetic_child_sp = GetValueForExpressionPath(expression,
2316 NULL, NULL, NULL,
2317 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
Enrico Granatad55546b2011-07-22 00:16:08 +00002318
2319 // Cache the value if we got one back...
2320 if (synthetic_child_sp.get())
2321 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002322 // 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 +00002323 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002324 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002325 }
2326 }
2327 return synthetic_child_sp;
2328}
2329
2330void
Enrico Granata86cc9822012-03-19 22:58:49 +00002331ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002332{
Enrico Granata86cc9822012-03-19 22:58:49 +00002333 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002334 return;
2335
Enrico Granatac5bc4122012-03-27 02:35:13 +00002336 TargetSP target_sp(GetTargetSP());
Enrico Granata5d5f60c2013-09-24 22:58:37 +00002337 if (target_sp && target_sp->GetEnableSyntheticValue() == false)
Enrico Granatac5bc4122012-03-27 02:35:13 +00002338 {
2339 m_synthetic_value = NULL;
2340 return;
2341 }
2342
Enrico Granatae3e91512012-10-22 18:18:36 +00002343 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2344
Enrico Granata5548cb52013-01-28 23:47:25 +00002345 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002346 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002347
Enrico Granata0c489f52012-03-01 04:24:26 +00002348 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002349 return;
2350
Enrico Granatae3e91512012-10-22 18:18:36 +00002351 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2352 return;
2353
Enrico Granata86cc9822012-03-19 22:58:49 +00002354 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002355}
2356
Jim Ingham78a685a2011-04-16 00:01:13 +00002357void
Greg Claytonafacd142011-09-02 01:15:17 +00002358ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002359{
Greg Claytonafacd142011-09-02 01:15:17 +00002360 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002361 return;
2362
Jim Ingham58b59f92011-04-22 23:53:53 +00002363 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002364 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002365 ExecutionContext exe_ctx (GetExecutionContextRef());
2366 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002367 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002368 {
2369 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002370 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002371 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002372 }
2373}
2374
Jim Ingham58b59f92011-04-22 23:53:53 +00002375ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002376ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002377{
Greg Claytonafacd142011-09-02 01:15:17 +00002378 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002379 return ValueObjectSP();
2380
2381 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002382 {
Jim Ingham2837b762011-05-04 03:43:18 +00002383 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002384 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002385 if (m_dynamic_value)
2386 return m_dynamic_value->GetSP();
2387 else
2388 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002389}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002390
Jim Ingham60dbabb2011-12-08 19:44:08 +00002391ValueObjectSP
2392ValueObject::GetStaticValue()
2393{
2394 return GetSP();
2395}
2396
Enrico Granata886147f2012-05-08 18:47:08 +00002397lldb::ValueObjectSP
2398ValueObject::GetNonSyntheticValue ()
2399{
2400 return GetSP();
2401}
2402
Enrico Granatad55546b2011-07-22 00:16:08 +00002403ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002404ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002405{
Enrico Granata86cc9822012-03-19 22:58:49 +00002406 if (use_synthetic == false)
2407 return ValueObjectSP();
2408
Enrico Granatad55546b2011-07-22 00:16:08 +00002409 CalculateSyntheticValue(use_synthetic);
2410
2411 if (m_synthetic_value)
2412 return m_synthetic_value->GetSP();
2413 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002414 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002415}
2416
Greg Claytone221f822011-01-21 01:59:00 +00002417bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002418ValueObject::HasSyntheticValue()
2419{
Enrico Granata5548cb52013-01-28 23:47:25 +00002420 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002421
Enrico Granata0c489f52012-03-01 04:24:26 +00002422 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002423 return false;
2424
Enrico Granata86cc9822012-03-19 22:58:49 +00002425 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002426
2427 if (m_synthetic_value)
2428 return true;
2429 else
2430 return false;
2431}
2432
2433bool
Greg Claytone221f822011-01-21 01:59:00 +00002434ValueObject::GetBaseClassPath (Stream &s)
2435{
2436 if (IsBaseClass())
2437 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002438 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Clayton57ee3062013-07-11 22:46:58 +00002439 ClangASTType clang_type = GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002440 std::string cxx_class_name;
Greg Clayton57ee3062013-07-11 22:46:58 +00002441 bool this_had_base_class = clang_type.GetCXXClassName (cxx_class_name);
Greg Claytone221f822011-01-21 01:59:00 +00002442 if (this_had_base_class)
2443 {
2444 if (parent_had_base_class)
2445 s.PutCString("::");
2446 s.PutCString(cxx_class_name.c_str());
2447 }
2448 return parent_had_base_class || this_had_base_class;
2449 }
2450 return false;
2451}
2452
2453
2454ValueObject *
2455ValueObject::GetNonBaseClassParent()
2456{
Jim Ingham78a685a2011-04-16 00:01:13 +00002457 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002458 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002459 if (GetParent()->IsBaseClass())
2460 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002461 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002462 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002463 }
2464 return NULL;
2465}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002466
Enrico Granataa3c8f042014-08-19 22:29:08 +00002467
2468bool
2469ValueObject::IsBaseClass (uint32_t& depth)
2470{
2471 if (!IsBaseClass())
2472 {
2473 depth = 0;
2474 return false;
2475 }
2476 if (GetParent())
2477 {
2478 GetParent()->IsBaseClass(depth);
2479 depth = depth + 1;
2480 return true;
2481 }
2482 // TODO: a base of no parent? weird..
2483 depth = 1;
2484 return true;
2485}
2486
Greg Clayton1d3afba2010-10-05 00:00:42 +00002487void
Enrico Granata4becb372011-06-29 22:27:15 +00002488ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002489{
Enrico Granata986fa5f2014-12-09 21:41:16 +00002490 // synthetic children do not actually "exist" as part of the hierarchy, and sometimes they are consed up in ways
2491 // that don't make sense from an underlying language/API standpoint. So, use a special code path here to return
2492 // something that can hopefully be used in expression
2493 if (m_is_synthetic_children_generated)
2494 {
2495 UpdateValueIfNeeded();
2496
2497 if (m_value.GetValueType() == Value::eValueTypeLoadAddress)
2498 {
2499 if (IsPointerOrReferenceType())
2500 {
2501 s.Printf("((%s)0x%" PRIx64 ")",
2502 GetTypeName().AsCString("void"),
2503 GetValueAsUnsigned(0));
2504 return;
2505 }
2506 else
2507 {
2508 uint64_t load_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
2509 if (load_addr != LLDB_INVALID_ADDRESS)
2510 {
2511 s.Printf("(*( (%s *)0x%" PRIx64 "))",
2512 GetTypeName().AsCString("void"),
2513 load_addr);
2514 return;
2515 }
2516 }
2517 }
2518
2519 if (CanProvideValue())
2520 {
2521 s.Printf("((%s)%s)",
2522 GetTypeName().AsCString("void"),
2523 GetValueAsCString());
2524 return;
2525 }
2526
2527 return;
2528 }
2529
Greg Claytone221f822011-01-21 01:59:00 +00002530 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002531
Enrico Granata86cc9822012-03-19 22:58:49 +00002532 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002533 {
Enrico Granata4becb372011-06-29 22:27:15 +00002534 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2535 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2536 // the eHonorPointers mode is meant to produce strings in this latter format
2537 s.PutCString("*(");
2538 }
Greg Claytone221f822011-01-21 01:59:00 +00002539
Enrico Granata4becb372011-06-29 22:27:15 +00002540 ValueObject* parent = GetParent();
2541
2542 if (parent)
2543 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002544
2545 // if we are a deref_of_parent just because we are synthetic array
2546 // members made up to allow ptr[%d] syntax to work in variable
2547 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002548 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002549 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002550
Greg Claytone221f822011-01-21 01:59:00 +00002551 if (!IsBaseClass())
2552 {
2553 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002554 {
Greg Claytone221f822011-01-21 01:59:00 +00002555 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2556 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002557 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002558 ClangASTType non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002559 if (non_base_class_parent_clang_type)
2560 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002561 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002562 {
2563 s.PutCString("->");
2564 }
Enrico Granata4becb372011-06-29 22:27:15 +00002565 else
2566 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002567 const uint32_t non_base_class_parent_type_info = non_base_class_parent_clang_type.GetTypeInfo();
2568
Enrico Granata622be232014-10-21 20:52:14 +00002569 if (non_base_class_parent_type_info & eTypeIsPointer)
Enrico Granata4becb372011-06-29 22:27:15 +00002570 {
2571 s.PutCString("->");
2572 }
Enrico Granata622be232014-10-21 20:52:14 +00002573 else if ((non_base_class_parent_type_info & eTypeHasChildren) &&
2574 !(non_base_class_parent_type_info & eTypeIsArray))
Enrico Granata4becb372011-06-29 22:27:15 +00002575 {
2576 s.PutChar('.');
2577 }
Greg Claytone221f822011-01-21 01:59:00 +00002578 }
2579 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002580 }
Greg Claytone221f822011-01-21 01:59:00 +00002581
2582 const char *name = GetName().GetCString();
2583 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002584 {
Greg Claytone221f822011-01-21 01:59:00 +00002585 if (qualify_cxx_base_classes)
2586 {
2587 if (GetBaseClassPath (s))
2588 s.PutCString("::");
2589 }
2590 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002591 }
2592 }
2593 }
2594
Enrico Granata86cc9822012-03-19 22:58:49 +00002595 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002596 {
Greg Claytone221f822011-01-21 01:59:00 +00002597 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002598 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002599}
2600
Greg Claytonafacd142011-09-02 01:15:17 +00002601ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002602ValueObject::GetValueForExpressionPath(const char* expression,
2603 const char** first_unparsed,
2604 ExpressionPathScanEndReason* reason_to_stop,
2605 ExpressionPathEndResultType* final_value_type,
2606 const GetValueForExpressionPathOptions& options,
2607 ExpressionPathAftermath* final_task_on_target)
2608{
2609
2610 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002611 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2612 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002613 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002614
2615 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2616 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2617 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2618 final_value_type ? final_value_type : &dummy_final_value_type,
2619 options,
2620 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2621
Enrico Granata86cc9822012-03-19 22:58:49 +00002622 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002623 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002624
Enrico Granata86cc9822012-03-19 22:58:49 +00002625 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 +00002626 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002627 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002628 {
2629 Error error;
2630 ValueObjectSP final_value = ret_val->Dereference(error);
2631 if (error.Fail() || !final_value.get())
2632 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002633 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002634 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002635 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002636 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002637 return ValueObjectSP();
2638 }
2639 else
2640 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002641 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002642 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002643 return final_value;
2644 }
2645 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002646 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002647 {
2648 Error error;
2649 ValueObjectSP final_value = ret_val->AddressOf(error);
2650 if (error.Fail() || !final_value.get())
2651 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002652 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002653 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002654 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002655 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002656 return ValueObjectSP();
2657 }
2658 else
2659 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002660 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002661 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002662 return final_value;
2663 }
2664 }
2665 }
2666 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2667}
2668
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002669int
2670ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002671 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002672 const char** first_unparsed,
2673 ExpressionPathScanEndReason* reason_to_stop,
2674 ExpressionPathEndResultType* final_value_type,
2675 const GetValueForExpressionPathOptions& options,
2676 ExpressionPathAftermath* final_task_on_target)
2677{
2678 const char* dummy_first_unparsed;
2679 ExpressionPathScanEndReason dummy_reason_to_stop;
2680 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002681 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002682
2683 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2684 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2685 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2686 final_value_type ? final_value_type : &dummy_final_value_type,
2687 options,
2688 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2689
2690 if (!ret_val.get()) // if there are errors, I add nothing to the list
2691 return 0;
2692
Enrico Granata86ea8d82012-03-29 01:34:34 +00002693 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002694 {
2695 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002696 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002697 {
2698 list->Append(ret_val);
2699 return 1;
2700 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002701 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 +00002702 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002703 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002704 {
2705 Error error;
2706 ValueObjectSP final_value = ret_val->Dereference(error);
2707 if (error.Fail() || !final_value.get())
2708 {
Greg Clayton23f59502012-07-17 03:23:13 +00002709 if (reason_to_stop)
2710 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2711 if (final_value_type)
2712 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002713 return 0;
2714 }
2715 else
2716 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002717 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002718 list->Append(final_value);
2719 return 1;
2720 }
2721 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002722 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002723 {
2724 Error error;
2725 ValueObjectSP final_value = ret_val->AddressOf(error);
2726 if (error.Fail() || !final_value.get())
2727 {
Greg Clayton23f59502012-07-17 03:23:13 +00002728 if (reason_to_stop)
2729 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2730 if (final_value_type)
2731 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002732 return 0;
2733 }
2734 else
2735 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002736 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002737 list->Append(final_value);
2738 return 1;
2739 }
2740 }
2741 }
2742 }
2743 else
2744 {
2745 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2746 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2747 ret_val,
2748 list,
2749 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2750 final_value_type ? final_value_type : &dummy_final_value_type,
2751 options,
2752 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2753 }
2754 // in any non-covered case, just do the obviously right thing
2755 list->Append(ret_val);
2756 return 1;
2757}
2758
Greg Claytonafacd142011-09-02 01:15:17 +00002759ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002760ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2761 const char** first_unparsed,
2762 ExpressionPathScanEndReason* reason_to_stop,
2763 ExpressionPathEndResultType* final_result,
2764 const GetValueForExpressionPathOptions& options,
2765 ExpressionPathAftermath* what_next)
2766{
2767 ValueObjectSP root = GetSP();
2768
2769 if (!root.get())
2770 return ValueObjectSP();
2771
2772 *first_unparsed = expression_cstr;
2773
2774 while (true)
2775 {
2776
2777 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2778
Greg Clayton57ee3062013-07-11 22:46:58 +00002779 ClangASTType root_clang_type = root->GetClangType();
2780 ClangASTType pointee_clang_type;
2781 Flags pointee_clang_type_info;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002782
Greg Clayton57ee3062013-07-11 22:46:58 +00002783 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002784 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00002785 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002786
2787 if (!expression_cstr || *expression_cstr == '\0')
2788 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002789 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002790 return root;
2791 }
2792
2793 switch (*expression_cstr)
2794 {
2795 case '-':
2796 {
2797 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granata622be232014-10-21 20:52:14 +00002798 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 +00002799 {
2800 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002801 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2802 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002803 return ValueObjectSP();
2804 }
Enrico Granata622be232014-10-21 20:52:14 +00002805 if (root_clang_type_info.Test(eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2806 root_clang_type_info.Test(eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002807 options.m_no_fragile_ivar)
2808 {
2809 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002810 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2811 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002812 return ValueObjectSP();
2813 }
2814 if (expression_cstr[1] != '>')
2815 {
2816 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002817 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2818 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002819 return ValueObjectSP();
2820 }
2821 expression_cstr++; // skip the -
2822 }
2823 case '.': // or fallthrough from ->
2824 {
2825 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granata622be232014-10-21 20:52:14 +00002826 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 +00002827 {
2828 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002829 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2830 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002831 return ValueObjectSP();
2832 }
2833 expression_cstr++; // skip .
2834 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2835 ConstString child_name;
2836 if (!next_separator) // if no other separator just expand this last layer
2837 {
2838 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002839 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2840
2841 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002842 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002843 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002844 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2845 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002846 return child_valobj_sp;
2847 }
2848 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2849 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002850 if (root->IsSynthetic())
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002851 {
2852 *first_unparsed = expression_cstr;
Enrico Granatad07cfd32014-10-08 18:27:36 +00002853 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchSyntheticChild;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002854 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2855 return ValueObjectSP();
2856 }
2857
2858 child_valobj_sp = root->GetSyntheticValue();
Enrico Granata86cc9822012-03-19 22:58:49 +00002859 if (child_valobj_sp.get())
2860 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002861 }
2862
2863 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2864 // so we hit the "else" branch, and return an error
2865 if(child_valobj_sp.get()) // if it worked, just return
2866 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002867 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002868 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2869 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002870 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002871 }
2872 else
2873 {
2874 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002875 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2876 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002877 return ValueObjectSP();
2878 }
2879 }
2880 else // other layers do expand
2881 {
2882 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002883 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2884 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002885 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002886 root = child_valobj_sp;
2887 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002888 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002889 continue;
2890 }
2891 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2892 {
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002893 if (root->IsSynthetic())
2894 {
2895 *first_unparsed = expression_cstr;
2896 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2897 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2898 return ValueObjectSP();
2899 }
2900
Enrico Granata86cc9822012-03-19 22:58:49 +00002901 child_valobj_sp = root->GetSyntheticValue(true);
2902 if (child_valobj_sp)
2903 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002904 }
2905
2906 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2907 // so we hit the "else" branch, and return an error
2908 if(child_valobj_sp.get()) // if it worked, move on
2909 {
2910 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002911 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002912 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002913 continue;
2914 }
2915 else
2916 {
2917 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002918 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2919 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002920 return ValueObjectSP();
2921 }
2922 }
2923 break;
2924 }
2925 case '[':
2926 {
Enrico Granata622be232014-10-21 20:52:14 +00002927 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 +00002928 {
Enrico Granata622be232014-10-21 20:52:14 +00002929 if (!root_clang_type_info.Test(eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002930 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002931 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2932 {
2933 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002934 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2935 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002936 return ValueObjectSP();
2937 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002938 }
2939 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2940 {
2941 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002942 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2943 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002944 return ValueObjectSP();
2945 }
2946 }
2947 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2948 {
Enrico Granata622be232014-10-21 20:52:14 +00002949 if (!root_clang_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002950 {
2951 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002952 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2953 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002954 return ValueObjectSP();
2955 }
2956 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2957 {
2958 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002959 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2960 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002961 return root;
2962 }
2963 }
2964 const char *separator_position = ::strchr(expression_cstr+1,'-');
2965 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2966 if (!close_bracket_position) // if there is no ], this is a syntax error
2967 {
2968 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002969 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2970 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002971 return ValueObjectSP();
2972 }
2973 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2974 {
2975 char *end = NULL;
2976 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2977 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2978 {
2979 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002980 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2981 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002982 return ValueObjectSP();
2983 }
2984 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2985 {
Enrico Granata622be232014-10-21 20:52:14 +00002986 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002987 {
2988 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002989 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2990 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002991 return root;
2992 }
2993 else
2994 {
2995 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002996 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2997 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002998 return ValueObjectSP();
2999 }
3000 }
3001 // from here on we do have a valid index
Enrico Granata622be232014-10-21 20:52:14 +00003002 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003003 {
Greg Claytondaf515f2011-07-09 20:12:33 +00003004 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
3005 if (!child_valobj_sp)
3006 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003007 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00003008 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
3009 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00003010 if (child_valobj_sp)
3011 {
3012 root = child_valobj_sp;
3013 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003014 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00003015 continue;
3016 }
3017 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003018 {
3019 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003020 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3021 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003022 return ValueObjectSP();
3023 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003024 }
Enrico Granata622be232014-10-21 20:52:14 +00003025 else if (root_clang_type_info.Test(eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003026 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003027 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 +00003028 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003029 {
3030 Error error;
3031 root = root->Dereference(error);
3032 if (error.Fail() || !root.get())
3033 {
3034 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003035 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3036 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003037 return ValueObjectSP();
3038 }
3039 else
3040 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003041 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003042 continue;
3043 }
3044 }
3045 else
3046 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003047 if (root->GetClangType().GetMinimumLanguage() == eLanguageTypeObjC
Enrico Granata622be232014-10-21 20:52:14 +00003048 && pointee_clang_type_info.AllClear(eTypeIsPointer)
Greg Clayton84db9102012-03-26 23:03:23 +00003049 && root->HasSyntheticValue()
3050 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00003051 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003052 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003053 }
3054 else
3055 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003056 if (!root.get())
3057 {
3058 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003059 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3060 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003061 return ValueObjectSP();
3062 }
3063 else
3064 {
3065 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003066 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003067 continue;
3068 }
3069 }
3070 }
Enrico Granata622be232014-10-21 20:52:14 +00003071 else if (root_clang_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003072 {
3073 root = root->GetSyntheticBitFieldChild(index, index, true);
3074 if (!root.get())
3075 {
3076 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003077 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3078 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003079 return ValueObjectSP();
3080 }
3081 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3082 {
3083 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003084 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3085 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003086 return root;
3087 }
3088 }
Enrico Granata622be232014-10-21 20:52:14 +00003089 else if (root_clang_type_info.Test(eTypeIsVector))
Enrico Granata08a1bb82013-06-19 00:00:45 +00003090 {
3091 root = root->GetChildAtIndex(index, true);
3092 if (!root.get())
3093 {
3094 *first_unparsed = expression_cstr;
3095 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3096 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3097 return ValueObjectSP();
3098 }
3099 else
3100 {
3101 *first_unparsed = end+1; // skip ]
3102 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3103 continue;
3104 }
3105 }
Enrico Granata86cc9822012-03-19 22:58:49 +00003106 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00003107 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003108 if (root->HasSyntheticValue())
3109 root = root->GetSyntheticValue();
3110 else if (!root->IsSynthetic())
3111 {
3112 *first_unparsed = expression_cstr;
3113 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3114 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3115 return ValueObjectSP();
3116 }
3117 // if we are here, then root itself is a synthetic VO.. should be good to go
3118
Enrico Granata27b625e2011-08-09 01:04:56 +00003119 if (!root.get())
3120 {
3121 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003122 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3123 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3124 return ValueObjectSP();
3125 }
3126 root = root->GetChildAtIndex(index, true);
3127 if (!root.get())
3128 {
3129 *first_unparsed = expression_cstr;
3130 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3131 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003132 return ValueObjectSP();
3133 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00003134 else
3135 {
3136 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003137 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00003138 continue;
3139 }
Enrico Granata27b625e2011-08-09 01:04:56 +00003140 }
3141 else
3142 {
3143 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003144 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3145 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003146 return ValueObjectSP();
3147 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003148 }
3149 else // we have a low and a high index
3150 {
3151 char *end = NULL;
3152 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3153 if (!end || end != separator_position) // if something weird is in our way return an error
3154 {
3155 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003156 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3157 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003158 return ValueObjectSP();
3159 }
3160 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3161 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3162 {
3163 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003164 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3165 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003166 return ValueObjectSP();
3167 }
3168 if (index_lower > index_higher) // swap indices if required
3169 {
3170 unsigned long temp = index_lower;
3171 index_lower = index_higher;
3172 index_higher = temp;
3173 }
Enrico Granata622be232014-10-21 20:52:14 +00003174 if (root_clang_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003175 {
3176 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3177 if (!root.get())
3178 {
3179 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003180 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3181 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003182 return ValueObjectSP();
3183 }
3184 else
3185 {
3186 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003187 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3188 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003189 return root;
3190 }
3191 }
Enrico Granata622be232014-10-21 20:52:14 +00003192 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 +00003193 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granata622be232014-10-21 20:52:14 +00003194 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003195 {
3196 Error error;
3197 root = root->Dereference(error);
3198 if (error.Fail() || !root.get())
3199 {
3200 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003201 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3202 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003203 return ValueObjectSP();
3204 }
3205 else
3206 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003207 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003208 continue;
3209 }
3210 }
3211 else
3212 {
3213 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003214 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3215 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003216 return root;
3217 }
3218 }
3219 break;
3220 }
3221 default: // some non-separator is in the way
3222 {
3223 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003224 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3225 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003226 return ValueObjectSP();
3227 break;
3228 }
3229 }
3230 }
3231}
3232
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003233int
3234ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3235 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00003236 ValueObjectSP root,
3237 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003238 ExpressionPathScanEndReason* reason_to_stop,
3239 ExpressionPathEndResultType* final_result,
3240 const GetValueForExpressionPathOptions& options,
3241 ExpressionPathAftermath* what_next)
3242{
3243 if (!root.get())
3244 return 0;
3245
3246 *first_unparsed = expression_cstr;
3247
3248 while (true)
3249 {
3250
3251 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3252
Greg Clayton57ee3062013-07-11 22:46:58 +00003253 ClangASTType root_clang_type = root->GetClangType();
3254 ClangASTType pointee_clang_type;
3255 Flags pointee_clang_type_info;
3256 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003257 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00003258 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003259
3260 if (!expression_cstr || *expression_cstr == '\0')
3261 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003262 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003263 list->Append(root);
3264 return 1;
3265 }
3266
3267 switch (*expression_cstr)
3268 {
3269 case '[':
3270 {
Enrico Granata622be232014-10-21 20:52:14 +00003271 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 +00003272 {
Enrico Granata622be232014-10-21 20:52:14 +00003273 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 +00003274 {
3275 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003276 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3277 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003278 return 0;
3279 }
3280 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3281 {
3282 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003283 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3284 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003285 return 0;
3286 }
3287 }
3288 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3289 {
Enrico Granata622be232014-10-21 20:52:14 +00003290 if (!root_clang_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003291 {
3292 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003293 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3294 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003295 return 0;
3296 }
3297 else // expand this into list
3298 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003299 const size_t max_index = root->GetNumChildren() - 1;
3300 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003301 {
3302 ValueObjectSP child =
3303 root->GetChildAtIndex(index, true);
3304 list->Append(child);
3305 }
3306 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003307 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3308 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003309 return max_index; // tell me number of items I added to the VOList
3310 }
3311 }
3312 const char *separator_position = ::strchr(expression_cstr+1,'-');
3313 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3314 if (!close_bracket_position) // if there is no ], this is a syntax error
3315 {
3316 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003317 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3318 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003319 return 0;
3320 }
3321 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3322 {
3323 char *end = NULL;
3324 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3325 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3326 {
3327 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003328 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3329 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003330 return 0;
3331 }
3332 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3333 {
Enrico Granata622be232014-10-21 20:52:14 +00003334 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003335 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003336 const size_t max_index = root->GetNumChildren() - 1;
3337 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003338 {
3339 ValueObjectSP child =
3340 root->GetChildAtIndex(index, true);
3341 list->Append(child);
3342 }
3343 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003344 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3345 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003346 return max_index; // tell me number of items I added to the VOList
3347 }
3348 else
3349 {
3350 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003351 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3352 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003353 return 0;
3354 }
3355 }
3356 // from here on we do have a valid index
Enrico Granata622be232014-10-21 20:52:14 +00003357 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003358 {
3359 root = root->GetChildAtIndex(index, true);
3360 if (!root.get())
3361 {
3362 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003363 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3364 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003365 return 0;
3366 }
3367 else
3368 {
3369 list->Append(root);
3370 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003371 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3372 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003373 return 1;
3374 }
3375 }
Enrico Granata622be232014-10-21 20:52:14 +00003376 else if (root_clang_type_info.Test(eTypeIsPointer))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003377 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003378 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 +00003379 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003380 {
3381 Error error;
3382 root = root->Dereference(error);
3383 if (error.Fail() || !root.get())
3384 {
3385 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003386 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3387 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003388 return 0;
3389 }
3390 else
3391 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003392 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003393 continue;
3394 }
3395 }
3396 else
3397 {
3398 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3399 if (!root.get())
3400 {
3401 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003402 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3403 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003404 return 0;
3405 }
3406 else
3407 {
3408 list->Append(root);
3409 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003410 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3411 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003412 return 1;
3413 }
3414 }
3415 }
3416 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3417 {
3418 root = root->GetSyntheticBitFieldChild(index, index, true);
3419 if (!root.get())
3420 {
3421 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003422 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3423 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003424 return 0;
3425 }
3426 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3427 {
3428 list->Append(root);
3429 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003430 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3431 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003432 return 1;
3433 }
3434 }
3435 }
3436 else // we have a low and a high index
3437 {
3438 char *end = NULL;
3439 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3440 if (!end || end != separator_position) // if something weird is in our way return an error
3441 {
3442 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003443 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3444 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003445 return 0;
3446 }
3447 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3448 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3449 {
3450 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003451 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3452 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003453 return 0;
3454 }
3455 if (index_lower > index_higher) // swap indices if required
3456 {
3457 unsigned long temp = index_lower;
3458 index_lower = index_higher;
3459 index_higher = temp;
3460 }
Enrico Granata622be232014-10-21 20:52:14 +00003461 if (root_clang_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003462 {
3463 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3464 if (!root.get())
3465 {
3466 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003467 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3468 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003469 return 0;
3470 }
3471 else
3472 {
3473 list->Append(root);
3474 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003475 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3476 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003477 return 1;
3478 }
3479 }
Enrico Granata622be232014-10-21 20:52:14 +00003480 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 +00003481 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granata622be232014-10-21 20:52:14 +00003482 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003483 {
3484 Error error;
3485 root = root->Dereference(error);
3486 if (error.Fail() || !root.get())
3487 {
3488 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003489 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3490 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003491 return 0;
3492 }
3493 else
3494 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003495 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003496 continue;
3497 }
3498 }
3499 else
3500 {
Johnny Chen44805302011-07-19 19:48:13 +00003501 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003502 index <= index_higher; index++)
3503 {
3504 ValueObjectSP child =
3505 root->GetChildAtIndex(index, true);
3506 list->Append(child);
3507 }
3508 *first_unparsed = end+1;
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 index_higher-index_lower+1; // tell me number of items I added to the VOList
3512 }
3513 }
3514 break;
3515 }
3516 default: // some non-[ separator, or something entirely wrong, is in the way
3517 {
3518 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003519 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3520 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003521 return 0;
3522 break;
3523 }
3524 }
3525 }
3526}
3527
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003528void
3529ValueObject::LogValueObject (Log *log)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003530{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003531 if (log)
3532 return LogValueObject (log, DumpValueObjectOptions::DefaultOptions());
Greg Clayton1d3afba2010-10-05 00:00:42 +00003533}
3534
Enrico Granata0c489f52012-03-01 04:24:26 +00003535void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003536ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003537{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003538 if (log)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003539 {
3540 StreamString s;
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003541 Dump (s, options);
Greg Claytonf830dbb2012-03-22 18:15:37 +00003542 if (s.GetSize())
3543 log->PutCString(s.GetData());
3544 }
3545}
3546
3547void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003548ValueObject::Dump (Stream &s)
Enrico Granata0c489f52012-03-01 04:24:26 +00003549{
Enrico Granata78639912014-12-20 01:41:27 +00003550 Dump (s, DumpValueObjectOptions::DefaultOptions());
Enrico Granata0c489f52012-03-01 04:24:26 +00003551}
3552
3553void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003554ValueObject::Dump (Stream &s,
3555 const DumpValueObjectOptions& options)
Enrico Granata0c489f52012-03-01 04:24:26 +00003556{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003557 ValueObjectPrinter printer(this,&s,options);
3558 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003559}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003560
3561ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003562ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003563{
3564 ValueObjectSP valobj_sp;
3565
Enrico Granatac3e320a2011-08-02 17:27:39 +00003566 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003567 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003568 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003569
3570 DataExtractor data;
3571 data.SetByteOrder (m_data.GetByteOrder());
3572 data.SetAddressByteSize(m_data.GetAddressByteSize());
3573
Enrico Granata9f1e2042012-04-24 22:15:37 +00003574 if (IsBitfield())
3575 {
3576 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
Greg Clayton57ee3062013-07-11 22:46:58 +00003577 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Enrico Granata9f1e2042012-04-24 22:15:37 +00003578 }
3579 else
Greg Clayton57ee3062013-07-11 22:46:58 +00003580 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003581
3582 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003583 GetClangType(),
3584 name,
3585 data,
3586 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003587 }
Jim Ingham6035b672011-03-31 00:19:25 +00003588
3589 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003590 {
Greg Claytoneeb15652013-12-10 23:16:40 +00003591 ExecutionContext exe_ctx (GetExecutionContextRef());
3592 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003593 }
3594 return valobj_sp;
3595}
3596
Enrico Granata538a88a2014-10-09 18:24:30 +00003597ValueObjectSP
3598ValueObject::GetQualifiedRepresentationIfAvailable (lldb::DynamicValueType dynValue,
3599 bool synthValue)
3600{
3601 ValueObjectSP result_sp(GetSP());
3602
3603 switch (dynValue)
3604 {
3605 case lldb::eDynamicCanRunTarget:
3606 case lldb::eDynamicDontRunTarget:
3607 {
3608 if (!result_sp->IsDynamic())
3609 {
3610 if (result_sp->GetDynamicValue(dynValue))
3611 result_sp = result_sp->GetDynamicValue(dynValue);
3612 }
3613 }
3614 break;
3615 case lldb::eNoDynamicValues:
Enrico Granata538a88a2014-10-09 18:24:30 +00003616 {
3617 if (result_sp->IsDynamic())
3618 {
3619 if (result_sp->GetStaticValue())
3620 result_sp = result_sp->GetStaticValue();
3621 }
3622 }
3623 break;
3624 }
3625
3626 if (synthValue)
3627 {
3628 if (!result_sp->IsSynthetic())
3629 {
3630 if (result_sp->GetSyntheticValue())
3631 result_sp = result_sp->GetSyntheticValue();
3632 }
3633 }
3634 else
3635 {
3636 if (result_sp->IsSynthetic())
3637 {
3638 if (result_sp->GetNonSyntheticValue())
3639 result_sp = result_sp->GetNonSyntheticValue();
3640 }
3641 }
3642
3643 return result_sp;
3644}
3645
Greg Clayton759e7442014-07-19 00:12:57 +00003646lldb::addr_t
3647ValueObject::GetCPPVTableAddress (AddressType &address_type)
3648{
3649 ClangASTType pointee_type;
3650 ClangASTType this_type(GetClangType());
3651 uint32_t type_info = this_type.GetTypeInfo(&pointee_type);
3652 if (type_info)
3653 {
3654 bool ptr_or_ref = false;
Enrico Granata622be232014-10-21 20:52:14 +00003655 if (type_info & (eTypeIsPointer | eTypeIsReference))
Greg Clayton759e7442014-07-19 00:12:57 +00003656 {
3657 ptr_or_ref = true;
3658 type_info = pointee_type.GetTypeInfo();
3659 }
3660
Enrico Granata622be232014-10-21 20:52:14 +00003661 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus;
Greg Clayton759e7442014-07-19 00:12:57 +00003662 if ((type_info & cpp_class) == cpp_class)
3663 {
3664 if (ptr_or_ref)
3665 {
3666 address_type = GetAddressTypeOfChildren();
3667 return GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
3668 }
3669 else
3670 return GetAddressOf (false, &address_type);
3671 }
3672 }
3673
3674 address_type = eAddressTypeInvalid;
3675 return LLDB_INVALID_ADDRESS;
3676}
3677
Greg Claytonafacd142011-09-02 01:15:17 +00003678ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003679ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003680{
Jim Ingham58b59f92011-04-22 23:53:53 +00003681 if (m_deref_valobj)
3682 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003683
Greg Clayton54979cd2010-12-15 05:08:08 +00003684 const bool is_pointer_type = IsPointerType();
3685 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003686 {
3687 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003688 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003689
3690 std::string child_name_str;
3691 uint32_t child_byte_size = 0;
3692 int32_t child_byte_offset = 0;
3693 uint32_t child_bitfield_bit_size = 0;
3694 uint32_t child_bitfield_bit_offset = 0;
3695 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003696 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003697 const bool transparent_pointers = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00003698 ClangASTType clang_type = GetClangType();
3699 ClangASTType child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003700
Greg Claytoncc4d0142012-02-17 07:49:44 +00003701 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003702
Greg Clayton57ee3062013-07-11 22:46:58 +00003703 child_clang_type = clang_type.GetChildClangTypeAtIndex (&exe_ctx,
Greg Clayton57ee3062013-07-11 22:46:58 +00003704 0,
3705 transparent_pointers,
3706 omit_empty_base_classes,
3707 ignore_array_bounds,
3708 child_name_str,
3709 child_byte_size,
3710 child_byte_offset,
3711 child_bitfield_bit_size,
3712 child_bitfield_bit_offset,
3713 child_is_base_class,
Greg Clayton759e7442014-07-19 00:12:57 +00003714 child_is_deref_of_parent,
3715 this);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003716 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003717 {
3718 ConstString child_name;
3719 if (!child_name_str.empty())
3720 child_name.SetCString (child_name_str.c_str());
3721
Jim Ingham58b59f92011-04-22 23:53:53 +00003722 m_deref_valobj = new ValueObjectChild (*this,
Jim Ingham58b59f92011-04-22 23:53:53 +00003723 child_clang_type,
3724 child_name,
3725 child_byte_size,
3726 child_byte_offset,
3727 child_bitfield_bit_size,
3728 child_bitfield_bit_offset,
3729 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003730 child_is_deref_of_parent,
3731 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003732 }
3733 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003734
Jim Ingham58b59f92011-04-22 23:53:53 +00003735 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003736 {
3737 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003738 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003739 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003740 else
3741 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003742 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003743 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003744
3745 if (is_pointer_type)
3746 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3747 else
3748 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003749 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003750 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003751}
3752
Greg Claytonafacd142011-09-02 01:15:17 +00003753ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003754ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003755{
Jim Ingham78a685a2011-04-16 00:01:13 +00003756 if (m_addr_of_valobj_sp)
3757 return m_addr_of_valobj_sp;
3758
Greg Claytone0d378b2011-03-24 21:19:54 +00003759 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003760 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003761 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003762 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003763 if (addr != LLDB_INVALID_ADDRESS)
3764 {
3765 switch (address_type)
3766 {
3767 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003768 {
3769 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003770 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003771 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3772 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003773 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003774
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003775 case eAddressTypeFile:
3776 case eAddressTypeLoad:
3777 case eAddressTypeHost:
3778 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003779 ClangASTType clang_type = GetClangType();
3780 if (clang_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003781 {
3782 std::string name (1, '&');
3783 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003784 ExecutionContext exe_ctx (GetExecutionContextRef());
3785 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00003786 clang_type.GetPointerType(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003787 ConstString (name.c_str()),
3788 addr,
3789 eAddressTypeInvalid,
3790 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003791 }
3792 }
3793 break;
3794 }
3795 }
Sean Callananed185ab2013-04-19 19:47:32 +00003796 else
3797 {
3798 StreamString expr_path_strm;
3799 GetExpressionPath(expr_path_strm, true);
3800 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3801 }
3802
Jim Ingham78a685a2011-04-16 00:01:13 +00003803 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003804}
3805
Greg Clayton9a142cf2012-02-03 05:34:10 +00003806ValueObjectSP
3807ValueObject::Cast (const ClangASTType &clang_ast_type)
3808{
Greg Clayton81e871e2012-02-04 02:27:34 +00003809 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003810}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003811
Greg Claytonafacd142011-09-02 01:15:17 +00003812ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003813ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3814{
Greg Claytonafacd142011-09-02 01:15:17 +00003815 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003816 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003817 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003818
3819 if (ptr_value != LLDB_INVALID_ADDRESS)
3820 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003821 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003822 ExecutionContext exe_ctx (GetExecutionContextRef());
3823 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003824 name,
3825 ptr_addr,
3826 clang_ast_type);
3827 }
3828 return valobj_sp;
3829}
3830
Greg Claytonafacd142011-09-02 01:15:17 +00003831ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003832ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3833{
Greg Claytonafacd142011-09-02 01:15:17 +00003834 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003835 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003836 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003837
3838 if (ptr_value != LLDB_INVALID_ADDRESS)
3839 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003840 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003841 ExecutionContext exe_ctx (GetExecutionContextRef());
3842 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003843 name,
3844 ptr_addr,
3845 type_sp);
3846 }
3847 return valobj_sp;
3848}
3849
Jim Ingham6035b672011-03-31 00:19:25 +00003850ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003851 m_mod_id(),
3852 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003853 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003854{
3855}
3856
3857ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003858 m_mod_id(),
3859 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003860 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003861{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003862 ExecutionContext exe_ctx(exe_scope);
3863 TargetSP target_sp (exe_ctx.GetTargetSP());
3864 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003865 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003866 m_exe_ctx_ref.SetTargetSP (target_sp);
3867 ProcessSP process_sp (exe_ctx.GetProcessSP());
3868 if (!process_sp)
3869 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003870
Greg Claytoncc4d0142012-02-17 07:49:44 +00003871 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003872 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003873 m_mod_id = process_sp->GetModID();
3874 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003875
Greg Claytoncc4d0142012-02-17 07:49:44 +00003876 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003877
Greg Claytoncc4d0142012-02-17 07:49:44 +00003878 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003879 {
3880 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003881 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003882 }
Jim Ingham6035b672011-03-31 00:19:25 +00003883
Greg Claytoncc4d0142012-02-17 07:49:44 +00003884 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003885 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003886 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003887
Jason Molendab57e4a12013-11-04 09:33:30 +00003888 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003889 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003890 {
3891 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003892 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003893 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003894 if (frame_sp)
3895 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003896 }
3897 }
3898 }
Jim Ingham6035b672011-03-31 00:19:25 +00003899}
3900
3901ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003902 m_mod_id(),
3903 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003904 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003905{
3906}
3907
3908ValueObject::EvaluationPoint::~EvaluationPoint ()
3909{
3910}
3911
Jim Ingham6035b672011-03-31 00:19:25 +00003912// This function checks the EvaluationPoint against the current process state. If the current
3913// state matches the evaluation point, or the evaluation point is already invalid, then we return
3914// false, meaning "no change". If the current state is different, we update our state, and return
3915// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3916// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003917// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003918
3919bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003920ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003921{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003922
3923 // 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 +00003924 const bool thread_and_frame_only_if_stopped = true;
3925 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
Jim Ingham73ca05a2011-12-17 01:35:57 +00003926
Greg Claytoncc4d0142012-02-17 07:49:44 +00003927 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003928 return false;
3929
Jim Ingham6035b672011-03-31 00:19:25 +00003930 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003931 Process *process = exe_ctx.GetProcessPtr();
3932 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003933 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003934
Jim Ingham6035b672011-03-31 00:19:25 +00003935 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003936 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003937
Jim Ingham78a685a2011-04-16 00:01:13 +00003938 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3939 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003940 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003941 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003942
Greg Clayton23f59502012-07-17 03:23:13 +00003943 bool changed = false;
3944 const bool was_valid = m_mod_id.IsValid();
3945 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003946 {
3947 if (m_mod_id == current_mod_id)
3948 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003949 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003950 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003951 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003952 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003953 else
3954 {
3955 m_mod_id = current_mod_id;
3956 m_needs_update = true;
3957 changed = true;
3958 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003959 }
Jim Ingham6035b672011-03-31 00:19:25 +00003960
Jim Ingham73ca05a2011-12-17 01:35:57 +00003961 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3962 // That way we'll be sure to return a valid exe_scope.
3963 // 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 +00003964
Greg Claytoncc4d0142012-02-17 07:49:44 +00003965 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003966 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003967 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3968 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003969 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003970 if (m_exe_ctx_ref.HasFrameRef())
3971 {
Jason Molendab57e4a12013-11-04 09:33:30 +00003972 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003973 if (!frame_sp)
3974 {
3975 // We used to have a frame, but now it is gone
3976 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003977 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00003978 }
3979 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003980 }
Jim Ingham6035b672011-03-31 00:19:25 +00003981 else
3982 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003983 // We used to have a thread, but now it is gone
3984 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003985 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00003986 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003987
Jim Ingham6035b672011-03-31 00:19:25 +00003988 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003989 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003990}
3991
Jim Ingham61be0902011-05-02 18:13:59 +00003992void
3993ValueObject::EvaluationPoint::SetUpdated ()
3994{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003995 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3996 if (process_sp)
3997 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003998 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003999}
4000
4001
Enrico Granataf2bbf712011-07-15 02:26:42 +00004002
4003void
Enrico Granata86cc9822012-03-19 22:58:49 +00004004ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004005{
Enrico Granata86cc9822012-03-19 22:58:49 +00004006 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4007 m_value_str.clear();
4008
4009 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4010 m_location_str.clear();
4011
4012 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
Enrico Granata86cc9822012-03-19 22:58:49 +00004013 m_summary_str.clear();
Enrico Granata86cc9822012-03-19 22:58:49 +00004014
4015 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4016 m_object_desc_str.clear();
4017
4018 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4019 {
4020 if (m_synthetic_value)
4021 m_synthetic_value = NULL;
4022 }
Enrico Granata744794a2014-09-05 21:46:22 +00004023
4024 if ((clear_mask & eClearUserVisibleDataItemsValidator) == eClearUserVisibleDataItemsValidator)
4025 m_validation_result.reset();
Johnny Chen44805302011-07-19 19:48:13 +00004026}
Enrico Granata9128ee22011-09-06 19:20:51 +00004027
4028SymbolContextScope *
4029ValueObject::GetSymbolContextScope()
4030{
4031 if (m_parent)
4032 {
4033 if (!m_parent->IsPointerOrReferenceType())
4034 return m_parent->GetSymbolContextScope();
4035 }
4036 return NULL;
4037}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004038
4039lldb::ValueObjectSP
4040ValueObject::CreateValueObjectFromExpression (const char* name,
4041 const char* expression,
4042 const ExecutionContext& exe_ctx)
4043{
Enrico Granata972be532014-12-17 21:18:43 +00004044 return CreateValueObjectFromExpression(name, expression, exe_ctx, EvaluateExpressionOptions());
4045}
4046
4047
4048lldb::ValueObjectSP
4049ValueObject::CreateValueObjectFromExpression (const char* name,
4050 const char* expression,
4051 const ExecutionContext& exe_ctx,
4052 const EvaluateExpressionOptions& options)
4053{
Enrico Granatab2698cd2012-09-13 18:27:09 +00004054 lldb::ValueObjectSP retval_sp;
4055 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4056 if (!target_sp)
4057 return retval_sp;
4058 if (!expression || !*expression)
4059 return retval_sp;
4060 target_sp->EvaluateExpression (expression,
4061 exe_ctx.GetFrameSP().get(),
Enrico Granata972be532014-12-17 21:18:43 +00004062 retval_sp,
4063 options);
Enrico Granatab2698cd2012-09-13 18:27:09 +00004064 if (retval_sp && name && *name)
4065 retval_sp->SetName(ConstString(name));
4066 return retval_sp;
4067}
4068
4069lldb::ValueObjectSP
4070ValueObject::CreateValueObjectFromAddress (const char* name,
4071 uint64_t address,
4072 const ExecutionContext& exe_ctx,
4073 ClangASTType type)
4074{
Greg Clayton57ee3062013-07-11 22:46:58 +00004075 if (type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004076 {
Greg Clayton57ee3062013-07-11 22:46:58 +00004077 ClangASTType pointer_type(type.GetPointerType());
4078 if (pointer_type)
4079 {
4080 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4081 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4082 pointer_type,
4083 ConstString(name),
4084 buffer,
Enrico Granata972be532014-12-17 21:18:43 +00004085 exe_ctx.GetByteOrder(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004086 exe_ctx.GetAddressByteSize()));
4087 if (ptr_result_valobj_sp)
4088 {
4089 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4090 Error err;
4091 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4092 if (ptr_result_valobj_sp && name && *name)
4093 ptr_result_valobj_sp->SetName(ConstString(name));
4094 }
4095 return ptr_result_valobj_sp;
4096 }
Enrico Granatab2698cd2012-09-13 18:27:09 +00004097 }
Greg Clayton57ee3062013-07-11 22:46:58 +00004098 return lldb::ValueObjectSP();
Enrico Granatab2698cd2012-09-13 18:27:09 +00004099}
4100
4101lldb::ValueObjectSP
4102ValueObject::CreateValueObjectFromData (const char* name,
Enrico Granata7ca1c762014-03-31 23:02:25 +00004103 const DataExtractor& data,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004104 const ExecutionContext& exe_ctx,
4105 ClangASTType type)
4106{
4107 lldb::ValueObjectSP new_value_sp;
4108 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004109 type,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004110 ConstString(name),
4111 data,
4112 LLDB_INVALID_ADDRESS);
4113 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4114 if (new_value_sp && name && *name)
4115 new_value_sp->SetName(ConstString(name));
4116 return new_value_sp;
4117}
Enrico Granata4873e522013-04-11 22:48:58 +00004118
4119ModuleSP
4120ValueObject::GetModule ()
4121{
4122 ValueObject* root(GetRoot());
4123 if (root != this)
4124 return root->GetModule();
4125 return lldb::ModuleSP();
4126}
4127
4128ValueObject*
4129ValueObject::GetRoot ()
4130{
4131 if (m_root)
4132 return m_root;
Enrico Granatade61eba2015-01-22 03:07:34 +00004133 return (m_root = FollowParentChain( [] (ValueObject* vo) -> bool {
4134 return (vo->m_parent != nullptr);
4135 }));
4136}
4137
4138ValueObject*
4139ValueObject::FollowParentChain (std::function<bool(ValueObject*)> f)
4140{
4141 ValueObject* vo = this;
4142 while (vo)
Enrico Granata4873e522013-04-11 22:48:58 +00004143 {
Enrico Granatade61eba2015-01-22 03:07:34 +00004144 if (f(vo) == false)
4145 break;
4146 vo = vo->m_parent;
Enrico Granata4873e522013-04-11 22:48:58 +00004147 }
Enrico Granatade61eba2015-01-22 03:07:34 +00004148 return vo;
Enrico Granata4873e522013-04-11 22:48:58 +00004149}
4150
4151AddressType
4152ValueObject::GetAddressTypeOfChildren()
4153{
4154 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
4155 {
4156 ValueObject* root(GetRoot());
4157 if (root != this)
4158 return root->GetAddressTypeOfChildren();
4159 }
4160 return m_address_type_of_ptr_or_ref_children;
4161}
4162
4163lldb::DynamicValueType
4164ValueObject::GetDynamicValueType ()
4165{
4166 ValueObject* with_dv_info = this;
4167 while (with_dv_info)
4168 {
4169 if (with_dv_info->HasDynamicValueTypeInfo())
4170 return with_dv_info->GetDynamicValueTypeImpl();
4171 with_dv_info = with_dv_info->m_parent;
4172 }
4173 return lldb::eNoDynamicValues;
4174}
Enrico Granata39d51412013-05-31 17:43:40 +00004175
Enrico Granata4873e522013-04-11 22:48:58 +00004176lldb::Format
4177ValueObject::GetFormat () const
4178{
4179 const ValueObject* with_fmt_info = this;
4180 while (with_fmt_info)
4181 {
4182 if (with_fmt_info->m_format != lldb::eFormatDefault)
4183 return with_fmt_info->m_format;
4184 with_fmt_info = with_fmt_info->m_parent;
4185 }
4186 return m_format;
4187}
Enrico Granatad07cfd32014-10-08 18:27:36 +00004188
Enrico Granatac1247f52014-11-06 21:23:20 +00004189lldb::LanguageType
4190ValueObject::GetPreferredDisplayLanguage ()
4191{
Enrico Granataed3228a2015-01-21 01:47:13 +00004192 lldb::LanguageType type = m_preferred_display_language;
4193 if (m_preferred_display_language == lldb::eLanguageTypeUnknown)
Enrico Granatac1247f52014-11-06 21:23:20 +00004194 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004195 if (GetRoot())
Enrico Granatac1247f52014-11-06 21:23:20 +00004196 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004197 if (GetRoot() == this)
Enrico Granatac1247f52014-11-06 21:23:20 +00004198 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004199 if (StackFrameSP frame_sp = GetFrameSP())
4200 {
4201 const SymbolContext& sc(frame_sp->GetSymbolContext(eSymbolContextCompUnit));
4202 if (CompileUnit* cu = sc.comp_unit)
4203 type = cu->GetLanguage();
4204 }
4205 }
4206 else
4207 {
4208 type = GetRoot()->GetPreferredDisplayLanguage();
Enrico Granatac1247f52014-11-06 21:23:20 +00004209 }
4210 }
Enrico Granatac1247f52014-11-06 21:23:20 +00004211 }
Enrico Granataed3228a2015-01-21 01:47:13 +00004212 return (m_preferred_display_language = type); // only compute it once
4213}
4214
4215void
4216ValueObject::SetPreferredDisplayLanguage (lldb::LanguageType lt)
4217{
4218 m_preferred_display_language = lt;
Enrico Granatac1247f52014-11-06 21:23:20 +00004219}
4220
Enrico Granatad07cfd32014-10-08 18:27:36 +00004221bool
4222ValueObject::CanProvideValue ()
4223{
Sean Callanan7375f3e2014-12-09 21:18:59 +00004224 // we need to support invalid types as providers of values because some bare-board
4225 // debugging scenarios have no notion of types, but still manage to have raw numeric
4226 // values for things like registers. sigh.
4227 const ClangASTType &type(GetClangType());
4228 return (false == type.IsValid()) || (0 != (type.GetTypeInfo() & eTypeHasValue));
4229}
4230
4231bool
4232ValueObject::IsChecksumEmpty ()
4233{
4234 return m_value_checksum.empty();
Enrico Granatad07cfd32014-10-08 18:27:36 +00004235}
Enrico Granata0c10a852014-12-08 23:13:56 +00004236
4237ValueObjectSP
4238ValueObject::Persist ()
4239{
4240 if (!UpdateValueIfNeeded())
4241 return nullptr;
4242
4243 TargetSP target_sp(GetTargetSP());
4244 if (!target_sp)
4245 return nullptr;
4246
4247 ConstString name(target_sp->GetPersistentVariables().GetNextPersistentVariableName());
4248
4249 ClangExpressionVariableSP clang_var_sp(new ClangExpressionVariable(target_sp.get(), GetValue(), name));
4250 if (clang_var_sp)
4251 {
4252 clang_var_sp->m_live_sp = clang_var_sp->m_frozen_sp;
4253 clang_var_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
4254 target_sp->GetPersistentVariables().AddVariable(clang_var_sp);
4255 }
4256
4257 return clang_var_sp->GetValueObject();
4258}
Enrico Granatae29df232014-12-09 19:51:20 +00004259
4260bool
4261ValueObject::IsSyntheticChildrenGenerated ()
4262{
4263 return m_is_synthetic_children_generated;
4264}
4265
4266void
4267ValueObject::SetSyntheticChildrenGenerated (bool b)
4268{
4269 m_is_synthetic_children_generated = b;
4270}