blob: e66d6d0d0867808def2301e9ad7cbe3ba6434eb4 [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
10#include "lldb/Core/ValueObject.h"
11
12// C Includes
Greg Claytonf5e56de2010-09-14 23:36:40 +000013#include <stdlib.h>
14
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015// C++ Includes
16// Other libraries and framework includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "llvm/Support/raw_ostream.h"
Jim Ingham5a369122010-09-28 01:25:32 +000018#include "clang/AST/Type.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019
20// Project includes
21#include "lldb/Core/DataBufferHeap.h"
Enrico Granata4becb372011-06-29 22:27:15 +000022#include "lldb/Core/Debugger.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000023#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000024#include "lldb/Core/Module.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025#include "lldb/Core/StreamString.h"
Enrico Granata21fd13f2012-10-27 02:05:48 +000026#include "lldb/Core/ValueObjectCast.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Core/ValueObjectChild.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000028#include "lldb/Core/ValueObjectConstResult.h"
Jim Ingham78a685a2011-04-16 00:01:13 +000029#include "lldb/Core/ValueObjectDynamicValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030#include "lldb/Core/ValueObjectList.h"
Greg Claytonb2dcc362011-05-05 23:32:56 +000031#include "lldb/Core/ValueObjectMemory.h"
Enrico Granatad55546b2011-07-22 00:16:08 +000032#include "lldb/Core/ValueObjectSyntheticFilter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033
Enrico Granata5548cb52013-01-28 23:47:25 +000034#include "lldb/DataFormatters/DataVisualization.h"
Enrico Granata2206b482014-10-30 18:27:31 +000035#include "lldb/DataFormatters/StringPrinter.h"
Enrico Granata4d93b8c2013-09-30 19:11:51 +000036#include "lldb/DataFormatters/ValueObjectPrinter.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000037
Sean Callanan30e33972015-09-03 00:48:23 +000038#include "Plugins/ExpressionParser/Clang/ClangExpressionVariable.h"
Enrico Granata0c10a852014-12-08 23:13:56 +000039#include "lldb/Expression/ClangPersistentVariables.h"
40
Greg Clayton7fb56d02011-02-01 01:31:41 +000041#include "lldb/Host/Endian.h"
42
Enrico Granata61a80ba2011-08-12 16:42:31 +000043#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granataf2bbf712011-07-15 02:26:42 +000044
Greg Claytona1e5dc82015-08-11 22:53:00 +000045#include "lldb/Symbol/CompilerType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046#include "lldb/Symbol/ClangASTContext.h"
Enrico Granatac1247f52014-11-06 21:23:20 +000047#include "lldb/Symbol/CompileUnit.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000048#include "lldb/Symbol/Type.h"
49
Jim Ingham53c47f12010-09-10 23:12:17 +000050#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000051#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000052#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053#include "lldb/Target/Process.h"
54#include "lldb/Target/RegisterContext.h"
Greg Claytond5944cd2013-12-06 01:12:00 +000055#include "lldb/Target/SectionLoadList.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000056#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058
59using namespace lldb;
60using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000061using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062
Greg Claytonafacd142011-09-02 01:15:17 +000063static user_id_t g_value_obj_uid = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000064
65//----------------------------------------------------------------------
66// ValueObject constructor
67//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000068ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000069 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000070 m_parent (&parent),
Enrico Granata4873e522013-04-11 22:48:58 +000071 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +000072 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000073 m_name (),
74 m_data (),
75 m_value (),
76 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000077 m_value_str (),
78 m_old_value_str (),
79 m_location_str (),
80 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000081 m_object_desc_str (),
Enrico Granata744794a2014-09-05 21:46:22 +000082 m_validation_result(),
Jim Ingham58b59f92011-04-22 23:53:53 +000083 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000084 m_children (),
85 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000086 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000087 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000088 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000089 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +000090 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000091 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +000092 m_type_summary_sp(),
93 m_type_format_sp(),
94 m_synthetic_children_sp(),
Enrico Granata744794a2014-09-05 21:46:22 +000095 m_type_validator_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +000096 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +000097 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
Sean Callanan7375f3e2014-12-09 21:18:59 +000098 m_value_checksum(),
Enrico Granataed3228a2015-01-21 01:47:13 +000099 m_preferred_display_language(lldb::eLanguageTypeUnknown),
Greg Clayton288bdf92010-09-02 02:59:18 +0000100 m_value_is_valid (false),
101 m_value_did_change (false),
102 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000103 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000104 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000105 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000106 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000107 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000108 m_is_getting_summary(false),
Enrico Granatae29df232014-12-09 19:51:20 +0000109 m_did_calculate_complete_objc_class_type(false),
110 m_is_synthetic_children_generated(parent.m_is_synthetic_children_generated)
Jim Ingham6035b672011-03-31 00:19:25 +0000111{
Jim Ingham58b59f92011-04-22 23:53:53 +0000112 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000113}
114
115//----------------------------------------------------------------------
116// ValueObject constructor
117//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000118ValueObject::ValueObject (ExecutionContextScope *exe_scope,
119 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000120 UserID (++g_value_obj_uid), // Unique identifier for every value object
121 m_parent (NULL),
Enrico Granata4873e522013-04-11 22:48:58 +0000122 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000123 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000124 m_name (),
125 m_data (),
126 m_value (),
127 m_error (),
128 m_value_str (),
129 m_old_value_str (),
130 m_location_str (),
131 m_summary_str (),
132 m_object_desc_str (),
Enrico Granata744794a2014-09-05 21:46:22 +0000133 m_validation_result(),
Jim Ingham58b59f92011-04-22 23:53:53 +0000134 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000135 m_children (),
136 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000137 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000138 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000139 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000140 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +0000141 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000142 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +0000143 m_type_summary_sp(),
144 m_type_format_sp(),
145 m_synthetic_children_sp(),
Enrico Granata744794a2014-09-05 21:46:22 +0000146 m_type_validator_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000147 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000148 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Sean Callanan7375f3e2014-12-09 21:18:59 +0000149 m_value_checksum(),
Enrico Granataed3228a2015-01-21 01:47:13 +0000150 m_preferred_display_language(lldb::eLanguageTypeUnknown),
Jim Ingham6035b672011-03-31 00:19:25 +0000151 m_value_is_valid (false),
152 m_value_did_change (false),
153 m_children_count_valid (false),
154 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000155 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000156 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000157 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000158 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000159 m_is_getting_summary(false),
Enrico Granatae29df232014-12-09 19:51:20 +0000160 m_did_calculate_complete_objc_class_type(false),
161 m_is_synthetic_children_generated(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000162{
Jim Ingham58b59f92011-04-22 23:53:53 +0000163 m_manager = new ValueObjectManager();
164 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000165}
166
167//----------------------------------------------------------------------
168// Destructor
169//----------------------------------------------------------------------
170ValueObject::~ValueObject ()
171{
172}
173
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000174bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000175ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000176{
Enrico Granata4becb372011-06-29 22:27:15 +0000177
Enrico Granata9128ee22011-09-06 19:20:51 +0000178 bool did_change_formats = false;
179
Enrico Granata0a3958e2011-07-02 00:25:22 +0000180 if (update_format)
Enrico Granata5548cb52013-01-28 23:47:25 +0000181 did_change_formats = UpdateFormatsIfNeeded();
Enrico Granata4becb372011-06-29 22:27:15 +0000182
Greg Claytonb71f3842010-10-05 03:13:51 +0000183 // If this is a constant value, then our success is predicated on whether
184 // we have an error or not
185 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000186 {
Enrico Granatab1c6c482013-10-09 00:33:55 +0000187 // if you are constant, things might still have changed behind your back
188 // (e.g. you are a frozen object and things have changed deeper than you cared to freeze-dry yourself)
189 // in this case, your value has not changed, but "computed" entries might have, so you might now have
190 // a different summary, or a different object description. clear these so we will recompute them
Enrico Granata9128ee22011-09-06 19:20:51 +0000191 if (update_format && !did_change_formats)
Enrico Granatab1c6c482013-10-09 00:33:55 +0000192 ClearUserVisibleData(eClearUserVisibleDataItemsSummary | eClearUserVisibleDataItemsDescription);
Greg Claytonb71f3842010-10-05 03:13:51 +0000193 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000194 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000195
Sean Callanan7375f3e2014-12-09 21:18:59 +0000196 bool first_update = IsChecksumEmpty();
Jim Ingham6035b672011-03-31 00:19:25 +0000197
Enrico Granatabb642e52015-05-16 01:27:00 +0000198 if (NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000199 {
Jim Ingham6035b672011-03-31 00:19:25 +0000200 m_update_point.SetUpdated();
201
202 // Save the old value using swap to avoid a string copy which
203 // also will clear our m_value_str
204 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000205 {
Jim Ingham6035b672011-03-31 00:19:25 +0000206 m_old_value_valid = false;
207 }
208 else
209 {
210 m_old_value_valid = true;
211 m_old_value_str.swap (m_value_str);
Enrico Granata86cc9822012-03-19 22:58:49 +0000212 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham6035b672011-03-31 00:19:25 +0000213 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000214
Enrico Granataf2bbf712011-07-15 02:26:42 +0000215 ClearUserVisibleData();
216
Greg Claytonefbc7d22012-03-09 04:23:44 +0000217 if (IsInScope())
Jim Ingham6035b672011-03-31 00:19:25 +0000218 {
Greg Claytonefbc7d22012-03-09 04:23:44 +0000219 const bool value_was_valid = GetValueIsValid();
220 SetValueDidChange (false);
221
222 m_error.Clear();
223
224 // Call the pure virtual function to update the value
Sean Callanan7375f3e2014-12-09 21:18:59 +0000225
226 bool need_compare_checksums = false;
227 llvm::SmallVector<uint8_t, 16> old_checksum;
228
229 if (!first_update && CanProvideValue())
230 {
231 need_compare_checksums = true;
232 old_checksum.resize(m_value_checksum.size());
233 std::copy(m_value_checksum.begin(), m_value_checksum.end(), old_checksum.begin());
234 }
235
Greg Claytonefbc7d22012-03-09 04:23:44 +0000236 bool success = UpdateValue ();
237
238 SetValueIsValid (success);
239
Sean Callanan7375f3e2014-12-09 21:18:59 +0000240 if (success)
241 {
242 const uint64_t max_checksum_size = 128;
243 m_data.Checksum(m_value_checksum,
244 max_checksum_size);
245 }
246 else
247 {
248 need_compare_checksums = false;
249 m_value_checksum.clear();
250 }
251
Enrico Granata20c321c2015-01-08 19:11:43 +0000252 assert (!need_compare_checksums || (!old_checksum.empty() && !m_value_checksum.empty()));
253
Greg Claytonefbc7d22012-03-09 04:23:44 +0000254 if (first_update)
255 SetValueDidChange (false);
256 else if (!m_value_did_change && success == false)
257 {
258 // The value wasn't gotten successfully, so we mark this
259 // as changed if the value used to be valid and now isn't
260 SetValueDidChange (value_was_valid);
261 }
Sean Callanan7375f3e2014-12-09 21:18:59 +0000262 else if (need_compare_checksums)
263 {
264 SetValueDidChange(memcmp(&old_checksum[0], &m_value_checksum[0], m_value_checksum.size()));
265 }
266
Greg Claytonefbc7d22012-03-09 04:23:44 +0000267 }
268 else
269 {
270 m_error.SetErrorString("out of scope");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000271 }
272 }
273 return m_error.Success();
274}
275
Enrico Granata9128ee22011-09-06 19:20:51 +0000276bool
Enrico Granata5548cb52013-01-28 23:47:25 +0000277ValueObject::UpdateFormatsIfNeeded()
Enrico Granata4becb372011-06-29 22:27:15 +0000278{
Greg Clayton5160ce52013-03-27 23:08:40 +0000279 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000280 if (log)
Enrico Granatad2284832012-10-17 22:23:56 +0000281 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000282 GetName().GetCString(), static_cast<void*>(this),
283 m_last_format_mgr_revision,
284 DataVisualization::GetCurrentRevision());
285
Enrico Granata9128ee22011-09-06 19:20:51 +0000286 bool any_change = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000287
Enrico Granata5548cb52013-01-28 23:47:25 +0000288 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()))
Enrico Granata4becb372011-06-29 22:27:15 +0000289 {
Enrico Granataa0db6ed2014-04-09 21:06:11 +0000290 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
291 any_change = true;
292
Enrico Granata852cc952013-10-08 19:03:22 +0000293 SetValueFormat(DataVisualization::GetFormat (*this, eNoDynamicValues));
Enrico Granata5548cb52013-01-28 23:47:25 +0000294 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000295#ifndef LLDB_DISABLE_PYTHON
Enrico Granata5548cb52013-01-28 23:47:25 +0000296 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000297#endif
Enrico Granata744794a2014-09-05 21:46:22 +0000298 SetValidator(DataVisualization::GetValidator(*this, GetDynamicValueType()));
Enrico Granata4becb372011-06-29 22:27:15 +0000299 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000300
Enrico Granata9128ee22011-09-06 19:20:51 +0000301 return any_change;
Enrico Granata4becb372011-06-29 22:27:15 +0000302}
303
Jim Ingham16e0c682011-08-12 23:34:31 +0000304void
305ValueObject::SetNeedsUpdate ()
306{
307 m_update_point.SetNeedsUpdate();
308 // We have to clear the value string here so ConstResult children will notice if their values are
309 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000310 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000311}
312
Enrico Granata13ac0e22012-10-17 19:03:34 +0000313void
Enrico Granatae3e91512012-10-22 18:18:36 +0000314ValueObject::ClearDynamicTypeInformation ()
Enrico Granata13ac0e22012-10-17 19:03:34 +0000315{
Enrico Granata38c54632013-10-30 00:04:29 +0000316 m_children_count_valid = false;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000317 m_did_calculate_complete_objc_class_type = false;
Enrico Granatae3e91512012-10-22 18:18:36 +0000318 m_last_format_mgr_revision = 0;
Greg Claytona1e5dc82015-08-11 22:53:00 +0000319 m_override_type = CompilerType();
Enrico Granatae3e91512012-10-22 18:18:36 +0000320 SetValueFormat(lldb::TypeFormatImplSP());
321 SetSummaryFormat(lldb::TypeSummaryImplSP());
322 SetSyntheticChildren(lldb::SyntheticChildrenSP());
Enrico Granata13ac0e22012-10-17 19:03:34 +0000323}
324
Greg Claytona1e5dc82015-08-11 22:53:00 +0000325CompilerType
Sean Callanan72772842012-02-22 23:57:45 +0000326ValueObject::MaybeCalculateCompleteType ()
327{
Greg Clayton99558cc42015-08-24 23:46:31 +0000328 CompilerType clang_type(GetCompilerTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000329
Sean Callanan72772842012-02-22 23:57:45 +0000330 if (m_did_calculate_complete_objc_class_type)
331 {
332 if (m_override_type.IsValid())
333 return m_override_type;
334 else
Greg Clayton57ee3062013-07-11 22:46:58 +0000335 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000336 }
337
Greg Claytona1e5dc82015-08-11 22:53:00 +0000338 CompilerType class_type;
Greg Clayton57ee3062013-07-11 22:46:58 +0000339 bool is_pointer_type = false;
Sean Callanan72772842012-02-22 23:57:45 +0000340
Greg Claytond8d4a572015-08-11 21:38:15 +0000341 if (ClangASTContext::IsObjCObjectPointerType(clang_type, &class_type))
Sean Callanan72772842012-02-22 23:57:45 +0000342 {
343 is_pointer_type = true;
344 }
Greg Claytond8d4a572015-08-11 21:38:15 +0000345 else if (ClangASTContext::IsObjCObjectOrInterfaceType(clang_type))
Sean Callanan72772842012-02-22 23:57:45 +0000346 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000347 class_type = clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000348 }
349 else
350 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000351 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000352 }
353
354 m_did_calculate_complete_objc_class_type = true;
355
Greg Clayton57ee3062013-07-11 22:46:58 +0000356 if (class_type)
Sean Callanan72772842012-02-22 23:57:45 +0000357 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000358 ConstString class_name (class_type.GetConstTypeName());
Sean Callanan72772842012-02-22 23:57:45 +0000359
Greg Clayton57ee3062013-07-11 22:46:58 +0000360 if (class_name)
361 {
362 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
363
364 if (process_sp)
365 {
366 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
367
368 if (objc_language_runtime)
369 {
370 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name);
371
372 if (complete_objc_class_type_sp)
373 {
Greg Clayton99558cc42015-08-24 23:46:31 +0000374 CompilerType complete_class(complete_objc_class_type_sp->GetFullCompilerType ());
Greg Clayton57ee3062013-07-11 22:46:58 +0000375
376 if (complete_class.GetCompleteType())
377 {
378 if (is_pointer_type)
379 {
380 m_override_type = complete_class.GetPointerType();
381 }
382 else
383 {
384 m_override_type = complete_class;
385 }
386
387 if (m_override_type.IsValid())
388 return m_override_type;
389 }
390 }
391 }
392 }
393 }
Sean Callanan72772842012-02-22 23:57:45 +0000394 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000395 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000396}
397
Greg Claytona1e5dc82015-08-11 22:53:00 +0000398CompilerType
Greg Clayton99558cc42015-08-24 23:46:31 +0000399ValueObject::GetCompilerType ()
Sean Callanan72772842012-02-22 23:57:45 +0000400{
Greg Clayton57ee3062013-07-11 22:46:58 +0000401 return MaybeCalculateCompleteType();
Sean Callanan72772842012-02-22 23:57:45 +0000402}
403
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000404TypeImpl
405ValueObject::GetTypeImpl ()
406{
Greg Clayton99558cc42015-08-24 23:46:31 +0000407 return TypeImpl(GetCompilerType());
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000408}
409
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000410DataExtractor &
411ValueObject::GetDataExtractor ()
412{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000413 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000414 return m_data;
415}
416
417const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000418ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000419{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000420 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000421 return m_error;
422}
423
424const ConstString &
425ValueObject::GetName() const
426{
427 return m_name;
428}
429
430const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000431ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000432{
Enrico Granata82fabf82013-04-30 20:45:04 +0000433 return GetLocationAsCStringImpl(m_value,
434 m_data);
435}
436
437const char *
438ValueObject::GetLocationAsCStringImpl (const Value& value,
439 const DataExtractor& data)
440{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000441 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000442 {
443 if (m_location_str.empty())
444 {
445 StreamString sstr;
Enrico Granata82fabf82013-04-30 20:45:04 +0000446
447 Value::ValueType value_type = value.GetValueType();
448
449 switch (value_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000450 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000451 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +0000452 case Value::eValueTypeVector:
Enrico Granata82fabf82013-04-30 20:45:04 +0000453 if (value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000454 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000455 RegisterInfo *reg_info = value.GetRegisterInfo();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000456 if (reg_info)
457 {
458 if (reg_info->name)
459 m_location_str = reg_info->name;
460 else if (reg_info->alt_name)
461 m_location_str = reg_info->alt_name;
Enrico Granata82fabf82013-04-30 20:45:04 +0000462 if (m_location_str.empty())
463 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000464 }
465 }
Enrico Granata82fabf82013-04-30 20:45:04 +0000466 if (m_location_str.empty())
467 m_location_str = (value_type == Value::eValueTypeVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000468 break;
469
470 case Value::eValueTypeLoadAddress:
471 case Value::eValueTypeFileAddress:
472 case Value::eValueTypeHostAddress:
473 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000474 uint32_t addr_nibble_size = data.GetAddressByteSize() * 2;
475 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000476 m_location_str.swap(sstr.GetString());
477 }
478 break;
479 }
480 }
481 }
482 return m_location_str.c_str();
483}
484
485Value &
486ValueObject::GetValue()
487{
488 return m_value;
489}
490
491const Value &
492ValueObject::GetValue() const
493{
494 return m_value;
495}
496
497bool
Jim Ingham6035b672011-03-31 00:19:25 +0000498ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000499{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000500 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
501 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000502 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000503 Value tmp_value(m_value);
Greg Clayton57ee3062013-07-11 22:46:58 +0000504 scalar = tmp_value.ResolveValue(&exe_ctx);
Greg Claytondcad5022011-12-29 01:26:56 +0000505 if (scalar.IsValid())
506 {
507 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
508 if (bitfield_bit_size)
509 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
510 return true;
511 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000512 }
Greg Claytondcad5022011-12-29 01:26:56 +0000513 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000514}
515
516bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000517ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000518{
Greg Clayton288bdf92010-09-02 02:59:18 +0000519 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000520}
521
522
523void
524ValueObject::SetValueIsValid (bool b)
525{
Greg Clayton288bdf92010-09-02 02:59:18 +0000526 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000527}
528
529bool
Jim Ingham6035b672011-03-31 00:19:25 +0000530ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000531{
Greg Clayton288bdf92010-09-02 02:59:18 +0000532 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000533}
534
535void
536ValueObject::SetValueDidChange (bool value_changed)
537{
Greg Clayton288bdf92010-09-02 02:59:18 +0000538 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000539}
540
541ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000542ValueObject::GetChildAtIndex (size_t idx, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000543{
544 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000545 // We may need to update our value if we are dynamic
546 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000547 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000548 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000549 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000550 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000551 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000552 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000553 // No we haven't created the child at this index, so lets have our
554 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000555 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000556 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000557
Enrico Granata9d60f602012-03-09 03:09:58 +0000558 ValueObject* child = m_children.GetChildAtIndex(idx);
559 if (child != NULL)
560 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000561 }
562 return child_sp;
563}
564
Enrico Granata3309d882013-01-12 01:00:22 +0000565ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000566ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
567 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000568{
569 if (idxs.size() == 0)
570 return GetSP();
571 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000572 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000573 {
574 root = root->GetChildAtIndex(idx, true);
575 if (!root)
576 {
577 if (index_of_error)
578 *index_of_error = idx;
579 return root;
580 }
581 }
582 return root;
583}
584
585ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000586ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
587 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000588{
589 if (idxs.size() == 0)
590 return GetSP();
591 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000592 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000593 {
594 root = root->GetChildAtIndex(idx.first, idx.second);
595 if (!root)
596 {
597 if (index_of_error)
598 *index_of_error = idx.first;
599 return root;
600 }
601 }
602 return root;
603}
604
605lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000606ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
607 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000608{
609 if (idxs.size() == 0)
610 return GetSP();
611 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000612 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000613 {
614 root = root->GetChildAtIndex(idx, true);
615 if (!root)
616 {
617 if (index_of_error)
618 *index_of_error = idx;
619 return root;
620 }
621 }
622 return root;
623}
624
625lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000626ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
627 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000628{
629 if (idxs.size() == 0)
630 return GetSP();
631 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000632 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000633 {
634 root = root->GetChildAtIndex(idx.first, idx.second);
635 if (!root)
636 {
637 if (index_of_error)
638 *index_of_error = idx.first;
639 return root;
640 }
641 }
642 return root;
643}
644
Enrico Granatae2e220a2013-09-12 00:48:47 +0000645lldb::ValueObjectSP
646ValueObject::GetChildAtNamePath (const std::initializer_list<ConstString> &names,
647 ConstString* name_of_error)
648{
649 if (names.size() == 0)
650 return GetSP();
651 ValueObjectSP root(GetSP());
652 for (ConstString name : names)
653 {
654 root = root->GetChildMemberWithName(name, true);
655 if (!root)
656 {
657 if (name_of_error)
658 *name_of_error = name;
659 return root;
660 }
661 }
662 return root;
663}
664
665lldb::ValueObjectSP
666ValueObject::GetChildAtNamePath (const std::vector<ConstString> &names,
667 ConstString* name_of_error)
668{
669 if (names.size() == 0)
670 return GetSP();
671 ValueObjectSP root(GetSP());
672 for (ConstString name : names)
673 {
674 root = root->GetChildMemberWithName(name, true);
675 if (!root)
676 {
677 if (name_of_error)
678 *name_of_error = name;
679 return root;
680 }
681 }
682 return root;
683}
684
685lldb::ValueObjectSP
686ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names,
687 ConstString* name_of_error)
688{
689 if (names.size() == 0)
690 return GetSP();
691 ValueObjectSP root(GetSP());
692 for (std::pair<ConstString, bool> name : names)
693 {
694 root = root->GetChildMemberWithName(name.first, name.second);
695 if (!root)
696 {
697 if (name_of_error)
698 *name_of_error = name.first;
699 return root;
700 }
701 }
702 return root;
703}
704
705lldb::ValueObjectSP
706ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names,
707 ConstString* name_of_error)
708{
709 if (names.size() == 0)
710 return GetSP();
711 ValueObjectSP root(GetSP());
712 for (std::pair<ConstString, bool> name : names)
713 {
714 root = root->GetChildMemberWithName(name.first, name.second);
715 if (!root)
716 {
717 if (name_of_error)
718 *name_of_error = name.first;
719 return root;
720 }
721 }
722 return root;
723}
724
Greg Claytonc7bece562013-01-25 18:06:21 +0000725size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000726ValueObject::GetIndexOfChildWithName (const ConstString &name)
727{
728 bool omit_empty_base_classes = true;
Greg Clayton99558cc42015-08-24 23:46:31 +0000729 return GetCompilerType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000730}
731
732ValueObjectSP
733ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
734{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000735 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000736 // classes (which really aren't part of the expression path), so we
737 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000738 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000739
Greg Claytondea8cb42011-06-29 22:09:02 +0000740 // We may need to update our value if we are dynamic
741 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000742 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000743
744 std::vector<uint32_t> child_indexes;
Greg Claytondea8cb42011-06-29 22:09:02 +0000745 bool omit_empty_base_classes = true;
Greg Clayton99558cc42015-08-24 23:46:31 +0000746 const size_t num_child_indexes = GetCompilerType().GetIndexOfChildMemberWithName (name.GetCString(),
Greg Clayton57ee3062013-07-11 22:46:58 +0000747 omit_empty_base_classes,
748 child_indexes);
Greg Claytondea8cb42011-06-29 22:09:02 +0000749 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000750 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000751 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
752 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
753
754 child_sp = GetChildAtIndex(*pos, can_create);
755 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000756 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000757 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000758 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000759 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
760 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000761 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000762 else
763 {
764 child_sp.reset();
765 }
766
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000767 }
768 }
769 return child_sp;
770}
771
772
Greg Claytonc7bece562013-01-25 18:06:21 +0000773size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000774ValueObject::GetNumChildren ()
775{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000776 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000777 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000778 {
779 SetNumChildren (CalculateNumChildren());
780 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000781 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000782}
Greg Clayton4a792072012-10-23 01:50:10 +0000783
784bool
785ValueObject::MightHaveChildren()
786{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000787 bool has_children = false;
Greg Clayton2452ab72013-02-08 22:02:02 +0000788 const uint32_t type_info = GetTypeInfo();
789 if (type_info)
Greg Clayton4a792072012-10-23 01:50:10 +0000790 {
Enrico Granata622be232014-10-21 20:52:14 +0000791 if (type_info & (eTypeHasChildren |
792 eTypeIsPointer |
793 eTypeIsReference))
Greg Clayton4a792072012-10-23 01:50:10 +0000794 has_children = true;
795 }
796 else
797 {
798 has_children = GetNumChildren () > 0;
799 }
800 return has_children;
801}
802
803// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000804void
Greg Claytonc7bece562013-01-25 18:06:21 +0000805ValueObject::SetNumChildren (size_t num_children)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000806{
Greg Clayton288bdf92010-09-02 02:59:18 +0000807 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000808 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000809}
810
811void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000812ValueObject::SetName (const ConstString &name)
813{
814 m_name = name;
815}
816
Jim Ingham58b59f92011-04-22 23:53:53 +0000817ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000818ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000819{
Jim Ingham2eec4872011-05-07 00:10:58 +0000820 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000821
Greg Claytondea8cb42011-06-29 22:09:02 +0000822 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000823 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000824 std::string child_name_str;
825 uint32_t child_byte_size = 0;
826 int32_t child_byte_offset = 0;
827 uint32_t child_bitfield_bit_size = 0;
828 uint32_t child_bitfield_bit_offset = 0;
829 bool child_is_base_class = false;
830 bool child_is_deref_of_parent = false;
831
832 const bool transparent_pointers = synthetic_array_member == false;
Greg Claytona1e5dc82015-08-11 22:53:00 +0000833 CompilerType child_clang_type;
Greg Claytondea8cb42011-06-29 22:09:02 +0000834
Greg Claytoncc4d0142012-02-17 07:49:44 +0000835 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000836
Greg Clayton99558cc42015-08-24 23:46:31 +0000837 child_clang_type = GetCompilerType().GetChildClangTypeAtIndex (&exe_ctx,
Greg Clayton57ee3062013-07-11 22:46:58 +0000838 idx,
839 transparent_pointers,
840 omit_empty_base_classes,
841 ignore_array_bounds,
842 child_name_str,
843 child_byte_size,
844 child_byte_offset,
845 child_bitfield_bit_size,
846 child_bitfield_bit_offset,
847 child_is_base_class,
Greg Clayton759e7442014-07-19 00:12:57 +0000848 child_is_deref_of_parent,
849 this);
Greg Clayton4ef877f2012-12-06 02:33:54 +0000850 if (child_clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000851 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000852 if (synthetic_index)
853 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000854
Greg Claytondea8cb42011-06-29 22:09:02 +0000855 ConstString child_name;
856 if (!child_name_str.empty())
857 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000858
Greg Claytondea8cb42011-06-29 22:09:02 +0000859 valobj = new ValueObjectChild (*this,
Greg Claytondea8cb42011-06-29 22:09:02 +0000860 child_clang_type,
861 child_name,
862 child_byte_size,
863 child_byte_offset,
864 child_bitfield_bit_size,
865 child_bitfield_bit_offset,
866 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000867 child_is_deref_of_parent,
868 eAddressTypeInvalid);
869 //if (valobj)
870 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
871 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000872
Jim Ingham58b59f92011-04-22 23:53:53 +0000873 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000874}
875
Enrico Granata0c489f52012-03-01 04:24:26 +0000876bool
877ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
878 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000879{
Enrico Granatac1247f52014-11-06 21:23:20 +0000880 return GetSummaryAsCString(summary_ptr, destination, TypeSummaryOptions());
881}
882
883bool
884ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
885 std::string& destination,
886 const TypeSummaryOptions& options)
887{
Enrico Granata0c489f52012-03-01 04:24:26 +0000888 destination.clear();
889
890 // ideally we would like to bail out if passing NULL, but if we do so
891 // we end up not providing the summary for function pointers anymore
892 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
893 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000894
895 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000896
897 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
898 // information that we might care to see in a crash log. might be useful in very specific situations though.
899 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
900 GetTypeName().GetCString(),
901 GetName().GetCString(),
902 summary_ptr->GetDescription().c_str());*/
903
Enrico Granataff0f23d2014-12-10 02:00:45 +0000904 if (UpdateValueIfNeeded (false) && summary_ptr)
Enrico Granata0c489f52012-03-01 04:24:26 +0000905 {
Enrico Granataff0f23d2014-12-10 02:00:45 +0000906 if (HasSyntheticValue())
907 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
908 summary_ptr->FormatObject(this, destination, options);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000909 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000910 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000911 return !destination.empty();
912}
913
914const char *
915ValueObject::GetSummaryAsCString ()
916{
917 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
918 {
919 GetSummaryAsCString(GetSummaryFormat().get(),
Enrico Granatac1247f52014-11-06 21:23:20 +0000920 m_summary_str,
Enrico Granata49bfafb2014-11-18 23:36:25 +0000921 TypeSummaryOptions());
Enrico Granata0c489f52012-03-01 04:24:26 +0000922 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000923 if (m_summary_str.empty())
924 return NULL;
925 return m_summary_str.c_str();
926}
927
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000928bool
Enrico Granata49bfafb2014-11-18 23:36:25 +0000929ValueObject::GetSummaryAsCString (std::string& destination,
930 const TypeSummaryOptions& options)
931{
932 return GetSummaryAsCString(GetSummaryFormat().get(),
933 destination,
934 options);
935}
936
937bool
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000938ValueObject::IsCStringContainer(bool check_pointer)
939{
Greg Claytona1e5dc82015-08-11 22:53:00 +0000940 CompilerType pointee_or_element_clang_type;
Greg Clayton57ee3062013-07-11 22:46:58 +0000941 const Flags type_flags (GetTypeInfo (&pointee_or_element_clang_type));
Enrico Granata622be232014-10-21 20:52:14 +0000942 bool is_char_arr_ptr (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Greg Clayton57ee3062013-07-11 22:46:58 +0000943 pointee_or_element_clang_type.IsCharType ());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000944 if (!is_char_arr_ptr)
945 return false;
946 if (!check_pointer)
947 return true;
Enrico Granata622be232014-10-21 20:52:14 +0000948 if (type_flags.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000949 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000950 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000951 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000952 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000953 return (cstr_address != LLDB_INVALID_ADDRESS);
954}
955
Enrico Granata9128ee22011-09-06 19:20:51 +0000956size_t
957ValueObject::GetPointeeData (DataExtractor& data,
958 uint32_t item_idx,
959 uint32_t item_count)
960{
Greg Claytona1e5dc82015-08-11 22:53:00 +0000961 CompilerType pointee_or_element_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +0000962 const uint32_t type_info = GetTypeInfo (&pointee_or_element_clang_type);
Enrico Granata622be232014-10-21 20:52:14 +0000963 const bool is_pointer_type = type_info & eTypeIsPointer;
964 const bool is_array_type = type_info & eTypeIsArray;
Greg Clayton2452ab72013-02-08 22:02:02 +0000965 if (!(is_pointer_type || is_array_type))
Enrico Granata9128ee22011-09-06 19:20:51 +0000966 return 0;
967
968 if (item_count == 0)
969 return 0;
970
Enrico Granata951bdd52015-01-28 01:09:45 +0000971 ExecutionContext exe_ctx (GetExecutionContextRef());
972
Greg Clayton526ae042015-02-12 00:34:25 +0000973 const uint64_t item_type_size = pointee_or_element_clang_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
Enrico Granata9128ee22011-09-06 19:20:51 +0000974 const uint64_t bytes = item_count * item_type_size;
Enrico Granata9128ee22011-09-06 19:20:51 +0000975 const uint64_t offset = item_idx * item_type_size;
976
977 if (item_idx == 0 && item_count == 1) // simply a deref
978 {
Greg Clayton2452ab72013-02-08 22:02:02 +0000979 if (is_pointer_type)
Enrico Granata9128ee22011-09-06 19:20:51 +0000980 {
981 Error error;
982 ValueObjectSP pointee_sp = Dereference(error);
983 if (error.Fail() || pointee_sp.get() == NULL)
984 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +0000985 return pointee_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +0000986 }
987 else
988 {
989 ValueObjectSP child_sp = GetChildAtIndex(0, true);
990 if (child_sp.get() == NULL)
991 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +0000992 Error error;
993 return child_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +0000994 }
995 return true;
996 }
997 else /* (items > 1) */
998 {
999 Error error;
1000 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
1001 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
1002
1003 AddressType addr_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001004 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001005
Enrico Granata9128ee22011-09-06 19:20:51 +00001006 switch (addr_type)
1007 {
1008 case eAddressTypeFile:
1009 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001010 ModuleSP module_sp (GetModule());
1011 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001012 {
Enrico Granata9c2efe32012-08-07 01:49:34 +00001013 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +00001014 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001015 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001016 ExecutionContext exe_ctx (GetExecutionContextRef());
1017 Target* target = exe_ctx.GetTargetPtr();
1018 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +00001019 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001020 heap_buf_ptr->SetByteSize(bytes);
1021 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
1022 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +00001023 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001024 data.SetData(data_sp);
1025 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +00001026 }
1027 }
1028 }
1029 }
1030 break;
1031 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +00001032 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001033 ExecutionContext exe_ctx (GetExecutionContextRef());
1034 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +00001035 if (process)
1036 {
1037 heap_buf_ptr->SetByteSize(bytes);
1038 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
Enrico Granata5e1480c2013-10-30 17:52:44 +00001039 if (error.Success() || bytes_read > 0)
Enrico Granata9128ee22011-09-06 19:20:51 +00001040 {
1041 data.SetData(data_sp);
1042 return bytes_read;
1043 }
1044 }
1045 }
1046 break;
1047 case eAddressTypeHost:
1048 {
Greg Clayton99558cc42015-08-24 23:46:31 +00001049 const uint64_t max_bytes = GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope());
Greg Clayton2452ab72013-02-08 22:02:02 +00001050 if (max_bytes > offset)
1051 {
1052 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
Siva Chandrae32f2b52015-05-05 00:41:35 +00001053 addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1054 if (addr == LLDB_INVALID_ADDRESS)
1055 break;
Greg Clayton2452ab72013-02-08 22:02:02 +00001056 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
1057 data.SetData(data_sp);
1058 return bytes_read;
1059 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001060 }
1061 break;
1062 case eAddressTypeInvalid:
Enrico Granata9128ee22011-09-06 19:20:51 +00001063 break;
1064 }
1065 }
1066 return 0;
1067}
1068
Greg Claytonfaac1112013-03-14 18:31:44 +00001069uint64_t
Sean Callanan866e91c2014-02-28 22:27:53 +00001070ValueObject::GetData (DataExtractor& data, Error &error)
Enrico Granata9128ee22011-09-06 19:20:51 +00001071{
1072 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001073 ExecutionContext exe_ctx (GetExecutionContextRef());
Sean Callanan866e91c2014-02-28 22:27:53 +00001074 error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001075 if (error.Fail())
Sean Callananed185ab2013-04-19 19:47:32 +00001076 {
1077 if (m_data.GetByteSize())
1078 {
1079 data = m_data;
1080 return data.GetByteSize();
1081 }
1082 else
1083 {
1084 return 0;
1085 }
1086 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001087 data.SetAddressByteSize(m_data.GetAddressByteSize());
1088 data.SetByteOrder(m_data.GetByteOrder());
1089 return data.GetByteSize();
1090}
1091
Sean Callanan389823e2013-04-13 01:21:23 +00001092bool
1093ValueObject::SetData (DataExtractor &data, Error &error)
1094{
1095 error.Clear();
1096 // Make sure our value is up to date first so that our location and location
1097 // type is valid.
1098 if (!UpdateValueIfNeeded(false))
1099 {
1100 error.SetErrorString("unable to read value");
1101 return false;
1102 }
1103
1104 uint64_t count = 0;
Greg Clayton99558cc42015-08-24 23:46:31 +00001105 const Encoding encoding = GetCompilerType().GetEncoding(count);
Sean Callanan389823e2013-04-13 01:21:23 +00001106
1107 const size_t byte_size = GetByteSize();
1108
1109 Value::ValueType value_type = m_value.GetValueType();
1110
1111 switch (value_type)
1112 {
1113 case Value::eValueTypeScalar:
1114 {
1115 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1116
1117 if (!set_error.Success())
1118 {
1119 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1120 return false;
1121 }
1122 }
1123 break;
1124 case Value::eValueTypeLoadAddress:
1125 {
1126 // If it is a load address, then the scalar value is the storage location
1127 // of the data, and we have to shove this value down to that load location.
1128 ExecutionContext exe_ctx (GetExecutionContextRef());
1129 Process *process = exe_ctx.GetProcessPtr();
1130 if (process)
1131 {
1132 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1133 size_t bytes_written = process->WriteMemory(target_addr,
1134 data.GetDataStart(),
1135 byte_size,
1136 error);
1137 if (!error.Success())
1138 return false;
1139 if (bytes_written != byte_size)
1140 {
1141 error.SetErrorString("unable to write value to memory");
1142 return false;
1143 }
1144 }
1145 }
1146 break;
1147 case Value::eValueTypeHostAddress:
1148 {
1149 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1150 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1151 m_data.SetData(buffer_sp, 0);
1152 data.CopyByteOrderedData (0,
1153 byte_size,
1154 const_cast<uint8_t *>(m_data.GetDataStart()),
1155 byte_size,
1156 m_data.GetByteOrder());
1157 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1158 }
1159 break;
1160 case Value::eValueTypeFileAddress:
1161 case Value::eValueTypeVector:
1162 break;
1163 }
1164
1165 // If we have reached this point, then we have successfully changed the value.
1166 SetNeedsUpdate();
1167 return true;
1168}
1169
Enrico Granata9128ee22011-09-06 19:20:51 +00001170// will compute strlen(str), but without consuming more than
1171// maxlen bytes out of str (this serves the purpose of reading
1172// chunks of a string without having to worry about
1173// missing NULL terminators in the chunk)
1174// of course, if strlen(str) > maxlen, the function will return
1175// maxlen_value (which should be != maxlen, because that allows you
1176// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1177static uint32_t
1178strlen_or_inf (const char* str,
1179 uint32_t maxlen,
1180 uint32_t maxlen_value)
1181{
1182 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +00001183 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +00001184 {
Greg Clayton8dd5c172011-10-05 22:19:51 +00001185 while(*str)
1186 {
1187 len++;str++;
Greg Clayton2452ab72013-02-08 22:02:02 +00001188 if (len >= maxlen)
Greg Clayton8dd5c172011-10-05 22:19:51 +00001189 return maxlen_value;
1190 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001191 }
1192 return len;
1193}
1194
Enrico Granata2206b482014-10-30 18:27:31 +00001195static bool
1196CopyStringDataToBufferSP(const StreamString& source,
1197 lldb::DataBufferSP& destination)
1198{
1199 destination.reset(new DataBufferHeap(source.GetSize()+1,0));
1200 memcpy(destination->GetBytes(), source.GetString().c_str(), source.GetSize());
1201 return true;
1202}
1203
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001204size_t
Enrico Granata2206b482014-10-30 18:27:31 +00001205ValueObject::ReadPointedString (lldb::DataBufferSP& buffer_sp,
Greg Claytoncc4d0142012-02-17 07:49:44 +00001206 Error& error,
1207 uint32_t max_length,
1208 bool honor_array,
1209 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001210{
Enrico Granata2206b482014-10-30 18:27:31 +00001211 StreamString s;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001212 ExecutionContext exe_ctx (GetExecutionContextRef());
1213 Target* target = exe_ctx.GetTargetPtr();
Enrico Granata2206b482014-10-30 18:27:31 +00001214
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001215 if (!target)
1216 {
1217 s << "<no target to read from>";
1218 error.SetErrorString("no target to read from");
Enrico Granata2206b482014-10-30 18:27:31 +00001219 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001220 return 0;
1221 }
1222
1223 if (max_length == 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001224 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001225
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001226 size_t bytes_read = 0;
1227 size_t total_bytes_read = 0;
1228
Greg Clayton99558cc42015-08-24 23:46:31 +00001229 CompilerType clang_type = GetCompilerType();
Greg Claytona1e5dc82015-08-11 22:53:00 +00001230 CompilerType elem_or_pointee_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001231 const Flags type_flags (GetTypeInfo (&elem_or_pointee_clang_type));
Enrico Granata622be232014-10-21 20:52:14 +00001232 if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Greg Clayton57ee3062013-07-11 22:46:58 +00001233 elem_or_pointee_clang_type.IsCharType ())
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001234 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001235 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1236 AddressType cstr_address_type = eAddressTypeInvalid;
1237
1238 size_t cstr_len = 0;
1239 bool capped_data = false;
Enrico Granata622be232014-10-21 20:52:14 +00001240 if (type_flags.Test (eTypeIsArray))
Greg Claytoncc4d0142012-02-17 07:49:44 +00001241 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001242 // We have an array
Greg Clayton57ee3062013-07-11 22:46:58 +00001243 uint64_t array_size = 0;
1244 if (clang_type.IsArrayType(NULL, &array_size, NULL))
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001245 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001246 cstr_len = array_size;
1247 if (cstr_len > max_length)
1248 {
1249 capped_data = true;
1250 cstr_len = max_length;
1251 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001252 }
1253 cstr_address = GetAddressOf (true, &cstr_address_type);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001254 }
1255 else
1256 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001257 // We have a pointer
1258 cstr_address = GetPointerValue (&cstr_address_type);
1259 }
1260
1261 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1262 {
1263 s << "<invalid address>";
1264 error.SetErrorString("invalid address");
Enrico Granata2206b482014-10-30 18:27:31 +00001265 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001266 return 0;
1267 }
Enrico Granata2206b482014-10-30 18:27:31 +00001268
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001269 Address cstr_so_addr (cstr_address);
1270 DataExtractor data;
1271 if (cstr_len > 0 && honor_array)
1272 {
1273 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1274 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1275 GetPointeeData(data, 0, cstr_len);
Enrico Granata2206b482014-10-30 18:27:31 +00001276
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001277 if ((bytes_read = data.GetByteSize()) > 0)
1278 {
1279 total_bytes_read = bytes_read;
Enrico Granata2206b482014-10-30 18:27:31 +00001280 for (size_t offset = 0; offset < bytes_read; offset++)
1281 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001282 if (capped_data)
1283 s << "...";
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001284 }
1285 }
1286 else
1287 {
1288 cstr_len = max_length;
1289 const size_t k_max_buf_size = 64;
Enrico Granata2206b482014-10-30 18:27:31 +00001290
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001291 size_t offset = 0;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001292
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001293 int cstr_len_displayed = -1;
1294 bool capped_cstr = false;
1295 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1296 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1297 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001298 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001299 total_bytes_read += bytes_read;
1300 const char *cstr = data.PeekCStr(0);
1301 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1302 if (len > k_max_buf_size)
1303 len = k_max_buf_size;
Enrico Granata2206b482014-10-30 18:27:31 +00001304
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001305 if (cstr_len_displayed < 0)
1306 cstr_len_displayed = len;
Enrico Granata2206b482014-10-30 18:27:31 +00001307
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001308 if (len == 0)
1309 break;
1310 cstr_len_displayed += len;
1311 if (len > bytes_read)
1312 len = bytes_read;
1313 if (len > cstr_len)
1314 len = cstr_len;
1315
Enrico Granata2206b482014-10-30 18:27:31 +00001316 for (size_t offset = 0; offset < bytes_read; offset++)
1317 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001318
1319 if (len < k_max_buf_size)
1320 break;
1321
1322 if (len >= cstr_len)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001323 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001324 capped_cstr = true;
1325 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001326 }
Enrico Granata2206b482014-10-30 18:27:31 +00001327
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001328 cstr_len -= len;
1329 offset += len;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001330 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001331
1332 if (cstr_len_displayed >= 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001333 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001334 if (capped_cstr)
1335 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001336 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001337 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001338 }
1339 else
1340 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001341 error.SetErrorString("not a string object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001342 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001343 }
Enrico Granata2206b482014-10-30 18:27:31 +00001344 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001345 return total_bytes_read;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001346}
1347
Enrico Granata744794a2014-09-05 21:46:22 +00001348std::pair<TypeValidatorResult, std::string>
1349ValueObject::GetValidationStatus ()
1350{
1351 if (!UpdateValueIfNeeded(true))
1352 return {TypeValidatorResult::Success,""}; // not the validator's job to discuss update problems
1353
1354 if (m_validation_result.hasValue())
1355 return m_validation_result.getValue();
1356
1357 if (!m_type_validator_sp)
1358 return {TypeValidatorResult::Success,""}; // no validator no failure
1359
1360 auto outcome = m_type_validator_sp->FormatObject(this);
1361
1362 return (m_validation_result = {outcome.m_result,outcome.m_message}).getValue();
1363}
1364
Jim Ingham53c47f12010-09-10 23:12:17 +00001365const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001366ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001367{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001368
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001369 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001370 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001371
1372 if (!m_object_desc_str.empty())
1373 return m_object_desc_str.c_str();
1374
Greg Claytoncc4d0142012-02-17 07:49:44 +00001375 ExecutionContext exe_ctx (GetExecutionContextRef());
1376 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001377 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001378 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001379
Jim Ingham53c47f12010-09-10 23:12:17 +00001380 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001381
Greg Claytonafacd142011-09-02 01:15:17 +00001382 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001383 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1384
Jim Inghama2cf2632010-12-23 02:29:54 +00001385 if (runtime == NULL)
1386 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001387 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Greg Clayton99558cc42015-08-24 23:46:31 +00001388 CompilerType clang_type = GetCompilerType();
Greg Clayton57ee3062013-07-11 22:46:58 +00001389 if (clang_type)
Jim Inghama2cf2632010-12-23 02:29:54 +00001390 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001391 bool is_signed;
Greg Clayton57ee3062013-07-11 22:46:58 +00001392 if (clang_type.IsIntegerType (is_signed) || clang_type.IsPointerType ())
Jim Inghamb7603bb2011-03-18 00:05:18 +00001393 {
Greg Claytonafacd142011-09-02 01:15:17 +00001394 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001395 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001396 }
1397 }
1398
Jim Ingham8d543de2011-03-31 23:01:21 +00001399 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001400 {
1401 m_object_desc_str.append (s.GetData());
1402 }
Sean Callanan672ad942010-10-23 00:18:49 +00001403
1404 if (m_object_desc_str.empty())
1405 return NULL;
1406 else
1407 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001408}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001409
Enrico Granata0c489f52012-03-01 04:24:26 +00001410bool
Enrico Granata4939b982013-12-22 09:24:22 +00001411ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format,
1412 std::string& destination)
1413{
1414 if (UpdateValueIfNeeded(false))
1415 return format.FormatObject(this,destination);
1416 else
1417 return false;
1418}
1419
1420bool
Enrico Granata0c489f52012-03-01 04:24:26 +00001421ValueObject::GetValueAsCString (lldb::Format format,
1422 std::string& destination)
1423{
Enrico Granata30f287f2013-12-28 08:44:02 +00001424 return GetValueAsCString(TypeFormatImpl_Format(format),destination);
Enrico Granata0c489f52012-03-01 04:24:26 +00001425}
1426
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001427const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001428ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001429{
Enrico Granatab294fd22013-05-31 19:18:19 +00001430 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001431 {
Enrico Granata4939b982013-12-22 09:24:22 +00001432 lldb::TypeFormatImplSP format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001433 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001434 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001435 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001436 if (m_type_format_sp)
Enrico Granata4939b982013-12-22 09:24:22 +00001437 format_sp = m_type_format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001438 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001439 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001440 if (m_is_bitfield_for_scalar)
1441 my_format = eFormatUnsigned;
1442 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001443 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001444 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001445 {
1446 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1447 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001448 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001449 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001450 else
1451 {
Greg Clayton99558cc42015-08-24 23:46:31 +00001452 my_format = GetValue().GetCompilerType().GetFormat();
Enrico Granata0c489f52012-03-01 04:24:26 +00001453 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001454 }
1455 }
1456 }
Enrico Granatab294fd22013-05-31 19:18:19 +00001457 if (my_format != m_last_format || m_value_str.empty())
Enrico Granata297e69f2012-03-06 23:21:16 +00001458 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001459 m_last_format = my_format;
Enrico Granata4939b982013-12-22 09:24:22 +00001460 if (!format_sp)
Enrico Granata30f287f2013-12-28 08:44:02 +00001461 format_sp.reset(new TypeFormatImpl_Format(my_format));
Enrico Granata4939b982013-12-22 09:24:22 +00001462 if (GetValueAsCString(*format_sp.get(), m_value_str))
Enrico Granata297e69f2012-03-06 23:21:16 +00001463 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001464 if (!m_value_did_change && m_old_value_valid)
1465 {
1466 // The value was gotten successfully, so we consider the
1467 // value as changed if the value string differs
1468 SetValueDidChange (m_old_value_str != m_value_str);
1469 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001470 }
1471 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001472 }
1473 if (m_value_str.empty())
1474 return NULL;
1475 return m_value_str.c_str();
1476}
1477
Enrico Granatac3e320a2011-08-02 17:27:39 +00001478// if > 8bytes, 0 is returned. this method should mostly be used
1479// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001480uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001481ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001482{
1483 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001484 if (CanProvideValue())
Enrico Granatac3e320a2011-08-02 17:27:39 +00001485 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001486 Scalar scalar;
1487 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001488 {
1489 if (success)
1490 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001491 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001492 }
1493 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001494 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001495
1496 if (success)
1497 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001498 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001499}
1500
Enrico Granatad7373f62013-10-31 18:57:50 +00001501int64_t
1502ValueObject::GetValueAsSigned (int64_t fail_value, bool *success)
1503{
1504 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001505 if (CanProvideValue())
Enrico Granatad7373f62013-10-31 18:57:50 +00001506 {
1507 Scalar scalar;
1508 if (ResolveValue (scalar))
1509 {
1510 if (success)
1511 *success = true;
Tamas Berghammer5a9919f2015-01-23 10:54:21 +00001512 return scalar.SLongLong(fail_value);
Enrico Granatad7373f62013-10-31 18:57:50 +00001513 }
1514 // fallthrough, otherwise...
1515 }
1516
1517 if (success)
1518 *success = false;
Tamas Berghammer5a9919f2015-01-23 10:54:21 +00001519 return fail_value;
Enrico Granatad7373f62013-10-31 18:57:50 +00001520}
1521
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001522// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1523// this call up to date by returning true for your new special cases. We will eventually move
1524// to checking this call result before trying to display special cases
1525bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001526ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1527 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001528{
Greg Clayton57ee3062013-07-11 22:46:58 +00001529 Flags flags(GetTypeInfo());
Enrico Granata622be232014-10-21 20:52:14 +00001530 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001531 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001532 {
1533 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001534 (custom_format == eFormatCString ||
1535 custom_format == eFormatCharArray ||
1536 custom_format == eFormatChar ||
1537 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001538 return true;
1539
Enrico Granata622be232014-10-21 20:52:14 +00001540 if (flags.Test(eTypeIsArray))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001541 {
Greg Claytonafacd142011-09-02 01:15:17 +00001542 if ((custom_format == eFormatBytes) ||
1543 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001544 return true;
1545
Greg Claytonafacd142011-09-02 01:15:17 +00001546 if ((custom_format == eFormatVectorOfChar) ||
1547 (custom_format == eFormatVectorOfFloat32) ||
1548 (custom_format == eFormatVectorOfFloat64) ||
1549 (custom_format == eFormatVectorOfSInt16) ||
1550 (custom_format == eFormatVectorOfSInt32) ||
1551 (custom_format == eFormatVectorOfSInt64) ||
1552 (custom_format == eFormatVectorOfSInt8) ||
1553 (custom_format == eFormatVectorOfUInt128) ||
1554 (custom_format == eFormatVectorOfUInt16) ||
1555 (custom_format == eFormatVectorOfUInt32) ||
1556 (custom_format == eFormatVectorOfUInt64) ||
1557 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001558 return true;
1559 }
1560 }
1561 return false;
1562}
1563
Enrico Granata9fc19442011-07-06 02:13:41 +00001564bool
1565ValueObject::DumpPrintableRepresentation(Stream& s,
1566 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001567 Format custom_format,
Enrico Granata0dba9b32014-01-08 01:36:59 +00001568 PrintableRepresentationSpecialCases special,
1569 bool do_dump_error)
Enrico Granata9fc19442011-07-06 02:13:41 +00001570{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001571
Greg Clayton57ee3062013-07-11 22:46:58 +00001572 Flags flags(GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001573
Enrico Granata86cc9822012-03-19 22:58:49 +00001574 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1575 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1576
1577 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001578 {
Enrico Granata622be232014-10-21 20:52:14 +00001579 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001580 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001581 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001582 // when being asked to get a printable display an array or pointer type directly,
1583 // try to "do the right thing"
1584
1585 if (IsCStringContainer(true) &&
1586 (custom_format == eFormatCString ||
1587 custom_format == eFormatCharArray ||
1588 custom_format == eFormatChar ||
1589 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001590 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001591 Error error;
Enrico Granata2206b482014-10-30 18:27:31 +00001592 lldb::DataBufferSP buffer_sp;
1593 ReadPointedString(buffer_sp,
Enrico Granata86cc9822012-03-19 22:58:49 +00001594 error,
1595 0,
1596 (custom_format == eFormatVectorOfChar) ||
1597 (custom_format == eFormatCharArray));
Enrico Granataebdc1ac2014-11-05 21:20:48 +00001598 lldb_private::formatters::ReadBufferAndDumpToStreamOptions options(*this);
Enrico Granata2206b482014-10-30 18:27:31 +00001599 options.SetData(DataExtractor(buffer_sp, lldb::eByteOrderInvalid, 8)); // none of this matters for a string - pass some defaults
1600 options.SetStream(&s);
1601 options.SetPrefixToken(0);
1602 options.SetQuote('"');
1603 options.SetSourceSize(buffer_sp->GetByteSize());
Enrico Granata2206b482014-10-30 18:27:31 +00001604 lldb_private::formatters::ReadBufferAndDumpToStream<lldb_private::formatters::StringElementType::ASCII>(options);
Enrico Granata86cc9822012-03-19 22:58:49 +00001605 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001606 }
1607
Enrico Granata86cc9822012-03-19 22:58:49 +00001608 if (custom_format == eFormatEnum)
1609 return false;
1610
1611 // this only works for arrays, because I have no way to know when
1612 // the pointed memory ends, and no special \0 end of data marker
Enrico Granata622be232014-10-21 20:52:14 +00001613 if (flags.Test(eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001614 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001615 if ((custom_format == eFormatBytes) ||
1616 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001617 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001618 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001619
1620 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001621 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001622 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001623
1624 if (low)
1625 s << ',';
1626
1627 ValueObjectSP child = GetChildAtIndex(low,true);
1628 if (!child.get())
1629 {
1630 s << "<invalid child>";
1631 continue;
1632 }
1633 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1634 }
1635
1636 s << ']';
1637
1638 return true;
1639 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001640
Enrico Granata86cc9822012-03-19 22:58:49 +00001641 if ((custom_format == eFormatVectorOfChar) ||
1642 (custom_format == eFormatVectorOfFloat32) ||
1643 (custom_format == eFormatVectorOfFloat64) ||
1644 (custom_format == eFormatVectorOfSInt16) ||
1645 (custom_format == eFormatVectorOfSInt32) ||
1646 (custom_format == eFormatVectorOfSInt64) ||
1647 (custom_format == eFormatVectorOfSInt8) ||
1648 (custom_format == eFormatVectorOfUInt128) ||
1649 (custom_format == eFormatVectorOfUInt16) ||
1650 (custom_format == eFormatVectorOfUInt32) ||
1651 (custom_format == eFormatVectorOfUInt64) ||
1652 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1653 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001654 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001655
1656 Format format = FormatManager::GetSingleItemFormat(custom_format);
1657
1658 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001659 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001660 {
1661
1662 if (low)
1663 s << ',';
1664
1665 ValueObjectSP child = GetChildAtIndex(low,true);
1666 if (!child.get())
1667 {
1668 s << "<invalid child>";
1669 continue;
1670 }
1671 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1672 }
1673
1674 s << ']';
1675
1676 return true;
1677 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001678 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001679
1680 if ((custom_format == eFormatBoolean) ||
1681 (custom_format == eFormatBinary) ||
1682 (custom_format == eFormatChar) ||
1683 (custom_format == eFormatCharPrintable) ||
1684 (custom_format == eFormatComplexFloat) ||
1685 (custom_format == eFormatDecimal) ||
1686 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001687 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001688 (custom_format == eFormatFloat) ||
1689 (custom_format == eFormatOctal) ||
1690 (custom_format == eFormatOSType) ||
1691 (custom_format == eFormatUnicode16) ||
1692 (custom_format == eFormatUnicode32) ||
1693 (custom_format == eFormatUnsigned) ||
1694 (custom_format == eFormatPointer) ||
1695 (custom_format == eFormatComplexInteger) ||
1696 (custom_format == eFormatComplex) ||
1697 (custom_format == eFormatDefault)) // use the [] operator
1698 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001699 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001700 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001701
1702 if (only_special)
1703 return false;
1704
Enrico Granata86cc9822012-03-19 22:58:49 +00001705 bool var_success = false;
1706
1707 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001708 const char *cstr = NULL;
Enrico Granata2c75f112013-06-21 00:04:51 +00001709
1710 // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1711 // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1712 // area for cases where our desired output is not backed by some other longer-term storage
Greg Claytonc7bece562013-01-25 18:06:21 +00001713 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001714
Enrico Granata465f4bc2014-02-15 01:24:44 +00001715 if (custom_format != eFormatInvalid)
Enrico Granata86cc9822012-03-19 22:58:49 +00001716 SetFormat(custom_format);
1717
1718 switch(val_obj_display)
1719 {
1720 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001721 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001722 break;
1723
1724 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001725 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001726 break;
1727
1728 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001729 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001730 break;
1731
1732 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001733 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001734 break;
1735
1736 case eValueObjectRepresentationStyleChildrenCount:
Deepak Panickal99fbc072014-03-03 15:39:47 +00001737 strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren());
Greg Claytonc7bece562013-01-25 18:06:21 +00001738 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001739 break;
1740
1741 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001742 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001743 break;
Enrico Granata2c75f112013-06-21 00:04:51 +00001744
1745 case eValueObjectRepresentationStyleName:
1746 cstr = GetName().AsCString();
1747 break;
1748
1749 case eValueObjectRepresentationStyleExpressionPath:
1750 GetExpressionPath(strm, false);
1751 cstr = strm.GetString().c_str();
1752 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001753 }
1754
Greg Claytonc7bece562013-01-25 18:06:21 +00001755 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001756 {
1757 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001758 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001759 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1760 {
Enrico Granatad07cfd32014-10-08 18:27:36 +00001761 if (!CanProvideValue())
Enrico Granata86cc9822012-03-19 22:58:49 +00001762 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001763 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1764 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001765 }
1766 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001767 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001768 }
1769 }
1770
Greg Claytonc7bece562013-01-25 18:06:21 +00001771 if (cstr)
1772 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001773 else
1774 {
1775 if (m_error.Fail())
Enrico Granata0dba9b32014-01-08 01:36:59 +00001776 {
1777 if (do_dump_error)
1778 s.Printf("<%s>", m_error.AsCString());
1779 else
1780 return false;
1781 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001782 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1783 s.PutCString("<no summary available>");
1784 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1785 s.PutCString("<no value available>");
1786 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1787 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1788 else
1789 s.PutCString("<no printable representation>");
1790 }
1791
1792 // we should only return false here if we could not do *anything*
1793 // even if we have an error message as output, that's a success
1794 // from our callers' perspective, so return true
1795 var_success = true;
Enrico Granata465f4bc2014-02-15 01:24:44 +00001796
1797 if (custom_format != eFormatInvalid)
1798 SetFormat(eFormatDefault);
Enrico Granata86cc9822012-03-19 22:58:49 +00001799 }
1800
Enrico Granataf4efecd2011-07-12 22:56:10 +00001801 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001802}
1803
Greg Clayton737b9322010-09-13 03:32:57 +00001804addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001805ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001806{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001807 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001808 return LLDB_INVALID_ADDRESS;
1809
Greg Clayton73b472d2010-10-27 03:32:59 +00001810 switch (m_value.GetValueType())
1811 {
1812 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001813 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001814 if (scalar_is_load_address)
1815 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001816 if(address_type)
1817 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001818 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1819 }
1820 break;
1821
1822 case Value::eValueTypeLoadAddress:
1823 case Value::eValueTypeFileAddress:
Greg Clayton73b472d2010-10-27 03:32:59 +00001824 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001825 if(address_type)
1826 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001827 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1828 }
1829 break;
Siva Chandraa3747a92015-05-04 19:43:34 +00001830 case Value::eValueTypeHostAddress:
Siva Chandrae32f2b52015-05-05 00:41:35 +00001831 {
1832 if(address_type)
1833 *address_type = m_value.GetValueAddressType ();
1834 return LLDB_INVALID_ADDRESS;
1835 }
Siva Chandraa3747a92015-05-04 19:43:34 +00001836 break;
Greg Clayton73b472d2010-10-27 03:32:59 +00001837 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001838 if (address_type)
1839 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001840 return LLDB_INVALID_ADDRESS;
1841}
1842
1843addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001844ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001845{
Greg Claytonafacd142011-09-02 01:15:17 +00001846 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001847 if(address_type)
1848 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001849
Enrico Granatac3e320a2011-08-02 17:27:39 +00001850 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001851 return address;
1852
Greg Clayton73b472d2010-10-27 03:32:59 +00001853 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001854 {
1855 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001856 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001857 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001858 break;
1859
Enrico Granata9128ee22011-09-06 19:20:51 +00001860 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001861 case Value::eValueTypeLoadAddress:
1862 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001863 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001864 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001865 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001866 }
1867 break;
1868 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001869
Enrico Granata9128ee22011-09-06 19:20:51 +00001870 if (address_type)
1871 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001872
Greg Clayton737b9322010-09-13 03:32:57 +00001873 return address;
1874}
1875
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001876bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001877ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001878{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001879 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001880 // Make sure our value is up to date first so that our location and location
1881 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001882 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001883 {
1884 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001885 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001886 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001887
Greg Claytonfaac1112013-03-14 18:31:44 +00001888 uint64_t count = 0;
Greg Clayton99558cc42015-08-24 23:46:31 +00001889 const Encoding encoding = GetCompilerType().GetEncoding (count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001890
Greg Claytonb1320972010-07-14 00:18:15 +00001891 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001892
Jim Ingham16e0c682011-08-12 23:34:31 +00001893 Value::ValueType value_type = m_value.GetValueType();
1894
1895 if (value_type == Value::eValueTypeScalar)
1896 {
1897 // If the value is already a scalar, then let the scalar change itself:
1898 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1899 }
Sagar Thakur8536fd12015-08-20 09:12:46 +00001900 else if (byte_size <= 16)
Jim Ingham16e0c682011-08-12 23:34:31 +00001901 {
1902 // If the value fits in a scalar, then make a new scalar and again let the
1903 // scalar code do the conversion, then figure out where to put the new value.
1904 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001905 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1906 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001907 {
Jim Ingham4b536182011-08-09 02:12:22 +00001908 switch (value_type)
1909 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001910 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001911 {
1912 // If it is a load address, then the scalar value is the storage location
1913 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001914 ExecutionContext exe_ctx (GetExecutionContextRef());
1915 Process *process = exe_ctx.GetProcessPtr();
1916 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001917 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001918 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001919 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1920 new_scalar,
1921 byte_size,
1922 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001923 if (!error.Success())
1924 return false;
1925 if (bytes_written != byte_size)
1926 {
1927 error.SetErrorString("unable to write value to memory");
1928 return false;
1929 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001930 }
1931 }
Jim Ingham4b536182011-08-09 02:12:22 +00001932 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001933 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001934 {
1935 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1936 DataExtractor new_data;
1937 new_data.SetByteOrder (m_data.GetByteOrder());
1938
1939 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1940 m_data.SetData(buffer_sp, 0);
1941 bool success = new_scalar.GetData(new_data);
1942 if (success)
1943 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001944 new_data.CopyByteOrderedData (0,
1945 byte_size,
1946 const_cast<uint8_t *>(m_data.GetDataStart()),
1947 byte_size,
1948 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001949 }
1950 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1951
1952 }
Jim Ingham4b536182011-08-09 02:12:22 +00001953 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001954 case Value::eValueTypeFileAddress:
1955 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001956 case Value::eValueTypeVector:
1957 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001958 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001959 }
1960 else
1961 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001962 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001963 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001964 }
1965 else
1966 {
1967 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001968 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001969 return false;
1970 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001971
1972 // If we have reached this point, then we have successfully changed the value.
1973 SetNeedsUpdate();
1974 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001975}
1976
Greg Clayton81e871e2012-02-04 02:27:34 +00001977bool
1978ValueObject::GetDeclaration (Declaration &decl)
1979{
1980 decl.Clear();
1981 return false;
1982}
1983
Greg Clayton84db9102012-03-26 23:03:23 +00001984ConstString
1985ValueObject::GetTypeName()
1986{
Greg Clayton99558cc42015-08-24 23:46:31 +00001987 return GetCompilerType().GetConstTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00001988}
1989
1990ConstString
Enrico Granatae8daa2f2014-05-17 19:14:17 +00001991ValueObject::GetDisplayTypeName()
1992{
1993 return GetTypeName();
1994}
1995
1996ConstString
Greg Clayton84db9102012-03-26 23:03:23 +00001997ValueObject::GetQualifiedTypeName()
1998{
Greg Clayton99558cc42015-08-24 23:46:31 +00001999 return GetCompilerType().GetConstQualifiedTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00002000}
2001
2002
Greg Claytonafacd142011-09-02 01:15:17 +00002003LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00002004ValueObject::GetObjectRuntimeLanguage ()
2005{
Greg Clayton99558cc42015-08-24 23:46:31 +00002006 return GetCompilerType().GetMinimumLanguage ();
Jim Ingham5a369122010-09-28 01:25:32 +00002007}
2008
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002009void
Jim Ingham58b59f92011-04-22 23:53:53 +00002010ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002011{
Jim Ingham58b59f92011-04-22 23:53:53 +00002012 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002013}
2014
2015ValueObjectSP
2016ValueObject::GetSyntheticChild (const ConstString &key) const
2017{
2018 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00002019 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002020 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00002021 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002022 return synthetic_child_sp;
2023}
2024
Greg Clayton2452ab72013-02-08 22:02:02 +00002025uint32_t
Greg Claytona1e5dc82015-08-11 22:53:00 +00002026ValueObject::GetTypeInfo (CompilerType *pointee_or_element_clang_type)
Greg Clayton2452ab72013-02-08 22:02:02 +00002027{
Greg Clayton99558cc42015-08-24 23:46:31 +00002028 return GetCompilerType().GetTypeInfo (pointee_or_element_clang_type);
Greg Clayton2452ab72013-02-08 22:02:02 +00002029}
2030
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002031bool
2032ValueObject::IsPointerType ()
2033{
Greg Clayton99558cc42015-08-24 23:46:31 +00002034 return GetCompilerType().IsPointerType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002035}
2036
Jim Inghamb7603bb2011-03-18 00:05:18 +00002037bool
Greg Claytondaf515f2011-07-09 20:12:33 +00002038ValueObject::IsArrayType ()
2039{
Greg Clayton99558cc42015-08-24 23:46:31 +00002040 return GetCompilerType().IsArrayType (NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00002041}
2042
2043bool
Enrico Granata9fc19442011-07-06 02:13:41 +00002044ValueObject::IsScalarType ()
2045{
Greg Clayton99558cc42015-08-24 23:46:31 +00002046 return GetCompilerType().IsScalarType ();
Enrico Granata9fc19442011-07-06 02:13:41 +00002047}
2048
2049bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00002050ValueObject::IsIntegerType (bool &is_signed)
2051{
Greg Clayton99558cc42015-08-24 23:46:31 +00002052 return GetCompilerType().IsIntegerType (is_signed);
Jim Inghamb7603bb2011-03-18 00:05:18 +00002053}
Greg Clayton73b472d2010-10-27 03:32:59 +00002054
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002055bool
2056ValueObject::IsPointerOrReferenceType ()
2057{
Greg Clayton99558cc42015-08-24 23:46:31 +00002058 return GetCompilerType().IsPointerOrReferenceType ();
Greg Clayton007d5be2011-05-30 00:49:24 +00002059}
2060
2061bool
Greg Claytondea8cb42011-06-29 22:09:02 +00002062ValueObject::IsPossibleDynamicType ()
2063{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002064 ExecutionContext exe_ctx (GetExecutionContextRef());
2065 Process *process = exe_ctx.GetProcessPtr();
2066 if (process)
2067 return process->IsPossibleDynamicValue(*this);
2068 else
Greg Clayton99558cc42015-08-24 23:46:31 +00002069 return GetCompilerType().IsPossibleDynamicType (NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00002070}
2071
Enrico Granata9e7b3882012-12-13 23:50:33 +00002072bool
Enrico Granata560558e2015-02-11 02:35:39 +00002073ValueObject::IsRuntimeSupportValue ()
2074{
2075 Process *process(GetProcessSP().get());
2076 if (process)
2077 {
2078 LanguageRuntime *runtime = process->GetLanguageRuntime(GetObjectRuntimeLanguage());
2079 if (!runtime)
2080 runtime = process->GetObjCLanguageRuntime();
2081 if (runtime)
2082 return runtime->IsRuntimeSupportValue(*this);
2083 }
2084 return false;
2085}
2086
2087bool
Enrico Granata9e7b3882012-12-13 23:50:33 +00002088ValueObject::IsObjCNil ()
2089{
Enrico Granata622be232014-10-21 20:52:14 +00002090 const uint32_t mask = eTypeIsObjC | eTypeIsPointer;
Greg Clayton99558cc42015-08-24 23:46:31 +00002091 bool isObjCpointer = (((GetCompilerType().GetTypeInfo(NULL)) & mask) == mask);
Enrico Granata7277d202013-03-15 23:33:15 +00002092 if (!isObjCpointer)
2093 return false;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002094 bool canReadValue = true;
2095 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
Enrico Granata7277d202013-03-15 23:33:15 +00002096 return canReadValue && isZero;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002097}
2098
Greg Claytondaf515f2011-07-09 20:12:33 +00002099// This allows you to create an array member using and index
2100// that doesn't not fall in the normal bounds of the array.
2101// Many times structure can be defined as:
2102// struct Collection
2103// {
2104// uint32_t item_count;
2105// Item item_array[0];
2106// };
2107// The size of the "item_array" is 1, but many times in practice
2108// there are more items in "item_array".
2109
2110ValueObjectSP
Bruce Mitchener11d86362015-02-26 23:55:39 +00002111ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00002112{
2113 ValueObjectSP synthetic_child_sp;
Bruce Mitchener11d86362015-02-26 23:55:39 +00002114 if (IsPointerType () || IsArrayType())
Greg Claytondaf515f2011-07-09 20:12:33 +00002115 {
2116 char index_str[64];
Deepak Panickal99fbc072014-03-03 15:39:47 +00002117 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
Greg Claytondaf515f2011-07-09 20:12:33 +00002118 ConstString index_const_str(index_str);
2119 // Check if we have already created a synthetic array member in this
2120 // valid object. If we have we will re-use it.
2121 synthetic_child_sp = GetSyntheticChild (index_const_str);
2122 if (!synthetic_child_sp)
2123 {
2124 ValueObject *synthetic_child;
2125 // We haven't made a synthetic array member for INDEX yet, so
2126 // lets make one and cache it for any future reference.
2127 synthetic_child = CreateChildAtIndex(0, true, index);
Bruce Mitchener11d86362015-02-26 23:55:39 +00002128
Greg Claytondaf515f2011-07-09 20:12:33 +00002129 // Cache the value if we got one back...
2130 if (synthetic_child)
2131 {
2132 AddSyntheticChild(index_const_str, synthetic_child);
2133 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002134 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00002135 synthetic_child_sp->m_is_array_item_for_pointer = true;
2136 }
2137 }
2138 }
2139 return synthetic_child_sp;
2140}
2141
Enrico Granata9fc19442011-07-06 02:13:41 +00002142ValueObjectSP
2143ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2144{
2145 ValueObjectSP synthetic_child_sp;
2146 if (IsScalarType ())
2147 {
2148 char index_str[64];
2149 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2150 ConstString index_const_str(index_str);
2151 // Check if we have already created a synthetic array member in this
2152 // valid object. If we have we will re-use it.
2153 synthetic_child_sp = GetSyntheticChild (index_const_str);
2154 if (!synthetic_child_sp)
2155 {
Enrico Granata9fc19442011-07-06 02:13:41 +00002156 // We haven't made a synthetic array member for INDEX yet, so
2157 // lets make one and cache it for any future reference.
Greg Clayton57ee3062013-07-11 22:46:58 +00002158 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
Greg Clayton99558cc42015-08-24 23:46:31 +00002159 GetCompilerType(),
Greg Clayton57ee3062013-07-11 22:46:58 +00002160 index_const_str,
2161 GetByteSize(),
2162 0,
2163 to-from+1,
2164 from,
2165 false,
2166 false,
2167 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002168
2169 // Cache the value if we got one back...
2170 if (synthetic_child)
2171 {
2172 AddSyntheticChild(index_const_str, synthetic_child);
2173 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002174 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002175 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2176 }
2177 }
2178 }
2179 return synthetic_child_sp;
2180}
2181
Greg Claytonafacd142011-09-02 01:15:17 +00002182ValueObjectSP
Greg Claytona1e5dc82015-08-11 22:53:00 +00002183ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const CompilerType& type, bool can_create)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002184{
2185
2186 ValueObjectSP synthetic_child_sp;
2187
2188 char name_str[64];
2189 snprintf(name_str, sizeof(name_str), "@%i", offset);
2190 ConstString name_const_str(name_str);
2191
2192 // Check if we have already created a synthetic array member in this
2193 // valid object. If we have we will re-use it.
2194 synthetic_child_sp = GetSyntheticChild (name_const_str);
2195
2196 if (synthetic_child_sp.get())
2197 return synthetic_child_sp;
2198
2199 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002200 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002201
Enrico Granata951bdd52015-01-28 01:09:45 +00002202 ExecutionContext exe_ctx (GetExecutionContextRef());
2203
Enrico Granata6f3533f2011-07-29 19:53:35 +00002204 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
Greg Clayton57ee3062013-07-11 22:46:58 +00002205 type,
Enrico Granata6f3533f2011-07-29 19:53:35 +00002206 name_const_str,
Greg Clayton526ae042015-02-12 00:34:25 +00002207 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
Enrico Granata6f3533f2011-07-29 19:53:35 +00002208 offset,
2209 0,
2210 0,
2211 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002212 false,
2213 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002214 if (synthetic_child)
2215 {
2216 AddSyntheticChild(name_const_str, synthetic_child);
2217 synthetic_child_sp = synthetic_child->GetSP();
2218 synthetic_child_sp->SetName(name_const_str);
2219 synthetic_child_sp->m_is_child_at_offset = true;
2220 }
2221 return synthetic_child_sp;
2222}
2223
Enrico Granata32556cd2014-08-26 20:54:04 +00002224ValueObjectSP
Greg Claytona1e5dc82015-08-11 22:53:00 +00002225ValueObject::GetSyntheticBase (uint32_t offset, const CompilerType& type, bool can_create)
Enrico Granata32556cd2014-08-26 20:54:04 +00002226{
2227 ValueObjectSP synthetic_child_sp;
2228
2229 char name_str[64];
2230 snprintf(name_str, sizeof(name_str), "%s", type.GetTypeName().AsCString("<unknown>"));
2231 ConstString name_const_str(name_str);
2232
2233 // Check if we have already created a synthetic array member in this
2234 // valid object. If we have we will re-use it.
2235 synthetic_child_sp = GetSyntheticChild (name_const_str);
2236
2237 if (synthetic_child_sp.get())
2238 return synthetic_child_sp;
2239
2240 if (!can_create)
2241 return ValueObjectSP();
2242
Enrico Granata32556cd2014-08-26 20:54:04 +00002243 const bool is_base_class = true;
2244
Enrico Granata951bdd52015-01-28 01:09:45 +00002245 ExecutionContext exe_ctx (GetExecutionContextRef());
2246
Enrico Granata32556cd2014-08-26 20:54:04 +00002247 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2248 type,
2249 name_const_str,
Greg Clayton526ae042015-02-12 00:34:25 +00002250 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
Enrico Granata32556cd2014-08-26 20:54:04 +00002251 offset,
2252 0,
2253 0,
2254 is_base_class,
2255 false,
2256 eAddressTypeInvalid);
2257 if (synthetic_child)
2258 {
2259 AddSyntheticChild(name_const_str, synthetic_child);
2260 synthetic_child_sp = synthetic_child->GetSP();
2261 synthetic_child_sp->SetName(name_const_str);
2262 }
2263 return synthetic_child_sp;
2264}
2265
2266
Enrico Granatad55546b2011-07-22 00:16:08 +00002267// your expression path needs to have a leading . or ->
2268// (unless it somehow "looks like" an array, in which case it has
2269// a leading [ symbol). while the [ is meaningful and should be shown
2270// to the user, . and -> are just parser design, but by no means
2271// added information for the user.. strip them off
2272static const char*
2273SkipLeadingExpressionPathSeparators(const char* expression)
2274{
2275 if (!expression || !expression[0])
2276 return expression;
2277 if (expression[0] == '.')
2278 return expression+1;
2279 if (expression[0] == '-' && expression[1] == '>')
2280 return expression+2;
2281 return expression;
2282}
2283
Greg Claytonafacd142011-09-02 01:15:17 +00002284ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002285ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2286{
2287 ValueObjectSP synthetic_child_sp;
2288 ConstString name_const_string(expression);
2289 // Check if we have already created a synthetic array member in this
2290 // valid object. If we have we will re-use it.
2291 synthetic_child_sp = GetSyntheticChild (name_const_string);
2292 if (!synthetic_child_sp)
2293 {
2294 // We haven't made a synthetic array member for expression yet, so
2295 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002296 synthetic_child_sp = GetValueForExpressionPath(expression,
2297 NULL, NULL, NULL,
Enrico Granataef238c12015-03-12 22:30:58 +00002298 GetValueForExpressionPathOptions().SetSyntheticChildrenTraversal(GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None));
Enrico Granatad55546b2011-07-22 00:16:08 +00002299
2300 // Cache the value if we got one back...
2301 if (synthetic_child_sp.get())
2302 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002303 // 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 +00002304 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002305 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002306 }
2307 }
2308 return synthetic_child_sp;
2309}
2310
2311void
Enrico Granata86cc9822012-03-19 22:58:49 +00002312ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002313{
Enrico Granata86cc9822012-03-19 22:58:49 +00002314 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002315 return;
2316
Enrico Granatac5bc4122012-03-27 02:35:13 +00002317 TargetSP target_sp(GetTargetSP());
Enrico Granata5d5f60c2013-09-24 22:58:37 +00002318 if (target_sp && target_sp->GetEnableSyntheticValue() == false)
Enrico Granatac5bc4122012-03-27 02:35:13 +00002319 {
2320 m_synthetic_value = NULL;
2321 return;
2322 }
2323
Enrico Granatae3e91512012-10-22 18:18:36 +00002324 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2325
Enrico Granata5548cb52013-01-28 23:47:25 +00002326 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002327 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002328
Enrico Granata0c489f52012-03-01 04:24:26 +00002329 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002330 return;
2331
Enrico Granatae3e91512012-10-22 18:18:36 +00002332 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2333 return;
2334
Enrico Granata86cc9822012-03-19 22:58:49 +00002335 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002336}
2337
Jim Ingham78a685a2011-04-16 00:01:13 +00002338void
Greg Claytonafacd142011-09-02 01:15:17 +00002339ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002340{
Greg Claytonafacd142011-09-02 01:15:17 +00002341 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002342 return;
2343
Jim Ingham58b59f92011-04-22 23:53:53 +00002344 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002345 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002346 ExecutionContext exe_ctx (GetExecutionContextRef());
2347 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002348 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002349 {
2350 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002351 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002352 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002353 }
2354}
2355
Jim Ingham58b59f92011-04-22 23:53:53 +00002356ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002357ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002358{
Greg Claytonafacd142011-09-02 01:15:17 +00002359 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002360 return ValueObjectSP();
2361
2362 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002363 {
Jim Ingham2837b762011-05-04 03:43:18 +00002364 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002365 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002366 if (m_dynamic_value)
2367 return m_dynamic_value->GetSP();
2368 else
2369 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002370}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002371
Jim Ingham60dbabb2011-12-08 19:44:08 +00002372ValueObjectSP
2373ValueObject::GetStaticValue()
2374{
2375 return GetSP();
2376}
2377
Enrico Granata886147f2012-05-08 18:47:08 +00002378lldb::ValueObjectSP
2379ValueObject::GetNonSyntheticValue ()
2380{
2381 return GetSP();
2382}
2383
Enrico Granatad55546b2011-07-22 00:16:08 +00002384ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002385ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002386{
Enrico Granata86cc9822012-03-19 22:58:49 +00002387 if (use_synthetic == false)
2388 return ValueObjectSP();
2389
Enrico Granatad55546b2011-07-22 00:16:08 +00002390 CalculateSyntheticValue(use_synthetic);
2391
2392 if (m_synthetic_value)
2393 return m_synthetic_value->GetSP();
2394 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002395 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002396}
2397
Greg Claytone221f822011-01-21 01:59:00 +00002398bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002399ValueObject::HasSyntheticValue()
2400{
Enrico Granata5548cb52013-01-28 23:47:25 +00002401 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002402
Enrico Granata0c489f52012-03-01 04:24:26 +00002403 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002404 return false;
2405
Enrico Granata86cc9822012-03-19 22:58:49 +00002406 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002407
2408 if (m_synthetic_value)
2409 return true;
2410 else
2411 return false;
2412}
2413
2414bool
Greg Claytone221f822011-01-21 01:59:00 +00002415ValueObject::GetBaseClassPath (Stream &s)
2416{
2417 if (IsBaseClass())
2418 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002419 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Clayton99558cc42015-08-24 23:46:31 +00002420 CompilerType clang_type = GetCompilerType();
Greg Claytone221f822011-01-21 01:59:00 +00002421 std::string cxx_class_name;
Greg Claytond8d4a572015-08-11 21:38:15 +00002422 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
Greg Claytone221f822011-01-21 01:59:00 +00002423 if (this_had_base_class)
2424 {
2425 if (parent_had_base_class)
2426 s.PutCString("::");
2427 s.PutCString(cxx_class_name.c_str());
2428 }
2429 return parent_had_base_class || this_had_base_class;
2430 }
2431 return false;
2432}
2433
2434
2435ValueObject *
2436ValueObject::GetNonBaseClassParent()
2437{
Jim Ingham78a685a2011-04-16 00:01:13 +00002438 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002439 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002440 if (GetParent()->IsBaseClass())
2441 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002442 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002443 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002444 }
2445 return NULL;
2446}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002447
Enrico Granataa3c8f042014-08-19 22:29:08 +00002448
2449bool
2450ValueObject::IsBaseClass (uint32_t& depth)
2451{
2452 if (!IsBaseClass())
2453 {
2454 depth = 0;
2455 return false;
2456 }
2457 if (GetParent())
2458 {
2459 GetParent()->IsBaseClass(depth);
2460 depth = depth + 1;
2461 return true;
2462 }
2463 // TODO: a base of no parent? weird..
2464 depth = 1;
2465 return true;
2466}
2467
Greg Clayton1d3afba2010-10-05 00:00:42 +00002468void
Enrico Granata4becb372011-06-29 22:27:15 +00002469ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002470{
Enrico Granata986fa5f2014-12-09 21:41:16 +00002471 // synthetic children do not actually "exist" as part of the hierarchy, and sometimes they are consed up in ways
2472 // that don't make sense from an underlying language/API standpoint. So, use a special code path here to return
2473 // something that can hopefully be used in expression
2474 if (m_is_synthetic_children_generated)
2475 {
2476 UpdateValueIfNeeded();
2477
2478 if (m_value.GetValueType() == Value::eValueTypeLoadAddress)
2479 {
2480 if (IsPointerOrReferenceType())
2481 {
2482 s.Printf("((%s)0x%" PRIx64 ")",
2483 GetTypeName().AsCString("void"),
2484 GetValueAsUnsigned(0));
2485 return;
2486 }
2487 else
2488 {
2489 uint64_t load_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
2490 if (load_addr != LLDB_INVALID_ADDRESS)
2491 {
2492 s.Printf("(*( (%s *)0x%" PRIx64 "))",
2493 GetTypeName().AsCString("void"),
2494 load_addr);
2495 return;
2496 }
2497 }
2498 }
2499
2500 if (CanProvideValue())
2501 {
2502 s.Printf("((%s)%s)",
2503 GetTypeName().AsCString("void"),
2504 GetValueAsCString());
2505 return;
2506 }
2507
2508 return;
2509 }
2510
Greg Claytone221f822011-01-21 01:59:00 +00002511 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002512
Enrico Granata86cc9822012-03-19 22:58:49 +00002513 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002514 {
Enrico Granata4becb372011-06-29 22:27:15 +00002515 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2516 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2517 // the eHonorPointers mode is meant to produce strings in this latter format
2518 s.PutCString("*(");
2519 }
Greg Claytone221f822011-01-21 01:59:00 +00002520
Enrico Granata4becb372011-06-29 22:27:15 +00002521 ValueObject* parent = GetParent();
2522
2523 if (parent)
2524 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002525
2526 // if we are a deref_of_parent just because we are synthetic array
2527 // members made up to allow ptr[%d] syntax to work in variable
2528 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002529 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002530 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002531
Greg Claytone221f822011-01-21 01:59:00 +00002532 if (!IsBaseClass())
2533 {
2534 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002535 {
Greg Claytone221f822011-01-21 01:59:00 +00002536 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2537 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002538 {
Greg Clayton99558cc42015-08-24 23:46:31 +00002539 CompilerType non_base_class_parent_clang_type = non_base_class_parent->GetCompilerType();
Greg Claytone221f822011-01-21 01:59:00 +00002540 if (non_base_class_parent_clang_type)
2541 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002542 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002543 {
2544 s.PutCString("->");
2545 }
Enrico Granata4becb372011-06-29 22:27:15 +00002546 else
2547 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002548 const uint32_t non_base_class_parent_type_info = non_base_class_parent_clang_type.GetTypeInfo();
2549
Enrico Granata622be232014-10-21 20:52:14 +00002550 if (non_base_class_parent_type_info & eTypeIsPointer)
Enrico Granata4becb372011-06-29 22:27:15 +00002551 {
2552 s.PutCString("->");
2553 }
Enrico Granata622be232014-10-21 20:52:14 +00002554 else if ((non_base_class_parent_type_info & eTypeHasChildren) &&
2555 !(non_base_class_parent_type_info & eTypeIsArray))
Enrico Granata4becb372011-06-29 22:27:15 +00002556 {
2557 s.PutChar('.');
2558 }
Greg Claytone221f822011-01-21 01:59:00 +00002559 }
2560 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002561 }
Greg Claytone221f822011-01-21 01:59:00 +00002562
2563 const char *name = GetName().GetCString();
2564 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002565 {
Greg Claytone221f822011-01-21 01:59:00 +00002566 if (qualify_cxx_base_classes)
2567 {
2568 if (GetBaseClassPath (s))
2569 s.PutCString("::");
2570 }
2571 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002572 }
2573 }
2574 }
2575
Enrico Granata86cc9822012-03-19 22:58:49 +00002576 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002577 {
Greg Claytone221f822011-01-21 01:59:00 +00002578 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002579 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002580}
2581
Greg Claytonafacd142011-09-02 01:15:17 +00002582ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002583ValueObject::GetValueForExpressionPath(const char* expression,
2584 const char** first_unparsed,
2585 ExpressionPathScanEndReason* reason_to_stop,
2586 ExpressionPathEndResultType* final_value_type,
2587 const GetValueForExpressionPathOptions& options,
2588 ExpressionPathAftermath* final_task_on_target)
2589{
2590
2591 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002592 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2593 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002594 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002595
2596 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2597 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2598 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2599 final_value_type ? final_value_type : &dummy_final_value_type,
2600 options,
2601 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2602
Enrico Granata86cc9822012-03-19 22:58:49 +00002603 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002604 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002605
Enrico Granata86cc9822012-03-19 22:58:49 +00002606 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 +00002607 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002608 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002609 {
2610 Error error;
2611 ValueObjectSP final_value = ret_val->Dereference(error);
2612 if (error.Fail() || !final_value.get())
2613 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002614 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002615 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002616 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002617 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002618 return ValueObjectSP();
2619 }
2620 else
2621 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002622 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002623 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002624 return final_value;
2625 }
2626 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002627 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002628 {
2629 Error error;
2630 ValueObjectSP final_value = ret_val->AddressOf(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::eExpressionPathScanEndReasonTakingAddressFailed;
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 }
2646 }
2647 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2648}
2649
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002650int
2651ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002652 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002653 const char** first_unparsed,
2654 ExpressionPathScanEndReason* reason_to_stop,
2655 ExpressionPathEndResultType* final_value_type,
2656 const GetValueForExpressionPathOptions& options,
2657 ExpressionPathAftermath* final_task_on_target)
2658{
2659 const char* dummy_first_unparsed;
2660 ExpressionPathScanEndReason dummy_reason_to_stop;
2661 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002662 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002663
2664 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2665 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2666 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2667 final_value_type ? final_value_type : &dummy_final_value_type,
2668 options,
2669 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2670
2671 if (!ret_val.get()) // if there are errors, I add nothing to the list
2672 return 0;
2673
Enrico Granata86ea8d82012-03-29 01:34:34 +00002674 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002675 {
2676 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002677 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002678 {
2679 list->Append(ret_val);
2680 return 1;
2681 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002682 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 +00002683 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002684 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002685 {
2686 Error error;
2687 ValueObjectSP final_value = ret_val->Dereference(error);
2688 if (error.Fail() || !final_value.get())
2689 {
Greg Clayton23f59502012-07-17 03:23:13 +00002690 if (reason_to_stop)
2691 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2692 if (final_value_type)
2693 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002694 return 0;
2695 }
2696 else
2697 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002698 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002699 list->Append(final_value);
2700 return 1;
2701 }
2702 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002703 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002704 {
2705 Error error;
2706 ValueObjectSP final_value = ret_val->AddressOf(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::eExpressionPathScanEndReasonTakingAddressFailed;
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 }
2722 }
2723 }
2724 else
2725 {
2726 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2727 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2728 ret_val,
2729 list,
2730 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2731 final_value_type ? final_value_type : &dummy_final_value_type,
2732 options,
2733 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2734 }
2735 // in any non-covered case, just do the obviously right thing
2736 list->Append(ret_val);
2737 return 1;
2738}
2739
Greg Claytonafacd142011-09-02 01:15:17 +00002740ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002741ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2742 const char** first_unparsed,
2743 ExpressionPathScanEndReason* reason_to_stop,
2744 ExpressionPathEndResultType* final_result,
2745 const GetValueForExpressionPathOptions& options,
2746 ExpressionPathAftermath* what_next)
2747{
2748 ValueObjectSP root = GetSP();
2749
2750 if (!root.get())
2751 return ValueObjectSP();
2752
2753 *first_unparsed = expression_cstr;
2754
2755 while (true)
2756 {
2757
2758 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2759
Greg Clayton99558cc42015-08-24 23:46:31 +00002760 CompilerType root_clang_type = root->GetCompilerType();
Greg Claytona1e5dc82015-08-11 22:53:00 +00002761 CompilerType pointee_clang_type;
Greg Clayton57ee3062013-07-11 22:46:58 +00002762 Flags pointee_clang_type_info;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002763
Greg Clayton57ee3062013-07-11 22:46:58 +00002764 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002765 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00002766 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002767
2768 if (!expression_cstr || *expression_cstr == '\0')
2769 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002770 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002771 return root;
2772 }
2773
2774 switch (*expression_cstr)
2775 {
2776 case '-':
2777 {
2778 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granata622be232014-10-21 20:52:14 +00002779 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 +00002780 {
2781 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002782 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2783 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002784 return ValueObjectSP();
2785 }
Enrico Granata622be232014-10-21 20:52:14 +00002786 if (root_clang_type_info.Test(eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2787 root_clang_type_info.Test(eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002788 options.m_no_fragile_ivar)
2789 {
2790 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002791 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2792 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002793 return ValueObjectSP();
2794 }
2795 if (expression_cstr[1] != '>')
2796 {
2797 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002798 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2799 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002800 return ValueObjectSP();
2801 }
2802 expression_cstr++; // skip the -
2803 }
2804 case '.': // or fallthrough from ->
2805 {
2806 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granata622be232014-10-21 20:52:14 +00002807 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 +00002808 {
2809 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002810 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2811 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002812 return ValueObjectSP();
2813 }
2814 expression_cstr++; // skip .
2815 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2816 ConstString child_name;
2817 if (!next_separator) // if no other separator just expand this last layer
2818 {
2819 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002820 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2821
2822 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002823 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002824 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002825 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2826 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002827 return child_valobj_sp;
2828 }
Enrico Granataef238c12015-03-12 22:30:58 +00002829 else
Enrico Granata8c9d3562011-08-11 17:08:01 +00002830 {
Enrico Granataef238c12015-03-12 22:30:58 +00002831 switch (options.m_synthetic_children_traversal)
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002832 {
Enrico Granataef238c12015-03-12 22:30:58 +00002833 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None:
2834 break;
2835 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic:
2836 if (root->IsSynthetic())
2837 {
2838 child_valobj_sp = root->GetNonSyntheticValue();
2839 if (child_valobj_sp.get())
2840 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2841 }
2842 break;
2843 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic:
2844 if (!root->IsSynthetic())
2845 {
2846 child_valobj_sp = root->GetSyntheticValue();
2847 if (child_valobj_sp.get())
2848 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2849 }
2850 break;
2851 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both:
2852 if (root->IsSynthetic())
2853 {
2854 child_valobj_sp = root->GetNonSyntheticValue();
2855 if (child_valobj_sp.get())
2856 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2857 }
2858 else
2859 {
2860 child_valobj_sp = root->GetSyntheticValue();
2861 if (child_valobj_sp.get())
2862 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2863 }
2864 break;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002865 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002866 }
2867
2868 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2869 // so we hit the "else" branch, and return an error
2870 if(child_valobj_sp.get()) // if it worked, just return
2871 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002872 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002873 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2874 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002875 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002876 }
2877 else
2878 {
2879 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002880 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2881 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002882 return ValueObjectSP();
2883 }
2884 }
2885 else // other layers do expand
2886 {
2887 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002888 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2889 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002890 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002891 root = child_valobj_sp;
2892 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002893 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002894 continue;
2895 }
Enrico Granataef238c12015-03-12 22:30:58 +00002896 else
Enrico Granata8c9d3562011-08-11 17:08:01 +00002897 {
Enrico Granataef238c12015-03-12 22:30:58 +00002898 switch (options.m_synthetic_children_traversal)
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002899 {
Enrico Granataef238c12015-03-12 22:30:58 +00002900 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None:
2901 break;
2902 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic:
2903 if (root->IsSynthetic())
2904 {
2905 child_valobj_sp = root->GetNonSyntheticValue();
2906 if (child_valobj_sp.get())
2907 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2908 }
2909 break;
2910 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic:
2911 if (!root->IsSynthetic())
2912 {
2913 child_valobj_sp = root->GetSyntheticValue();
2914 if (child_valobj_sp.get())
2915 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2916 }
2917 break;
2918 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both:
2919 if (root->IsSynthetic())
2920 {
2921 child_valobj_sp = root->GetNonSyntheticValue();
2922 if (child_valobj_sp.get())
2923 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2924 }
2925 else
2926 {
2927 child_valobj_sp = root->GetSyntheticValue();
2928 if (child_valobj_sp.get())
2929 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2930 }
2931 break;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002932 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002933 }
2934
2935 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2936 // so we hit the "else" branch, and return an error
2937 if(child_valobj_sp.get()) // if it worked, move on
2938 {
2939 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002940 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002941 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002942 continue;
2943 }
2944 else
2945 {
2946 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002947 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2948 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002949 return ValueObjectSP();
2950 }
2951 }
2952 break;
2953 }
2954 case '[':
2955 {
Enrico Granata622be232014-10-21 20:52:14 +00002956 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 +00002957 {
Enrico Granata622be232014-10-21 20:52:14 +00002958 if (!root_clang_type_info.Test(eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002959 {
Enrico Granataef238c12015-03-12 22:30:58 +00002960 if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None) // ...only chance left is synthetic
Enrico Granata27b625e2011-08-09 01:04:56 +00002961 {
2962 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002963 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2964 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002965 return ValueObjectSP();
2966 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002967 }
2968 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2969 {
2970 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002971 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2972 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002973 return ValueObjectSP();
2974 }
2975 }
2976 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2977 {
Enrico Granata622be232014-10-21 20:52:14 +00002978 if (!root_clang_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002979 {
2980 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002981 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2982 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002983 return ValueObjectSP();
2984 }
2985 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2986 {
2987 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002988 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2989 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002990 return root;
2991 }
2992 }
2993 const char *separator_position = ::strchr(expression_cstr+1,'-');
2994 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2995 if (!close_bracket_position) // if there is no ], this is a syntax error
2996 {
2997 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002998 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2999 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003000 return ValueObjectSP();
3001 }
3002 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3003 {
3004 char *end = NULL;
3005 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3006 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3007 {
3008 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003009 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3010 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003011 return ValueObjectSP();
3012 }
3013 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3014 {
Enrico Granata622be232014-10-21 20:52:14 +00003015 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003016 {
3017 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003018 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3019 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003020 return root;
3021 }
3022 else
3023 {
3024 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003025 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3026 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003027 return ValueObjectSP();
3028 }
3029 }
3030 // from here on we do have a valid index
Enrico Granata622be232014-10-21 20:52:14 +00003031 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003032 {
Greg Claytondaf515f2011-07-09 20:12:33 +00003033 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
3034 if (!child_valobj_sp)
Bruce Mitchener11d86362015-02-26 23:55:39 +00003035 child_valobj_sp = root->GetSyntheticArrayMember(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003036 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00003037 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
3038 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00003039 if (child_valobj_sp)
3040 {
3041 root = child_valobj_sp;
3042 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003043 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00003044 continue;
3045 }
3046 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003047 {
3048 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003049 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3050 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003051 return ValueObjectSP();
3052 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003053 }
Enrico Granata622be232014-10-21 20:52:14 +00003054 else if (root_clang_type_info.Test(eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003055 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003056 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 +00003057 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003058 {
3059 Error error;
3060 root = root->Dereference(error);
3061 if (error.Fail() || !root.get())
3062 {
3063 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003064 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3065 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003066 return ValueObjectSP();
3067 }
3068 else
3069 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003070 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003071 continue;
3072 }
3073 }
3074 else
3075 {
Greg Clayton99558cc42015-08-24 23:46:31 +00003076 if (root->GetCompilerType().GetMinimumLanguage() == eLanguageTypeObjC
Enrico Granata622be232014-10-21 20:52:14 +00003077 && pointee_clang_type_info.AllClear(eTypeIsPointer)
Greg Clayton84db9102012-03-26 23:03:23 +00003078 && root->HasSyntheticValue()
Enrico Granataef238c12015-03-12 22:30:58 +00003079 && (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic ||
3080 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both))
Enrico Granata27b625e2011-08-09 01:04:56 +00003081 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003082 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003083 }
3084 else
Bruce Mitchener11d86362015-02-26 23:55:39 +00003085 root = root->GetSyntheticArrayMember(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003086 if (!root.get())
3087 {
3088 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003089 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3090 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003091 return ValueObjectSP();
3092 }
3093 else
3094 {
3095 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003096 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003097 continue;
3098 }
3099 }
3100 }
Enrico Granata622be232014-10-21 20:52:14 +00003101 else if (root_clang_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003102 {
3103 root = root->GetSyntheticBitFieldChild(index, index, true);
3104 if (!root.get())
3105 {
3106 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003107 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3108 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003109 return ValueObjectSP();
3110 }
3111 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3112 {
3113 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003114 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3115 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003116 return root;
3117 }
3118 }
Enrico Granata622be232014-10-21 20:52:14 +00003119 else if (root_clang_type_info.Test(eTypeIsVector))
Enrico Granata08a1bb82013-06-19 00:00:45 +00003120 {
3121 root = root->GetChildAtIndex(index, true);
3122 if (!root.get())
3123 {
3124 *first_unparsed = expression_cstr;
3125 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3126 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3127 return ValueObjectSP();
3128 }
3129 else
3130 {
3131 *first_unparsed = end+1; // skip ]
3132 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3133 continue;
3134 }
3135 }
Enrico Granataef238c12015-03-12 22:30:58 +00003136 else if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic ||
3137 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both)
Enrico Granata27b625e2011-08-09 01:04:56 +00003138 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003139 if (root->HasSyntheticValue())
3140 root = root->GetSyntheticValue();
3141 else if (!root->IsSynthetic())
3142 {
3143 *first_unparsed = expression_cstr;
3144 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3145 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3146 return ValueObjectSP();
3147 }
3148 // if we are here, then root itself is a synthetic VO.. should be good to go
3149
Enrico Granata27b625e2011-08-09 01:04:56 +00003150 if (!root.get())
3151 {
3152 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003153 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3154 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3155 return ValueObjectSP();
3156 }
3157 root = root->GetChildAtIndex(index, true);
3158 if (!root.get())
3159 {
3160 *first_unparsed = expression_cstr;
3161 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3162 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003163 return ValueObjectSP();
3164 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00003165 else
3166 {
3167 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003168 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00003169 continue;
3170 }
Enrico Granata27b625e2011-08-09 01:04:56 +00003171 }
3172 else
3173 {
3174 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003175 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3176 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003177 return ValueObjectSP();
3178 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003179 }
3180 else // we have a low and a high index
3181 {
3182 char *end = NULL;
3183 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3184 if (!end || end != separator_position) // if something weird is in our way return an error
3185 {
3186 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003187 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3188 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003189 return ValueObjectSP();
3190 }
3191 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3192 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3193 {
3194 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003195 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3196 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003197 return ValueObjectSP();
3198 }
3199 if (index_lower > index_higher) // swap indices if required
3200 {
3201 unsigned long temp = index_lower;
3202 index_lower = index_higher;
3203 index_higher = temp;
3204 }
Enrico Granata622be232014-10-21 20:52:14 +00003205 if (root_clang_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003206 {
3207 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3208 if (!root.get())
3209 {
3210 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003211 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3212 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003213 return ValueObjectSP();
3214 }
3215 else
3216 {
3217 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003218 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3219 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003220 return root;
3221 }
3222 }
Enrico Granata622be232014-10-21 20:52:14 +00003223 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 +00003224 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granata622be232014-10-21 20:52:14 +00003225 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003226 {
3227 Error error;
3228 root = root->Dereference(error);
3229 if (error.Fail() || !root.get())
3230 {
3231 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003232 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3233 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003234 return ValueObjectSP();
3235 }
3236 else
3237 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003238 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003239 continue;
3240 }
3241 }
3242 else
3243 {
3244 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003245 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3246 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003247 return root;
3248 }
3249 }
3250 break;
3251 }
3252 default: // some non-separator is in the way
3253 {
3254 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003255 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3256 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003257 return ValueObjectSP();
3258 break;
3259 }
3260 }
3261 }
3262}
3263
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003264int
3265ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3266 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00003267 ValueObjectSP root,
3268 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003269 ExpressionPathScanEndReason* reason_to_stop,
3270 ExpressionPathEndResultType* final_result,
3271 const GetValueForExpressionPathOptions& options,
3272 ExpressionPathAftermath* what_next)
3273{
3274 if (!root.get())
3275 return 0;
3276
3277 *first_unparsed = expression_cstr;
3278
3279 while (true)
3280 {
3281
3282 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3283
Greg Clayton99558cc42015-08-24 23:46:31 +00003284 CompilerType root_clang_type = root->GetCompilerType();
Greg Claytona1e5dc82015-08-11 22:53:00 +00003285 CompilerType pointee_clang_type;
Greg Clayton57ee3062013-07-11 22:46:58 +00003286 Flags pointee_clang_type_info;
3287 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003288 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00003289 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003290
3291 if (!expression_cstr || *expression_cstr == '\0')
3292 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003293 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003294 list->Append(root);
3295 return 1;
3296 }
3297
3298 switch (*expression_cstr)
3299 {
3300 case '[':
3301 {
Enrico Granata622be232014-10-21 20:52:14 +00003302 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 +00003303 {
Enrico Granata622be232014-10-21 20:52:14 +00003304 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 +00003305 {
3306 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003307 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3308 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003309 return 0;
3310 }
3311 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3312 {
3313 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003314 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3315 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003316 return 0;
3317 }
3318 }
3319 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3320 {
Enrico Granata622be232014-10-21 20:52:14 +00003321 if (!root_clang_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003322 {
3323 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003324 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3325 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003326 return 0;
3327 }
3328 else // expand this into list
3329 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003330 const size_t max_index = root->GetNumChildren() - 1;
3331 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003332 {
3333 ValueObjectSP child =
3334 root->GetChildAtIndex(index, true);
3335 list->Append(child);
3336 }
3337 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003338 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3339 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003340 return max_index; // tell me number of items I added to the VOList
3341 }
3342 }
3343 const char *separator_position = ::strchr(expression_cstr+1,'-');
3344 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3345 if (!close_bracket_position) // if there is no ], this is a syntax error
3346 {
3347 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003348 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3349 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003350 return 0;
3351 }
3352 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3353 {
3354 char *end = NULL;
3355 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3356 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3357 {
3358 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003359 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3360 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003361 return 0;
3362 }
3363 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3364 {
Enrico Granata622be232014-10-21 20:52:14 +00003365 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003366 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003367 const size_t max_index = root->GetNumChildren() - 1;
3368 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003369 {
3370 ValueObjectSP child =
3371 root->GetChildAtIndex(index, true);
3372 list->Append(child);
3373 }
3374 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003375 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3376 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003377 return max_index; // tell me number of items I added to the VOList
3378 }
3379 else
3380 {
3381 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003382 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3383 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003384 return 0;
3385 }
3386 }
3387 // from here on we do have a valid index
Enrico Granata622be232014-10-21 20:52:14 +00003388 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003389 {
3390 root = root->GetChildAtIndex(index, true);
3391 if (!root.get())
3392 {
3393 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003394 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3395 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003396 return 0;
3397 }
3398 else
3399 {
3400 list->Append(root);
3401 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003402 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3403 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003404 return 1;
3405 }
3406 }
Enrico Granata622be232014-10-21 20:52:14 +00003407 else if (root_clang_type_info.Test(eTypeIsPointer))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003408 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003409 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 +00003410 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003411 {
3412 Error error;
3413 root = root->Dereference(error);
3414 if (error.Fail() || !root.get())
3415 {
3416 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003417 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3418 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003419 return 0;
3420 }
3421 else
3422 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003423 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003424 continue;
3425 }
3426 }
3427 else
3428 {
Bruce Mitchener11d86362015-02-26 23:55:39 +00003429 root = root->GetSyntheticArrayMember(index, true);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003430 if (!root.get())
3431 {
3432 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003433 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3434 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003435 return 0;
3436 }
3437 else
3438 {
3439 list->Append(root);
3440 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003441 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3442 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003443 return 1;
3444 }
3445 }
3446 }
3447 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3448 {
3449 root = root->GetSyntheticBitFieldChild(index, index, true);
3450 if (!root.get())
3451 {
3452 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003453 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3454 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003455 return 0;
3456 }
3457 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3458 {
3459 list->Append(root);
3460 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003461 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3462 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003463 return 1;
3464 }
3465 }
3466 }
3467 else // we have a low and a high index
3468 {
3469 char *end = NULL;
3470 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3471 if (!end || end != separator_position) // if something weird is in our way return an error
3472 {
3473 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003474 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3475 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003476 return 0;
3477 }
3478 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3479 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3480 {
3481 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003482 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3483 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003484 return 0;
3485 }
3486 if (index_lower > index_higher) // swap indices if required
3487 {
3488 unsigned long temp = index_lower;
3489 index_lower = index_higher;
3490 index_higher = temp;
3491 }
Enrico Granata622be232014-10-21 20:52:14 +00003492 if (root_clang_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003493 {
3494 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3495 if (!root.get())
3496 {
3497 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003498 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3499 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003500 return 0;
3501 }
3502 else
3503 {
3504 list->Append(root);
3505 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003506 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3507 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003508 return 1;
3509 }
3510 }
Enrico Granata622be232014-10-21 20:52:14 +00003511 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 +00003512 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granata622be232014-10-21 20:52:14 +00003513 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003514 {
3515 Error error;
3516 root = root->Dereference(error);
3517 if (error.Fail() || !root.get())
3518 {
3519 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003520 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3521 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003522 return 0;
3523 }
3524 else
3525 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003526 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003527 continue;
3528 }
3529 }
3530 else
3531 {
Johnny Chen44805302011-07-19 19:48:13 +00003532 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003533 index <= index_higher; index++)
3534 {
3535 ValueObjectSP child =
3536 root->GetChildAtIndex(index, true);
3537 list->Append(child);
3538 }
3539 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003540 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3541 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003542 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3543 }
3544 }
3545 break;
3546 }
3547 default: // some non-[ separator, or something entirely wrong, is in the way
3548 {
3549 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003550 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3551 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003552 return 0;
3553 break;
3554 }
3555 }
3556 }
3557}
3558
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003559void
3560ValueObject::LogValueObject (Log *log)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003561{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003562 if (log)
Enrico Granatad5957332015-06-03 20:43:54 +00003563 return LogValueObject (log, DumpValueObjectOptions(*this));
Greg Clayton1d3afba2010-10-05 00:00:42 +00003564}
3565
Enrico Granata0c489f52012-03-01 04:24:26 +00003566void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003567ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003568{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003569 if (log)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003570 {
3571 StreamString s;
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003572 Dump (s, options);
Greg Claytonf830dbb2012-03-22 18:15:37 +00003573 if (s.GetSize())
3574 log->PutCString(s.GetData());
3575 }
3576}
3577
3578void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003579ValueObject::Dump (Stream &s)
Enrico Granata0c489f52012-03-01 04:24:26 +00003580{
Enrico Granatad5957332015-06-03 20:43:54 +00003581 Dump (s, DumpValueObjectOptions(*this));
Enrico Granata0c489f52012-03-01 04:24:26 +00003582}
3583
3584void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003585ValueObject::Dump (Stream &s,
3586 const DumpValueObjectOptions& options)
Enrico Granata0c489f52012-03-01 04:24:26 +00003587{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003588 ValueObjectPrinter printer(this,&s,options);
3589 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003590}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003591
3592ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003593ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003594{
3595 ValueObjectSP valobj_sp;
3596
Enrico Granatac3e320a2011-08-02 17:27:39 +00003597 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003598 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003599 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003600
3601 DataExtractor data;
3602 data.SetByteOrder (m_data.GetByteOrder());
3603 data.SetAddressByteSize(m_data.GetAddressByteSize());
3604
Enrico Granata9f1e2042012-04-24 22:15:37 +00003605 if (IsBitfield())
3606 {
3607 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
Greg Clayton57ee3062013-07-11 22:46:58 +00003608 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Enrico Granata9f1e2042012-04-24 22:15:37 +00003609 }
3610 else
Greg Clayton57ee3062013-07-11 22:46:58 +00003611 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003612
3613 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton99558cc42015-08-24 23:46:31 +00003614 GetCompilerType(),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003615 name,
3616 data,
3617 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003618 }
Jim Ingham6035b672011-03-31 00:19:25 +00003619
3620 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003621 {
Greg Claytoneeb15652013-12-10 23:16:40 +00003622 ExecutionContext exe_ctx (GetExecutionContextRef());
3623 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003624 }
3625 return valobj_sp;
3626}
3627
Enrico Granata538a88a2014-10-09 18:24:30 +00003628ValueObjectSP
3629ValueObject::GetQualifiedRepresentationIfAvailable (lldb::DynamicValueType dynValue,
3630 bool synthValue)
3631{
3632 ValueObjectSP result_sp(GetSP());
3633
3634 switch (dynValue)
3635 {
3636 case lldb::eDynamicCanRunTarget:
3637 case lldb::eDynamicDontRunTarget:
3638 {
3639 if (!result_sp->IsDynamic())
3640 {
3641 if (result_sp->GetDynamicValue(dynValue))
3642 result_sp = result_sp->GetDynamicValue(dynValue);
3643 }
3644 }
3645 break;
3646 case lldb::eNoDynamicValues:
Enrico Granata538a88a2014-10-09 18:24:30 +00003647 {
3648 if (result_sp->IsDynamic())
3649 {
3650 if (result_sp->GetStaticValue())
3651 result_sp = result_sp->GetStaticValue();
3652 }
3653 }
3654 break;
3655 }
3656
3657 if (synthValue)
3658 {
3659 if (!result_sp->IsSynthetic())
3660 {
3661 if (result_sp->GetSyntheticValue())
3662 result_sp = result_sp->GetSyntheticValue();
3663 }
3664 }
3665 else
3666 {
3667 if (result_sp->IsSynthetic())
3668 {
3669 if (result_sp->GetNonSyntheticValue())
3670 result_sp = result_sp->GetNonSyntheticValue();
3671 }
3672 }
3673
3674 return result_sp;
3675}
3676
Greg Clayton759e7442014-07-19 00:12:57 +00003677lldb::addr_t
3678ValueObject::GetCPPVTableAddress (AddressType &address_type)
3679{
Greg Claytona1e5dc82015-08-11 22:53:00 +00003680 CompilerType pointee_type;
Greg Clayton99558cc42015-08-24 23:46:31 +00003681 CompilerType this_type(GetCompilerType());
Greg Clayton759e7442014-07-19 00:12:57 +00003682 uint32_t type_info = this_type.GetTypeInfo(&pointee_type);
3683 if (type_info)
3684 {
3685 bool ptr_or_ref = false;
Enrico Granata622be232014-10-21 20:52:14 +00003686 if (type_info & (eTypeIsPointer | eTypeIsReference))
Greg Clayton759e7442014-07-19 00:12:57 +00003687 {
3688 ptr_or_ref = true;
3689 type_info = pointee_type.GetTypeInfo();
3690 }
3691
Enrico Granata622be232014-10-21 20:52:14 +00003692 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus;
Greg Clayton759e7442014-07-19 00:12:57 +00003693 if ((type_info & cpp_class) == cpp_class)
3694 {
3695 if (ptr_or_ref)
3696 {
3697 address_type = GetAddressTypeOfChildren();
3698 return GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
3699 }
3700 else
3701 return GetAddressOf (false, &address_type);
3702 }
3703 }
3704
3705 address_type = eAddressTypeInvalid;
3706 return LLDB_INVALID_ADDRESS;
3707}
3708
Greg Claytonafacd142011-09-02 01:15:17 +00003709ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003710ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003711{
Jim Ingham58b59f92011-04-22 23:53:53 +00003712 if (m_deref_valobj)
3713 return m_deref_valobj->GetSP();
Chaoren Lind7bdc272015-07-31 00:35:40 +00003714
3715 const bool is_pointer_or_reference_type = IsPointerOrReferenceType();
3716 if (is_pointer_or_reference_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003717 {
3718 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003719 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003720
3721 std::string child_name_str;
3722 uint32_t child_byte_size = 0;
3723 int32_t child_byte_offset = 0;
3724 uint32_t child_bitfield_bit_size = 0;
3725 uint32_t child_bitfield_bit_offset = 0;
3726 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003727 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003728 const bool transparent_pointers = false;
Greg Clayton99558cc42015-08-24 23:46:31 +00003729 CompilerType clang_type = GetCompilerType();
Greg Claytona1e5dc82015-08-11 22:53:00 +00003730 CompilerType child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003731
Greg Claytoncc4d0142012-02-17 07:49:44 +00003732 ExecutionContext exe_ctx (GetExecutionContextRef());
Chaoren Lind7bdc272015-07-31 00:35:40 +00003733
Greg Clayton57ee3062013-07-11 22:46:58 +00003734 child_clang_type = clang_type.GetChildClangTypeAtIndex (&exe_ctx,
Greg Clayton57ee3062013-07-11 22:46:58 +00003735 0,
3736 transparent_pointers,
3737 omit_empty_base_classes,
3738 ignore_array_bounds,
3739 child_name_str,
3740 child_byte_size,
3741 child_byte_offset,
3742 child_bitfield_bit_size,
3743 child_bitfield_bit_offset,
3744 child_is_base_class,
Greg Clayton759e7442014-07-19 00:12:57 +00003745 child_is_deref_of_parent,
3746 this);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003747 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003748 {
3749 ConstString child_name;
3750 if (!child_name_str.empty())
3751 child_name.SetCString (child_name_str.c_str());
3752
Jim Ingham58b59f92011-04-22 23:53:53 +00003753 m_deref_valobj = new ValueObjectChild (*this,
Jim Ingham58b59f92011-04-22 23:53:53 +00003754 child_clang_type,
3755 child_name,
3756 child_byte_size,
3757 child_byte_offset,
3758 child_bitfield_bit_size,
3759 child_bitfield_bit_offset,
3760 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003761 child_is_deref_of_parent,
3762 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003763 }
3764 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003765
Jim Ingham58b59f92011-04-22 23:53:53 +00003766 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003767 {
3768 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003769 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003770 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003771 else
3772 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003773 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003774 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003775
Chaoren Lind7bdc272015-07-31 00:35:40 +00003776 if (is_pointer_or_reference_type)
Greg Clayton54979cd2010-12-15 05:08:08 +00003777 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3778 else
Chaoren Lind7bdc272015-07-31 00:35:40 +00003779 error.SetErrorStringWithFormat("not a pointer or reference type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003780 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003781 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003782}
3783
Greg Claytonafacd142011-09-02 01:15:17 +00003784ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003785ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003786{
Jim Ingham78a685a2011-04-16 00:01:13 +00003787 if (m_addr_of_valobj_sp)
3788 return m_addr_of_valobj_sp;
3789
Greg Claytone0d378b2011-03-24 21:19:54 +00003790 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003791 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003792 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003793 error.Clear();
Siva Chandraa3747a92015-05-04 19:43:34 +00003794 if (addr != LLDB_INVALID_ADDRESS && address_type != eAddressTypeHost)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003795 {
3796 switch (address_type)
3797 {
3798 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003799 {
3800 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003801 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003802 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3803 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003804 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003805
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003806 case eAddressTypeFile:
3807 case eAddressTypeLoad:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003808 {
Greg Clayton99558cc42015-08-24 23:46:31 +00003809 CompilerType clang_type = GetCompilerType();
Greg Clayton57ee3062013-07-11 22:46:58 +00003810 if (clang_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003811 {
3812 std::string name (1, '&');
3813 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003814 ExecutionContext exe_ctx (GetExecutionContextRef());
3815 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00003816 clang_type.GetPointerType(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003817 ConstString (name.c_str()),
3818 addr,
3819 eAddressTypeInvalid,
3820 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003821 }
3822 }
3823 break;
Siva Chandraa3747a92015-05-04 19:43:34 +00003824 default:
3825 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003826 }
3827 }
Sean Callananed185ab2013-04-19 19:47:32 +00003828 else
3829 {
3830 StreamString expr_path_strm;
3831 GetExpressionPath(expr_path_strm, true);
3832 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3833 }
3834
Jim Ingham78a685a2011-04-16 00:01:13 +00003835 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003836}
3837
Greg Clayton9a142cf2012-02-03 05:34:10 +00003838ValueObjectSP
Greg Claytona1e5dc82015-08-11 22:53:00 +00003839ValueObject::Cast (const CompilerType &clang_ast_type)
Greg Clayton9a142cf2012-02-03 05:34:10 +00003840{
Greg Clayton81e871e2012-02-04 02:27:34 +00003841 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003842}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003843
Greg Claytonafacd142011-09-02 01:15:17 +00003844ValueObjectSP
Greg Claytona1e5dc82015-08-11 22:53:00 +00003845ValueObject::CastPointerType (const char *name, CompilerType &clang_ast_type)
Greg Claytonb2dcc362011-05-05 23:32:56 +00003846{
Greg Claytonafacd142011-09-02 01:15:17 +00003847 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003848 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003849 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003850
3851 if (ptr_value != LLDB_INVALID_ADDRESS)
3852 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003853 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003854 ExecutionContext exe_ctx (GetExecutionContextRef());
3855 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003856 name,
3857 ptr_addr,
3858 clang_ast_type);
3859 }
3860 return valobj_sp;
3861}
3862
Greg Claytonafacd142011-09-02 01:15:17 +00003863ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003864ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3865{
Greg Claytonafacd142011-09-02 01:15:17 +00003866 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003867 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003868 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003869
3870 if (ptr_value != LLDB_INVALID_ADDRESS)
3871 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003872 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003873 ExecutionContext exe_ctx (GetExecutionContextRef());
3874 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003875 name,
3876 ptr_addr,
3877 type_sp);
3878 }
3879 return valobj_sp;
3880}
3881
Jim Ingham6035b672011-03-31 00:19:25 +00003882ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003883 m_mod_id(),
3884 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003885 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003886{
3887}
3888
3889ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003890 m_mod_id(),
3891 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003892 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003893{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003894 ExecutionContext exe_ctx(exe_scope);
3895 TargetSP target_sp (exe_ctx.GetTargetSP());
3896 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003897 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003898 m_exe_ctx_ref.SetTargetSP (target_sp);
3899 ProcessSP process_sp (exe_ctx.GetProcessSP());
3900 if (!process_sp)
3901 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003902
Greg Claytoncc4d0142012-02-17 07:49:44 +00003903 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003904 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003905 m_mod_id = process_sp->GetModID();
3906 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003907
Greg Claytoncc4d0142012-02-17 07:49:44 +00003908 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003909
Greg Claytoncc4d0142012-02-17 07:49:44 +00003910 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003911 {
3912 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003913 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003914 }
Jim Ingham6035b672011-03-31 00:19:25 +00003915
Greg Claytoncc4d0142012-02-17 07:49:44 +00003916 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003917 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003918 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003919
Jason Molendab57e4a12013-11-04 09:33:30 +00003920 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003921 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003922 {
3923 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003924 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003925 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003926 if (frame_sp)
3927 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003928 }
3929 }
3930 }
Jim Ingham6035b672011-03-31 00:19:25 +00003931}
3932
3933ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003934 m_mod_id(),
3935 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003936 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003937{
3938}
3939
3940ValueObject::EvaluationPoint::~EvaluationPoint ()
3941{
3942}
3943
Jim Ingham6035b672011-03-31 00:19:25 +00003944// This function checks the EvaluationPoint against the current process state. If the current
3945// state matches the evaluation point, or the evaluation point is already invalid, then we return
3946// false, meaning "no change". If the current state is different, we update our state, and return
3947// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3948// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003949// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003950
3951bool
Enrico Granatabb642e52015-05-16 01:27:00 +00003952ValueObject::EvaluationPoint::SyncWithProcessState(bool accept_invalid_exe_ctx)
Jim Ingham6035b672011-03-31 00:19:25 +00003953{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003954 // 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 +00003955 const bool thread_and_frame_only_if_stopped = true;
3956 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
Jim Ingham73ca05a2011-12-17 01:35:57 +00003957
Greg Claytoncc4d0142012-02-17 07:49:44 +00003958 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003959 return false;
3960
Jim Ingham6035b672011-03-31 00:19:25 +00003961 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003962 Process *process = exe_ctx.GetProcessPtr();
3963 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003964 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003965
Jim Ingham6035b672011-03-31 00:19:25 +00003966 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003967 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003968
Jim Ingham78a685a2011-04-16 00:01:13 +00003969 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3970 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003971 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003972 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003973
Greg Clayton23f59502012-07-17 03:23:13 +00003974 bool changed = false;
3975 const bool was_valid = m_mod_id.IsValid();
3976 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003977 {
3978 if (m_mod_id == current_mod_id)
3979 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003980 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003981 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003982 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003983 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003984 else
3985 {
3986 m_mod_id = current_mod_id;
3987 m_needs_update = true;
3988 changed = true;
3989 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003990 }
Jim Ingham6035b672011-03-31 00:19:25 +00003991
Jim Ingham73ca05a2011-12-17 01:35:57 +00003992 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3993 // That way we'll be sure to return a valid exe_scope.
3994 // 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 +00003995
Enrico Granatabb642e52015-05-16 01:27:00 +00003996 if (!accept_invalid_exe_ctx)
Jim Ingham6035b672011-03-31 00:19:25 +00003997 {
Enrico Granatabb642e52015-05-16 01:27:00 +00003998 if (m_exe_ctx_ref.HasThreadRef())
Greg Clayton262f80d2011-07-06 16:49:27 +00003999 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004000 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
4001 if (thread_sp)
Greg Claytoncc4d0142012-02-17 07:49:44 +00004002 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004003 if (m_exe_ctx_ref.HasFrameRef())
Greg Claytoncc4d0142012-02-17 07:49:44 +00004004 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004005 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
4006 if (!frame_sp)
4007 {
4008 // We used to have a frame, but now it is gone
4009 SetInvalid();
4010 changed = was_valid;
4011 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00004012 }
4013 }
Enrico Granatabb642e52015-05-16 01:27:00 +00004014 else
4015 {
4016 // We used to have a thread, but now it is gone
4017 SetInvalid();
4018 changed = was_valid;
4019 }
Greg Clayton262f80d2011-07-06 16:49:27 +00004020 }
Jim Ingham6035b672011-03-31 00:19:25 +00004021 }
Enrico Granatabb642e52015-05-16 01:27:00 +00004022
Jim Ingham9ee01152011-12-10 01:49:43 +00004023 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00004024}
4025
Jim Ingham61be0902011-05-02 18:13:59 +00004026void
4027ValueObject::EvaluationPoint::SetUpdated ()
4028{
Greg Claytoncc4d0142012-02-17 07:49:44 +00004029 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
4030 if (process_sp)
4031 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00004032 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00004033}
4034
4035
Enrico Granataf2bbf712011-07-15 02:26:42 +00004036
4037void
Enrico Granata86cc9822012-03-19 22:58:49 +00004038ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004039{
Enrico Granata86cc9822012-03-19 22:58:49 +00004040 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4041 m_value_str.clear();
4042
4043 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4044 m_location_str.clear();
4045
4046 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
Enrico Granata86cc9822012-03-19 22:58:49 +00004047 m_summary_str.clear();
Enrico Granata86cc9822012-03-19 22:58:49 +00004048
4049 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4050 m_object_desc_str.clear();
4051
4052 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4053 {
4054 if (m_synthetic_value)
4055 m_synthetic_value = NULL;
4056 }
Enrico Granata744794a2014-09-05 21:46:22 +00004057
4058 if ((clear_mask & eClearUserVisibleDataItemsValidator) == eClearUserVisibleDataItemsValidator)
4059 m_validation_result.reset();
Johnny Chen44805302011-07-19 19:48:13 +00004060}
Enrico Granata9128ee22011-09-06 19:20:51 +00004061
4062SymbolContextScope *
4063ValueObject::GetSymbolContextScope()
4064{
4065 if (m_parent)
4066 {
4067 if (!m_parent->IsPointerOrReferenceType())
4068 return m_parent->GetSymbolContextScope();
4069 }
4070 return NULL;
4071}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004072
4073lldb::ValueObjectSP
4074ValueObject::CreateValueObjectFromExpression (const char* name,
4075 const char* expression,
4076 const ExecutionContext& exe_ctx)
4077{
Enrico Granata972be532014-12-17 21:18:43 +00004078 return CreateValueObjectFromExpression(name, expression, exe_ctx, EvaluateExpressionOptions());
4079}
4080
4081
4082lldb::ValueObjectSP
4083ValueObject::CreateValueObjectFromExpression (const char* name,
4084 const char* expression,
4085 const ExecutionContext& exe_ctx,
4086 const EvaluateExpressionOptions& options)
4087{
Enrico Granatab2698cd2012-09-13 18:27:09 +00004088 lldb::ValueObjectSP retval_sp;
4089 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4090 if (!target_sp)
4091 return retval_sp;
4092 if (!expression || !*expression)
4093 return retval_sp;
4094 target_sp->EvaluateExpression (expression,
4095 exe_ctx.GetFrameSP().get(),
Enrico Granata972be532014-12-17 21:18:43 +00004096 retval_sp,
4097 options);
Enrico Granatab2698cd2012-09-13 18:27:09 +00004098 if (retval_sp && name && *name)
4099 retval_sp->SetName(ConstString(name));
4100 return retval_sp;
4101}
4102
4103lldb::ValueObjectSP
4104ValueObject::CreateValueObjectFromAddress (const char* name,
4105 uint64_t address,
4106 const ExecutionContext& exe_ctx,
Greg Claytona1e5dc82015-08-11 22:53:00 +00004107 CompilerType type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004108{
Greg Clayton57ee3062013-07-11 22:46:58 +00004109 if (type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004110 {
Greg Claytona1e5dc82015-08-11 22:53:00 +00004111 CompilerType pointer_type(type.GetPointerType());
Greg Clayton57ee3062013-07-11 22:46:58 +00004112 if (pointer_type)
4113 {
4114 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4115 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4116 pointer_type,
4117 ConstString(name),
4118 buffer,
Enrico Granata972be532014-12-17 21:18:43 +00004119 exe_ctx.GetByteOrder(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004120 exe_ctx.GetAddressByteSize()));
4121 if (ptr_result_valobj_sp)
4122 {
4123 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4124 Error err;
4125 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4126 if (ptr_result_valobj_sp && name && *name)
4127 ptr_result_valobj_sp->SetName(ConstString(name));
4128 }
4129 return ptr_result_valobj_sp;
4130 }
Enrico Granatab2698cd2012-09-13 18:27:09 +00004131 }
Greg Clayton57ee3062013-07-11 22:46:58 +00004132 return lldb::ValueObjectSP();
Enrico Granatab2698cd2012-09-13 18:27:09 +00004133}
4134
4135lldb::ValueObjectSP
4136ValueObject::CreateValueObjectFromData (const char* name,
Enrico Granata7ca1c762014-03-31 23:02:25 +00004137 const DataExtractor& data,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004138 const ExecutionContext& exe_ctx,
Greg Claytona1e5dc82015-08-11 22:53:00 +00004139 CompilerType type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004140{
4141 lldb::ValueObjectSP new_value_sp;
4142 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004143 type,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004144 ConstString(name),
4145 data,
4146 LLDB_INVALID_ADDRESS);
4147 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4148 if (new_value_sp && name && *name)
4149 new_value_sp->SetName(ConstString(name));
4150 return new_value_sp;
4151}
Enrico Granata4873e522013-04-11 22:48:58 +00004152
4153ModuleSP
4154ValueObject::GetModule ()
4155{
4156 ValueObject* root(GetRoot());
4157 if (root != this)
4158 return root->GetModule();
4159 return lldb::ModuleSP();
4160}
4161
4162ValueObject*
4163ValueObject::GetRoot ()
4164{
4165 if (m_root)
4166 return m_root;
Enrico Granatade61eba2015-01-22 03:07:34 +00004167 return (m_root = FollowParentChain( [] (ValueObject* vo) -> bool {
4168 return (vo->m_parent != nullptr);
4169 }));
4170}
4171
4172ValueObject*
4173ValueObject::FollowParentChain (std::function<bool(ValueObject*)> f)
4174{
4175 ValueObject* vo = this;
4176 while (vo)
Enrico Granata4873e522013-04-11 22:48:58 +00004177 {
Enrico Granatade61eba2015-01-22 03:07:34 +00004178 if (f(vo) == false)
4179 break;
4180 vo = vo->m_parent;
Enrico Granata4873e522013-04-11 22:48:58 +00004181 }
Enrico Granatade61eba2015-01-22 03:07:34 +00004182 return vo;
Enrico Granata4873e522013-04-11 22:48:58 +00004183}
4184
4185AddressType
4186ValueObject::GetAddressTypeOfChildren()
4187{
4188 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
4189 {
4190 ValueObject* root(GetRoot());
4191 if (root != this)
4192 return root->GetAddressTypeOfChildren();
4193 }
4194 return m_address_type_of_ptr_or_ref_children;
4195}
4196
4197lldb::DynamicValueType
4198ValueObject::GetDynamicValueType ()
4199{
4200 ValueObject* with_dv_info = this;
4201 while (with_dv_info)
4202 {
4203 if (with_dv_info->HasDynamicValueTypeInfo())
4204 return with_dv_info->GetDynamicValueTypeImpl();
4205 with_dv_info = with_dv_info->m_parent;
4206 }
4207 return lldb::eNoDynamicValues;
4208}
Enrico Granata39d51412013-05-31 17:43:40 +00004209
Enrico Granata4873e522013-04-11 22:48:58 +00004210lldb::Format
4211ValueObject::GetFormat () const
4212{
4213 const ValueObject* with_fmt_info = this;
4214 while (with_fmt_info)
4215 {
4216 if (with_fmt_info->m_format != lldb::eFormatDefault)
4217 return with_fmt_info->m_format;
4218 with_fmt_info = with_fmt_info->m_parent;
4219 }
4220 return m_format;
4221}
Enrico Granatad07cfd32014-10-08 18:27:36 +00004222
Enrico Granatac1247f52014-11-06 21:23:20 +00004223lldb::LanguageType
4224ValueObject::GetPreferredDisplayLanguage ()
4225{
Enrico Granataed3228a2015-01-21 01:47:13 +00004226 lldb::LanguageType type = m_preferred_display_language;
4227 if (m_preferred_display_language == lldb::eLanguageTypeUnknown)
Enrico Granatac1247f52014-11-06 21:23:20 +00004228 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004229 if (GetRoot())
Enrico Granatac1247f52014-11-06 21:23:20 +00004230 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004231 if (GetRoot() == this)
Enrico Granatac1247f52014-11-06 21:23:20 +00004232 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004233 if (StackFrameSP frame_sp = GetFrameSP())
4234 {
4235 const SymbolContext& sc(frame_sp->GetSymbolContext(eSymbolContextCompUnit));
4236 if (CompileUnit* cu = sc.comp_unit)
4237 type = cu->GetLanguage();
4238 }
4239 }
4240 else
4241 {
4242 type = GetRoot()->GetPreferredDisplayLanguage();
Enrico Granatac1247f52014-11-06 21:23:20 +00004243 }
4244 }
Enrico Granatac1247f52014-11-06 21:23:20 +00004245 }
Enrico Granataed3228a2015-01-21 01:47:13 +00004246 return (m_preferred_display_language = type); // only compute it once
4247}
4248
4249void
4250ValueObject::SetPreferredDisplayLanguage (lldb::LanguageType lt)
4251{
4252 m_preferred_display_language = lt;
Enrico Granatac1247f52014-11-06 21:23:20 +00004253}
4254
Enrico Granatad07cfd32014-10-08 18:27:36 +00004255bool
4256ValueObject::CanProvideValue ()
4257{
Sean Callanan7375f3e2014-12-09 21:18:59 +00004258 // we need to support invalid types as providers of values because some bare-board
4259 // debugging scenarios have no notion of types, but still manage to have raw numeric
4260 // values for things like registers. sigh.
Greg Clayton99558cc42015-08-24 23:46:31 +00004261 const CompilerType &type(GetCompilerType());
Sean Callanan7375f3e2014-12-09 21:18:59 +00004262 return (false == type.IsValid()) || (0 != (type.GetTypeInfo() & eTypeHasValue));
4263}
4264
4265bool
4266ValueObject::IsChecksumEmpty ()
4267{
4268 return m_value_checksum.empty();
Enrico Granatad07cfd32014-10-08 18:27:36 +00004269}
Enrico Granata0c10a852014-12-08 23:13:56 +00004270
4271ValueObjectSP
4272ValueObject::Persist ()
4273{
4274 if (!UpdateValueIfNeeded())
4275 return nullptr;
4276
4277 TargetSP target_sp(GetTargetSP());
4278 if (!target_sp)
4279 return nullptr;
4280
4281 ConstString name(target_sp->GetPersistentVariables().GetNextPersistentVariableName());
4282
4283 ClangExpressionVariableSP clang_var_sp(new ClangExpressionVariable(target_sp.get(), GetValue(), name));
4284 if (clang_var_sp)
4285 {
4286 clang_var_sp->m_live_sp = clang_var_sp->m_frozen_sp;
4287 clang_var_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
4288 target_sp->GetPersistentVariables().AddVariable(clang_var_sp);
4289 }
4290
4291 return clang_var_sp->GetValueObject();
4292}
Enrico Granatae29df232014-12-09 19:51:20 +00004293
4294bool
4295ValueObject::IsSyntheticChildrenGenerated ()
4296{
4297 return m_is_synthetic_children_generated;
4298}
4299
4300void
4301ValueObject::SetSyntheticChildrenGenerated (bool b)
4302{
4303 m_is_synthetic_children_generated = b;
4304}