blob: d7ceb89cfcaf396f7b5d746a5dbcb0bef686a800 [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"
18
19// Project includes
20#include "lldb/Core/DataBufferHeap.h"
Enrico Granata4becb372011-06-29 22:27:15 +000021#include "lldb/Core/Debugger.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000022#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000023#include "lldb/Core/Module.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024#include "lldb/Core/StreamString.h"
Enrico Granata21fd13f2012-10-27 02:05:48 +000025#include "lldb/Core/ValueObjectCast.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026#include "lldb/Core/ValueObjectChild.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000027#include "lldb/Core/ValueObjectConstResult.h"
Jim Ingham78a685a2011-04-16 00:01:13 +000028#include "lldb/Core/ValueObjectDynamicValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Core/ValueObjectList.h"
Greg Claytonb2dcc362011-05-05 23:32:56 +000030#include "lldb/Core/ValueObjectMemory.h"
Enrico Granatad55546b2011-07-22 00:16:08 +000031#include "lldb/Core/ValueObjectSyntheticFilter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032
Enrico Granata5548cb52013-01-28 23:47:25 +000033#include "lldb/DataFormatters/DataVisualization.h"
Enrico Granata2206b482014-10-30 18:27:31 +000034#include "lldb/DataFormatters/StringPrinter.h"
Enrico Granata4d93b8c2013-09-30 19:11:51 +000035#include "lldb/DataFormatters/ValueObjectPrinter.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000036
Sean Callanan30e33972015-09-03 00:48:23 +000037#include "Plugins/ExpressionParser/Clang/ClangExpressionVariable.h"
Sean Callanan4dbb2712015-09-25 20:35:58 +000038#include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h"
Enrico Granata0c10a852014-12-08 23:13:56 +000039
Greg Clayton7fb56d02011-02-01 01:31:41 +000040#include "lldb/Host/Endian.h"
41
Enrico Granata61a80ba2011-08-12 16:42:31 +000042#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granataf2bbf712011-07-15 02:26:42 +000043
Greg Claytona1e5dc82015-08-11 22:53:00 +000044#include "lldb/Symbol/CompilerType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000045#include "lldb/Symbol/ClangASTContext.h"
Enrico Granatac1247f52014-11-06 21:23:20 +000046#include "lldb/Symbol/CompileUnit.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000047#include "lldb/Symbol/Type.h"
48
Jim Ingham53c47f12010-09-10 23:12:17 +000049#include "lldb/Target/ExecutionContext.h"
Enrico Granata407b5c62015-11-02 21:52:05 +000050#include "lldb/Target/Language.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{
Enrico Granata4edfef42015-10-06 17:55:14 +0000279 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_DATAFORMATTERS));
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{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000328 CompilerType compiler_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
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000335 return compiler_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
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000341 if (ClangASTContext::IsObjCObjectPointerType(compiler_type, &class_type))
Sean Callanan72772842012-02-22 23:57:45 +0000342 {
343 is_pointer_type = true;
344 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000345 else if (ClangASTContext::IsObjCObjectOrInterfaceType(compiler_type))
Sean Callanan72772842012-02-22 23:57:45 +0000346 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000347 class_type = compiler_type;
Sean Callanan72772842012-02-22 23:57:45 +0000348 }
349 else
350 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000351 return compiler_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 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000395 return compiler_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
Jim Ingham98e6daf2015-10-31 00:02:18 +0000517ValueObject::IsLogicalTrue (Error& error)
518{
Enrico Granata407b5c62015-11-02 21:52:05 +0000519 if (Language *language = Language::FindPlugin(GetObjectRuntimeLanguage()))
520 {
521 LazyBool is_logical_true = language->IsLogicalTrue(*this, error);
522 switch (is_logical_true)
523 {
524 case eLazyBoolYes:
525 case eLazyBoolNo:
526 return (is_logical_true == true);
527 case eLazyBoolCalculate:
Enrico Granata407b5c62015-11-02 21:52:05 +0000528 break;
529 }
530 }
531
Jim Ingham98e6daf2015-10-31 00:02:18 +0000532 Scalar scalar_value;
533
534 if (!ResolveValue (scalar_value))
535 {
536 error.SetErrorString("failed to get a scalar result");
537 return false;
538 }
539
540 bool ret;
541 if (scalar_value.ULongLong(1) == 0)
542 ret = false;
543 else
544 ret = true;
545 error.Clear();
546 return ret;
547}
548
549bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000550ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000551{
Greg Clayton288bdf92010-09-02 02:59:18 +0000552 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000553}
554
555
556void
557ValueObject::SetValueIsValid (bool b)
558{
Greg Clayton288bdf92010-09-02 02:59:18 +0000559 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000560}
561
562bool
Jim Ingham6035b672011-03-31 00:19:25 +0000563ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000564{
Greg Clayton288bdf92010-09-02 02:59:18 +0000565 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000566}
567
568void
569ValueObject::SetValueDidChange (bool value_changed)
570{
Greg Clayton288bdf92010-09-02 02:59:18 +0000571 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000572}
573
574ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000575ValueObject::GetChildAtIndex (size_t idx, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000576{
577 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000578 // We may need to update our value if we are dynamic
579 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000580 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000581 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000582 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000583 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000584 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000585 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000586 // No we haven't created the child at this index, so lets have our
587 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000588 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000589 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000590
Enrico Granata9d60f602012-03-09 03:09:58 +0000591 ValueObject* child = m_children.GetChildAtIndex(idx);
592 if (child != NULL)
593 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000594 }
595 return child_sp;
596}
597
Enrico Granata3309d882013-01-12 01:00:22 +0000598ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000599ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
600 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000601{
602 if (idxs.size() == 0)
603 return GetSP();
604 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000605 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000606 {
607 root = root->GetChildAtIndex(idx, true);
608 if (!root)
609 {
610 if (index_of_error)
611 *index_of_error = idx;
612 return root;
613 }
614 }
615 return root;
616}
617
618ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000619ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
620 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000621{
622 if (idxs.size() == 0)
623 return GetSP();
624 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000625 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000626 {
627 root = root->GetChildAtIndex(idx.first, idx.second);
628 if (!root)
629 {
630 if (index_of_error)
631 *index_of_error = idx.first;
632 return root;
633 }
634 }
635 return root;
636}
637
638lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000639ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
640 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000641{
642 if (idxs.size() == 0)
643 return GetSP();
644 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000645 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000646 {
647 root = root->GetChildAtIndex(idx, true);
648 if (!root)
649 {
650 if (index_of_error)
651 *index_of_error = idx;
652 return root;
653 }
654 }
655 return root;
656}
657
658lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000659ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
660 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000661{
662 if (idxs.size() == 0)
663 return GetSP();
664 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000665 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000666 {
667 root = root->GetChildAtIndex(idx.first, idx.second);
668 if (!root)
669 {
670 if (index_of_error)
671 *index_of_error = idx.first;
672 return root;
673 }
674 }
675 return root;
676}
677
Enrico Granatae2e220a2013-09-12 00:48:47 +0000678lldb::ValueObjectSP
679ValueObject::GetChildAtNamePath (const std::initializer_list<ConstString> &names,
680 ConstString* name_of_error)
681{
682 if (names.size() == 0)
683 return GetSP();
684 ValueObjectSP root(GetSP());
685 for (ConstString name : names)
686 {
687 root = root->GetChildMemberWithName(name, true);
688 if (!root)
689 {
690 if (name_of_error)
691 *name_of_error = name;
692 return root;
693 }
694 }
695 return root;
696}
697
698lldb::ValueObjectSP
699ValueObject::GetChildAtNamePath (const std::vector<ConstString> &names,
700 ConstString* name_of_error)
701{
702 if (names.size() == 0)
703 return GetSP();
704 ValueObjectSP root(GetSP());
705 for (ConstString name : names)
706 {
707 root = root->GetChildMemberWithName(name, true);
708 if (!root)
709 {
710 if (name_of_error)
711 *name_of_error = name;
712 return root;
713 }
714 }
715 return root;
716}
717
718lldb::ValueObjectSP
719ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names,
720 ConstString* name_of_error)
721{
722 if (names.size() == 0)
723 return GetSP();
724 ValueObjectSP root(GetSP());
725 for (std::pair<ConstString, bool> name : names)
726 {
727 root = root->GetChildMemberWithName(name.first, name.second);
728 if (!root)
729 {
730 if (name_of_error)
731 *name_of_error = name.first;
732 return root;
733 }
734 }
735 return root;
736}
737
738lldb::ValueObjectSP
739ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names,
740 ConstString* name_of_error)
741{
742 if (names.size() == 0)
743 return GetSP();
744 ValueObjectSP root(GetSP());
745 for (std::pair<ConstString, bool> name : names)
746 {
747 root = root->GetChildMemberWithName(name.first, name.second);
748 if (!root)
749 {
750 if (name_of_error)
751 *name_of_error = name.first;
752 return root;
753 }
754 }
755 return root;
756}
757
Greg Claytonc7bece562013-01-25 18:06:21 +0000758size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000759ValueObject::GetIndexOfChildWithName (const ConstString &name)
760{
761 bool omit_empty_base_classes = true;
Greg Clayton99558cc42015-08-24 23:46:31 +0000762 return GetCompilerType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000763}
764
765ValueObjectSP
766ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
767{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000768 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000769 // classes (which really aren't part of the expression path), so we
770 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000771 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000772
Greg Claytondea8cb42011-06-29 22:09:02 +0000773 // We may need to update our value if we are dynamic
774 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000775 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000776
777 std::vector<uint32_t> child_indexes;
Greg Claytondea8cb42011-06-29 22:09:02 +0000778 bool omit_empty_base_classes = true;
Greg Clayton99558cc42015-08-24 23:46:31 +0000779 const size_t num_child_indexes = GetCompilerType().GetIndexOfChildMemberWithName (name.GetCString(),
Greg Clayton57ee3062013-07-11 22:46:58 +0000780 omit_empty_base_classes,
781 child_indexes);
Greg Claytondea8cb42011-06-29 22:09:02 +0000782 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000783 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000784 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
785 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
786
787 child_sp = GetChildAtIndex(*pos, can_create);
788 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000789 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000790 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000791 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000792 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
793 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000794 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000795 else
796 {
797 child_sp.reset();
798 }
799
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000800 }
801 }
802 return child_sp;
803}
804
805
Greg Claytonc7bece562013-01-25 18:06:21 +0000806size_t
Siva Chandra9ac7a6c2015-10-21 19:28:08 +0000807ValueObject::GetNumChildren (uint32_t max)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000808{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000809 UpdateValueIfNeeded();
Siva Chandra9ac7a6c2015-10-21 19:28:08 +0000810
811 if (max < UINT32_MAX)
812 {
813 if (m_children_count_valid)
814 {
815 size_t children_count = m_children.GetChildrenCount();
816 return children_count <= max ? children_count : max;
817 }
818 else
819 return CalculateNumChildren(max);
820 }
821
Greg Clayton288bdf92010-09-02 02:59:18 +0000822 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000823 {
824 SetNumChildren (CalculateNumChildren());
825 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000826 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000827}
Greg Clayton4a792072012-10-23 01:50:10 +0000828
829bool
830ValueObject::MightHaveChildren()
831{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000832 bool has_children = false;
Greg Clayton2452ab72013-02-08 22:02:02 +0000833 const uint32_t type_info = GetTypeInfo();
834 if (type_info)
Greg Clayton4a792072012-10-23 01:50:10 +0000835 {
Enrico Granata622be232014-10-21 20:52:14 +0000836 if (type_info & (eTypeHasChildren |
837 eTypeIsPointer |
838 eTypeIsReference))
Greg Clayton4a792072012-10-23 01:50:10 +0000839 has_children = true;
840 }
841 else
842 {
843 has_children = GetNumChildren () > 0;
844 }
845 return has_children;
846}
847
848// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000849void
Greg Claytonc7bece562013-01-25 18:06:21 +0000850ValueObject::SetNumChildren (size_t num_children)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000851{
Greg Clayton288bdf92010-09-02 02:59:18 +0000852 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000853 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000854}
855
856void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000857ValueObject::SetName (const ConstString &name)
858{
859 m_name = name;
860}
861
Jim Ingham58b59f92011-04-22 23:53:53 +0000862ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000863ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000864{
Jim Ingham2eec4872011-05-07 00:10:58 +0000865 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000866
Greg Claytondea8cb42011-06-29 22:09:02 +0000867 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000868 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000869 std::string child_name_str;
870 uint32_t child_byte_size = 0;
871 int32_t child_byte_offset = 0;
872 uint32_t child_bitfield_bit_size = 0;
873 uint32_t child_bitfield_bit_offset = 0;
874 bool child_is_base_class = false;
875 bool child_is_deref_of_parent = false;
876
877 const bool transparent_pointers = synthetic_array_member == false;
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000878 CompilerType child_compiler_type;
Greg Claytondea8cb42011-06-29 22:09:02 +0000879
Greg Claytoncc4d0142012-02-17 07:49:44 +0000880 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000881
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000882 child_compiler_type = GetCompilerType().GetChildCompilerTypeAtIndex (&exe_ctx,
883 idx,
884 transparent_pointers,
885 omit_empty_base_classes,
886 ignore_array_bounds,
887 child_name_str,
888 child_byte_size,
889 child_byte_offset,
890 child_bitfield_bit_size,
891 child_bitfield_bit_offset,
892 child_is_base_class,
893 child_is_deref_of_parent,
894 this);
895 if (child_compiler_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000896 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000897 if (synthetic_index)
898 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000899
Greg Claytondea8cb42011-06-29 22:09:02 +0000900 ConstString child_name;
901 if (!child_name_str.empty())
902 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000903
Greg Claytondea8cb42011-06-29 22:09:02 +0000904 valobj = new ValueObjectChild (*this,
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000905 child_compiler_type,
Greg Claytondea8cb42011-06-29 22:09:02 +0000906 child_name,
907 child_byte_size,
908 child_byte_offset,
909 child_bitfield_bit_size,
910 child_bitfield_bit_offset,
911 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000912 child_is_deref_of_parent,
913 eAddressTypeInvalid);
914 //if (valobj)
915 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
916 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000917
Jim Ingham58b59f92011-04-22 23:53:53 +0000918 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000919}
920
Enrico Granata0c489f52012-03-01 04:24:26 +0000921bool
922ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
Enrico Granata31fda932015-10-07 01:41:23 +0000923 std::string& destination,
924 lldb::LanguageType lang)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000925{
Enrico Granata31fda932015-10-07 01:41:23 +0000926 return GetSummaryAsCString(summary_ptr, destination, TypeSummaryOptions().SetLanguage(lang));
Enrico Granatac1247f52014-11-06 21:23:20 +0000927}
928
929bool
930ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
931 std::string& destination,
932 const TypeSummaryOptions& options)
933{
Enrico Granata0c489f52012-03-01 04:24:26 +0000934 destination.clear();
Enrico Granata31fda932015-10-07 01:41:23 +0000935
Enrico Granata0c489f52012-03-01 04:24:26 +0000936 // ideally we would like to bail out if passing NULL, but if we do so
937 // we end up not providing the summary for function pointers anymore
938 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
939 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000940
941 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000942
Enrico Granata31fda932015-10-07 01:41:23 +0000943 TypeSummaryOptions actual_options(options);
944
945 if (actual_options.GetLanguage() == lldb::eLanguageTypeUnknown)
946 actual_options.SetLanguage(GetPreferredDisplayLanguage());
947
Enrico Granataf18c03e2012-04-04 17:34:10 +0000948 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
949 // information that we might care to see in a crash log. might be useful in very specific situations though.
950 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
Enrico Granata31fda932015-10-07 01:41:23 +0000951 GetTypeName().GetCString(),
952 GetName().GetCString(),
953 summary_ptr->GetDescription().c_str());*/
Enrico Granataf18c03e2012-04-04 17:34:10 +0000954
Enrico Granataff0f23d2014-12-10 02:00:45 +0000955 if (UpdateValueIfNeeded (false) && summary_ptr)
Enrico Granata0c489f52012-03-01 04:24:26 +0000956 {
Enrico Granataff0f23d2014-12-10 02:00:45 +0000957 if (HasSyntheticValue())
958 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
Enrico Granata31fda932015-10-07 01:41:23 +0000959 summary_ptr->FormatObject(this, destination, actual_options);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000960 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000961 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000962 return !destination.empty();
963}
964
965const char *
Enrico Granata31fda932015-10-07 01:41:23 +0000966ValueObject::GetSummaryAsCString (lldb::LanguageType lang)
Enrico Granata0c489f52012-03-01 04:24:26 +0000967{
968 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
969 {
Enrico Granata31fda932015-10-07 01:41:23 +0000970 TypeSummaryOptions summary_options;
971 summary_options.SetLanguage(lang);
Enrico Granata0c489f52012-03-01 04:24:26 +0000972 GetSummaryAsCString(GetSummaryFormat().get(),
Enrico Granatac1247f52014-11-06 21:23:20 +0000973 m_summary_str,
Enrico Granata31fda932015-10-07 01:41:23 +0000974 summary_options);
Enrico Granata0c489f52012-03-01 04:24:26 +0000975 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000976 if (m_summary_str.empty())
977 return NULL;
978 return m_summary_str.c_str();
979}
980
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000981bool
Enrico Granata49bfafb2014-11-18 23:36:25 +0000982ValueObject::GetSummaryAsCString (std::string& destination,
983 const TypeSummaryOptions& options)
984{
985 return GetSummaryAsCString(GetSummaryFormat().get(),
Enrico Granata31fda932015-10-07 01:41:23 +0000986 destination,
987 options);
Enrico Granata49bfafb2014-11-18 23:36:25 +0000988}
989
990bool
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000991ValueObject::IsCStringContainer(bool check_pointer)
992{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000993 CompilerType pointee_or_element_compiler_type;
994 const Flags type_flags (GetTypeInfo (&pointee_or_element_compiler_type));
Enrico Granata622be232014-10-21 20:52:14 +0000995 bool is_char_arr_ptr (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000996 pointee_or_element_compiler_type.IsCharType ());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000997 if (!is_char_arr_ptr)
998 return false;
999 if (!check_pointer)
1000 return true;
Enrico Granata622be232014-10-21 20:52:14 +00001001 if (type_flags.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001002 return true;
Greg Claytonafacd142011-09-02 01:15:17 +00001003 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001004 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +00001005 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001006 return (cstr_address != LLDB_INVALID_ADDRESS);
1007}
1008
Enrico Granata9128ee22011-09-06 19:20:51 +00001009size_t
1010ValueObject::GetPointeeData (DataExtractor& data,
1011 uint32_t item_idx,
1012 uint32_t item_count)
1013{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001014 CompilerType pointee_or_element_compiler_type;
1015 const uint32_t type_info = GetTypeInfo (&pointee_or_element_compiler_type);
Enrico Granata622be232014-10-21 20:52:14 +00001016 const bool is_pointer_type = type_info & eTypeIsPointer;
1017 const bool is_array_type = type_info & eTypeIsArray;
Greg Clayton2452ab72013-02-08 22:02:02 +00001018 if (!(is_pointer_type || is_array_type))
Enrico Granata9128ee22011-09-06 19:20:51 +00001019 return 0;
1020
1021 if (item_count == 0)
1022 return 0;
1023
Enrico Granata951bdd52015-01-28 01:09:45 +00001024 ExecutionContext exe_ctx (GetExecutionContextRef());
1025
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001026 const uint64_t item_type_size = pointee_or_element_compiler_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
Enrico Granata9128ee22011-09-06 19:20:51 +00001027 const uint64_t bytes = item_count * item_type_size;
Enrico Granata9128ee22011-09-06 19:20:51 +00001028 const uint64_t offset = item_idx * item_type_size;
1029
1030 if (item_idx == 0 && item_count == 1) // simply a deref
1031 {
Greg Clayton2452ab72013-02-08 22:02:02 +00001032 if (is_pointer_type)
Enrico Granata9128ee22011-09-06 19:20:51 +00001033 {
1034 Error error;
1035 ValueObjectSP pointee_sp = Dereference(error);
1036 if (error.Fail() || pointee_sp.get() == NULL)
1037 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +00001038 return pointee_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +00001039 }
1040 else
1041 {
1042 ValueObjectSP child_sp = GetChildAtIndex(0, true);
1043 if (child_sp.get() == NULL)
1044 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +00001045 Error error;
1046 return child_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +00001047 }
1048 return true;
1049 }
1050 else /* (items > 1) */
1051 {
1052 Error error;
1053 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
1054 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
1055
1056 AddressType addr_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001057 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001058
Enrico Granata9128ee22011-09-06 19:20:51 +00001059 switch (addr_type)
1060 {
1061 case eAddressTypeFile:
1062 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001063 ModuleSP module_sp (GetModule());
1064 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001065 {
Enrico Granata9c2efe32012-08-07 01:49:34 +00001066 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +00001067 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001068 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001069 ExecutionContext exe_ctx (GetExecutionContextRef());
1070 Target* target = exe_ctx.GetTargetPtr();
1071 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +00001072 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001073 heap_buf_ptr->SetByteSize(bytes);
1074 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
1075 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +00001076 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001077 data.SetData(data_sp);
1078 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +00001079 }
1080 }
1081 }
1082 }
1083 break;
1084 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +00001085 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001086 ExecutionContext exe_ctx (GetExecutionContextRef());
1087 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +00001088 if (process)
1089 {
1090 heap_buf_ptr->SetByteSize(bytes);
1091 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
Enrico Granata5e1480c2013-10-30 17:52:44 +00001092 if (error.Success() || bytes_read > 0)
Enrico Granata9128ee22011-09-06 19:20:51 +00001093 {
1094 data.SetData(data_sp);
1095 return bytes_read;
1096 }
1097 }
1098 }
1099 break;
1100 case eAddressTypeHost:
1101 {
Greg Clayton99558cc42015-08-24 23:46:31 +00001102 const uint64_t max_bytes = GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope());
Greg Clayton2452ab72013-02-08 22:02:02 +00001103 if (max_bytes > offset)
1104 {
1105 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
Siva Chandrae32f2b52015-05-05 00:41:35 +00001106 addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Enrico Granata7339b9d2015-11-03 02:34:43 +00001107 if (addr == 0 || addr == LLDB_INVALID_ADDRESS)
Siva Chandrae32f2b52015-05-05 00:41:35 +00001108 break;
Greg Clayton2452ab72013-02-08 22:02:02 +00001109 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
1110 data.SetData(data_sp);
1111 return bytes_read;
1112 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001113 }
1114 break;
1115 case eAddressTypeInvalid:
Enrico Granata9128ee22011-09-06 19:20:51 +00001116 break;
1117 }
1118 }
1119 return 0;
1120}
1121
Greg Claytonfaac1112013-03-14 18:31:44 +00001122uint64_t
Sean Callanan866e91c2014-02-28 22:27:53 +00001123ValueObject::GetData (DataExtractor& data, Error &error)
Enrico Granata9128ee22011-09-06 19:20:51 +00001124{
1125 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001126 ExecutionContext exe_ctx (GetExecutionContextRef());
Sean Callanan866e91c2014-02-28 22:27:53 +00001127 error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001128 if (error.Fail())
Sean Callananed185ab2013-04-19 19:47:32 +00001129 {
1130 if (m_data.GetByteSize())
1131 {
1132 data = m_data;
1133 return data.GetByteSize();
1134 }
1135 else
1136 {
1137 return 0;
1138 }
1139 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001140 data.SetAddressByteSize(m_data.GetAddressByteSize());
1141 data.SetByteOrder(m_data.GetByteOrder());
1142 return data.GetByteSize();
1143}
1144
Sean Callanan389823e2013-04-13 01:21:23 +00001145bool
1146ValueObject::SetData (DataExtractor &data, Error &error)
1147{
1148 error.Clear();
1149 // Make sure our value is up to date first so that our location and location
1150 // type is valid.
1151 if (!UpdateValueIfNeeded(false))
1152 {
1153 error.SetErrorString("unable to read value");
1154 return false;
1155 }
1156
1157 uint64_t count = 0;
Greg Clayton99558cc42015-08-24 23:46:31 +00001158 const Encoding encoding = GetCompilerType().GetEncoding(count);
Sean Callanan389823e2013-04-13 01:21:23 +00001159
1160 const size_t byte_size = GetByteSize();
1161
1162 Value::ValueType value_type = m_value.GetValueType();
1163
1164 switch (value_type)
1165 {
1166 case Value::eValueTypeScalar:
1167 {
1168 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1169
1170 if (!set_error.Success())
1171 {
1172 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1173 return false;
1174 }
1175 }
1176 break;
1177 case Value::eValueTypeLoadAddress:
1178 {
1179 // If it is a load address, then the scalar value is the storage location
1180 // of the data, and we have to shove this value down to that load location.
1181 ExecutionContext exe_ctx (GetExecutionContextRef());
1182 Process *process = exe_ctx.GetProcessPtr();
1183 if (process)
1184 {
1185 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1186 size_t bytes_written = process->WriteMemory(target_addr,
1187 data.GetDataStart(),
1188 byte_size,
1189 error);
1190 if (!error.Success())
1191 return false;
1192 if (bytes_written != byte_size)
1193 {
1194 error.SetErrorString("unable to write value to memory");
1195 return false;
1196 }
1197 }
1198 }
1199 break;
1200 case Value::eValueTypeHostAddress:
1201 {
1202 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1203 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1204 m_data.SetData(buffer_sp, 0);
1205 data.CopyByteOrderedData (0,
1206 byte_size,
1207 const_cast<uint8_t *>(m_data.GetDataStart()),
1208 byte_size,
1209 m_data.GetByteOrder());
1210 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1211 }
1212 break;
1213 case Value::eValueTypeFileAddress:
1214 case Value::eValueTypeVector:
1215 break;
1216 }
1217
1218 // If we have reached this point, then we have successfully changed the value.
1219 SetNeedsUpdate();
1220 return true;
1221}
1222
Enrico Granata9128ee22011-09-06 19:20:51 +00001223// will compute strlen(str), but without consuming more than
1224// maxlen bytes out of str (this serves the purpose of reading
1225// chunks of a string without having to worry about
1226// missing NULL terminators in the chunk)
1227// of course, if strlen(str) > maxlen, the function will return
1228// maxlen_value (which should be != maxlen, because that allows you
1229// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1230static uint32_t
1231strlen_or_inf (const char* str,
1232 uint32_t maxlen,
1233 uint32_t maxlen_value)
1234{
1235 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +00001236 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +00001237 {
Greg Clayton8dd5c172011-10-05 22:19:51 +00001238 while(*str)
1239 {
1240 len++;str++;
Greg Clayton2452ab72013-02-08 22:02:02 +00001241 if (len >= maxlen)
Greg Clayton8dd5c172011-10-05 22:19:51 +00001242 return maxlen_value;
1243 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001244 }
1245 return len;
1246}
1247
Enrico Granata2206b482014-10-30 18:27:31 +00001248static bool
1249CopyStringDataToBufferSP(const StreamString& source,
1250 lldb::DataBufferSP& destination)
1251{
1252 destination.reset(new DataBufferHeap(source.GetSize()+1,0));
1253 memcpy(destination->GetBytes(), source.GetString().c_str(), source.GetSize());
1254 return true;
1255}
1256
Enrico Granatab7662922015-11-04 00:02:08 +00001257std::pair<size_t,bool>
Enrico Granata2206b482014-10-30 18:27:31 +00001258ValueObject::ReadPointedString (lldb::DataBufferSP& buffer_sp,
Greg Claytoncc4d0142012-02-17 07:49:44 +00001259 Error& error,
1260 uint32_t max_length,
1261 bool honor_array,
1262 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001263{
Enrico Granatab7662922015-11-04 00:02:08 +00001264 bool was_capped = false;
Enrico Granata2206b482014-10-30 18:27:31 +00001265 StreamString s;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001266 ExecutionContext exe_ctx (GetExecutionContextRef());
1267 Target* target = exe_ctx.GetTargetPtr();
Enrico Granata2206b482014-10-30 18:27:31 +00001268
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001269 if (!target)
1270 {
1271 s << "<no target to read from>";
1272 error.SetErrorString("no target to read from");
Enrico Granata2206b482014-10-30 18:27:31 +00001273 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granatab7662922015-11-04 00:02:08 +00001274 return {0,was_capped};
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001275 }
1276
1277 if (max_length == 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001278 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001279
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001280 size_t bytes_read = 0;
1281 size_t total_bytes_read = 0;
1282
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001283 CompilerType compiler_type = GetCompilerType();
1284 CompilerType elem_or_pointee_compiler_type;
1285 const Flags type_flags (GetTypeInfo (&elem_or_pointee_compiler_type));
Enrico Granata622be232014-10-21 20:52:14 +00001286 if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001287 elem_or_pointee_compiler_type.IsCharType ())
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001288 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001289 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1290 AddressType cstr_address_type = eAddressTypeInvalid;
1291
1292 size_t cstr_len = 0;
1293 bool capped_data = false;
Enrico Granata622be232014-10-21 20:52:14 +00001294 if (type_flags.Test (eTypeIsArray))
Greg Claytoncc4d0142012-02-17 07:49:44 +00001295 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001296 // We have an array
Greg Clayton57ee3062013-07-11 22:46:58 +00001297 uint64_t array_size = 0;
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001298 if (compiler_type.IsArrayType(NULL, &array_size, NULL))
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001299 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001300 cstr_len = array_size;
1301 if (cstr_len > max_length)
1302 {
1303 capped_data = true;
1304 cstr_len = max_length;
1305 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001306 }
1307 cstr_address = GetAddressOf (true, &cstr_address_type);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001308 }
1309 else
1310 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001311 // We have a pointer
1312 cstr_address = GetPointerValue (&cstr_address_type);
1313 }
1314
1315 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1316 {
1317 s << "<invalid address>";
1318 error.SetErrorString("invalid address");
Enrico Granata2206b482014-10-30 18:27:31 +00001319 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granatab7662922015-11-04 00:02:08 +00001320 return {0,was_capped};
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001321 }
Enrico Granata2206b482014-10-30 18:27:31 +00001322
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001323 Address cstr_so_addr (cstr_address);
1324 DataExtractor data;
1325 if (cstr_len > 0 && honor_array)
1326 {
1327 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1328 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1329 GetPointeeData(data, 0, cstr_len);
Enrico Granata2206b482014-10-30 18:27:31 +00001330
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001331 if ((bytes_read = data.GetByteSize()) > 0)
1332 {
1333 total_bytes_read = bytes_read;
Enrico Granata2206b482014-10-30 18:27:31 +00001334 for (size_t offset = 0; offset < bytes_read; offset++)
1335 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001336 if (capped_data)
Enrico Granatab7662922015-11-04 00:02:08 +00001337 was_capped = true;
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001338 }
1339 }
1340 else
1341 {
1342 cstr_len = max_length;
1343 const size_t k_max_buf_size = 64;
Enrico Granata2206b482014-10-30 18:27:31 +00001344
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001345 size_t offset = 0;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001346
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001347 int cstr_len_displayed = -1;
1348 bool capped_cstr = false;
1349 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1350 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1351 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001352 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001353 total_bytes_read += bytes_read;
1354 const char *cstr = data.PeekCStr(0);
1355 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1356 if (len > k_max_buf_size)
1357 len = k_max_buf_size;
Enrico Granata2206b482014-10-30 18:27:31 +00001358
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001359 if (cstr_len_displayed < 0)
1360 cstr_len_displayed = len;
Enrico Granata2206b482014-10-30 18:27:31 +00001361
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001362 if (len == 0)
1363 break;
1364 cstr_len_displayed += len;
1365 if (len > bytes_read)
1366 len = bytes_read;
1367 if (len > cstr_len)
1368 len = cstr_len;
1369
Enrico Granata2206b482014-10-30 18:27:31 +00001370 for (size_t offset = 0; offset < bytes_read; offset++)
1371 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001372
1373 if (len < k_max_buf_size)
1374 break;
1375
1376 if (len >= cstr_len)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001377 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001378 capped_cstr = true;
1379 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001380 }
Enrico Granata2206b482014-10-30 18:27:31 +00001381
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001382 cstr_len -= len;
1383 offset += len;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001384 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001385
1386 if (cstr_len_displayed >= 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001387 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001388 if (capped_cstr)
Enrico Granatab7662922015-11-04 00:02:08 +00001389 was_capped = true;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001390 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001391 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001392 }
1393 else
1394 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001395 error.SetErrorString("not a string object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001396 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001397 }
Enrico Granata2206b482014-10-30 18:27:31 +00001398 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granatab7662922015-11-04 00:02:08 +00001399 return {total_bytes_read,was_capped};
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001400}
1401
Enrico Granata744794a2014-09-05 21:46:22 +00001402std::pair<TypeValidatorResult, std::string>
1403ValueObject::GetValidationStatus ()
1404{
1405 if (!UpdateValueIfNeeded(true))
1406 return {TypeValidatorResult::Success,""}; // not the validator's job to discuss update problems
1407
1408 if (m_validation_result.hasValue())
1409 return m_validation_result.getValue();
1410
1411 if (!m_type_validator_sp)
1412 return {TypeValidatorResult::Success,""}; // no validator no failure
1413
1414 auto outcome = m_type_validator_sp->FormatObject(this);
1415
1416 return (m_validation_result = {outcome.m_result,outcome.m_message}).getValue();
1417}
1418
Jim Ingham53c47f12010-09-10 23:12:17 +00001419const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001420ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001421{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001422
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001423 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001424 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001425
1426 if (!m_object_desc_str.empty())
1427 return m_object_desc_str.c_str();
1428
Greg Claytoncc4d0142012-02-17 07:49:44 +00001429 ExecutionContext exe_ctx (GetExecutionContextRef());
1430 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001431 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001432 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001433
Jim Ingham53c47f12010-09-10 23:12:17 +00001434 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001435
Greg Claytonafacd142011-09-02 01:15:17 +00001436 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001437 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1438
Jim Inghama2cf2632010-12-23 02:29:54 +00001439 if (runtime == NULL)
1440 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001441 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001442 CompilerType compiler_type = GetCompilerType();
1443 if (compiler_type)
Jim Inghama2cf2632010-12-23 02:29:54 +00001444 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001445 bool is_signed;
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001446 if (compiler_type.IsIntegerType (is_signed) || compiler_type.IsPointerType ())
Jim Inghamb7603bb2011-03-18 00:05:18 +00001447 {
Greg Claytonafacd142011-09-02 01:15:17 +00001448 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001449 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001450 }
1451 }
1452
Jim Ingham8d543de2011-03-31 23:01:21 +00001453 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001454 {
1455 m_object_desc_str.append (s.GetData());
1456 }
Sean Callanan672ad942010-10-23 00:18:49 +00001457
1458 if (m_object_desc_str.empty())
1459 return NULL;
1460 else
1461 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001462}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001463
Enrico Granata0c489f52012-03-01 04:24:26 +00001464bool
Enrico Granata4939b982013-12-22 09:24:22 +00001465ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format,
1466 std::string& destination)
1467{
1468 if (UpdateValueIfNeeded(false))
1469 return format.FormatObject(this,destination);
1470 else
1471 return false;
1472}
1473
1474bool
Enrico Granata0c489f52012-03-01 04:24:26 +00001475ValueObject::GetValueAsCString (lldb::Format format,
1476 std::string& destination)
1477{
Enrico Granata30f287f2013-12-28 08:44:02 +00001478 return GetValueAsCString(TypeFormatImpl_Format(format),destination);
Enrico Granata0c489f52012-03-01 04:24:26 +00001479}
1480
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001481const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001482ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001483{
Enrico Granatab294fd22013-05-31 19:18:19 +00001484 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001485 {
Enrico Granata4939b982013-12-22 09:24:22 +00001486 lldb::TypeFormatImplSP format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001487 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001488 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001489 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001490 if (m_type_format_sp)
Enrico Granata4939b982013-12-22 09:24:22 +00001491 format_sp = m_type_format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001492 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001493 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001494 if (m_is_bitfield_for_scalar)
1495 my_format = eFormatUnsigned;
1496 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001497 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001498 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001499 {
1500 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1501 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001502 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001503 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001504 else
1505 {
Greg Clayton99558cc42015-08-24 23:46:31 +00001506 my_format = GetValue().GetCompilerType().GetFormat();
Enrico Granata0c489f52012-03-01 04:24:26 +00001507 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001508 }
1509 }
1510 }
Enrico Granatab294fd22013-05-31 19:18:19 +00001511 if (my_format != m_last_format || m_value_str.empty())
Enrico Granata297e69f2012-03-06 23:21:16 +00001512 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001513 m_last_format = my_format;
Enrico Granata4939b982013-12-22 09:24:22 +00001514 if (!format_sp)
Enrico Granata30f287f2013-12-28 08:44:02 +00001515 format_sp.reset(new TypeFormatImpl_Format(my_format));
Enrico Granata4939b982013-12-22 09:24:22 +00001516 if (GetValueAsCString(*format_sp.get(), m_value_str))
Enrico Granata297e69f2012-03-06 23:21:16 +00001517 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001518 if (!m_value_did_change && m_old_value_valid)
1519 {
1520 // The value was gotten successfully, so we consider the
1521 // value as changed if the value string differs
1522 SetValueDidChange (m_old_value_str != m_value_str);
1523 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001524 }
1525 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001526 }
1527 if (m_value_str.empty())
1528 return NULL;
1529 return m_value_str.c_str();
1530}
1531
Enrico Granatac3e320a2011-08-02 17:27:39 +00001532// if > 8bytes, 0 is returned. this method should mostly be used
1533// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001534uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001535ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001536{
1537 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001538 if (CanProvideValue())
Enrico Granatac3e320a2011-08-02 17:27:39 +00001539 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001540 Scalar scalar;
1541 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001542 {
1543 if (success)
1544 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001545 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001546 }
1547 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001548 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001549
1550 if (success)
1551 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001552 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001553}
1554
Enrico Granatad7373f62013-10-31 18:57:50 +00001555int64_t
1556ValueObject::GetValueAsSigned (int64_t fail_value, bool *success)
1557{
1558 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001559 if (CanProvideValue())
Enrico Granatad7373f62013-10-31 18:57:50 +00001560 {
1561 Scalar scalar;
1562 if (ResolveValue (scalar))
1563 {
1564 if (success)
1565 *success = true;
Tamas Berghammer5a9919f2015-01-23 10:54:21 +00001566 return scalar.SLongLong(fail_value);
Enrico Granatad7373f62013-10-31 18:57:50 +00001567 }
1568 // fallthrough, otherwise...
1569 }
1570
1571 if (success)
1572 *success = false;
Tamas Berghammer5a9919f2015-01-23 10:54:21 +00001573 return fail_value;
Enrico Granatad7373f62013-10-31 18:57:50 +00001574}
1575
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001576// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1577// this call up to date by returning true for your new special cases. We will eventually move
1578// to checking this call result before trying to display special cases
1579bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001580ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1581 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001582{
Greg Clayton57ee3062013-07-11 22:46:58 +00001583 Flags flags(GetTypeInfo());
Enrico Granata622be232014-10-21 20:52:14 +00001584 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001585 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001586 {
1587 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001588 (custom_format == eFormatCString ||
1589 custom_format == eFormatCharArray ||
1590 custom_format == eFormatChar ||
1591 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001592 return true;
1593
Enrico Granata622be232014-10-21 20:52:14 +00001594 if (flags.Test(eTypeIsArray))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001595 {
Greg Claytonafacd142011-09-02 01:15:17 +00001596 if ((custom_format == eFormatBytes) ||
1597 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001598 return true;
1599
Greg Claytonafacd142011-09-02 01:15:17 +00001600 if ((custom_format == eFormatVectorOfChar) ||
1601 (custom_format == eFormatVectorOfFloat32) ||
1602 (custom_format == eFormatVectorOfFloat64) ||
1603 (custom_format == eFormatVectorOfSInt16) ||
1604 (custom_format == eFormatVectorOfSInt32) ||
1605 (custom_format == eFormatVectorOfSInt64) ||
1606 (custom_format == eFormatVectorOfSInt8) ||
1607 (custom_format == eFormatVectorOfUInt128) ||
1608 (custom_format == eFormatVectorOfUInt16) ||
1609 (custom_format == eFormatVectorOfUInt32) ||
1610 (custom_format == eFormatVectorOfUInt64) ||
1611 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001612 return true;
1613 }
1614 }
1615 return false;
1616}
1617
Enrico Granata9fc19442011-07-06 02:13:41 +00001618bool
1619ValueObject::DumpPrintableRepresentation(Stream& s,
1620 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001621 Format custom_format,
Enrico Granata0dba9b32014-01-08 01:36:59 +00001622 PrintableRepresentationSpecialCases special,
1623 bool do_dump_error)
Enrico Granata9fc19442011-07-06 02:13:41 +00001624{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001625
Greg Clayton57ee3062013-07-11 22:46:58 +00001626 Flags flags(GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001627
Enrico Granata86cc9822012-03-19 22:58:49 +00001628 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1629 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1630
1631 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001632 {
Enrico Granata622be232014-10-21 20:52:14 +00001633 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001634 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001635 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001636 // when being asked to get a printable display an array or pointer type directly,
1637 // try to "do the right thing"
1638
1639 if (IsCStringContainer(true) &&
1640 (custom_format == eFormatCString ||
1641 custom_format == eFormatCharArray ||
1642 custom_format == eFormatChar ||
1643 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001644 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001645 Error error;
Enrico Granata2206b482014-10-30 18:27:31 +00001646 lldb::DataBufferSP buffer_sp;
Enrico Granatab7662922015-11-04 00:02:08 +00001647 std::pair<size_t, bool> read_string = ReadPointedString(buffer_sp,
1648 error,
1649 0,
1650 (custom_format == eFormatVectorOfChar) ||
1651 (custom_format == eFormatCharArray));
Enrico Granataac494532015-09-09 22:30:24 +00001652 lldb_private::formatters::StringPrinter::ReadBufferAndDumpToStreamOptions options(*this);
Enrico Granata2206b482014-10-30 18:27:31 +00001653 options.SetData(DataExtractor(buffer_sp, lldb::eByteOrderInvalid, 8)); // none of this matters for a string - pass some defaults
1654 options.SetStream(&s);
1655 options.SetPrefixToken(0);
1656 options.SetQuote('"');
1657 options.SetSourceSize(buffer_sp->GetByteSize());
Enrico Granatab7662922015-11-04 00:02:08 +00001658 options.SetIsTruncated(read_string.second);
Enrico Granataac494532015-09-09 22:30:24 +00001659 formatters::StringPrinter::ReadBufferAndDumpToStream<lldb_private::formatters::StringPrinter::StringElementType::ASCII>(options);
Enrico Granata86cc9822012-03-19 22:58:49 +00001660 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001661 }
1662
Enrico Granata86cc9822012-03-19 22:58:49 +00001663 if (custom_format == eFormatEnum)
1664 return false;
1665
1666 // this only works for arrays, because I have no way to know when
1667 // the pointed memory ends, and no special \0 end of data marker
Enrico Granata622be232014-10-21 20:52:14 +00001668 if (flags.Test(eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001669 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001670 if ((custom_format == eFormatBytes) ||
1671 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001672 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001673 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001674
1675 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001676 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001677 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001678
1679 if (low)
1680 s << ',';
1681
1682 ValueObjectSP child = GetChildAtIndex(low,true);
1683 if (!child.get())
1684 {
1685 s << "<invalid child>";
1686 continue;
1687 }
1688 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1689 }
1690
1691 s << ']';
1692
1693 return true;
1694 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001695
Enrico Granata86cc9822012-03-19 22:58:49 +00001696 if ((custom_format == eFormatVectorOfChar) ||
1697 (custom_format == eFormatVectorOfFloat32) ||
1698 (custom_format == eFormatVectorOfFloat64) ||
1699 (custom_format == eFormatVectorOfSInt16) ||
1700 (custom_format == eFormatVectorOfSInt32) ||
1701 (custom_format == eFormatVectorOfSInt64) ||
1702 (custom_format == eFormatVectorOfSInt8) ||
1703 (custom_format == eFormatVectorOfUInt128) ||
1704 (custom_format == eFormatVectorOfUInt16) ||
1705 (custom_format == eFormatVectorOfUInt32) ||
1706 (custom_format == eFormatVectorOfUInt64) ||
1707 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1708 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001709 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001710
1711 Format format = FormatManager::GetSingleItemFormat(custom_format);
1712
1713 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001714 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001715 {
1716
1717 if (low)
1718 s << ',';
1719
1720 ValueObjectSP child = GetChildAtIndex(low,true);
1721 if (!child.get())
1722 {
1723 s << "<invalid child>";
1724 continue;
1725 }
1726 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1727 }
1728
1729 s << ']';
1730
1731 return true;
1732 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001733 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001734
1735 if ((custom_format == eFormatBoolean) ||
1736 (custom_format == eFormatBinary) ||
1737 (custom_format == eFormatChar) ||
1738 (custom_format == eFormatCharPrintable) ||
1739 (custom_format == eFormatComplexFloat) ||
1740 (custom_format == eFormatDecimal) ||
1741 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001742 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001743 (custom_format == eFormatFloat) ||
1744 (custom_format == eFormatOctal) ||
1745 (custom_format == eFormatOSType) ||
1746 (custom_format == eFormatUnicode16) ||
1747 (custom_format == eFormatUnicode32) ||
1748 (custom_format == eFormatUnsigned) ||
1749 (custom_format == eFormatPointer) ||
1750 (custom_format == eFormatComplexInteger) ||
1751 (custom_format == eFormatComplex) ||
1752 (custom_format == eFormatDefault)) // use the [] operator
1753 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001754 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001755 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001756
1757 if (only_special)
1758 return false;
1759
Enrico Granata86cc9822012-03-19 22:58:49 +00001760 bool var_success = false;
1761
1762 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001763 const char *cstr = NULL;
Enrico Granata2c75f112013-06-21 00:04:51 +00001764
1765 // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1766 // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1767 // area for cases where our desired output is not backed by some other longer-term storage
Greg Claytonc7bece562013-01-25 18:06:21 +00001768 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001769
Enrico Granata465f4bc2014-02-15 01:24:44 +00001770 if (custom_format != eFormatInvalid)
Enrico Granata86cc9822012-03-19 22:58:49 +00001771 SetFormat(custom_format);
1772
1773 switch(val_obj_display)
1774 {
1775 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001776 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001777 break;
1778
1779 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001780 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001781 break;
1782
1783 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001784 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001785 break;
1786
1787 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001788 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001789 break;
1790
1791 case eValueObjectRepresentationStyleChildrenCount:
Deepak Panickal99fbc072014-03-03 15:39:47 +00001792 strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren());
Greg Claytonc7bece562013-01-25 18:06:21 +00001793 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001794 break;
1795
1796 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001797 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001798 break;
Enrico Granata2c75f112013-06-21 00:04:51 +00001799
1800 case eValueObjectRepresentationStyleName:
1801 cstr = GetName().AsCString();
1802 break;
1803
1804 case eValueObjectRepresentationStyleExpressionPath:
1805 GetExpressionPath(strm, false);
1806 cstr = strm.GetString().c_str();
1807 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001808 }
1809
Greg Claytonc7bece562013-01-25 18:06:21 +00001810 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001811 {
1812 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001813 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001814 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1815 {
Enrico Granatad07cfd32014-10-08 18:27:36 +00001816 if (!CanProvideValue())
Enrico Granata86cc9822012-03-19 22:58:49 +00001817 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001818 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1819 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001820 }
1821 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001822 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001823 }
1824 }
1825
Greg Claytonc7bece562013-01-25 18:06:21 +00001826 if (cstr)
1827 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001828 else
1829 {
1830 if (m_error.Fail())
Enrico Granata0dba9b32014-01-08 01:36:59 +00001831 {
1832 if (do_dump_error)
1833 s.Printf("<%s>", m_error.AsCString());
1834 else
1835 return false;
1836 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001837 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1838 s.PutCString("<no summary available>");
1839 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1840 s.PutCString("<no value available>");
1841 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1842 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1843 else
1844 s.PutCString("<no printable representation>");
1845 }
1846
1847 // we should only return false here if we could not do *anything*
1848 // even if we have an error message as output, that's a success
1849 // from our callers' perspective, so return true
1850 var_success = true;
Enrico Granata465f4bc2014-02-15 01:24:44 +00001851
1852 if (custom_format != eFormatInvalid)
1853 SetFormat(eFormatDefault);
Enrico Granata86cc9822012-03-19 22:58:49 +00001854 }
1855
Enrico Granataf4efecd2011-07-12 22:56:10 +00001856 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001857}
1858
Greg Clayton737b9322010-09-13 03:32:57 +00001859addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001860ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001861{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001862 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001863 return LLDB_INVALID_ADDRESS;
1864
Greg Clayton73b472d2010-10-27 03:32:59 +00001865 switch (m_value.GetValueType())
1866 {
1867 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001868 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001869 if (scalar_is_load_address)
1870 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001871 if(address_type)
1872 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001873 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1874 }
1875 break;
1876
1877 case Value::eValueTypeLoadAddress:
1878 case Value::eValueTypeFileAddress:
Greg Clayton73b472d2010-10-27 03:32:59 +00001879 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001880 if(address_type)
1881 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001882 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1883 }
1884 break;
Siva Chandraa3747a92015-05-04 19:43:34 +00001885 case Value::eValueTypeHostAddress:
Siva Chandrae32f2b52015-05-05 00:41:35 +00001886 {
1887 if(address_type)
1888 *address_type = m_value.GetValueAddressType ();
1889 return LLDB_INVALID_ADDRESS;
1890 }
Siva Chandraa3747a92015-05-04 19:43:34 +00001891 break;
Greg Clayton73b472d2010-10-27 03:32:59 +00001892 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001893 if (address_type)
1894 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001895 return LLDB_INVALID_ADDRESS;
1896}
1897
1898addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001899ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001900{
Greg Claytonafacd142011-09-02 01:15:17 +00001901 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001902 if(address_type)
1903 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001904
Enrico Granatac3e320a2011-08-02 17:27:39 +00001905 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001906 return address;
1907
Greg Clayton73b472d2010-10-27 03:32:59 +00001908 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001909 {
1910 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001911 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001912 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001913 break;
1914
Enrico Granata9128ee22011-09-06 19:20:51 +00001915 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001916 case Value::eValueTypeLoadAddress:
1917 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001918 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001919 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001920 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001921 }
1922 break;
1923 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001924
Enrico Granata9128ee22011-09-06 19:20:51 +00001925 if (address_type)
1926 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001927
Greg Clayton737b9322010-09-13 03:32:57 +00001928 return address;
1929}
1930
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001931bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001932ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001933{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001934 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001935 // Make sure our value is up to date first so that our location and location
1936 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001937 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001938 {
1939 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001940 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001941 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001942
Greg Claytonfaac1112013-03-14 18:31:44 +00001943 uint64_t count = 0;
Greg Clayton99558cc42015-08-24 23:46:31 +00001944 const Encoding encoding = GetCompilerType().GetEncoding (count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001945
Greg Claytonb1320972010-07-14 00:18:15 +00001946 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001947
Jim Ingham16e0c682011-08-12 23:34:31 +00001948 Value::ValueType value_type = m_value.GetValueType();
1949
1950 if (value_type == Value::eValueTypeScalar)
1951 {
1952 // If the value is already a scalar, then let the scalar change itself:
1953 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1954 }
Sagar Thakur8536fd12015-08-20 09:12:46 +00001955 else if (byte_size <= 16)
Jim Ingham16e0c682011-08-12 23:34:31 +00001956 {
1957 // If the value fits in a scalar, then make a new scalar and again let the
1958 // scalar code do the conversion, then figure out where to put the new value.
1959 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001960 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1961 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001962 {
Jim Ingham4b536182011-08-09 02:12:22 +00001963 switch (value_type)
1964 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001965 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001966 {
1967 // If it is a load address, then the scalar value is the storage location
1968 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001969 ExecutionContext exe_ctx (GetExecutionContextRef());
1970 Process *process = exe_ctx.GetProcessPtr();
1971 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001972 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001973 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001974 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1975 new_scalar,
1976 byte_size,
1977 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001978 if (!error.Success())
1979 return false;
1980 if (bytes_written != byte_size)
1981 {
1982 error.SetErrorString("unable to write value to memory");
1983 return false;
1984 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001985 }
1986 }
Jim Ingham4b536182011-08-09 02:12:22 +00001987 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001988 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001989 {
1990 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1991 DataExtractor new_data;
1992 new_data.SetByteOrder (m_data.GetByteOrder());
1993
1994 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1995 m_data.SetData(buffer_sp, 0);
1996 bool success = new_scalar.GetData(new_data);
1997 if (success)
1998 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001999 new_data.CopyByteOrderedData (0,
2000 byte_size,
2001 const_cast<uint8_t *>(m_data.GetDataStart()),
2002 byte_size,
2003 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00002004 }
2005 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
2006
2007 }
Jim Ingham4b536182011-08-09 02:12:22 +00002008 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00002009 case Value::eValueTypeFileAddress:
2010 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00002011 case Value::eValueTypeVector:
2012 break;
Jim Ingham4b536182011-08-09 02:12:22 +00002013 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002014 }
2015 else
2016 {
Jim Ingham16e0c682011-08-12 23:34:31 +00002017 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002018 }
Jim Ingham16e0c682011-08-12 23:34:31 +00002019 }
2020 else
2021 {
2022 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00002023 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002024 return false;
2025 }
Jim Ingham16e0c682011-08-12 23:34:31 +00002026
2027 // If we have reached this point, then we have successfully changed the value.
2028 SetNeedsUpdate();
2029 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002030}
2031
Greg Clayton81e871e2012-02-04 02:27:34 +00002032bool
2033ValueObject::GetDeclaration (Declaration &decl)
2034{
2035 decl.Clear();
2036 return false;
2037}
2038
Greg Clayton84db9102012-03-26 23:03:23 +00002039ConstString
2040ValueObject::GetTypeName()
2041{
Greg Clayton99558cc42015-08-24 23:46:31 +00002042 return GetCompilerType().GetConstTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00002043}
2044
2045ConstString
Enrico Granatae8daa2f2014-05-17 19:14:17 +00002046ValueObject::GetDisplayTypeName()
2047{
2048 return GetTypeName();
2049}
2050
2051ConstString
Greg Clayton84db9102012-03-26 23:03:23 +00002052ValueObject::GetQualifiedTypeName()
2053{
Greg Clayton99558cc42015-08-24 23:46:31 +00002054 return GetCompilerType().GetConstQualifiedTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00002055}
2056
2057
Greg Claytonafacd142011-09-02 01:15:17 +00002058LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00002059ValueObject::GetObjectRuntimeLanguage ()
2060{
Greg Clayton99558cc42015-08-24 23:46:31 +00002061 return GetCompilerType().GetMinimumLanguage ();
Jim Ingham5a369122010-09-28 01:25:32 +00002062}
2063
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002064void
Jim Ingham58b59f92011-04-22 23:53:53 +00002065ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002066{
Jim Ingham58b59f92011-04-22 23:53:53 +00002067 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002068}
2069
2070ValueObjectSP
2071ValueObject::GetSyntheticChild (const ConstString &key) const
2072{
2073 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00002074 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002075 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00002076 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002077 return synthetic_child_sp;
2078}
2079
Greg Clayton2452ab72013-02-08 22:02:02 +00002080uint32_t
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002081ValueObject::GetTypeInfo (CompilerType *pointee_or_element_compiler_type)
Greg Clayton2452ab72013-02-08 22:02:02 +00002082{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002083 return GetCompilerType().GetTypeInfo (pointee_or_element_compiler_type);
Greg Clayton2452ab72013-02-08 22:02:02 +00002084}
2085
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002086bool
2087ValueObject::IsPointerType ()
2088{
Greg Clayton99558cc42015-08-24 23:46:31 +00002089 return GetCompilerType().IsPointerType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002090}
2091
Jim Inghamb7603bb2011-03-18 00:05:18 +00002092bool
Greg Claytondaf515f2011-07-09 20:12:33 +00002093ValueObject::IsArrayType ()
2094{
Greg Clayton99558cc42015-08-24 23:46:31 +00002095 return GetCompilerType().IsArrayType (NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00002096}
2097
2098bool
Enrico Granata9fc19442011-07-06 02:13:41 +00002099ValueObject::IsScalarType ()
2100{
Greg Clayton99558cc42015-08-24 23:46:31 +00002101 return GetCompilerType().IsScalarType ();
Enrico Granata9fc19442011-07-06 02:13:41 +00002102}
2103
2104bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00002105ValueObject::IsIntegerType (bool &is_signed)
2106{
Greg Clayton99558cc42015-08-24 23:46:31 +00002107 return GetCompilerType().IsIntegerType (is_signed);
Jim Inghamb7603bb2011-03-18 00:05:18 +00002108}
Greg Clayton73b472d2010-10-27 03:32:59 +00002109
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002110bool
2111ValueObject::IsPointerOrReferenceType ()
2112{
Greg Clayton99558cc42015-08-24 23:46:31 +00002113 return GetCompilerType().IsPointerOrReferenceType ();
Greg Clayton007d5be2011-05-30 00:49:24 +00002114}
2115
2116bool
Greg Claytondea8cb42011-06-29 22:09:02 +00002117ValueObject::IsPossibleDynamicType ()
2118{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002119 ExecutionContext exe_ctx (GetExecutionContextRef());
2120 Process *process = exe_ctx.GetProcessPtr();
2121 if (process)
2122 return process->IsPossibleDynamicValue(*this);
2123 else
Greg Clayton99558cc42015-08-24 23:46:31 +00002124 return GetCompilerType().IsPossibleDynamicType (NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00002125}
2126
Enrico Granata9e7b3882012-12-13 23:50:33 +00002127bool
Enrico Granata560558e2015-02-11 02:35:39 +00002128ValueObject::IsRuntimeSupportValue ()
2129{
2130 Process *process(GetProcessSP().get());
2131 if (process)
2132 {
2133 LanguageRuntime *runtime = process->GetLanguageRuntime(GetObjectRuntimeLanguage());
2134 if (!runtime)
2135 runtime = process->GetObjCLanguageRuntime();
2136 if (runtime)
2137 return runtime->IsRuntimeSupportValue(*this);
2138 }
2139 return false;
2140}
2141
2142bool
Enrico Granata9e7b3882012-12-13 23:50:33 +00002143ValueObject::IsObjCNil ()
2144{
Enrico Granata622be232014-10-21 20:52:14 +00002145 const uint32_t mask = eTypeIsObjC | eTypeIsPointer;
Greg Clayton99558cc42015-08-24 23:46:31 +00002146 bool isObjCpointer = (((GetCompilerType().GetTypeInfo(NULL)) & mask) == mask);
Enrico Granata7277d202013-03-15 23:33:15 +00002147 if (!isObjCpointer)
2148 return false;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002149 bool canReadValue = true;
2150 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
Enrico Granata7277d202013-03-15 23:33:15 +00002151 return canReadValue && isZero;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002152}
2153
Greg Claytondaf515f2011-07-09 20:12:33 +00002154// This allows you to create an array member using and index
2155// that doesn't not fall in the normal bounds of the array.
2156// Many times structure can be defined as:
2157// struct Collection
2158// {
2159// uint32_t item_count;
2160// Item item_array[0];
2161// };
2162// The size of the "item_array" is 1, but many times in practice
2163// there are more items in "item_array".
2164
2165ValueObjectSP
Bruce Mitchener11d86362015-02-26 23:55:39 +00002166ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00002167{
2168 ValueObjectSP synthetic_child_sp;
Bruce Mitchener11d86362015-02-26 23:55:39 +00002169 if (IsPointerType () || IsArrayType())
Greg Claytondaf515f2011-07-09 20:12:33 +00002170 {
2171 char index_str[64];
Deepak Panickal99fbc072014-03-03 15:39:47 +00002172 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
Greg Claytondaf515f2011-07-09 20:12:33 +00002173 ConstString index_const_str(index_str);
2174 // Check if we have already created a synthetic array member in this
2175 // valid object. If we have we will re-use it.
2176 synthetic_child_sp = GetSyntheticChild (index_const_str);
2177 if (!synthetic_child_sp)
2178 {
2179 ValueObject *synthetic_child;
2180 // We haven't made a synthetic array member for INDEX yet, so
2181 // lets make one and cache it for any future reference.
2182 synthetic_child = CreateChildAtIndex(0, true, index);
Bruce Mitchener11d86362015-02-26 23:55:39 +00002183
Greg Claytondaf515f2011-07-09 20:12:33 +00002184 // Cache the value if we got one back...
2185 if (synthetic_child)
2186 {
2187 AddSyntheticChild(index_const_str, synthetic_child);
2188 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002189 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00002190 synthetic_child_sp->m_is_array_item_for_pointer = true;
2191 }
2192 }
2193 }
2194 return synthetic_child_sp;
2195}
2196
Enrico Granata9fc19442011-07-06 02:13:41 +00002197ValueObjectSP
2198ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2199{
2200 ValueObjectSP synthetic_child_sp;
2201 if (IsScalarType ())
2202 {
2203 char index_str[64];
2204 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2205 ConstString index_const_str(index_str);
2206 // Check if we have already created a synthetic array member in this
2207 // valid object. If we have we will re-use it.
2208 synthetic_child_sp = GetSyntheticChild (index_const_str);
2209 if (!synthetic_child_sp)
2210 {
Enrico Granata9fc19442011-07-06 02:13:41 +00002211 // We haven't made a synthetic array member for INDEX yet, so
2212 // lets make one and cache it for any future reference.
Greg Clayton57ee3062013-07-11 22:46:58 +00002213 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
Greg Clayton99558cc42015-08-24 23:46:31 +00002214 GetCompilerType(),
Greg Clayton57ee3062013-07-11 22:46:58 +00002215 index_const_str,
2216 GetByteSize(),
2217 0,
2218 to-from+1,
2219 from,
2220 false,
2221 false,
2222 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002223
2224 // Cache the value if we got one back...
2225 if (synthetic_child)
2226 {
2227 AddSyntheticChild(index_const_str, synthetic_child);
2228 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002229 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002230 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2231 }
2232 }
2233 }
2234 return synthetic_child_sp;
2235}
2236
Greg Claytonafacd142011-09-02 01:15:17 +00002237ValueObjectSP
Greg Claytona1e5dc82015-08-11 22:53:00 +00002238ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const CompilerType& type, bool can_create)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002239{
2240
2241 ValueObjectSP synthetic_child_sp;
2242
2243 char name_str[64];
2244 snprintf(name_str, sizeof(name_str), "@%i", offset);
2245 ConstString name_const_str(name_str);
2246
2247 // Check if we have already created a synthetic array member in this
2248 // valid object. If we have we will re-use it.
2249 synthetic_child_sp = GetSyntheticChild (name_const_str);
2250
2251 if (synthetic_child_sp.get())
2252 return synthetic_child_sp;
2253
2254 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002255 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002256
Enrico Granata951bdd52015-01-28 01:09:45 +00002257 ExecutionContext exe_ctx (GetExecutionContextRef());
2258
Enrico Granata6f3533f2011-07-29 19:53:35 +00002259 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
Greg Clayton57ee3062013-07-11 22:46:58 +00002260 type,
Enrico Granata6f3533f2011-07-29 19:53:35 +00002261 name_const_str,
Greg Clayton526ae042015-02-12 00:34:25 +00002262 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
Enrico Granata6f3533f2011-07-29 19:53:35 +00002263 offset,
2264 0,
2265 0,
2266 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002267 false,
2268 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002269 if (synthetic_child)
2270 {
2271 AddSyntheticChild(name_const_str, synthetic_child);
2272 synthetic_child_sp = synthetic_child->GetSP();
2273 synthetic_child_sp->SetName(name_const_str);
2274 synthetic_child_sp->m_is_child_at_offset = true;
2275 }
2276 return synthetic_child_sp;
2277}
2278
Enrico Granata32556cd2014-08-26 20:54:04 +00002279ValueObjectSP
Greg Claytona1e5dc82015-08-11 22:53:00 +00002280ValueObject::GetSyntheticBase (uint32_t offset, const CompilerType& type, bool can_create)
Enrico Granata32556cd2014-08-26 20:54:04 +00002281{
2282 ValueObjectSP synthetic_child_sp;
2283
2284 char name_str[64];
2285 snprintf(name_str, sizeof(name_str), "%s", type.GetTypeName().AsCString("<unknown>"));
2286 ConstString name_const_str(name_str);
2287
2288 // Check if we have already created a synthetic array member in this
2289 // valid object. If we have we will re-use it.
2290 synthetic_child_sp = GetSyntheticChild (name_const_str);
2291
2292 if (synthetic_child_sp.get())
2293 return synthetic_child_sp;
2294
2295 if (!can_create)
2296 return ValueObjectSP();
2297
Enrico Granata32556cd2014-08-26 20:54:04 +00002298 const bool is_base_class = true;
2299
Enrico Granata951bdd52015-01-28 01:09:45 +00002300 ExecutionContext exe_ctx (GetExecutionContextRef());
2301
Enrico Granata32556cd2014-08-26 20:54:04 +00002302 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2303 type,
2304 name_const_str,
Greg Clayton526ae042015-02-12 00:34:25 +00002305 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
Enrico Granata32556cd2014-08-26 20:54:04 +00002306 offset,
2307 0,
2308 0,
2309 is_base_class,
2310 false,
2311 eAddressTypeInvalid);
2312 if (synthetic_child)
2313 {
2314 AddSyntheticChild(name_const_str, synthetic_child);
2315 synthetic_child_sp = synthetic_child->GetSP();
2316 synthetic_child_sp->SetName(name_const_str);
2317 }
2318 return synthetic_child_sp;
2319}
2320
2321
Enrico Granatad55546b2011-07-22 00:16:08 +00002322// your expression path needs to have a leading . or ->
2323// (unless it somehow "looks like" an array, in which case it has
2324// a leading [ symbol). while the [ is meaningful and should be shown
2325// to the user, . and -> are just parser design, but by no means
2326// added information for the user.. strip them off
2327static const char*
2328SkipLeadingExpressionPathSeparators(const char* expression)
2329{
2330 if (!expression || !expression[0])
2331 return expression;
2332 if (expression[0] == '.')
2333 return expression+1;
2334 if (expression[0] == '-' && expression[1] == '>')
2335 return expression+2;
2336 return expression;
2337}
2338
Greg Claytonafacd142011-09-02 01:15:17 +00002339ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002340ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2341{
2342 ValueObjectSP synthetic_child_sp;
2343 ConstString name_const_string(expression);
2344 // Check if we have already created a synthetic array member in this
2345 // valid object. If we have we will re-use it.
2346 synthetic_child_sp = GetSyntheticChild (name_const_string);
2347 if (!synthetic_child_sp)
2348 {
2349 // We haven't made a synthetic array member for expression yet, so
2350 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002351 synthetic_child_sp = GetValueForExpressionPath(expression,
2352 NULL, NULL, NULL,
Enrico Granataef238c12015-03-12 22:30:58 +00002353 GetValueForExpressionPathOptions().SetSyntheticChildrenTraversal(GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None));
Enrico Granatad55546b2011-07-22 00:16:08 +00002354
2355 // Cache the value if we got one back...
2356 if (synthetic_child_sp.get())
2357 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002358 // 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 +00002359 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002360 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002361 }
2362 }
2363 return synthetic_child_sp;
2364}
2365
2366void
Enrico Granata86cc9822012-03-19 22:58:49 +00002367ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002368{
Enrico Granata86cc9822012-03-19 22:58:49 +00002369 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002370 return;
2371
Enrico Granatac5bc4122012-03-27 02:35:13 +00002372 TargetSP target_sp(GetTargetSP());
Enrico Granata5d5f60c2013-09-24 22:58:37 +00002373 if (target_sp && target_sp->GetEnableSyntheticValue() == false)
Enrico Granatac5bc4122012-03-27 02:35:13 +00002374 {
2375 m_synthetic_value = NULL;
2376 return;
2377 }
2378
Enrico Granatae3e91512012-10-22 18:18:36 +00002379 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2380
Enrico Granata5548cb52013-01-28 23:47:25 +00002381 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002382 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002383
Enrico Granata0c489f52012-03-01 04:24:26 +00002384 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002385 return;
2386
Enrico Granatae3e91512012-10-22 18:18:36 +00002387 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2388 return;
2389
Enrico Granata86cc9822012-03-19 22:58:49 +00002390 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002391}
2392
Jim Ingham78a685a2011-04-16 00:01:13 +00002393void
Greg Claytonafacd142011-09-02 01:15:17 +00002394ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002395{
Greg Claytonafacd142011-09-02 01:15:17 +00002396 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002397 return;
2398
Jim Ingham58b59f92011-04-22 23:53:53 +00002399 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002400 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002401 ExecutionContext exe_ctx (GetExecutionContextRef());
2402 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002403 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002404 {
2405 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002406 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002407 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002408 }
2409}
2410
Jim Ingham58b59f92011-04-22 23:53:53 +00002411ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002412ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002413{
Greg Claytonafacd142011-09-02 01:15:17 +00002414 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002415 return ValueObjectSP();
2416
2417 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002418 {
Jim Ingham2837b762011-05-04 03:43:18 +00002419 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002420 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002421 if (m_dynamic_value)
2422 return m_dynamic_value->GetSP();
2423 else
2424 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002425}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002426
Jim Ingham60dbabb2011-12-08 19:44:08 +00002427ValueObjectSP
2428ValueObject::GetStaticValue()
2429{
2430 return GetSP();
2431}
2432
Enrico Granata886147f2012-05-08 18:47:08 +00002433lldb::ValueObjectSP
2434ValueObject::GetNonSyntheticValue ()
2435{
2436 return GetSP();
2437}
2438
Enrico Granatad55546b2011-07-22 00:16:08 +00002439ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002440ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002441{
Enrico Granata86cc9822012-03-19 22:58:49 +00002442 if (use_synthetic == false)
2443 return ValueObjectSP();
2444
Enrico Granatad55546b2011-07-22 00:16:08 +00002445 CalculateSyntheticValue(use_synthetic);
2446
2447 if (m_synthetic_value)
2448 return m_synthetic_value->GetSP();
2449 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002450 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002451}
2452
Greg Claytone221f822011-01-21 01:59:00 +00002453bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002454ValueObject::HasSyntheticValue()
2455{
Enrico Granata5548cb52013-01-28 23:47:25 +00002456 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002457
Enrico Granata0c489f52012-03-01 04:24:26 +00002458 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002459 return false;
2460
Enrico Granata86cc9822012-03-19 22:58:49 +00002461 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002462
2463 if (m_synthetic_value)
2464 return true;
2465 else
2466 return false;
2467}
2468
2469bool
Greg Claytone221f822011-01-21 01:59:00 +00002470ValueObject::GetBaseClassPath (Stream &s)
2471{
2472 if (IsBaseClass())
2473 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002474 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002475 CompilerType compiler_type = GetCompilerType();
Greg Claytone221f822011-01-21 01:59:00 +00002476 std::string cxx_class_name;
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002477 bool this_had_base_class = ClangASTContext::GetCXXClassName (compiler_type, cxx_class_name);
Greg Claytone221f822011-01-21 01:59:00 +00002478 if (this_had_base_class)
2479 {
2480 if (parent_had_base_class)
2481 s.PutCString("::");
2482 s.PutCString(cxx_class_name.c_str());
2483 }
2484 return parent_had_base_class || this_had_base_class;
2485 }
2486 return false;
2487}
2488
2489
2490ValueObject *
2491ValueObject::GetNonBaseClassParent()
2492{
Jim Ingham78a685a2011-04-16 00:01:13 +00002493 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002494 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002495 if (GetParent()->IsBaseClass())
2496 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002497 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002498 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002499 }
2500 return NULL;
2501}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002502
Enrico Granataa3c8f042014-08-19 22:29:08 +00002503
2504bool
2505ValueObject::IsBaseClass (uint32_t& depth)
2506{
2507 if (!IsBaseClass())
2508 {
2509 depth = 0;
2510 return false;
2511 }
2512 if (GetParent())
2513 {
2514 GetParent()->IsBaseClass(depth);
2515 depth = depth + 1;
2516 return true;
2517 }
2518 // TODO: a base of no parent? weird..
2519 depth = 1;
2520 return true;
2521}
2522
Greg Clayton1d3afba2010-10-05 00:00:42 +00002523void
Enrico Granata4becb372011-06-29 22:27:15 +00002524ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002525{
Enrico Granata986fa5f2014-12-09 21:41:16 +00002526 // synthetic children do not actually "exist" as part of the hierarchy, and sometimes they are consed up in ways
2527 // that don't make sense from an underlying language/API standpoint. So, use a special code path here to return
2528 // something that can hopefully be used in expression
2529 if (m_is_synthetic_children_generated)
2530 {
2531 UpdateValueIfNeeded();
2532
2533 if (m_value.GetValueType() == Value::eValueTypeLoadAddress)
2534 {
2535 if (IsPointerOrReferenceType())
2536 {
2537 s.Printf("((%s)0x%" PRIx64 ")",
2538 GetTypeName().AsCString("void"),
2539 GetValueAsUnsigned(0));
2540 return;
2541 }
2542 else
2543 {
2544 uint64_t load_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
2545 if (load_addr != LLDB_INVALID_ADDRESS)
2546 {
2547 s.Printf("(*( (%s *)0x%" PRIx64 "))",
2548 GetTypeName().AsCString("void"),
2549 load_addr);
2550 return;
2551 }
2552 }
2553 }
2554
2555 if (CanProvideValue())
2556 {
2557 s.Printf("((%s)%s)",
2558 GetTypeName().AsCString("void"),
2559 GetValueAsCString());
2560 return;
2561 }
2562
2563 return;
2564 }
2565
Greg Claytone221f822011-01-21 01:59:00 +00002566 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002567
Enrico Granata86cc9822012-03-19 22:58:49 +00002568 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002569 {
Enrico Granata4becb372011-06-29 22:27:15 +00002570 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2571 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2572 // the eHonorPointers mode is meant to produce strings in this latter format
2573 s.PutCString("*(");
2574 }
Greg Claytone221f822011-01-21 01:59:00 +00002575
Enrico Granata4becb372011-06-29 22:27:15 +00002576 ValueObject* parent = GetParent();
2577
2578 if (parent)
2579 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002580
2581 // if we are a deref_of_parent just because we are synthetic array
2582 // members made up to allow ptr[%d] syntax to work in variable
2583 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002584 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002585 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002586
Greg Claytone221f822011-01-21 01:59:00 +00002587 if (!IsBaseClass())
2588 {
2589 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002590 {
Greg Claytone221f822011-01-21 01:59:00 +00002591 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2592 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002593 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002594 CompilerType non_base_class_parent_compiler_type = non_base_class_parent->GetCompilerType();
2595 if (non_base_class_parent_compiler_type)
Greg Claytone221f822011-01-21 01:59:00 +00002596 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002597 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002598 {
2599 s.PutCString("->");
2600 }
Enrico Granata4becb372011-06-29 22:27:15 +00002601 else
2602 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002603 const uint32_t non_base_class_parent_type_info = non_base_class_parent_compiler_type.GetTypeInfo();
Greg Clayton57ee3062013-07-11 22:46:58 +00002604
Enrico Granata622be232014-10-21 20:52:14 +00002605 if (non_base_class_parent_type_info & eTypeIsPointer)
Enrico Granata4becb372011-06-29 22:27:15 +00002606 {
2607 s.PutCString("->");
2608 }
Enrico Granata622be232014-10-21 20:52:14 +00002609 else if ((non_base_class_parent_type_info & eTypeHasChildren) &&
2610 !(non_base_class_parent_type_info & eTypeIsArray))
Enrico Granata4becb372011-06-29 22:27:15 +00002611 {
2612 s.PutChar('.');
2613 }
Greg Claytone221f822011-01-21 01:59:00 +00002614 }
2615 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002616 }
Greg Claytone221f822011-01-21 01:59:00 +00002617
2618 const char *name = GetName().GetCString();
2619 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002620 {
Greg Claytone221f822011-01-21 01:59:00 +00002621 if (qualify_cxx_base_classes)
2622 {
2623 if (GetBaseClassPath (s))
2624 s.PutCString("::");
2625 }
2626 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002627 }
2628 }
2629 }
2630
Enrico Granata86cc9822012-03-19 22:58:49 +00002631 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002632 {
Greg Claytone221f822011-01-21 01:59:00 +00002633 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002634 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002635}
2636
Greg Claytonafacd142011-09-02 01:15:17 +00002637ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002638ValueObject::GetValueForExpressionPath(const char* expression,
2639 const char** first_unparsed,
2640 ExpressionPathScanEndReason* reason_to_stop,
2641 ExpressionPathEndResultType* final_value_type,
2642 const GetValueForExpressionPathOptions& options,
2643 ExpressionPathAftermath* final_task_on_target)
2644{
2645
2646 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002647 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2648 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002649 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002650
2651 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2652 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2653 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2654 final_value_type ? final_value_type : &dummy_final_value_type,
2655 options,
2656 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2657
Enrico Granata86cc9822012-03-19 22:58:49 +00002658 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002659 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002660
Enrico Granata86cc9822012-03-19 22:58:49 +00002661 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 +00002662 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002663 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002664 {
2665 Error error;
2666 ValueObjectSP final_value = ret_val->Dereference(error);
2667 if (error.Fail() || !final_value.get())
2668 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002669 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002670 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002671 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002672 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002673 return ValueObjectSP();
2674 }
2675 else
2676 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002677 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002678 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002679 return final_value;
2680 }
2681 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002682 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002683 {
2684 Error error;
2685 ValueObjectSP final_value = ret_val->AddressOf(error);
2686 if (error.Fail() || !final_value.get())
2687 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002688 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002689 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002690 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002691 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002692 return ValueObjectSP();
2693 }
2694 else
2695 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002696 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002697 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002698 return final_value;
2699 }
2700 }
2701 }
2702 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2703}
2704
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002705int
2706ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002707 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002708 const char** first_unparsed,
2709 ExpressionPathScanEndReason* reason_to_stop,
2710 ExpressionPathEndResultType* final_value_type,
2711 const GetValueForExpressionPathOptions& options,
2712 ExpressionPathAftermath* final_task_on_target)
2713{
2714 const char* dummy_first_unparsed;
2715 ExpressionPathScanEndReason dummy_reason_to_stop;
2716 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002717 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002718
2719 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2720 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2721 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2722 final_value_type ? final_value_type : &dummy_final_value_type,
2723 options,
2724 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2725
2726 if (!ret_val.get()) // if there are errors, I add nothing to the list
2727 return 0;
2728
Enrico Granata86ea8d82012-03-29 01:34:34 +00002729 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002730 {
2731 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002732 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002733 {
2734 list->Append(ret_val);
2735 return 1;
2736 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002737 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 +00002738 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002739 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002740 {
2741 Error error;
2742 ValueObjectSP final_value = ret_val->Dereference(error);
2743 if (error.Fail() || !final_value.get())
2744 {
Greg Clayton23f59502012-07-17 03:23:13 +00002745 if (reason_to_stop)
2746 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2747 if (final_value_type)
2748 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002749 return 0;
2750 }
2751 else
2752 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002753 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002754 list->Append(final_value);
2755 return 1;
2756 }
2757 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002758 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002759 {
2760 Error error;
2761 ValueObjectSP final_value = ret_val->AddressOf(error);
2762 if (error.Fail() || !final_value.get())
2763 {
Greg Clayton23f59502012-07-17 03:23:13 +00002764 if (reason_to_stop)
2765 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2766 if (final_value_type)
2767 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002768 return 0;
2769 }
2770 else
2771 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002772 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002773 list->Append(final_value);
2774 return 1;
2775 }
2776 }
2777 }
2778 }
2779 else
2780 {
2781 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2782 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2783 ret_val,
2784 list,
2785 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2786 final_value_type ? final_value_type : &dummy_final_value_type,
2787 options,
2788 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2789 }
2790 // in any non-covered case, just do the obviously right thing
2791 list->Append(ret_val);
2792 return 1;
2793}
2794
Greg Claytonafacd142011-09-02 01:15:17 +00002795ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002796ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2797 const char** first_unparsed,
2798 ExpressionPathScanEndReason* reason_to_stop,
2799 ExpressionPathEndResultType* final_result,
2800 const GetValueForExpressionPathOptions& options,
2801 ExpressionPathAftermath* what_next)
2802{
2803 ValueObjectSP root = GetSP();
2804
2805 if (!root.get())
2806 return ValueObjectSP();
2807
2808 *first_unparsed = expression_cstr;
2809
2810 while (true)
2811 {
2812
2813 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2814
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002815 CompilerType root_compiler_type = root->GetCompilerType();
2816 CompilerType pointee_compiler_type;
2817 Flags pointee_compiler_type_info;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002818
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002819 Flags root_compiler_type_info(root_compiler_type.GetTypeInfo(&pointee_compiler_type));
2820 if (pointee_compiler_type)
2821 pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002822
2823 if (!expression_cstr || *expression_cstr == '\0')
2824 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002825 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002826 return root;
2827 }
2828
2829 switch (*expression_cstr)
2830 {
2831 case '-':
2832 {
2833 if (options.m_check_dot_vs_arrow_syntax &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002834 root_compiler_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 +00002835 {
2836 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002837 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2838 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002839 return ValueObjectSP();
2840 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002841 if (root_compiler_type_info.Test(eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2842 root_compiler_type_info.Test(eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002843 options.m_no_fragile_ivar)
2844 {
2845 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002846 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2847 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002848 return ValueObjectSP();
2849 }
2850 if (expression_cstr[1] != '>')
2851 {
2852 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002853 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2854 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002855 return ValueObjectSP();
2856 }
2857 expression_cstr++; // skip the -
2858 }
2859 case '.': // or fallthrough from ->
2860 {
2861 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002862 root_compiler_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 +00002863 {
2864 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002865 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2866 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002867 return ValueObjectSP();
2868 }
2869 expression_cstr++; // skip .
2870 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2871 ConstString child_name;
2872 if (!next_separator) // if no other separator just expand this last layer
2873 {
2874 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002875 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2876
2877 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002878 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002879 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002880 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2881 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002882 return child_valobj_sp;
2883 }
Enrico Granataef238c12015-03-12 22:30:58 +00002884 else
Enrico Granata8c9d3562011-08-11 17:08:01 +00002885 {
Enrico Granataef238c12015-03-12 22:30:58 +00002886 switch (options.m_synthetic_children_traversal)
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002887 {
Enrico Granataef238c12015-03-12 22:30:58 +00002888 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None:
2889 break;
2890 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic:
2891 if (root->IsSynthetic())
2892 {
2893 child_valobj_sp = root->GetNonSyntheticValue();
2894 if (child_valobj_sp.get())
2895 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2896 }
2897 break;
2898 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic:
2899 if (!root->IsSynthetic())
2900 {
2901 child_valobj_sp = root->GetSyntheticValue();
2902 if (child_valobj_sp.get())
2903 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2904 }
2905 break;
2906 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both:
2907 if (root->IsSynthetic())
2908 {
2909 child_valobj_sp = root->GetNonSyntheticValue();
2910 if (child_valobj_sp.get())
2911 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2912 }
2913 else
2914 {
2915 child_valobj_sp = root->GetSyntheticValue();
2916 if (child_valobj_sp.get())
2917 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2918 }
2919 break;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002920 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002921 }
2922
2923 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2924 // so we hit the "else" branch, and return an error
2925 if(child_valobj_sp.get()) // if it worked, just return
2926 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002927 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002928 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2929 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002930 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002931 }
2932 else
2933 {
2934 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002935 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2936 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002937 return ValueObjectSP();
2938 }
2939 }
2940 else // other layers do expand
2941 {
2942 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002943 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2944 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002945 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002946 root = child_valobj_sp;
2947 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002948 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002949 continue;
2950 }
Enrico Granataef238c12015-03-12 22:30:58 +00002951 else
Enrico Granata8c9d3562011-08-11 17:08:01 +00002952 {
Enrico Granataef238c12015-03-12 22:30:58 +00002953 switch (options.m_synthetic_children_traversal)
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002954 {
Enrico Granataef238c12015-03-12 22:30:58 +00002955 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None:
2956 break;
2957 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic:
2958 if (root->IsSynthetic())
2959 {
2960 child_valobj_sp = root->GetNonSyntheticValue();
2961 if (child_valobj_sp.get())
2962 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2963 }
2964 break;
2965 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic:
2966 if (!root->IsSynthetic())
2967 {
2968 child_valobj_sp = root->GetSyntheticValue();
2969 if (child_valobj_sp.get())
2970 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2971 }
2972 break;
2973 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both:
2974 if (root->IsSynthetic())
2975 {
2976 child_valobj_sp = root->GetNonSyntheticValue();
2977 if (child_valobj_sp.get())
2978 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2979 }
2980 else
2981 {
2982 child_valobj_sp = root->GetSyntheticValue();
2983 if (child_valobj_sp.get())
2984 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2985 }
2986 break;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002987 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002988 }
2989
2990 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2991 // so we hit the "else" branch, and return an error
2992 if(child_valobj_sp.get()) // if it worked, move on
2993 {
2994 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002995 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002996 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002997 continue;
2998 }
2999 else
3000 {
3001 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003002 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3003 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003004 return ValueObjectSP();
3005 }
3006 }
3007 break;
3008 }
3009 case '[':
3010 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003011 if (!root_compiler_type_info.Test(eTypeIsArray) && !root_compiler_type_info.Test(eTypeIsPointer) && !root_compiler_type_info.Test(eTypeIsVector)) // if this is not a T[] nor a T*
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003012 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003013 if (!root_compiler_type_info.Test(eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003014 {
Enrico Granataef238c12015-03-12 22:30:58 +00003015 if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None) // ...only chance left is synthetic
Enrico Granata27b625e2011-08-09 01:04:56 +00003016 {
3017 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003018 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3019 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003020 return ValueObjectSP();
3021 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003022 }
3023 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3024 {
3025 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003026 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3027 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003028 return ValueObjectSP();
3029 }
3030 }
3031 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3032 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003033 if (!root_compiler_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003034 {
3035 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003036 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3037 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003038 return ValueObjectSP();
3039 }
3040 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
3041 {
3042 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003043 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3044 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003045 return root;
3046 }
3047 }
3048 const char *separator_position = ::strchr(expression_cstr+1,'-');
3049 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3050 if (!close_bracket_position) // if there is no ], this is a syntax error
3051 {
3052 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003053 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3054 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003055 return ValueObjectSP();
3056 }
3057 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3058 {
3059 char *end = NULL;
3060 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3061 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3062 {
3063 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003064 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3065 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003066 return ValueObjectSP();
3067 }
3068 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3069 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003070 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003071 {
3072 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003073 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3074 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003075 return root;
3076 }
3077 else
3078 {
3079 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003080 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3081 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003082 return ValueObjectSP();
3083 }
3084 }
3085 // from here on we do have a valid index
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003086 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003087 {
Greg Claytondaf515f2011-07-09 20:12:33 +00003088 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
3089 if (!child_valobj_sp)
Bruce Mitchener11d86362015-02-26 23:55:39 +00003090 child_valobj_sp = root->GetSyntheticArrayMember(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003091 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00003092 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
3093 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00003094 if (child_valobj_sp)
3095 {
3096 root = child_valobj_sp;
3097 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003098 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00003099 continue;
3100 }
3101 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003102 {
3103 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003104 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3105 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003106 return ValueObjectSP();
3107 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003108 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003109 else if (root_compiler_type_info.Test(eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003110 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003111 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
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003112 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003113 {
3114 Error error;
3115 root = root->Dereference(error);
3116 if (error.Fail() || !root.get())
3117 {
3118 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003119 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3120 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003121 return ValueObjectSP();
3122 }
3123 else
3124 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003125 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003126 continue;
3127 }
3128 }
3129 else
3130 {
Greg Clayton99558cc42015-08-24 23:46:31 +00003131 if (root->GetCompilerType().GetMinimumLanguage() == eLanguageTypeObjC
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003132 && pointee_compiler_type_info.AllClear(eTypeIsPointer)
Greg Clayton84db9102012-03-26 23:03:23 +00003133 && root->HasSyntheticValue()
Enrico Granataef238c12015-03-12 22:30:58 +00003134 && (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic ||
3135 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both))
Enrico Granata27b625e2011-08-09 01:04:56 +00003136 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003137 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003138 }
3139 else
Bruce Mitchener11d86362015-02-26 23:55:39 +00003140 root = root->GetSyntheticArrayMember(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003141 if (!root.get())
3142 {
3143 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003144 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3145 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003146 return ValueObjectSP();
3147 }
3148 else
3149 {
3150 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003151 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003152 continue;
3153 }
3154 }
3155 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003156 else if (root_compiler_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003157 {
3158 root = root->GetSyntheticBitFieldChild(index, index, true);
3159 if (!root.get())
3160 {
3161 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003162 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3163 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003164 return ValueObjectSP();
3165 }
3166 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3167 {
3168 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003169 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3170 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003171 return root;
3172 }
3173 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003174 else if (root_compiler_type_info.Test(eTypeIsVector))
Enrico Granata08a1bb82013-06-19 00:00:45 +00003175 {
3176 root = root->GetChildAtIndex(index, true);
3177 if (!root.get())
3178 {
3179 *first_unparsed = expression_cstr;
3180 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3181 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3182 return ValueObjectSP();
3183 }
3184 else
3185 {
3186 *first_unparsed = end+1; // skip ]
3187 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3188 continue;
3189 }
3190 }
Enrico Granataef238c12015-03-12 22:30:58 +00003191 else if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic ||
3192 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both)
Enrico Granata27b625e2011-08-09 01:04:56 +00003193 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003194 if (root->HasSyntheticValue())
3195 root = root->GetSyntheticValue();
3196 else if (!root->IsSynthetic())
3197 {
3198 *first_unparsed = expression_cstr;
3199 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3200 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3201 return ValueObjectSP();
3202 }
3203 // if we are here, then root itself is a synthetic VO.. should be good to go
3204
Enrico Granata27b625e2011-08-09 01:04:56 +00003205 if (!root.get())
3206 {
3207 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003208 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3209 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3210 return ValueObjectSP();
3211 }
3212 root = root->GetChildAtIndex(index, true);
3213 if (!root.get())
3214 {
3215 *first_unparsed = expression_cstr;
3216 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3217 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003218 return ValueObjectSP();
3219 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00003220 else
3221 {
3222 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003223 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00003224 continue;
3225 }
Enrico Granata27b625e2011-08-09 01:04:56 +00003226 }
3227 else
3228 {
3229 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003230 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3231 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003232 return ValueObjectSP();
3233 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003234 }
3235 else // we have a low and a high index
3236 {
3237 char *end = NULL;
3238 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3239 if (!end || end != separator_position) // if something weird is in our way return an error
3240 {
3241 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003242 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3243 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003244 return ValueObjectSP();
3245 }
3246 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3247 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3248 {
3249 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003250 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3251 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003252 return ValueObjectSP();
3253 }
3254 if (index_lower > index_higher) // swap indices if required
3255 {
3256 unsigned long temp = index_lower;
3257 index_lower = index_higher;
3258 index_higher = temp;
3259 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003260 if (root_compiler_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003261 {
3262 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3263 if (!root.get())
3264 {
3265 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003266 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3267 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003268 return ValueObjectSP();
3269 }
3270 else
3271 {
3272 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003273 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3274 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003275 return root;
3276 }
3277 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003278 else if (root_compiler_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 +00003279 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003280 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003281 {
3282 Error error;
3283 root = root->Dereference(error);
3284 if (error.Fail() || !root.get())
3285 {
3286 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003287 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3288 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003289 return ValueObjectSP();
3290 }
3291 else
3292 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003293 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003294 continue;
3295 }
3296 }
3297 else
3298 {
3299 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003300 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3301 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003302 return root;
3303 }
3304 }
3305 break;
3306 }
3307 default: // some non-separator is in the way
3308 {
3309 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003310 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3311 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003312 return ValueObjectSP();
3313 break;
3314 }
3315 }
3316 }
3317}
3318
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003319int
3320ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3321 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00003322 ValueObjectSP root,
3323 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003324 ExpressionPathScanEndReason* reason_to_stop,
3325 ExpressionPathEndResultType* final_result,
3326 const GetValueForExpressionPathOptions& options,
3327 ExpressionPathAftermath* what_next)
3328{
3329 if (!root.get())
3330 return 0;
3331
3332 *first_unparsed = expression_cstr;
3333
3334 while (true)
3335 {
3336
3337 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3338
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003339 CompilerType root_compiler_type = root->GetCompilerType();
3340 CompilerType pointee_compiler_type;
3341 Flags pointee_compiler_type_info;
3342 Flags root_compiler_type_info(root_compiler_type.GetTypeInfo(&pointee_compiler_type));
3343 if (pointee_compiler_type)
3344 pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003345
3346 if (!expression_cstr || *expression_cstr == '\0')
3347 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003348 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003349 list->Append(root);
3350 return 1;
3351 }
3352
3353 switch (*expression_cstr)
3354 {
3355 case '[':
3356 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003357 if (!root_compiler_type_info.Test(eTypeIsArray) && !root_compiler_type_info.Test(eTypeIsPointer)) // if this is not a T[] nor a T*
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003358 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003359 if (!root_compiler_type_info.Test(eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003360 {
3361 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003362 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3363 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003364 return 0;
3365 }
3366 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3367 {
3368 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003369 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3370 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003371 return 0;
3372 }
3373 }
3374 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3375 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003376 if (!root_compiler_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003377 {
3378 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003379 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3380 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003381 return 0;
3382 }
3383 else // expand this into list
3384 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003385 const size_t max_index = root->GetNumChildren() - 1;
3386 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003387 {
3388 ValueObjectSP child =
3389 root->GetChildAtIndex(index, true);
3390 list->Append(child);
3391 }
3392 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003393 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3394 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003395 return max_index; // tell me number of items I added to the VOList
3396 }
3397 }
3398 const char *separator_position = ::strchr(expression_cstr+1,'-');
3399 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3400 if (!close_bracket_position) // if there is no ], this is a syntax error
3401 {
3402 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003403 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3404 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003405 return 0;
3406 }
3407 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3408 {
3409 char *end = NULL;
3410 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3411 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3412 {
3413 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003414 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3415 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003416 return 0;
3417 }
3418 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3419 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003420 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003421 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003422 const size_t max_index = root->GetNumChildren() - 1;
3423 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003424 {
3425 ValueObjectSP child =
3426 root->GetChildAtIndex(index, true);
3427 list->Append(child);
3428 }
3429 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003430 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3431 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003432 return max_index; // tell me number of items I added to the VOList
3433 }
3434 else
3435 {
3436 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003437 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3438 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003439 return 0;
3440 }
3441 }
3442 // from here on we do have a valid index
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003443 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003444 {
3445 root = root->GetChildAtIndex(index, true);
3446 if (!root.get())
3447 {
3448 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003449 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3450 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003451 return 0;
3452 }
3453 else
3454 {
3455 list->Append(root);
3456 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003457 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3458 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003459 return 1;
3460 }
3461 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003462 else if (root_compiler_type_info.Test(eTypeIsPointer))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003463 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003464 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
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003465 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003466 {
3467 Error error;
3468 root = root->Dereference(error);
3469 if (error.Fail() || !root.get())
3470 {
3471 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003472 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3473 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003474 return 0;
3475 }
3476 else
3477 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003478 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003479 continue;
3480 }
3481 }
3482 else
3483 {
Bruce Mitchener11d86362015-02-26 23:55:39 +00003484 root = root->GetSyntheticArrayMember(index, true);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003485 if (!root.get())
3486 {
3487 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003488 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3489 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003490 return 0;
3491 }
3492 else
3493 {
3494 list->Append(root);
3495 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003496 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3497 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003498 return 1;
3499 }
3500 }
3501 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003502 else /*if (ClangASTContext::IsScalarType(root_compiler_type))*/
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003503 {
3504 root = root->GetSyntheticBitFieldChild(index, index, true);
3505 if (!root.get())
3506 {
3507 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003508 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3509 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003510 return 0;
3511 }
3512 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3513 {
3514 list->Append(root);
3515 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003516 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3517 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003518 return 1;
3519 }
3520 }
3521 }
3522 else // we have a low and a high index
3523 {
3524 char *end = NULL;
3525 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3526 if (!end || end != separator_position) // if something weird is in our way return an error
3527 {
3528 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003529 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3530 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003531 return 0;
3532 }
3533 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3534 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3535 {
3536 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003537 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3538 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003539 return 0;
3540 }
3541 if (index_lower > index_higher) // swap indices if required
3542 {
3543 unsigned long temp = index_lower;
3544 index_lower = index_higher;
3545 index_higher = temp;
3546 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003547 if (root_compiler_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003548 {
3549 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3550 if (!root.get())
3551 {
3552 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003553 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3554 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003555 return 0;
3556 }
3557 else
3558 {
3559 list->Append(root);
3560 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003561 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3562 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003563 return 1;
3564 }
3565 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003566 else if (root_compiler_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 +00003567 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003568 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003569 {
3570 Error error;
3571 root = root->Dereference(error);
3572 if (error.Fail() || !root.get())
3573 {
3574 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003575 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3576 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003577 return 0;
3578 }
3579 else
3580 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003581 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003582 continue;
3583 }
3584 }
3585 else
3586 {
Johnny Chen44805302011-07-19 19:48:13 +00003587 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003588 index <= index_higher; index++)
3589 {
3590 ValueObjectSP child =
3591 root->GetChildAtIndex(index, true);
3592 list->Append(child);
3593 }
3594 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003595 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3596 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003597 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3598 }
3599 }
3600 break;
3601 }
3602 default: // some non-[ separator, or something entirely wrong, is in the way
3603 {
3604 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003605 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3606 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003607 return 0;
3608 break;
3609 }
3610 }
3611 }
3612}
3613
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003614void
3615ValueObject::LogValueObject (Log *log)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003616{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003617 if (log)
Enrico Granatad5957332015-06-03 20:43:54 +00003618 return LogValueObject (log, DumpValueObjectOptions(*this));
Greg Clayton1d3afba2010-10-05 00:00:42 +00003619}
3620
Enrico Granata0c489f52012-03-01 04:24:26 +00003621void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003622ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003623{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003624 if (log)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003625 {
3626 StreamString s;
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003627 Dump (s, options);
Greg Claytonf830dbb2012-03-22 18:15:37 +00003628 if (s.GetSize())
3629 log->PutCString(s.GetData());
3630 }
3631}
3632
3633void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003634ValueObject::Dump (Stream &s)
Enrico Granata0c489f52012-03-01 04:24:26 +00003635{
Enrico Granatad5957332015-06-03 20:43:54 +00003636 Dump (s, DumpValueObjectOptions(*this));
Enrico Granata0c489f52012-03-01 04:24:26 +00003637}
3638
3639void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003640ValueObject::Dump (Stream &s,
3641 const DumpValueObjectOptions& options)
Enrico Granata0c489f52012-03-01 04:24:26 +00003642{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003643 ValueObjectPrinter printer(this,&s,options);
3644 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003645}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003646
3647ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003648ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003649{
3650 ValueObjectSP valobj_sp;
3651
Enrico Granatac3e320a2011-08-02 17:27:39 +00003652 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003653 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003654 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003655
3656 DataExtractor data;
3657 data.SetByteOrder (m_data.GetByteOrder());
3658 data.SetAddressByteSize(m_data.GetAddressByteSize());
3659
Enrico Granata9f1e2042012-04-24 22:15:37 +00003660 if (IsBitfield())
3661 {
3662 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
Greg Clayton57ee3062013-07-11 22:46:58 +00003663 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Enrico Granata9f1e2042012-04-24 22:15:37 +00003664 }
3665 else
Greg Clayton57ee3062013-07-11 22:46:58 +00003666 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003667
3668 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton99558cc42015-08-24 23:46:31 +00003669 GetCompilerType(),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003670 name,
3671 data,
3672 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003673 }
Jim Ingham6035b672011-03-31 00:19:25 +00003674
3675 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003676 {
Greg Claytoneeb15652013-12-10 23:16:40 +00003677 ExecutionContext exe_ctx (GetExecutionContextRef());
3678 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003679 }
3680 return valobj_sp;
3681}
3682
Enrico Granata538a88a2014-10-09 18:24:30 +00003683ValueObjectSP
3684ValueObject::GetQualifiedRepresentationIfAvailable (lldb::DynamicValueType dynValue,
3685 bool synthValue)
3686{
3687 ValueObjectSP result_sp(GetSP());
3688
3689 switch (dynValue)
3690 {
3691 case lldb::eDynamicCanRunTarget:
3692 case lldb::eDynamicDontRunTarget:
3693 {
3694 if (!result_sp->IsDynamic())
3695 {
3696 if (result_sp->GetDynamicValue(dynValue))
3697 result_sp = result_sp->GetDynamicValue(dynValue);
3698 }
3699 }
3700 break;
3701 case lldb::eNoDynamicValues:
Enrico Granata538a88a2014-10-09 18:24:30 +00003702 {
3703 if (result_sp->IsDynamic())
3704 {
3705 if (result_sp->GetStaticValue())
3706 result_sp = result_sp->GetStaticValue();
3707 }
3708 }
3709 break;
3710 }
3711
3712 if (synthValue)
3713 {
3714 if (!result_sp->IsSynthetic())
3715 {
3716 if (result_sp->GetSyntheticValue())
3717 result_sp = result_sp->GetSyntheticValue();
3718 }
3719 }
3720 else
3721 {
3722 if (result_sp->IsSynthetic())
3723 {
3724 if (result_sp->GetNonSyntheticValue())
3725 result_sp = result_sp->GetNonSyntheticValue();
3726 }
3727 }
3728
3729 return result_sp;
3730}
3731
Greg Clayton759e7442014-07-19 00:12:57 +00003732lldb::addr_t
3733ValueObject::GetCPPVTableAddress (AddressType &address_type)
3734{
Greg Claytona1e5dc82015-08-11 22:53:00 +00003735 CompilerType pointee_type;
Greg Clayton99558cc42015-08-24 23:46:31 +00003736 CompilerType this_type(GetCompilerType());
Greg Clayton759e7442014-07-19 00:12:57 +00003737 uint32_t type_info = this_type.GetTypeInfo(&pointee_type);
3738 if (type_info)
3739 {
3740 bool ptr_or_ref = false;
Enrico Granata622be232014-10-21 20:52:14 +00003741 if (type_info & (eTypeIsPointer | eTypeIsReference))
Greg Clayton759e7442014-07-19 00:12:57 +00003742 {
3743 ptr_or_ref = true;
3744 type_info = pointee_type.GetTypeInfo();
3745 }
3746
Enrico Granata622be232014-10-21 20:52:14 +00003747 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus;
Greg Clayton759e7442014-07-19 00:12:57 +00003748 if ((type_info & cpp_class) == cpp_class)
3749 {
3750 if (ptr_or_ref)
3751 {
3752 address_type = GetAddressTypeOfChildren();
3753 return GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
3754 }
3755 else
3756 return GetAddressOf (false, &address_type);
3757 }
3758 }
3759
3760 address_type = eAddressTypeInvalid;
3761 return LLDB_INVALID_ADDRESS;
3762}
3763
Greg Claytonafacd142011-09-02 01:15:17 +00003764ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003765ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003766{
Jim Ingham58b59f92011-04-22 23:53:53 +00003767 if (m_deref_valobj)
3768 return m_deref_valobj->GetSP();
Chaoren Lind7bdc272015-07-31 00:35:40 +00003769
3770 const bool is_pointer_or_reference_type = IsPointerOrReferenceType();
3771 if (is_pointer_or_reference_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003772 {
3773 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003774 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003775
3776 std::string child_name_str;
3777 uint32_t child_byte_size = 0;
3778 int32_t child_byte_offset = 0;
3779 uint32_t child_bitfield_bit_size = 0;
3780 uint32_t child_bitfield_bit_offset = 0;
3781 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003782 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003783 const bool transparent_pointers = false;
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003784 CompilerType compiler_type = GetCompilerType();
3785 CompilerType child_compiler_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003786
Greg Claytoncc4d0142012-02-17 07:49:44 +00003787 ExecutionContext exe_ctx (GetExecutionContextRef());
Chaoren Lind7bdc272015-07-31 00:35:40 +00003788
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003789 child_compiler_type = compiler_type.GetChildCompilerTypeAtIndex (&exe_ctx,
3790 0,
3791 transparent_pointers,
3792 omit_empty_base_classes,
3793 ignore_array_bounds,
3794 child_name_str,
3795 child_byte_size,
3796 child_byte_offset,
3797 child_bitfield_bit_size,
3798 child_bitfield_bit_offset,
3799 child_is_base_class,
3800 child_is_deref_of_parent,
3801 this);
3802 if (child_compiler_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003803 {
3804 ConstString child_name;
3805 if (!child_name_str.empty())
3806 child_name.SetCString (child_name_str.c_str());
3807
Jim Ingham58b59f92011-04-22 23:53:53 +00003808 m_deref_valobj = new ValueObjectChild (*this,
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003809 child_compiler_type,
Jim Ingham58b59f92011-04-22 23:53:53 +00003810 child_name,
3811 child_byte_size,
3812 child_byte_offset,
3813 child_bitfield_bit_size,
3814 child_bitfield_bit_offset,
3815 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003816 child_is_deref_of_parent,
3817 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003818 }
3819 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003820
Jim Ingham58b59f92011-04-22 23:53:53 +00003821 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003822 {
3823 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003824 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003825 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003826 else
3827 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003828 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003829 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003830
Chaoren Lind7bdc272015-07-31 00:35:40 +00003831 if (is_pointer_or_reference_type)
Greg Clayton54979cd2010-12-15 05:08:08 +00003832 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3833 else
Chaoren Lind7bdc272015-07-31 00:35:40 +00003834 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 +00003835 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003836 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003837}
3838
Greg Claytonafacd142011-09-02 01:15:17 +00003839ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003840ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003841{
Jim Ingham78a685a2011-04-16 00:01:13 +00003842 if (m_addr_of_valobj_sp)
3843 return m_addr_of_valobj_sp;
3844
Greg Claytone0d378b2011-03-24 21:19:54 +00003845 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003846 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003847 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003848 error.Clear();
Siva Chandraa3747a92015-05-04 19:43:34 +00003849 if (addr != LLDB_INVALID_ADDRESS && address_type != eAddressTypeHost)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003850 {
3851 switch (address_type)
3852 {
3853 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003854 {
3855 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003856 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003857 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3858 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003859 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003860
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003861 case eAddressTypeFile:
3862 case eAddressTypeLoad:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003863 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003864 CompilerType compiler_type = GetCompilerType();
3865 if (compiler_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003866 {
3867 std::string name (1, '&');
3868 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003869 ExecutionContext exe_ctx (GetExecutionContextRef());
3870 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003871 compiler_type.GetPointerType(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003872 ConstString (name.c_str()),
3873 addr,
3874 eAddressTypeInvalid,
3875 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003876 }
3877 }
3878 break;
Siva Chandraa3747a92015-05-04 19:43:34 +00003879 default:
3880 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003881 }
3882 }
Sean Callananed185ab2013-04-19 19:47:32 +00003883 else
3884 {
3885 StreamString expr_path_strm;
3886 GetExpressionPath(expr_path_strm, true);
3887 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3888 }
3889
Jim Ingham78a685a2011-04-16 00:01:13 +00003890 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003891}
3892
Greg Clayton9a142cf2012-02-03 05:34:10 +00003893ValueObjectSP
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003894ValueObject::Cast (const CompilerType &compiler_type)
Greg Clayton9a142cf2012-02-03 05:34:10 +00003895{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003896 return ValueObjectCast::Create (*this, GetName(), compiler_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003897}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003898
Greg Claytonafacd142011-09-02 01:15:17 +00003899ValueObjectSP
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003900ValueObject::CastPointerType (const char *name, CompilerType &compiler_type)
Greg Claytonb2dcc362011-05-05 23:32:56 +00003901{
Greg Claytonafacd142011-09-02 01:15:17 +00003902 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003903 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003904 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003905
3906 if (ptr_value != LLDB_INVALID_ADDRESS)
3907 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003908 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003909 ExecutionContext exe_ctx (GetExecutionContextRef());
3910 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003911 name,
3912 ptr_addr,
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003913 compiler_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003914 }
3915 return valobj_sp;
3916}
3917
Greg Claytonafacd142011-09-02 01:15:17 +00003918ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003919ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3920{
Greg Claytonafacd142011-09-02 01:15:17 +00003921 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003922 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003923 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003924
3925 if (ptr_value != LLDB_INVALID_ADDRESS)
3926 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003927 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003928 ExecutionContext exe_ctx (GetExecutionContextRef());
3929 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003930 name,
3931 ptr_addr,
3932 type_sp);
3933 }
3934 return valobj_sp;
3935}
3936
Jim Ingham6035b672011-03-31 00:19:25 +00003937ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003938 m_mod_id(),
3939 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003940 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003941{
3942}
3943
3944ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003945 m_mod_id(),
3946 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003947 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003948{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003949 ExecutionContext exe_ctx(exe_scope);
3950 TargetSP target_sp (exe_ctx.GetTargetSP());
3951 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003952 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003953 m_exe_ctx_ref.SetTargetSP (target_sp);
3954 ProcessSP process_sp (exe_ctx.GetProcessSP());
3955 if (!process_sp)
3956 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003957
Greg Claytoncc4d0142012-02-17 07:49:44 +00003958 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003959 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003960 m_mod_id = process_sp->GetModID();
3961 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003962
Greg Claytoncc4d0142012-02-17 07:49:44 +00003963 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003964
Greg Claytoncc4d0142012-02-17 07:49:44 +00003965 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003966 {
3967 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003968 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003969 }
Jim Ingham6035b672011-03-31 00:19:25 +00003970
Greg Claytoncc4d0142012-02-17 07:49:44 +00003971 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003972 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003973 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003974
Jason Molendab57e4a12013-11-04 09:33:30 +00003975 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003976 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003977 {
3978 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003979 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003980 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003981 if (frame_sp)
3982 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003983 }
3984 }
3985 }
Jim Ingham6035b672011-03-31 00:19:25 +00003986}
3987
3988ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003989 m_mod_id(),
3990 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003991 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003992{
3993}
3994
3995ValueObject::EvaluationPoint::~EvaluationPoint ()
3996{
3997}
3998
Jim Ingham6035b672011-03-31 00:19:25 +00003999// This function checks the EvaluationPoint against the current process state. If the current
4000// state matches the evaluation point, or the evaluation point is already invalid, then we return
4001// false, meaning "no change". If the current state is different, we update our state, and return
4002// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
4003// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00004004// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00004005
4006bool
Enrico Granatabb642e52015-05-16 01:27:00 +00004007ValueObject::EvaluationPoint::SyncWithProcessState(bool accept_invalid_exe_ctx)
Jim Ingham6035b672011-03-31 00:19:25 +00004008{
Jim Ingham73ca05a2011-12-17 01:35:57 +00004009 // 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 +00004010 const bool thread_and_frame_only_if_stopped = true;
4011 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
Jim Ingham73ca05a2011-12-17 01:35:57 +00004012
Greg Claytoncc4d0142012-02-17 07:49:44 +00004013 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00004014 return false;
4015
Jim Ingham6035b672011-03-31 00:19:25 +00004016 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00004017 Process *process = exe_ctx.GetProcessPtr();
4018 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00004019 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00004020
Jim Ingham6035b672011-03-31 00:19:25 +00004021 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00004022 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00004023
Jim Ingham78a685a2011-04-16 00:01:13 +00004024 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
4025 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00004026 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00004027 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00004028
Greg Clayton23f59502012-07-17 03:23:13 +00004029 bool changed = false;
4030 const bool was_valid = m_mod_id.IsValid();
4031 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004032 {
4033 if (m_mod_id == current_mod_id)
4034 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00004035 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004036 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00004037 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004038 }
Jim Ingham9ee01152011-12-10 01:49:43 +00004039 else
4040 {
4041 m_mod_id = current_mod_id;
4042 m_needs_update = true;
4043 changed = true;
4044 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004045 }
Jim Ingham6035b672011-03-31 00:19:25 +00004046
Jim Ingham73ca05a2011-12-17 01:35:57 +00004047 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
4048 // That way we'll be sure to return a valid exe_scope.
4049 // 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 +00004050
Enrico Granatabb642e52015-05-16 01:27:00 +00004051 if (!accept_invalid_exe_ctx)
Jim Ingham6035b672011-03-31 00:19:25 +00004052 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004053 if (m_exe_ctx_ref.HasThreadRef())
Greg Clayton262f80d2011-07-06 16:49:27 +00004054 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004055 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
4056 if (thread_sp)
Greg Claytoncc4d0142012-02-17 07:49:44 +00004057 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004058 if (m_exe_ctx_ref.HasFrameRef())
Greg Claytoncc4d0142012-02-17 07:49:44 +00004059 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004060 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
4061 if (!frame_sp)
4062 {
4063 // We used to have a frame, but now it is gone
4064 SetInvalid();
4065 changed = was_valid;
4066 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00004067 }
4068 }
Enrico Granatabb642e52015-05-16 01:27:00 +00004069 else
4070 {
4071 // We used to have a thread, but now it is gone
4072 SetInvalid();
4073 changed = was_valid;
4074 }
Greg Clayton262f80d2011-07-06 16:49:27 +00004075 }
Jim Ingham6035b672011-03-31 00:19:25 +00004076 }
Enrico Granatabb642e52015-05-16 01:27:00 +00004077
Jim Ingham9ee01152011-12-10 01:49:43 +00004078 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00004079}
4080
Jim Ingham61be0902011-05-02 18:13:59 +00004081void
4082ValueObject::EvaluationPoint::SetUpdated ()
4083{
Greg Claytoncc4d0142012-02-17 07:49:44 +00004084 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
4085 if (process_sp)
4086 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00004087 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00004088}
4089
4090
Enrico Granataf2bbf712011-07-15 02:26:42 +00004091
4092void
Enrico Granata86cc9822012-03-19 22:58:49 +00004093ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004094{
Enrico Granata86cc9822012-03-19 22:58:49 +00004095 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4096 m_value_str.clear();
4097
4098 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4099 m_location_str.clear();
4100
4101 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
Enrico Granata86cc9822012-03-19 22:58:49 +00004102 m_summary_str.clear();
Enrico Granata86cc9822012-03-19 22:58:49 +00004103
4104 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4105 m_object_desc_str.clear();
4106
4107 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4108 {
4109 if (m_synthetic_value)
4110 m_synthetic_value = NULL;
4111 }
Enrico Granata744794a2014-09-05 21:46:22 +00004112
4113 if ((clear_mask & eClearUserVisibleDataItemsValidator) == eClearUserVisibleDataItemsValidator)
4114 m_validation_result.reset();
Johnny Chen44805302011-07-19 19:48:13 +00004115}
Enrico Granata9128ee22011-09-06 19:20:51 +00004116
4117SymbolContextScope *
4118ValueObject::GetSymbolContextScope()
4119{
4120 if (m_parent)
4121 {
4122 if (!m_parent->IsPointerOrReferenceType())
4123 return m_parent->GetSymbolContextScope();
4124 }
4125 return NULL;
4126}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004127
4128lldb::ValueObjectSP
4129ValueObject::CreateValueObjectFromExpression (const char* name,
4130 const char* expression,
4131 const ExecutionContext& exe_ctx)
4132{
Enrico Granata972be532014-12-17 21:18:43 +00004133 return CreateValueObjectFromExpression(name, expression, exe_ctx, EvaluateExpressionOptions());
4134}
4135
4136
4137lldb::ValueObjectSP
4138ValueObject::CreateValueObjectFromExpression (const char* name,
4139 const char* expression,
4140 const ExecutionContext& exe_ctx,
4141 const EvaluateExpressionOptions& options)
4142{
Enrico Granatab2698cd2012-09-13 18:27:09 +00004143 lldb::ValueObjectSP retval_sp;
4144 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4145 if (!target_sp)
4146 return retval_sp;
4147 if (!expression || !*expression)
4148 return retval_sp;
4149 target_sp->EvaluateExpression (expression,
4150 exe_ctx.GetFrameSP().get(),
Enrico Granata972be532014-12-17 21:18:43 +00004151 retval_sp,
4152 options);
Enrico Granatab2698cd2012-09-13 18:27:09 +00004153 if (retval_sp && name && *name)
4154 retval_sp->SetName(ConstString(name));
4155 return retval_sp;
4156}
4157
4158lldb::ValueObjectSP
4159ValueObject::CreateValueObjectFromAddress (const char* name,
4160 uint64_t address,
4161 const ExecutionContext& exe_ctx,
Greg Claytona1e5dc82015-08-11 22:53:00 +00004162 CompilerType type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004163{
Greg Clayton57ee3062013-07-11 22:46:58 +00004164 if (type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004165 {
Greg Claytona1e5dc82015-08-11 22:53:00 +00004166 CompilerType pointer_type(type.GetPointerType());
Greg Clayton57ee3062013-07-11 22:46:58 +00004167 if (pointer_type)
4168 {
4169 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4170 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4171 pointer_type,
4172 ConstString(name),
4173 buffer,
Enrico Granata972be532014-12-17 21:18:43 +00004174 exe_ctx.GetByteOrder(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004175 exe_ctx.GetAddressByteSize()));
4176 if (ptr_result_valobj_sp)
4177 {
4178 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4179 Error err;
4180 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4181 if (ptr_result_valobj_sp && name && *name)
4182 ptr_result_valobj_sp->SetName(ConstString(name));
4183 }
4184 return ptr_result_valobj_sp;
4185 }
Enrico Granatab2698cd2012-09-13 18:27:09 +00004186 }
Greg Clayton57ee3062013-07-11 22:46:58 +00004187 return lldb::ValueObjectSP();
Enrico Granatab2698cd2012-09-13 18:27:09 +00004188}
4189
4190lldb::ValueObjectSP
4191ValueObject::CreateValueObjectFromData (const char* name,
Enrico Granata7ca1c762014-03-31 23:02:25 +00004192 const DataExtractor& data,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004193 const ExecutionContext& exe_ctx,
Greg Claytona1e5dc82015-08-11 22:53:00 +00004194 CompilerType type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004195{
4196 lldb::ValueObjectSP new_value_sp;
4197 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004198 type,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004199 ConstString(name),
4200 data,
4201 LLDB_INVALID_ADDRESS);
4202 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4203 if (new_value_sp && name && *name)
4204 new_value_sp->SetName(ConstString(name));
4205 return new_value_sp;
4206}
Enrico Granata4873e522013-04-11 22:48:58 +00004207
4208ModuleSP
4209ValueObject::GetModule ()
4210{
4211 ValueObject* root(GetRoot());
4212 if (root != this)
4213 return root->GetModule();
4214 return lldb::ModuleSP();
4215}
4216
4217ValueObject*
4218ValueObject::GetRoot ()
4219{
4220 if (m_root)
4221 return m_root;
Enrico Granatade61eba2015-01-22 03:07:34 +00004222 return (m_root = FollowParentChain( [] (ValueObject* vo) -> bool {
4223 return (vo->m_parent != nullptr);
4224 }));
4225}
4226
4227ValueObject*
4228ValueObject::FollowParentChain (std::function<bool(ValueObject*)> f)
4229{
4230 ValueObject* vo = this;
4231 while (vo)
Enrico Granata4873e522013-04-11 22:48:58 +00004232 {
Enrico Granatade61eba2015-01-22 03:07:34 +00004233 if (f(vo) == false)
4234 break;
4235 vo = vo->m_parent;
Enrico Granata4873e522013-04-11 22:48:58 +00004236 }
Enrico Granatade61eba2015-01-22 03:07:34 +00004237 return vo;
Enrico Granata4873e522013-04-11 22:48:58 +00004238}
4239
4240AddressType
4241ValueObject::GetAddressTypeOfChildren()
4242{
4243 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
4244 {
4245 ValueObject* root(GetRoot());
4246 if (root != this)
4247 return root->GetAddressTypeOfChildren();
4248 }
4249 return m_address_type_of_ptr_or_ref_children;
4250}
4251
4252lldb::DynamicValueType
4253ValueObject::GetDynamicValueType ()
4254{
4255 ValueObject* with_dv_info = this;
4256 while (with_dv_info)
4257 {
4258 if (with_dv_info->HasDynamicValueTypeInfo())
4259 return with_dv_info->GetDynamicValueTypeImpl();
4260 with_dv_info = with_dv_info->m_parent;
4261 }
4262 return lldb::eNoDynamicValues;
4263}
Enrico Granata39d51412013-05-31 17:43:40 +00004264
Enrico Granata4873e522013-04-11 22:48:58 +00004265lldb::Format
4266ValueObject::GetFormat () const
4267{
4268 const ValueObject* with_fmt_info = this;
4269 while (with_fmt_info)
4270 {
4271 if (with_fmt_info->m_format != lldb::eFormatDefault)
4272 return with_fmt_info->m_format;
4273 with_fmt_info = with_fmt_info->m_parent;
4274 }
4275 return m_format;
4276}
Enrico Granatad07cfd32014-10-08 18:27:36 +00004277
Enrico Granatac1247f52014-11-06 21:23:20 +00004278lldb::LanguageType
4279ValueObject::GetPreferredDisplayLanguage ()
4280{
Enrico Granataed3228a2015-01-21 01:47:13 +00004281 lldb::LanguageType type = m_preferred_display_language;
4282 if (m_preferred_display_language == lldb::eLanguageTypeUnknown)
Enrico Granatac1247f52014-11-06 21:23:20 +00004283 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004284 if (GetRoot())
Enrico Granatac1247f52014-11-06 21:23:20 +00004285 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004286 if (GetRoot() == this)
Enrico Granatac1247f52014-11-06 21:23:20 +00004287 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004288 if (StackFrameSP frame_sp = GetFrameSP())
4289 {
4290 const SymbolContext& sc(frame_sp->GetSymbolContext(eSymbolContextCompUnit));
4291 if (CompileUnit* cu = sc.comp_unit)
4292 type = cu->GetLanguage();
4293 }
4294 }
4295 else
4296 {
4297 type = GetRoot()->GetPreferredDisplayLanguage();
Enrico Granatac1247f52014-11-06 21:23:20 +00004298 }
4299 }
Enrico Granatac1247f52014-11-06 21:23:20 +00004300 }
Enrico Granataed3228a2015-01-21 01:47:13 +00004301 return (m_preferred_display_language = type); // only compute it once
4302}
4303
4304void
4305ValueObject::SetPreferredDisplayLanguage (lldb::LanguageType lt)
4306{
4307 m_preferred_display_language = lt;
Enrico Granatac1247f52014-11-06 21:23:20 +00004308}
4309
Enrico Granata73e8c4d2015-10-07 02:36:35 +00004310void
4311ValueObject::SetPreferredDisplayLanguageIfNeeded (lldb::LanguageType lt)
4312{
4313 if (m_preferred_display_language == lldb::eLanguageTypeUnknown)
4314 SetPreferredDisplayLanguage(lt);
4315}
4316
Enrico Granatad07cfd32014-10-08 18:27:36 +00004317bool
4318ValueObject::CanProvideValue ()
4319{
Sean Callanan7375f3e2014-12-09 21:18:59 +00004320 // we need to support invalid types as providers of values because some bare-board
4321 // debugging scenarios have no notion of types, but still manage to have raw numeric
4322 // values for things like registers. sigh.
Greg Clayton99558cc42015-08-24 23:46:31 +00004323 const CompilerType &type(GetCompilerType());
Sean Callanan7375f3e2014-12-09 21:18:59 +00004324 return (false == type.IsValid()) || (0 != (type.GetTypeInfo() & eTypeHasValue));
4325}
4326
4327bool
4328ValueObject::IsChecksumEmpty ()
4329{
4330 return m_value_checksum.empty();
Enrico Granatad07cfd32014-10-08 18:27:36 +00004331}
Enrico Granata0c10a852014-12-08 23:13:56 +00004332
4333ValueObjectSP
4334ValueObject::Persist ()
4335{
4336 if (!UpdateValueIfNeeded())
4337 return nullptr;
4338
4339 TargetSP target_sp(GetTargetSP());
4340 if (!target_sp)
4341 return nullptr;
4342
Sean Callananb92bd752015-10-01 16:28:02 +00004343 PersistentExpressionState *persistent_state = target_sp->GetPersistentExpressionStateForLanguage(GetPreferredDisplayLanguage());
Sean Callanan8f1f9a12015-09-30 19:57:57 +00004344
4345 if (!persistent_state)
4346 return nullptr;
4347
4348 ConstString name(persistent_state->GetNextPersistentVariableName());
Enrico Granata0c10a852014-12-08 23:13:56 +00004349
Sean Callanan9301ec12015-10-01 23:07:06 +00004350 ValueObjectSP const_result_sp = ValueObjectConstResult::Create (target_sp.get(), GetValue(), name);
4351
4352 ExpressionVariableSP clang_var_sp = persistent_state->CreatePersistentVariable(const_result_sp);
4353 clang_var_sp->m_live_sp = clang_var_sp->m_frozen_sp;
4354 clang_var_sp->m_flags |= ExpressionVariable::EVIsProgramReference;
Enrico Granata0c10a852014-12-08 23:13:56 +00004355
4356 return clang_var_sp->GetValueObject();
4357}
Enrico Granatae29df232014-12-09 19:51:20 +00004358
4359bool
4360ValueObject::IsSyntheticChildrenGenerated ()
4361{
4362 return m_is_synthetic_children_generated;
4363}
4364
4365void
4366ValueObject::SetSyntheticChildrenGenerated (bool b)
4367{
4368 m_is_synthetic_children_generated = b;
4369}