blob: 15c34b47b3ad81a8b16d178aa0c68bee193b55e7 [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:
528 default:
529 break;
530 }
531 }
532
Jim Ingham98e6daf2015-10-31 00:02:18 +0000533 Scalar scalar_value;
534
535 if (!ResolveValue (scalar_value))
536 {
537 error.SetErrorString("failed to get a scalar result");
538 return false;
539 }
540
541 bool ret;
542 if (scalar_value.ULongLong(1) == 0)
543 ret = false;
544 else
545 ret = true;
546 error.Clear();
547 return ret;
548}
549
550bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000551ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000552{
Greg Clayton288bdf92010-09-02 02:59:18 +0000553 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000554}
555
556
557void
558ValueObject::SetValueIsValid (bool b)
559{
Greg Clayton288bdf92010-09-02 02:59:18 +0000560 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000561}
562
563bool
Jim Ingham6035b672011-03-31 00:19:25 +0000564ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000565{
Greg Clayton288bdf92010-09-02 02:59:18 +0000566 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000567}
568
569void
570ValueObject::SetValueDidChange (bool value_changed)
571{
Greg Clayton288bdf92010-09-02 02:59:18 +0000572 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000573}
574
575ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000576ValueObject::GetChildAtIndex (size_t idx, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000577{
578 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000579 // We may need to update our value if we are dynamic
580 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000581 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000582 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000583 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000584 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000585 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000586 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000587 // No we haven't created the child at this index, so lets have our
588 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000589 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000590 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000591
Enrico Granata9d60f602012-03-09 03:09:58 +0000592 ValueObject* child = m_children.GetChildAtIndex(idx);
593 if (child != NULL)
594 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000595 }
596 return child_sp;
597}
598
Enrico Granata3309d882013-01-12 01:00:22 +0000599ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000600ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
601 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000602{
603 if (idxs.size() == 0)
604 return GetSP();
605 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000606 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000607 {
608 root = root->GetChildAtIndex(idx, true);
609 if (!root)
610 {
611 if (index_of_error)
612 *index_of_error = idx;
613 return root;
614 }
615 }
616 return root;
617}
618
619ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000620ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
621 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000622{
623 if (idxs.size() == 0)
624 return GetSP();
625 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000626 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000627 {
628 root = root->GetChildAtIndex(idx.first, idx.second);
629 if (!root)
630 {
631 if (index_of_error)
632 *index_of_error = idx.first;
633 return root;
634 }
635 }
636 return root;
637}
638
639lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000640ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
641 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000642{
643 if (idxs.size() == 0)
644 return GetSP();
645 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000646 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000647 {
648 root = root->GetChildAtIndex(idx, true);
649 if (!root)
650 {
651 if (index_of_error)
652 *index_of_error = idx;
653 return root;
654 }
655 }
656 return root;
657}
658
659lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000660ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
661 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000662{
663 if (idxs.size() == 0)
664 return GetSP();
665 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000666 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000667 {
668 root = root->GetChildAtIndex(idx.first, idx.second);
669 if (!root)
670 {
671 if (index_of_error)
672 *index_of_error = idx.first;
673 return root;
674 }
675 }
676 return root;
677}
678
Enrico Granatae2e220a2013-09-12 00:48:47 +0000679lldb::ValueObjectSP
680ValueObject::GetChildAtNamePath (const std::initializer_list<ConstString> &names,
681 ConstString* name_of_error)
682{
683 if (names.size() == 0)
684 return GetSP();
685 ValueObjectSP root(GetSP());
686 for (ConstString name : names)
687 {
688 root = root->GetChildMemberWithName(name, true);
689 if (!root)
690 {
691 if (name_of_error)
692 *name_of_error = name;
693 return root;
694 }
695 }
696 return root;
697}
698
699lldb::ValueObjectSP
700ValueObject::GetChildAtNamePath (const std::vector<ConstString> &names,
701 ConstString* name_of_error)
702{
703 if (names.size() == 0)
704 return GetSP();
705 ValueObjectSP root(GetSP());
706 for (ConstString name : names)
707 {
708 root = root->GetChildMemberWithName(name, true);
709 if (!root)
710 {
711 if (name_of_error)
712 *name_of_error = name;
713 return root;
714 }
715 }
716 return root;
717}
718
719lldb::ValueObjectSP
720ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names,
721 ConstString* name_of_error)
722{
723 if (names.size() == 0)
724 return GetSP();
725 ValueObjectSP root(GetSP());
726 for (std::pair<ConstString, bool> name : names)
727 {
728 root = root->GetChildMemberWithName(name.first, name.second);
729 if (!root)
730 {
731 if (name_of_error)
732 *name_of_error = name.first;
733 return root;
734 }
735 }
736 return root;
737}
738
739lldb::ValueObjectSP
740ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names,
741 ConstString* name_of_error)
742{
743 if (names.size() == 0)
744 return GetSP();
745 ValueObjectSP root(GetSP());
746 for (std::pair<ConstString, bool> name : names)
747 {
748 root = root->GetChildMemberWithName(name.first, name.second);
749 if (!root)
750 {
751 if (name_of_error)
752 *name_of_error = name.first;
753 return root;
754 }
755 }
756 return root;
757}
758
Greg Claytonc7bece562013-01-25 18:06:21 +0000759size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000760ValueObject::GetIndexOfChildWithName (const ConstString &name)
761{
762 bool omit_empty_base_classes = true;
Greg Clayton99558cc42015-08-24 23:46:31 +0000763 return GetCompilerType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000764}
765
766ValueObjectSP
767ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
768{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000769 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000770 // classes (which really aren't part of the expression path), so we
771 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000772 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000773
Greg Claytondea8cb42011-06-29 22:09:02 +0000774 // We may need to update our value if we are dynamic
775 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000776 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000777
778 std::vector<uint32_t> child_indexes;
Greg Claytondea8cb42011-06-29 22:09:02 +0000779 bool omit_empty_base_classes = true;
Greg Clayton99558cc42015-08-24 23:46:31 +0000780 const size_t num_child_indexes = GetCompilerType().GetIndexOfChildMemberWithName (name.GetCString(),
Greg Clayton57ee3062013-07-11 22:46:58 +0000781 omit_empty_base_classes,
782 child_indexes);
Greg Claytondea8cb42011-06-29 22:09:02 +0000783 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000784 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000785 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
786 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
787
788 child_sp = GetChildAtIndex(*pos, can_create);
789 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000790 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000791 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000792 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000793 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
794 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000795 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000796 else
797 {
798 child_sp.reset();
799 }
800
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000801 }
802 }
803 return child_sp;
804}
805
806
Greg Claytonc7bece562013-01-25 18:06:21 +0000807size_t
Siva Chandra9ac7a6c2015-10-21 19:28:08 +0000808ValueObject::GetNumChildren (uint32_t max)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000809{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000810 UpdateValueIfNeeded();
Siva Chandra9ac7a6c2015-10-21 19:28:08 +0000811
812 if (max < UINT32_MAX)
813 {
814 if (m_children_count_valid)
815 {
816 size_t children_count = m_children.GetChildrenCount();
817 return children_count <= max ? children_count : max;
818 }
819 else
820 return CalculateNumChildren(max);
821 }
822
Greg Clayton288bdf92010-09-02 02:59:18 +0000823 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000824 {
825 SetNumChildren (CalculateNumChildren());
826 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000827 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000828}
Greg Clayton4a792072012-10-23 01:50:10 +0000829
830bool
831ValueObject::MightHaveChildren()
832{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000833 bool has_children = false;
Greg Clayton2452ab72013-02-08 22:02:02 +0000834 const uint32_t type_info = GetTypeInfo();
835 if (type_info)
Greg Clayton4a792072012-10-23 01:50:10 +0000836 {
Enrico Granata622be232014-10-21 20:52:14 +0000837 if (type_info & (eTypeHasChildren |
838 eTypeIsPointer |
839 eTypeIsReference))
Greg Clayton4a792072012-10-23 01:50:10 +0000840 has_children = true;
841 }
842 else
843 {
844 has_children = GetNumChildren () > 0;
845 }
846 return has_children;
847}
848
849// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000850void
Greg Claytonc7bece562013-01-25 18:06:21 +0000851ValueObject::SetNumChildren (size_t num_children)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000852{
Greg Clayton288bdf92010-09-02 02:59:18 +0000853 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000854 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000855}
856
857void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000858ValueObject::SetName (const ConstString &name)
859{
860 m_name = name;
861}
862
Jim Ingham58b59f92011-04-22 23:53:53 +0000863ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000864ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000865{
Jim Ingham2eec4872011-05-07 00:10:58 +0000866 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000867
Greg Claytondea8cb42011-06-29 22:09:02 +0000868 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000869 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000870 std::string child_name_str;
871 uint32_t child_byte_size = 0;
872 int32_t child_byte_offset = 0;
873 uint32_t child_bitfield_bit_size = 0;
874 uint32_t child_bitfield_bit_offset = 0;
875 bool child_is_base_class = false;
876 bool child_is_deref_of_parent = false;
877
878 const bool transparent_pointers = synthetic_array_member == false;
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000879 CompilerType child_compiler_type;
Greg Claytondea8cb42011-06-29 22:09:02 +0000880
Greg Claytoncc4d0142012-02-17 07:49:44 +0000881 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000882
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000883 child_compiler_type = GetCompilerType().GetChildCompilerTypeAtIndex (&exe_ctx,
884 idx,
885 transparent_pointers,
886 omit_empty_base_classes,
887 ignore_array_bounds,
888 child_name_str,
889 child_byte_size,
890 child_byte_offset,
891 child_bitfield_bit_size,
892 child_bitfield_bit_offset,
893 child_is_base_class,
894 child_is_deref_of_parent,
895 this);
896 if (child_compiler_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000897 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000898 if (synthetic_index)
899 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000900
Greg Claytondea8cb42011-06-29 22:09:02 +0000901 ConstString child_name;
902 if (!child_name_str.empty())
903 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000904
Greg Claytondea8cb42011-06-29 22:09:02 +0000905 valobj = new ValueObjectChild (*this,
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000906 child_compiler_type,
Greg Claytondea8cb42011-06-29 22:09:02 +0000907 child_name,
908 child_byte_size,
909 child_byte_offset,
910 child_bitfield_bit_size,
911 child_bitfield_bit_offset,
912 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000913 child_is_deref_of_parent,
914 eAddressTypeInvalid);
915 //if (valobj)
916 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
917 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000918
Jim Ingham58b59f92011-04-22 23:53:53 +0000919 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000920}
921
Enrico Granata0c489f52012-03-01 04:24:26 +0000922bool
923ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
Enrico Granata31fda932015-10-07 01:41:23 +0000924 std::string& destination,
925 lldb::LanguageType lang)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000926{
Enrico Granata31fda932015-10-07 01:41:23 +0000927 return GetSummaryAsCString(summary_ptr, destination, TypeSummaryOptions().SetLanguage(lang));
Enrico Granatac1247f52014-11-06 21:23:20 +0000928}
929
930bool
931ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
932 std::string& destination,
933 const TypeSummaryOptions& options)
934{
Enrico Granata0c489f52012-03-01 04:24:26 +0000935 destination.clear();
Enrico Granata31fda932015-10-07 01:41:23 +0000936
Enrico Granata0c489f52012-03-01 04:24:26 +0000937 // ideally we would like to bail out if passing NULL, but if we do so
938 // we end up not providing the summary for function pointers anymore
939 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
940 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000941
942 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000943
Enrico Granata31fda932015-10-07 01:41:23 +0000944 TypeSummaryOptions actual_options(options);
945
946 if (actual_options.GetLanguage() == lldb::eLanguageTypeUnknown)
947 actual_options.SetLanguage(GetPreferredDisplayLanguage());
948
Enrico Granataf18c03e2012-04-04 17:34:10 +0000949 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
950 // information that we might care to see in a crash log. might be useful in very specific situations though.
951 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
Enrico Granata31fda932015-10-07 01:41:23 +0000952 GetTypeName().GetCString(),
953 GetName().GetCString(),
954 summary_ptr->GetDescription().c_str());*/
Enrico Granataf18c03e2012-04-04 17:34:10 +0000955
Enrico Granataff0f23d2014-12-10 02:00:45 +0000956 if (UpdateValueIfNeeded (false) && summary_ptr)
Enrico Granata0c489f52012-03-01 04:24:26 +0000957 {
Enrico Granataff0f23d2014-12-10 02:00:45 +0000958 if (HasSyntheticValue())
959 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 +0000960 summary_ptr->FormatObject(this, destination, actual_options);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000961 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000962 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000963 return !destination.empty();
964}
965
966const char *
Enrico Granata31fda932015-10-07 01:41:23 +0000967ValueObject::GetSummaryAsCString (lldb::LanguageType lang)
Enrico Granata0c489f52012-03-01 04:24:26 +0000968{
969 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
970 {
Enrico Granata31fda932015-10-07 01:41:23 +0000971 TypeSummaryOptions summary_options;
972 summary_options.SetLanguage(lang);
Enrico Granata0c489f52012-03-01 04:24:26 +0000973 GetSummaryAsCString(GetSummaryFormat().get(),
Enrico Granatac1247f52014-11-06 21:23:20 +0000974 m_summary_str,
Enrico Granata31fda932015-10-07 01:41:23 +0000975 summary_options);
Enrico Granata0c489f52012-03-01 04:24:26 +0000976 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000977 if (m_summary_str.empty())
978 return NULL;
979 return m_summary_str.c_str();
980}
981
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000982bool
Enrico Granata49bfafb2014-11-18 23:36:25 +0000983ValueObject::GetSummaryAsCString (std::string& destination,
984 const TypeSummaryOptions& options)
985{
986 return GetSummaryAsCString(GetSummaryFormat().get(),
Enrico Granata31fda932015-10-07 01:41:23 +0000987 destination,
988 options);
Enrico Granata49bfafb2014-11-18 23:36:25 +0000989}
990
991bool
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000992ValueObject::IsCStringContainer(bool check_pointer)
993{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000994 CompilerType pointee_or_element_compiler_type;
995 const Flags type_flags (GetTypeInfo (&pointee_or_element_compiler_type));
Enrico Granata622be232014-10-21 20:52:14 +0000996 bool is_char_arr_ptr (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000997 pointee_or_element_compiler_type.IsCharType ());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000998 if (!is_char_arr_ptr)
999 return false;
1000 if (!check_pointer)
1001 return true;
Enrico Granata622be232014-10-21 20:52:14 +00001002 if (type_flags.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001003 return true;
Greg Claytonafacd142011-09-02 01:15:17 +00001004 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001005 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +00001006 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001007 return (cstr_address != LLDB_INVALID_ADDRESS);
1008}
1009
Enrico Granata9128ee22011-09-06 19:20:51 +00001010size_t
1011ValueObject::GetPointeeData (DataExtractor& data,
1012 uint32_t item_idx,
1013 uint32_t item_count)
1014{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001015 CompilerType pointee_or_element_compiler_type;
1016 const uint32_t type_info = GetTypeInfo (&pointee_or_element_compiler_type);
Enrico Granata622be232014-10-21 20:52:14 +00001017 const bool is_pointer_type = type_info & eTypeIsPointer;
1018 const bool is_array_type = type_info & eTypeIsArray;
Greg Clayton2452ab72013-02-08 22:02:02 +00001019 if (!(is_pointer_type || is_array_type))
Enrico Granata9128ee22011-09-06 19:20:51 +00001020 return 0;
1021
1022 if (item_count == 0)
1023 return 0;
1024
Enrico Granata951bdd52015-01-28 01:09:45 +00001025 ExecutionContext exe_ctx (GetExecutionContextRef());
1026
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001027 const uint64_t item_type_size = pointee_or_element_compiler_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
Enrico Granata9128ee22011-09-06 19:20:51 +00001028 const uint64_t bytes = item_count * item_type_size;
Enrico Granata9128ee22011-09-06 19:20:51 +00001029 const uint64_t offset = item_idx * item_type_size;
1030
1031 if (item_idx == 0 && item_count == 1) // simply a deref
1032 {
Greg Clayton2452ab72013-02-08 22:02:02 +00001033 if (is_pointer_type)
Enrico Granata9128ee22011-09-06 19:20:51 +00001034 {
1035 Error error;
1036 ValueObjectSP pointee_sp = Dereference(error);
1037 if (error.Fail() || pointee_sp.get() == NULL)
1038 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +00001039 return pointee_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +00001040 }
1041 else
1042 {
1043 ValueObjectSP child_sp = GetChildAtIndex(0, true);
1044 if (child_sp.get() == NULL)
1045 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +00001046 Error error;
1047 return child_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +00001048 }
1049 return true;
1050 }
1051 else /* (items > 1) */
1052 {
1053 Error error;
1054 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
1055 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
1056
1057 AddressType addr_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001058 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001059
Enrico Granata9128ee22011-09-06 19:20:51 +00001060 switch (addr_type)
1061 {
1062 case eAddressTypeFile:
1063 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001064 ModuleSP module_sp (GetModule());
1065 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001066 {
Enrico Granata9c2efe32012-08-07 01:49:34 +00001067 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +00001068 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001069 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001070 ExecutionContext exe_ctx (GetExecutionContextRef());
1071 Target* target = exe_ctx.GetTargetPtr();
1072 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +00001073 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001074 heap_buf_ptr->SetByteSize(bytes);
1075 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
1076 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +00001077 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001078 data.SetData(data_sp);
1079 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +00001080 }
1081 }
1082 }
1083 }
1084 break;
1085 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +00001086 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001087 ExecutionContext exe_ctx (GetExecutionContextRef());
1088 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +00001089 if (process)
1090 {
1091 heap_buf_ptr->SetByteSize(bytes);
1092 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
Enrico Granata5e1480c2013-10-30 17:52:44 +00001093 if (error.Success() || bytes_read > 0)
Enrico Granata9128ee22011-09-06 19:20:51 +00001094 {
1095 data.SetData(data_sp);
1096 return bytes_read;
1097 }
1098 }
1099 }
1100 break;
1101 case eAddressTypeHost:
1102 {
Greg Clayton99558cc42015-08-24 23:46:31 +00001103 const uint64_t max_bytes = GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope());
Greg Clayton2452ab72013-02-08 22:02:02 +00001104 if (max_bytes > offset)
1105 {
1106 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
Siva Chandrae32f2b52015-05-05 00:41:35 +00001107 addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Enrico Granata7339b9d2015-11-03 02:34:43 +00001108 if (addr == 0 || addr == LLDB_INVALID_ADDRESS)
Siva Chandrae32f2b52015-05-05 00:41:35 +00001109 break;
Greg Clayton2452ab72013-02-08 22:02:02 +00001110 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
1111 data.SetData(data_sp);
1112 return bytes_read;
1113 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001114 }
1115 break;
1116 case eAddressTypeInvalid:
Enrico Granata9128ee22011-09-06 19:20:51 +00001117 break;
1118 }
1119 }
1120 return 0;
1121}
1122
Greg Claytonfaac1112013-03-14 18:31:44 +00001123uint64_t
Sean Callanan866e91c2014-02-28 22:27:53 +00001124ValueObject::GetData (DataExtractor& data, Error &error)
Enrico Granata9128ee22011-09-06 19:20:51 +00001125{
1126 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001127 ExecutionContext exe_ctx (GetExecutionContextRef());
Sean Callanan866e91c2014-02-28 22:27:53 +00001128 error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001129 if (error.Fail())
Sean Callananed185ab2013-04-19 19:47:32 +00001130 {
1131 if (m_data.GetByteSize())
1132 {
1133 data = m_data;
1134 return data.GetByteSize();
1135 }
1136 else
1137 {
1138 return 0;
1139 }
1140 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001141 data.SetAddressByteSize(m_data.GetAddressByteSize());
1142 data.SetByteOrder(m_data.GetByteOrder());
1143 return data.GetByteSize();
1144}
1145
Sean Callanan389823e2013-04-13 01:21:23 +00001146bool
1147ValueObject::SetData (DataExtractor &data, Error &error)
1148{
1149 error.Clear();
1150 // Make sure our value is up to date first so that our location and location
1151 // type is valid.
1152 if (!UpdateValueIfNeeded(false))
1153 {
1154 error.SetErrorString("unable to read value");
1155 return false;
1156 }
1157
1158 uint64_t count = 0;
Greg Clayton99558cc42015-08-24 23:46:31 +00001159 const Encoding encoding = GetCompilerType().GetEncoding(count);
Sean Callanan389823e2013-04-13 01:21:23 +00001160
1161 const size_t byte_size = GetByteSize();
1162
1163 Value::ValueType value_type = m_value.GetValueType();
1164
1165 switch (value_type)
1166 {
1167 case Value::eValueTypeScalar:
1168 {
1169 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1170
1171 if (!set_error.Success())
1172 {
1173 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1174 return false;
1175 }
1176 }
1177 break;
1178 case Value::eValueTypeLoadAddress:
1179 {
1180 // If it is a load address, then the scalar value is the storage location
1181 // of the data, and we have to shove this value down to that load location.
1182 ExecutionContext exe_ctx (GetExecutionContextRef());
1183 Process *process = exe_ctx.GetProcessPtr();
1184 if (process)
1185 {
1186 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1187 size_t bytes_written = process->WriteMemory(target_addr,
1188 data.GetDataStart(),
1189 byte_size,
1190 error);
1191 if (!error.Success())
1192 return false;
1193 if (bytes_written != byte_size)
1194 {
1195 error.SetErrorString("unable to write value to memory");
1196 return false;
1197 }
1198 }
1199 }
1200 break;
1201 case Value::eValueTypeHostAddress:
1202 {
1203 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1204 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1205 m_data.SetData(buffer_sp, 0);
1206 data.CopyByteOrderedData (0,
1207 byte_size,
1208 const_cast<uint8_t *>(m_data.GetDataStart()),
1209 byte_size,
1210 m_data.GetByteOrder());
1211 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1212 }
1213 break;
1214 case Value::eValueTypeFileAddress:
1215 case Value::eValueTypeVector:
1216 break;
1217 }
1218
1219 // If we have reached this point, then we have successfully changed the value.
1220 SetNeedsUpdate();
1221 return true;
1222}
1223
Enrico Granata9128ee22011-09-06 19:20:51 +00001224// will compute strlen(str), but without consuming more than
1225// maxlen bytes out of str (this serves the purpose of reading
1226// chunks of a string without having to worry about
1227// missing NULL terminators in the chunk)
1228// of course, if strlen(str) > maxlen, the function will return
1229// maxlen_value (which should be != maxlen, because that allows you
1230// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1231static uint32_t
1232strlen_or_inf (const char* str,
1233 uint32_t maxlen,
1234 uint32_t maxlen_value)
1235{
1236 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +00001237 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +00001238 {
Greg Clayton8dd5c172011-10-05 22:19:51 +00001239 while(*str)
1240 {
1241 len++;str++;
Greg Clayton2452ab72013-02-08 22:02:02 +00001242 if (len >= maxlen)
Greg Clayton8dd5c172011-10-05 22:19:51 +00001243 return maxlen_value;
1244 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001245 }
1246 return len;
1247}
1248
Enrico Granata2206b482014-10-30 18:27:31 +00001249static bool
1250CopyStringDataToBufferSP(const StreamString& source,
1251 lldb::DataBufferSP& destination)
1252{
1253 destination.reset(new DataBufferHeap(source.GetSize()+1,0));
1254 memcpy(destination->GetBytes(), source.GetString().c_str(), source.GetSize());
1255 return true;
1256}
1257
Enrico Granatab7662922015-11-04 00:02:08 +00001258std::pair<size_t,bool>
Enrico Granata2206b482014-10-30 18:27:31 +00001259ValueObject::ReadPointedString (lldb::DataBufferSP& buffer_sp,
Greg Claytoncc4d0142012-02-17 07:49:44 +00001260 Error& error,
1261 uint32_t max_length,
1262 bool honor_array,
1263 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001264{
Enrico Granatab7662922015-11-04 00:02:08 +00001265 bool was_capped = false;
Enrico Granata2206b482014-10-30 18:27:31 +00001266 StreamString s;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001267 ExecutionContext exe_ctx (GetExecutionContextRef());
1268 Target* target = exe_ctx.GetTargetPtr();
Enrico Granata2206b482014-10-30 18:27:31 +00001269
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001270 if (!target)
1271 {
1272 s << "<no target to read from>";
1273 error.SetErrorString("no target to read from");
Enrico Granata2206b482014-10-30 18:27:31 +00001274 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granatab7662922015-11-04 00:02:08 +00001275 return {0,was_capped};
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001276 }
1277
1278 if (max_length == 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001279 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001280
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001281 size_t bytes_read = 0;
1282 size_t total_bytes_read = 0;
1283
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001284 CompilerType compiler_type = GetCompilerType();
1285 CompilerType elem_or_pointee_compiler_type;
1286 const Flags type_flags (GetTypeInfo (&elem_or_pointee_compiler_type));
Enrico Granata622be232014-10-21 20:52:14 +00001287 if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001288 elem_or_pointee_compiler_type.IsCharType ())
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001289 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001290 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1291 AddressType cstr_address_type = eAddressTypeInvalid;
1292
1293 size_t cstr_len = 0;
1294 bool capped_data = false;
Enrico Granata622be232014-10-21 20:52:14 +00001295 if (type_flags.Test (eTypeIsArray))
Greg Claytoncc4d0142012-02-17 07:49:44 +00001296 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001297 // We have an array
Greg Clayton57ee3062013-07-11 22:46:58 +00001298 uint64_t array_size = 0;
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001299 if (compiler_type.IsArrayType(NULL, &array_size, NULL))
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001300 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001301 cstr_len = array_size;
1302 if (cstr_len > max_length)
1303 {
1304 capped_data = true;
1305 cstr_len = max_length;
1306 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001307 }
1308 cstr_address = GetAddressOf (true, &cstr_address_type);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001309 }
1310 else
1311 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001312 // We have a pointer
1313 cstr_address = GetPointerValue (&cstr_address_type);
1314 }
1315
1316 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1317 {
1318 s << "<invalid address>";
1319 error.SetErrorString("invalid address");
Enrico Granata2206b482014-10-30 18:27:31 +00001320 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granatab7662922015-11-04 00:02:08 +00001321 return {0,was_capped};
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001322 }
Enrico Granata2206b482014-10-30 18:27:31 +00001323
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001324 Address cstr_so_addr (cstr_address);
1325 DataExtractor data;
1326 if (cstr_len > 0 && honor_array)
1327 {
1328 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1329 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1330 GetPointeeData(data, 0, cstr_len);
Enrico Granata2206b482014-10-30 18:27:31 +00001331
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001332 if ((bytes_read = data.GetByteSize()) > 0)
1333 {
1334 total_bytes_read = bytes_read;
Enrico Granata2206b482014-10-30 18:27:31 +00001335 for (size_t offset = 0; offset < bytes_read; offset++)
1336 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001337 if (capped_data)
Enrico Granatab7662922015-11-04 00:02:08 +00001338 was_capped = true;
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001339 }
1340 }
1341 else
1342 {
1343 cstr_len = max_length;
1344 const size_t k_max_buf_size = 64;
Enrico Granata2206b482014-10-30 18:27:31 +00001345
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001346 size_t offset = 0;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001347
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001348 int cstr_len_displayed = -1;
1349 bool capped_cstr = false;
1350 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1351 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1352 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001353 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001354 total_bytes_read += bytes_read;
1355 const char *cstr = data.PeekCStr(0);
1356 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1357 if (len > k_max_buf_size)
1358 len = k_max_buf_size;
Enrico Granata2206b482014-10-30 18:27:31 +00001359
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001360 if (cstr_len_displayed < 0)
1361 cstr_len_displayed = len;
Enrico Granata2206b482014-10-30 18:27:31 +00001362
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001363 if (len == 0)
1364 break;
1365 cstr_len_displayed += len;
1366 if (len > bytes_read)
1367 len = bytes_read;
1368 if (len > cstr_len)
1369 len = cstr_len;
1370
Enrico Granata2206b482014-10-30 18:27:31 +00001371 for (size_t offset = 0; offset < bytes_read; offset++)
1372 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001373
1374 if (len < k_max_buf_size)
1375 break;
1376
1377 if (len >= cstr_len)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001378 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001379 capped_cstr = true;
1380 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001381 }
Enrico Granata2206b482014-10-30 18:27:31 +00001382
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001383 cstr_len -= len;
1384 offset += len;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001385 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001386
1387 if (cstr_len_displayed >= 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001388 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001389 if (capped_cstr)
Enrico Granatab7662922015-11-04 00:02:08 +00001390 was_capped = true;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001391 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001392 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001393 }
1394 else
1395 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001396 error.SetErrorString("not a string object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001397 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001398 }
Enrico Granata2206b482014-10-30 18:27:31 +00001399 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granatab7662922015-11-04 00:02:08 +00001400 return {total_bytes_read,was_capped};
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001401}
1402
Enrico Granata744794a2014-09-05 21:46:22 +00001403std::pair<TypeValidatorResult, std::string>
1404ValueObject::GetValidationStatus ()
1405{
1406 if (!UpdateValueIfNeeded(true))
1407 return {TypeValidatorResult::Success,""}; // not the validator's job to discuss update problems
1408
1409 if (m_validation_result.hasValue())
1410 return m_validation_result.getValue();
1411
1412 if (!m_type_validator_sp)
1413 return {TypeValidatorResult::Success,""}; // no validator no failure
1414
1415 auto outcome = m_type_validator_sp->FormatObject(this);
1416
1417 return (m_validation_result = {outcome.m_result,outcome.m_message}).getValue();
1418}
1419
Jim Ingham53c47f12010-09-10 23:12:17 +00001420const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001421ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001422{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001423
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001424 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001425 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001426
1427 if (!m_object_desc_str.empty())
1428 return m_object_desc_str.c_str();
1429
Greg Claytoncc4d0142012-02-17 07:49:44 +00001430 ExecutionContext exe_ctx (GetExecutionContextRef());
1431 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001432 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001433 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001434
Jim Ingham53c47f12010-09-10 23:12:17 +00001435 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001436
Greg Claytonafacd142011-09-02 01:15:17 +00001437 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001438 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1439
Jim Inghama2cf2632010-12-23 02:29:54 +00001440 if (runtime == NULL)
1441 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001442 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001443 CompilerType compiler_type = GetCompilerType();
1444 if (compiler_type)
Jim Inghama2cf2632010-12-23 02:29:54 +00001445 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001446 bool is_signed;
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001447 if (compiler_type.IsIntegerType (is_signed) || compiler_type.IsPointerType ())
Jim Inghamb7603bb2011-03-18 00:05:18 +00001448 {
Greg Claytonafacd142011-09-02 01:15:17 +00001449 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001450 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001451 }
1452 }
1453
Jim Ingham8d543de2011-03-31 23:01:21 +00001454 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001455 {
1456 m_object_desc_str.append (s.GetData());
1457 }
Sean Callanan672ad942010-10-23 00:18:49 +00001458
1459 if (m_object_desc_str.empty())
1460 return NULL;
1461 else
1462 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001463}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001464
Enrico Granata0c489f52012-03-01 04:24:26 +00001465bool
Enrico Granata4939b982013-12-22 09:24:22 +00001466ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format,
1467 std::string& destination)
1468{
1469 if (UpdateValueIfNeeded(false))
1470 return format.FormatObject(this,destination);
1471 else
1472 return false;
1473}
1474
1475bool
Enrico Granata0c489f52012-03-01 04:24:26 +00001476ValueObject::GetValueAsCString (lldb::Format format,
1477 std::string& destination)
1478{
Enrico Granata30f287f2013-12-28 08:44:02 +00001479 return GetValueAsCString(TypeFormatImpl_Format(format),destination);
Enrico Granata0c489f52012-03-01 04:24:26 +00001480}
1481
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001482const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001483ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001484{
Enrico Granatab294fd22013-05-31 19:18:19 +00001485 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001486 {
Enrico Granata4939b982013-12-22 09:24:22 +00001487 lldb::TypeFormatImplSP format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001488 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001489 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001490 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001491 if (m_type_format_sp)
Enrico Granata4939b982013-12-22 09:24:22 +00001492 format_sp = m_type_format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001493 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001494 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001495 if (m_is_bitfield_for_scalar)
1496 my_format = eFormatUnsigned;
1497 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001498 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001499 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001500 {
1501 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1502 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001503 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001504 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001505 else
1506 {
Greg Clayton99558cc42015-08-24 23:46:31 +00001507 my_format = GetValue().GetCompilerType().GetFormat();
Enrico Granata0c489f52012-03-01 04:24:26 +00001508 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001509 }
1510 }
1511 }
Enrico Granatab294fd22013-05-31 19:18:19 +00001512 if (my_format != m_last_format || m_value_str.empty())
Enrico Granata297e69f2012-03-06 23:21:16 +00001513 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001514 m_last_format = my_format;
Enrico Granata4939b982013-12-22 09:24:22 +00001515 if (!format_sp)
Enrico Granata30f287f2013-12-28 08:44:02 +00001516 format_sp.reset(new TypeFormatImpl_Format(my_format));
Enrico Granata4939b982013-12-22 09:24:22 +00001517 if (GetValueAsCString(*format_sp.get(), m_value_str))
Enrico Granata297e69f2012-03-06 23:21:16 +00001518 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001519 if (!m_value_did_change && m_old_value_valid)
1520 {
1521 // The value was gotten successfully, so we consider the
1522 // value as changed if the value string differs
1523 SetValueDidChange (m_old_value_str != m_value_str);
1524 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001525 }
1526 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001527 }
1528 if (m_value_str.empty())
1529 return NULL;
1530 return m_value_str.c_str();
1531}
1532
Enrico Granatac3e320a2011-08-02 17:27:39 +00001533// if > 8bytes, 0 is returned. this method should mostly be used
1534// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001535uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001536ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001537{
1538 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001539 if (CanProvideValue())
Enrico Granatac3e320a2011-08-02 17:27:39 +00001540 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001541 Scalar scalar;
1542 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001543 {
1544 if (success)
1545 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001546 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001547 }
1548 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001549 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001550
1551 if (success)
1552 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001553 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001554}
1555
Enrico Granatad7373f62013-10-31 18:57:50 +00001556int64_t
1557ValueObject::GetValueAsSigned (int64_t fail_value, bool *success)
1558{
1559 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001560 if (CanProvideValue())
Enrico Granatad7373f62013-10-31 18:57:50 +00001561 {
1562 Scalar scalar;
1563 if (ResolveValue (scalar))
1564 {
1565 if (success)
1566 *success = true;
Tamas Berghammer5a9919f2015-01-23 10:54:21 +00001567 return scalar.SLongLong(fail_value);
Enrico Granatad7373f62013-10-31 18:57:50 +00001568 }
1569 // fallthrough, otherwise...
1570 }
1571
1572 if (success)
1573 *success = false;
Tamas Berghammer5a9919f2015-01-23 10:54:21 +00001574 return fail_value;
Enrico Granatad7373f62013-10-31 18:57:50 +00001575}
1576
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001577// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1578// this call up to date by returning true for your new special cases. We will eventually move
1579// to checking this call result before trying to display special cases
1580bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001581ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1582 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001583{
Greg Clayton57ee3062013-07-11 22:46:58 +00001584 Flags flags(GetTypeInfo());
Enrico Granata622be232014-10-21 20:52:14 +00001585 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001586 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001587 {
1588 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001589 (custom_format == eFormatCString ||
1590 custom_format == eFormatCharArray ||
1591 custom_format == eFormatChar ||
1592 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001593 return true;
1594
Enrico Granata622be232014-10-21 20:52:14 +00001595 if (flags.Test(eTypeIsArray))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001596 {
Greg Claytonafacd142011-09-02 01:15:17 +00001597 if ((custom_format == eFormatBytes) ||
1598 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001599 return true;
1600
Greg Claytonafacd142011-09-02 01:15:17 +00001601 if ((custom_format == eFormatVectorOfChar) ||
1602 (custom_format == eFormatVectorOfFloat32) ||
1603 (custom_format == eFormatVectorOfFloat64) ||
1604 (custom_format == eFormatVectorOfSInt16) ||
1605 (custom_format == eFormatVectorOfSInt32) ||
1606 (custom_format == eFormatVectorOfSInt64) ||
1607 (custom_format == eFormatVectorOfSInt8) ||
1608 (custom_format == eFormatVectorOfUInt128) ||
1609 (custom_format == eFormatVectorOfUInt16) ||
1610 (custom_format == eFormatVectorOfUInt32) ||
1611 (custom_format == eFormatVectorOfUInt64) ||
1612 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001613 return true;
1614 }
1615 }
1616 return false;
1617}
1618
Enrico Granata9fc19442011-07-06 02:13:41 +00001619bool
1620ValueObject::DumpPrintableRepresentation(Stream& s,
1621 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001622 Format custom_format,
Enrico Granata0dba9b32014-01-08 01:36:59 +00001623 PrintableRepresentationSpecialCases special,
1624 bool do_dump_error)
Enrico Granata9fc19442011-07-06 02:13:41 +00001625{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001626
Greg Clayton57ee3062013-07-11 22:46:58 +00001627 Flags flags(GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001628
Enrico Granata86cc9822012-03-19 22:58:49 +00001629 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1630 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1631
1632 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001633 {
Enrico Granata622be232014-10-21 20:52:14 +00001634 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001635 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001636 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001637 // when being asked to get a printable display an array or pointer type directly,
1638 // try to "do the right thing"
1639
1640 if (IsCStringContainer(true) &&
1641 (custom_format == eFormatCString ||
1642 custom_format == eFormatCharArray ||
1643 custom_format == eFormatChar ||
1644 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001645 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001646 Error error;
Enrico Granata2206b482014-10-30 18:27:31 +00001647 lldb::DataBufferSP buffer_sp;
Enrico Granatab7662922015-11-04 00:02:08 +00001648 std::pair<size_t, bool> read_string = ReadPointedString(buffer_sp,
1649 error,
1650 0,
1651 (custom_format == eFormatVectorOfChar) ||
1652 (custom_format == eFormatCharArray));
Enrico Granataac494532015-09-09 22:30:24 +00001653 lldb_private::formatters::StringPrinter::ReadBufferAndDumpToStreamOptions options(*this);
Enrico Granata2206b482014-10-30 18:27:31 +00001654 options.SetData(DataExtractor(buffer_sp, lldb::eByteOrderInvalid, 8)); // none of this matters for a string - pass some defaults
1655 options.SetStream(&s);
1656 options.SetPrefixToken(0);
1657 options.SetQuote('"');
1658 options.SetSourceSize(buffer_sp->GetByteSize());
Enrico Granatab7662922015-11-04 00:02:08 +00001659 options.SetIsTruncated(read_string.second);
Enrico Granataac494532015-09-09 22:30:24 +00001660 formatters::StringPrinter::ReadBufferAndDumpToStream<lldb_private::formatters::StringPrinter::StringElementType::ASCII>(options);
Enrico Granata86cc9822012-03-19 22:58:49 +00001661 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001662 }
1663
Enrico Granata86cc9822012-03-19 22:58:49 +00001664 if (custom_format == eFormatEnum)
1665 return false;
1666
1667 // this only works for arrays, because I have no way to know when
1668 // the pointed memory ends, and no special \0 end of data marker
Enrico Granata622be232014-10-21 20:52:14 +00001669 if (flags.Test(eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001670 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001671 if ((custom_format == eFormatBytes) ||
1672 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001673 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001674 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001675
1676 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001677 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001678 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001679
1680 if (low)
1681 s << ',';
1682
1683 ValueObjectSP child = GetChildAtIndex(low,true);
1684 if (!child.get())
1685 {
1686 s << "<invalid child>";
1687 continue;
1688 }
1689 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1690 }
1691
1692 s << ']';
1693
1694 return true;
1695 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001696
Enrico Granata86cc9822012-03-19 22:58:49 +00001697 if ((custom_format == eFormatVectorOfChar) ||
1698 (custom_format == eFormatVectorOfFloat32) ||
1699 (custom_format == eFormatVectorOfFloat64) ||
1700 (custom_format == eFormatVectorOfSInt16) ||
1701 (custom_format == eFormatVectorOfSInt32) ||
1702 (custom_format == eFormatVectorOfSInt64) ||
1703 (custom_format == eFormatVectorOfSInt8) ||
1704 (custom_format == eFormatVectorOfUInt128) ||
1705 (custom_format == eFormatVectorOfUInt16) ||
1706 (custom_format == eFormatVectorOfUInt32) ||
1707 (custom_format == eFormatVectorOfUInt64) ||
1708 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1709 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001710 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001711
1712 Format format = FormatManager::GetSingleItemFormat(custom_format);
1713
1714 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001715 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001716 {
1717
1718 if (low)
1719 s << ',';
1720
1721 ValueObjectSP child = GetChildAtIndex(low,true);
1722 if (!child.get())
1723 {
1724 s << "<invalid child>";
1725 continue;
1726 }
1727 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1728 }
1729
1730 s << ']';
1731
1732 return true;
1733 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001734 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001735
1736 if ((custom_format == eFormatBoolean) ||
1737 (custom_format == eFormatBinary) ||
1738 (custom_format == eFormatChar) ||
1739 (custom_format == eFormatCharPrintable) ||
1740 (custom_format == eFormatComplexFloat) ||
1741 (custom_format == eFormatDecimal) ||
1742 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001743 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001744 (custom_format == eFormatFloat) ||
1745 (custom_format == eFormatOctal) ||
1746 (custom_format == eFormatOSType) ||
1747 (custom_format == eFormatUnicode16) ||
1748 (custom_format == eFormatUnicode32) ||
1749 (custom_format == eFormatUnsigned) ||
1750 (custom_format == eFormatPointer) ||
1751 (custom_format == eFormatComplexInteger) ||
1752 (custom_format == eFormatComplex) ||
1753 (custom_format == eFormatDefault)) // use the [] operator
1754 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001755 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001756 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001757
1758 if (only_special)
1759 return false;
1760
Enrico Granata86cc9822012-03-19 22:58:49 +00001761 bool var_success = false;
1762
1763 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001764 const char *cstr = NULL;
Enrico Granata2c75f112013-06-21 00:04:51 +00001765
1766 // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1767 // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1768 // area for cases where our desired output is not backed by some other longer-term storage
Greg Claytonc7bece562013-01-25 18:06:21 +00001769 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001770
Enrico Granata465f4bc2014-02-15 01:24:44 +00001771 if (custom_format != eFormatInvalid)
Enrico Granata86cc9822012-03-19 22:58:49 +00001772 SetFormat(custom_format);
1773
1774 switch(val_obj_display)
1775 {
1776 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001777 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001778 break;
1779
1780 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001781 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001782 break;
1783
1784 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001785 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001786 break;
1787
1788 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001789 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001790 break;
1791
1792 case eValueObjectRepresentationStyleChildrenCount:
Deepak Panickal99fbc072014-03-03 15:39:47 +00001793 strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren());
Greg Claytonc7bece562013-01-25 18:06:21 +00001794 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001795 break;
1796
1797 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001798 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001799 break;
Enrico Granata2c75f112013-06-21 00:04:51 +00001800
1801 case eValueObjectRepresentationStyleName:
1802 cstr = GetName().AsCString();
1803 break;
1804
1805 case eValueObjectRepresentationStyleExpressionPath:
1806 GetExpressionPath(strm, false);
1807 cstr = strm.GetString().c_str();
1808 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001809 }
1810
Greg Claytonc7bece562013-01-25 18:06:21 +00001811 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001812 {
1813 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001814 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001815 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1816 {
Enrico Granatad07cfd32014-10-08 18:27:36 +00001817 if (!CanProvideValue())
Enrico Granata86cc9822012-03-19 22:58:49 +00001818 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001819 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1820 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001821 }
1822 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001823 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001824 }
1825 }
1826
Greg Claytonc7bece562013-01-25 18:06:21 +00001827 if (cstr)
1828 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001829 else
1830 {
1831 if (m_error.Fail())
Enrico Granata0dba9b32014-01-08 01:36:59 +00001832 {
1833 if (do_dump_error)
1834 s.Printf("<%s>", m_error.AsCString());
1835 else
1836 return false;
1837 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001838 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1839 s.PutCString("<no summary available>");
1840 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1841 s.PutCString("<no value available>");
1842 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1843 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1844 else
1845 s.PutCString("<no printable representation>");
1846 }
1847
1848 // we should only return false here if we could not do *anything*
1849 // even if we have an error message as output, that's a success
1850 // from our callers' perspective, so return true
1851 var_success = true;
Enrico Granata465f4bc2014-02-15 01:24:44 +00001852
1853 if (custom_format != eFormatInvalid)
1854 SetFormat(eFormatDefault);
Enrico Granata86cc9822012-03-19 22:58:49 +00001855 }
1856
Enrico Granataf4efecd2011-07-12 22:56:10 +00001857 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001858}
1859
Greg Clayton737b9322010-09-13 03:32:57 +00001860addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001861ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001862{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001863 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001864 return LLDB_INVALID_ADDRESS;
1865
Greg Clayton73b472d2010-10-27 03:32:59 +00001866 switch (m_value.GetValueType())
1867 {
1868 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001869 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001870 if (scalar_is_load_address)
1871 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001872 if(address_type)
1873 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001874 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1875 }
1876 break;
1877
1878 case Value::eValueTypeLoadAddress:
1879 case Value::eValueTypeFileAddress:
Greg Clayton73b472d2010-10-27 03:32:59 +00001880 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001881 if(address_type)
1882 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001883 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1884 }
1885 break;
Siva Chandraa3747a92015-05-04 19:43:34 +00001886 case Value::eValueTypeHostAddress:
Siva Chandrae32f2b52015-05-05 00:41:35 +00001887 {
1888 if(address_type)
1889 *address_type = m_value.GetValueAddressType ();
1890 return LLDB_INVALID_ADDRESS;
1891 }
Siva Chandraa3747a92015-05-04 19:43:34 +00001892 break;
Greg Clayton73b472d2010-10-27 03:32:59 +00001893 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001894 if (address_type)
1895 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001896 return LLDB_INVALID_ADDRESS;
1897}
1898
1899addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001900ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001901{
Greg Claytonafacd142011-09-02 01:15:17 +00001902 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001903 if(address_type)
1904 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001905
Enrico Granatac3e320a2011-08-02 17:27:39 +00001906 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001907 return address;
1908
Greg Clayton73b472d2010-10-27 03:32:59 +00001909 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001910 {
1911 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001912 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001913 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001914 break;
1915
Enrico Granata9128ee22011-09-06 19:20:51 +00001916 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001917 case Value::eValueTypeLoadAddress:
1918 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001919 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001920 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001921 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001922 }
1923 break;
1924 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001925
Enrico Granata9128ee22011-09-06 19:20:51 +00001926 if (address_type)
1927 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001928
Greg Clayton737b9322010-09-13 03:32:57 +00001929 return address;
1930}
1931
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001932bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001933ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001934{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001935 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001936 // Make sure our value is up to date first so that our location and location
1937 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001938 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001939 {
1940 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001941 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001942 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001943
Greg Claytonfaac1112013-03-14 18:31:44 +00001944 uint64_t count = 0;
Greg Clayton99558cc42015-08-24 23:46:31 +00001945 const Encoding encoding = GetCompilerType().GetEncoding (count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001946
Greg Claytonb1320972010-07-14 00:18:15 +00001947 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001948
Jim Ingham16e0c682011-08-12 23:34:31 +00001949 Value::ValueType value_type = m_value.GetValueType();
1950
1951 if (value_type == Value::eValueTypeScalar)
1952 {
1953 // If the value is already a scalar, then let the scalar change itself:
1954 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1955 }
Sagar Thakur8536fd12015-08-20 09:12:46 +00001956 else if (byte_size <= 16)
Jim Ingham16e0c682011-08-12 23:34:31 +00001957 {
1958 // If the value fits in a scalar, then make a new scalar and again let the
1959 // scalar code do the conversion, then figure out where to put the new value.
1960 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001961 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1962 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001963 {
Jim Ingham4b536182011-08-09 02:12:22 +00001964 switch (value_type)
1965 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001966 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001967 {
1968 // If it is a load address, then the scalar value is the storage location
1969 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001970 ExecutionContext exe_ctx (GetExecutionContextRef());
1971 Process *process = exe_ctx.GetProcessPtr();
1972 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001973 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001974 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001975 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1976 new_scalar,
1977 byte_size,
1978 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001979 if (!error.Success())
1980 return false;
1981 if (bytes_written != byte_size)
1982 {
1983 error.SetErrorString("unable to write value to memory");
1984 return false;
1985 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001986 }
1987 }
Jim Ingham4b536182011-08-09 02:12:22 +00001988 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001989 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001990 {
1991 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1992 DataExtractor new_data;
1993 new_data.SetByteOrder (m_data.GetByteOrder());
1994
1995 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1996 m_data.SetData(buffer_sp, 0);
1997 bool success = new_scalar.GetData(new_data);
1998 if (success)
1999 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002000 new_data.CopyByteOrderedData (0,
2001 byte_size,
2002 const_cast<uint8_t *>(m_data.GetDataStart()),
2003 byte_size,
2004 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00002005 }
2006 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
2007
2008 }
Jim Ingham4b536182011-08-09 02:12:22 +00002009 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00002010 case Value::eValueTypeFileAddress:
2011 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00002012 case Value::eValueTypeVector:
2013 break;
Jim Ingham4b536182011-08-09 02:12:22 +00002014 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002015 }
2016 else
2017 {
Jim Ingham16e0c682011-08-12 23:34:31 +00002018 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002019 }
Jim Ingham16e0c682011-08-12 23:34:31 +00002020 }
2021 else
2022 {
2023 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00002024 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002025 return false;
2026 }
Jim Ingham16e0c682011-08-12 23:34:31 +00002027
2028 // If we have reached this point, then we have successfully changed the value.
2029 SetNeedsUpdate();
2030 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002031}
2032
Greg Clayton81e871e2012-02-04 02:27:34 +00002033bool
2034ValueObject::GetDeclaration (Declaration &decl)
2035{
2036 decl.Clear();
2037 return false;
2038}
2039
Greg Clayton84db9102012-03-26 23:03:23 +00002040ConstString
2041ValueObject::GetTypeName()
2042{
Greg Clayton99558cc42015-08-24 23:46:31 +00002043 return GetCompilerType().GetConstTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00002044}
2045
2046ConstString
Enrico Granatae8daa2f2014-05-17 19:14:17 +00002047ValueObject::GetDisplayTypeName()
2048{
2049 return GetTypeName();
2050}
2051
2052ConstString
Greg Clayton84db9102012-03-26 23:03:23 +00002053ValueObject::GetQualifiedTypeName()
2054{
Greg Clayton99558cc42015-08-24 23:46:31 +00002055 return GetCompilerType().GetConstQualifiedTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00002056}
2057
2058
Greg Claytonafacd142011-09-02 01:15:17 +00002059LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00002060ValueObject::GetObjectRuntimeLanguage ()
2061{
Greg Clayton99558cc42015-08-24 23:46:31 +00002062 return GetCompilerType().GetMinimumLanguage ();
Jim Ingham5a369122010-09-28 01:25:32 +00002063}
2064
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002065void
Jim Ingham58b59f92011-04-22 23:53:53 +00002066ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002067{
Jim Ingham58b59f92011-04-22 23:53:53 +00002068 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002069}
2070
2071ValueObjectSP
2072ValueObject::GetSyntheticChild (const ConstString &key) const
2073{
2074 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00002075 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002076 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00002077 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002078 return synthetic_child_sp;
2079}
2080
Greg Clayton2452ab72013-02-08 22:02:02 +00002081uint32_t
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002082ValueObject::GetTypeInfo (CompilerType *pointee_or_element_compiler_type)
Greg Clayton2452ab72013-02-08 22:02:02 +00002083{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002084 return GetCompilerType().GetTypeInfo (pointee_or_element_compiler_type);
Greg Clayton2452ab72013-02-08 22:02:02 +00002085}
2086
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002087bool
2088ValueObject::IsPointerType ()
2089{
Greg Clayton99558cc42015-08-24 23:46:31 +00002090 return GetCompilerType().IsPointerType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002091}
2092
Jim Inghamb7603bb2011-03-18 00:05:18 +00002093bool
Greg Claytondaf515f2011-07-09 20:12:33 +00002094ValueObject::IsArrayType ()
2095{
Greg Clayton99558cc42015-08-24 23:46:31 +00002096 return GetCompilerType().IsArrayType (NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00002097}
2098
2099bool
Enrico Granata9fc19442011-07-06 02:13:41 +00002100ValueObject::IsScalarType ()
2101{
Greg Clayton99558cc42015-08-24 23:46:31 +00002102 return GetCompilerType().IsScalarType ();
Enrico Granata9fc19442011-07-06 02:13:41 +00002103}
2104
2105bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00002106ValueObject::IsIntegerType (bool &is_signed)
2107{
Greg Clayton99558cc42015-08-24 23:46:31 +00002108 return GetCompilerType().IsIntegerType (is_signed);
Jim Inghamb7603bb2011-03-18 00:05:18 +00002109}
Greg Clayton73b472d2010-10-27 03:32:59 +00002110
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002111bool
2112ValueObject::IsPointerOrReferenceType ()
2113{
Greg Clayton99558cc42015-08-24 23:46:31 +00002114 return GetCompilerType().IsPointerOrReferenceType ();
Greg Clayton007d5be2011-05-30 00:49:24 +00002115}
2116
2117bool
Greg Claytondea8cb42011-06-29 22:09:02 +00002118ValueObject::IsPossibleDynamicType ()
2119{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002120 ExecutionContext exe_ctx (GetExecutionContextRef());
2121 Process *process = exe_ctx.GetProcessPtr();
2122 if (process)
2123 return process->IsPossibleDynamicValue(*this);
2124 else
Greg Clayton99558cc42015-08-24 23:46:31 +00002125 return GetCompilerType().IsPossibleDynamicType (NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00002126}
2127
Enrico Granata9e7b3882012-12-13 23:50:33 +00002128bool
Enrico Granata560558e2015-02-11 02:35:39 +00002129ValueObject::IsRuntimeSupportValue ()
2130{
2131 Process *process(GetProcessSP().get());
2132 if (process)
2133 {
2134 LanguageRuntime *runtime = process->GetLanguageRuntime(GetObjectRuntimeLanguage());
2135 if (!runtime)
2136 runtime = process->GetObjCLanguageRuntime();
2137 if (runtime)
2138 return runtime->IsRuntimeSupportValue(*this);
2139 }
2140 return false;
2141}
2142
2143bool
Enrico Granata9e7b3882012-12-13 23:50:33 +00002144ValueObject::IsObjCNil ()
2145{
Enrico Granata622be232014-10-21 20:52:14 +00002146 const uint32_t mask = eTypeIsObjC | eTypeIsPointer;
Greg Clayton99558cc42015-08-24 23:46:31 +00002147 bool isObjCpointer = (((GetCompilerType().GetTypeInfo(NULL)) & mask) == mask);
Enrico Granata7277d202013-03-15 23:33:15 +00002148 if (!isObjCpointer)
2149 return false;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002150 bool canReadValue = true;
2151 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
Enrico Granata7277d202013-03-15 23:33:15 +00002152 return canReadValue && isZero;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002153}
2154
Greg Claytondaf515f2011-07-09 20:12:33 +00002155// This allows you to create an array member using and index
2156// that doesn't not fall in the normal bounds of the array.
2157// Many times structure can be defined as:
2158// struct Collection
2159// {
2160// uint32_t item_count;
2161// Item item_array[0];
2162// };
2163// The size of the "item_array" is 1, but many times in practice
2164// there are more items in "item_array".
2165
2166ValueObjectSP
Bruce Mitchener11d86362015-02-26 23:55:39 +00002167ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00002168{
2169 ValueObjectSP synthetic_child_sp;
Bruce Mitchener11d86362015-02-26 23:55:39 +00002170 if (IsPointerType () || IsArrayType())
Greg Claytondaf515f2011-07-09 20:12:33 +00002171 {
2172 char index_str[64];
Deepak Panickal99fbc072014-03-03 15:39:47 +00002173 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
Greg Claytondaf515f2011-07-09 20:12:33 +00002174 ConstString index_const_str(index_str);
2175 // Check if we have already created a synthetic array member in this
2176 // valid object. If we have we will re-use it.
2177 synthetic_child_sp = GetSyntheticChild (index_const_str);
2178 if (!synthetic_child_sp)
2179 {
2180 ValueObject *synthetic_child;
2181 // We haven't made a synthetic array member for INDEX yet, so
2182 // lets make one and cache it for any future reference.
2183 synthetic_child = CreateChildAtIndex(0, true, index);
Bruce Mitchener11d86362015-02-26 23:55:39 +00002184
Greg Claytondaf515f2011-07-09 20:12:33 +00002185 // Cache the value if we got one back...
2186 if (synthetic_child)
2187 {
2188 AddSyntheticChild(index_const_str, synthetic_child);
2189 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002190 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00002191 synthetic_child_sp->m_is_array_item_for_pointer = true;
2192 }
2193 }
2194 }
2195 return synthetic_child_sp;
2196}
2197
Enrico Granata9fc19442011-07-06 02:13:41 +00002198ValueObjectSP
2199ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2200{
2201 ValueObjectSP synthetic_child_sp;
2202 if (IsScalarType ())
2203 {
2204 char index_str[64];
2205 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2206 ConstString index_const_str(index_str);
2207 // Check if we have already created a synthetic array member in this
2208 // valid object. If we have we will re-use it.
2209 synthetic_child_sp = GetSyntheticChild (index_const_str);
2210 if (!synthetic_child_sp)
2211 {
Enrico Granata9fc19442011-07-06 02:13:41 +00002212 // We haven't made a synthetic array member for INDEX yet, so
2213 // lets make one and cache it for any future reference.
Greg Clayton57ee3062013-07-11 22:46:58 +00002214 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
Greg Clayton99558cc42015-08-24 23:46:31 +00002215 GetCompilerType(),
Greg Clayton57ee3062013-07-11 22:46:58 +00002216 index_const_str,
2217 GetByteSize(),
2218 0,
2219 to-from+1,
2220 from,
2221 false,
2222 false,
2223 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002224
2225 // Cache the value if we got one back...
2226 if (synthetic_child)
2227 {
2228 AddSyntheticChild(index_const_str, synthetic_child);
2229 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002230 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002231 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2232 }
2233 }
2234 }
2235 return synthetic_child_sp;
2236}
2237
Greg Claytonafacd142011-09-02 01:15:17 +00002238ValueObjectSP
Greg Claytona1e5dc82015-08-11 22:53:00 +00002239ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const CompilerType& type, bool can_create)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002240{
2241
2242 ValueObjectSP synthetic_child_sp;
2243
2244 char name_str[64];
2245 snprintf(name_str, sizeof(name_str), "@%i", offset);
2246 ConstString name_const_str(name_str);
2247
2248 // Check if we have already created a synthetic array member in this
2249 // valid object. If we have we will re-use it.
2250 synthetic_child_sp = GetSyntheticChild (name_const_str);
2251
2252 if (synthetic_child_sp.get())
2253 return synthetic_child_sp;
2254
2255 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002256 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002257
Enrico Granata951bdd52015-01-28 01:09:45 +00002258 ExecutionContext exe_ctx (GetExecutionContextRef());
2259
Enrico Granata6f3533f2011-07-29 19:53:35 +00002260 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
Greg Clayton57ee3062013-07-11 22:46:58 +00002261 type,
Enrico Granata6f3533f2011-07-29 19:53:35 +00002262 name_const_str,
Greg Clayton526ae042015-02-12 00:34:25 +00002263 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
Enrico Granata6f3533f2011-07-29 19:53:35 +00002264 offset,
2265 0,
2266 0,
2267 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002268 false,
2269 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002270 if (synthetic_child)
2271 {
2272 AddSyntheticChild(name_const_str, synthetic_child);
2273 synthetic_child_sp = synthetic_child->GetSP();
2274 synthetic_child_sp->SetName(name_const_str);
2275 synthetic_child_sp->m_is_child_at_offset = true;
2276 }
2277 return synthetic_child_sp;
2278}
2279
Enrico Granata32556cd2014-08-26 20:54:04 +00002280ValueObjectSP
Greg Claytona1e5dc82015-08-11 22:53:00 +00002281ValueObject::GetSyntheticBase (uint32_t offset, const CompilerType& type, bool can_create)
Enrico Granata32556cd2014-08-26 20:54:04 +00002282{
2283 ValueObjectSP synthetic_child_sp;
2284
2285 char name_str[64];
2286 snprintf(name_str, sizeof(name_str), "%s", type.GetTypeName().AsCString("<unknown>"));
2287 ConstString name_const_str(name_str);
2288
2289 // Check if we have already created a synthetic array member in this
2290 // valid object. If we have we will re-use it.
2291 synthetic_child_sp = GetSyntheticChild (name_const_str);
2292
2293 if (synthetic_child_sp.get())
2294 return synthetic_child_sp;
2295
2296 if (!can_create)
2297 return ValueObjectSP();
2298
Enrico Granata32556cd2014-08-26 20:54:04 +00002299 const bool is_base_class = true;
2300
Enrico Granata951bdd52015-01-28 01:09:45 +00002301 ExecutionContext exe_ctx (GetExecutionContextRef());
2302
Enrico Granata32556cd2014-08-26 20:54:04 +00002303 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2304 type,
2305 name_const_str,
Greg Clayton526ae042015-02-12 00:34:25 +00002306 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
Enrico Granata32556cd2014-08-26 20:54:04 +00002307 offset,
2308 0,
2309 0,
2310 is_base_class,
2311 false,
2312 eAddressTypeInvalid);
2313 if (synthetic_child)
2314 {
2315 AddSyntheticChild(name_const_str, synthetic_child);
2316 synthetic_child_sp = synthetic_child->GetSP();
2317 synthetic_child_sp->SetName(name_const_str);
2318 }
2319 return synthetic_child_sp;
2320}
2321
2322
Enrico Granatad55546b2011-07-22 00:16:08 +00002323// your expression path needs to have a leading . or ->
2324// (unless it somehow "looks like" an array, in which case it has
2325// a leading [ symbol). while the [ is meaningful and should be shown
2326// to the user, . and -> are just parser design, but by no means
2327// added information for the user.. strip them off
2328static const char*
2329SkipLeadingExpressionPathSeparators(const char* expression)
2330{
2331 if (!expression || !expression[0])
2332 return expression;
2333 if (expression[0] == '.')
2334 return expression+1;
2335 if (expression[0] == '-' && expression[1] == '>')
2336 return expression+2;
2337 return expression;
2338}
2339
Greg Claytonafacd142011-09-02 01:15:17 +00002340ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002341ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2342{
2343 ValueObjectSP synthetic_child_sp;
2344 ConstString name_const_string(expression);
2345 // Check if we have already created a synthetic array member in this
2346 // valid object. If we have we will re-use it.
2347 synthetic_child_sp = GetSyntheticChild (name_const_string);
2348 if (!synthetic_child_sp)
2349 {
2350 // We haven't made a synthetic array member for expression yet, so
2351 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002352 synthetic_child_sp = GetValueForExpressionPath(expression,
2353 NULL, NULL, NULL,
Enrico Granataef238c12015-03-12 22:30:58 +00002354 GetValueForExpressionPathOptions().SetSyntheticChildrenTraversal(GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None));
Enrico Granatad55546b2011-07-22 00:16:08 +00002355
2356 // Cache the value if we got one back...
2357 if (synthetic_child_sp.get())
2358 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002359 // 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 +00002360 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002361 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002362 }
2363 }
2364 return synthetic_child_sp;
2365}
2366
2367void
Enrico Granata86cc9822012-03-19 22:58:49 +00002368ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002369{
Enrico Granata86cc9822012-03-19 22:58:49 +00002370 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002371 return;
2372
Enrico Granatac5bc4122012-03-27 02:35:13 +00002373 TargetSP target_sp(GetTargetSP());
Enrico Granata5d5f60c2013-09-24 22:58:37 +00002374 if (target_sp && target_sp->GetEnableSyntheticValue() == false)
Enrico Granatac5bc4122012-03-27 02:35:13 +00002375 {
2376 m_synthetic_value = NULL;
2377 return;
2378 }
2379
Enrico Granatae3e91512012-10-22 18:18:36 +00002380 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2381
Enrico Granata5548cb52013-01-28 23:47:25 +00002382 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002383 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002384
Enrico Granata0c489f52012-03-01 04:24:26 +00002385 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002386 return;
2387
Enrico Granatae3e91512012-10-22 18:18:36 +00002388 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2389 return;
2390
Enrico Granata86cc9822012-03-19 22:58:49 +00002391 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002392}
2393
Jim Ingham78a685a2011-04-16 00:01:13 +00002394void
Greg Claytonafacd142011-09-02 01:15:17 +00002395ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002396{
Greg Claytonafacd142011-09-02 01:15:17 +00002397 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002398 return;
2399
Jim Ingham58b59f92011-04-22 23:53:53 +00002400 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002401 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002402 ExecutionContext exe_ctx (GetExecutionContextRef());
2403 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002404 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002405 {
2406 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002407 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002408 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002409 }
2410}
2411
Jim Ingham58b59f92011-04-22 23:53:53 +00002412ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002413ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002414{
Greg Claytonafacd142011-09-02 01:15:17 +00002415 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002416 return ValueObjectSP();
2417
2418 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002419 {
Jim Ingham2837b762011-05-04 03:43:18 +00002420 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002421 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002422 if (m_dynamic_value)
2423 return m_dynamic_value->GetSP();
2424 else
2425 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002426}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002427
Jim Ingham60dbabb2011-12-08 19:44:08 +00002428ValueObjectSP
2429ValueObject::GetStaticValue()
2430{
2431 return GetSP();
2432}
2433
Enrico Granata886147f2012-05-08 18:47:08 +00002434lldb::ValueObjectSP
2435ValueObject::GetNonSyntheticValue ()
2436{
2437 return GetSP();
2438}
2439
Enrico Granatad55546b2011-07-22 00:16:08 +00002440ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002441ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002442{
Enrico Granata86cc9822012-03-19 22:58:49 +00002443 if (use_synthetic == false)
2444 return ValueObjectSP();
2445
Enrico Granatad55546b2011-07-22 00:16:08 +00002446 CalculateSyntheticValue(use_synthetic);
2447
2448 if (m_synthetic_value)
2449 return m_synthetic_value->GetSP();
2450 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002451 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002452}
2453
Greg Claytone221f822011-01-21 01:59:00 +00002454bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002455ValueObject::HasSyntheticValue()
2456{
Enrico Granata5548cb52013-01-28 23:47:25 +00002457 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002458
Enrico Granata0c489f52012-03-01 04:24:26 +00002459 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002460 return false;
2461
Enrico Granata86cc9822012-03-19 22:58:49 +00002462 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002463
2464 if (m_synthetic_value)
2465 return true;
2466 else
2467 return false;
2468}
2469
2470bool
Greg Claytone221f822011-01-21 01:59:00 +00002471ValueObject::GetBaseClassPath (Stream &s)
2472{
2473 if (IsBaseClass())
2474 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002475 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002476 CompilerType compiler_type = GetCompilerType();
Greg Claytone221f822011-01-21 01:59:00 +00002477 std::string cxx_class_name;
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002478 bool this_had_base_class = ClangASTContext::GetCXXClassName (compiler_type, cxx_class_name);
Greg Claytone221f822011-01-21 01:59:00 +00002479 if (this_had_base_class)
2480 {
2481 if (parent_had_base_class)
2482 s.PutCString("::");
2483 s.PutCString(cxx_class_name.c_str());
2484 }
2485 return parent_had_base_class || this_had_base_class;
2486 }
2487 return false;
2488}
2489
2490
2491ValueObject *
2492ValueObject::GetNonBaseClassParent()
2493{
Jim Ingham78a685a2011-04-16 00:01:13 +00002494 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002495 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002496 if (GetParent()->IsBaseClass())
2497 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002498 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002499 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002500 }
2501 return NULL;
2502}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002503
Enrico Granataa3c8f042014-08-19 22:29:08 +00002504
2505bool
2506ValueObject::IsBaseClass (uint32_t& depth)
2507{
2508 if (!IsBaseClass())
2509 {
2510 depth = 0;
2511 return false;
2512 }
2513 if (GetParent())
2514 {
2515 GetParent()->IsBaseClass(depth);
2516 depth = depth + 1;
2517 return true;
2518 }
2519 // TODO: a base of no parent? weird..
2520 depth = 1;
2521 return true;
2522}
2523
Greg Clayton1d3afba2010-10-05 00:00:42 +00002524void
Enrico Granata4becb372011-06-29 22:27:15 +00002525ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002526{
Enrico Granata986fa5f2014-12-09 21:41:16 +00002527 // synthetic children do not actually "exist" as part of the hierarchy, and sometimes they are consed up in ways
2528 // that don't make sense from an underlying language/API standpoint. So, use a special code path here to return
2529 // something that can hopefully be used in expression
2530 if (m_is_synthetic_children_generated)
2531 {
2532 UpdateValueIfNeeded();
2533
2534 if (m_value.GetValueType() == Value::eValueTypeLoadAddress)
2535 {
2536 if (IsPointerOrReferenceType())
2537 {
2538 s.Printf("((%s)0x%" PRIx64 ")",
2539 GetTypeName().AsCString("void"),
2540 GetValueAsUnsigned(0));
2541 return;
2542 }
2543 else
2544 {
2545 uint64_t load_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
2546 if (load_addr != LLDB_INVALID_ADDRESS)
2547 {
2548 s.Printf("(*( (%s *)0x%" PRIx64 "))",
2549 GetTypeName().AsCString("void"),
2550 load_addr);
2551 return;
2552 }
2553 }
2554 }
2555
2556 if (CanProvideValue())
2557 {
2558 s.Printf("((%s)%s)",
2559 GetTypeName().AsCString("void"),
2560 GetValueAsCString());
2561 return;
2562 }
2563
2564 return;
2565 }
2566
Greg Claytone221f822011-01-21 01:59:00 +00002567 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002568
Enrico Granata86cc9822012-03-19 22:58:49 +00002569 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002570 {
Enrico Granata4becb372011-06-29 22:27:15 +00002571 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2572 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2573 // the eHonorPointers mode is meant to produce strings in this latter format
2574 s.PutCString("*(");
2575 }
Greg Claytone221f822011-01-21 01:59:00 +00002576
Enrico Granata4becb372011-06-29 22:27:15 +00002577 ValueObject* parent = GetParent();
2578
2579 if (parent)
2580 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002581
2582 // if we are a deref_of_parent just because we are synthetic array
2583 // members made up to allow ptr[%d] syntax to work in variable
2584 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002585 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002586 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002587
Greg Claytone221f822011-01-21 01:59:00 +00002588 if (!IsBaseClass())
2589 {
2590 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002591 {
Greg Claytone221f822011-01-21 01:59:00 +00002592 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2593 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002594 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002595 CompilerType non_base_class_parent_compiler_type = non_base_class_parent->GetCompilerType();
2596 if (non_base_class_parent_compiler_type)
Greg Claytone221f822011-01-21 01:59:00 +00002597 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002598 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002599 {
2600 s.PutCString("->");
2601 }
Enrico Granata4becb372011-06-29 22:27:15 +00002602 else
2603 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002604 const uint32_t non_base_class_parent_type_info = non_base_class_parent_compiler_type.GetTypeInfo();
Greg Clayton57ee3062013-07-11 22:46:58 +00002605
Enrico Granata622be232014-10-21 20:52:14 +00002606 if (non_base_class_parent_type_info & eTypeIsPointer)
Enrico Granata4becb372011-06-29 22:27:15 +00002607 {
2608 s.PutCString("->");
2609 }
Enrico Granata622be232014-10-21 20:52:14 +00002610 else if ((non_base_class_parent_type_info & eTypeHasChildren) &&
2611 !(non_base_class_parent_type_info & eTypeIsArray))
Enrico Granata4becb372011-06-29 22:27:15 +00002612 {
2613 s.PutChar('.');
2614 }
Greg Claytone221f822011-01-21 01:59:00 +00002615 }
2616 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002617 }
Greg Claytone221f822011-01-21 01:59:00 +00002618
2619 const char *name = GetName().GetCString();
2620 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002621 {
Greg Claytone221f822011-01-21 01:59:00 +00002622 if (qualify_cxx_base_classes)
2623 {
2624 if (GetBaseClassPath (s))
2625 s.PutCString("::");
2626 }
2627 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002628 }
2629 }
2630 }
2631
Enrico Granata86cc9822012-03-19 22:58:49 +00002632 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002633 {
Greg Claytone221f822011-01-21 01:59:00 +00002634 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002635 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002636}
2637
Greg Claytonafacd142011-09-02 01:15:17 +00002638ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002639ValueObject::GetValueForExpressionPath(const char* expression,
2640 const char** first_unparsed,
2641 ExpressionPathScanEndReason* reason_to_stop,
2642 ExpressionPathEndResultType* final_value_type,
2643 const GetValueForExpressionPathOptions& options,
2644 ExpressionPathAftermath* final_task_on_target)
2645{
2646
2647 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002648 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2649 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002650 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002651
2652 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2653 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2654 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2655 final_value_type ? final_value_type : &dummy_final_value_type,
2656 options,
2657 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2658
Enrico Granata86cc9822012-03-19 22:58:49 +00002659 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002660 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002661
Enrico Granata86cc9822012-03-19 22:58:49 +00002662 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 +00002663 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002664 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002665 {
2666 Error error;
2667 ValueObjectSP final_value = ret_val->Dereference(error);
2668 if (error.Fail() || !final_value.get())
2669 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002670 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002671 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002672 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002673 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002674 return ValueObjectSP();
2675 }
2676 else
2677 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002678 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002679 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002680 return final_value;
2681 }
2682 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002683 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002684 {
2685 Error error;
2686 ValueObjectSP final_value = ret_val->AddressOf(error);
2687 if (error.Fail() || !final_value.get())
2688 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002689 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002690 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002691 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002692 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002693 return ValueObjectSP();
2694 }
2695 else
2696 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002697 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002698 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002699 return final_value;
2700 }
2701 }
2702 }
2703 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2704}
2705
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002706int
2707ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002708 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002709 const char** first_unparsed,
2710 ExpressionPathScanEndReason* reason_to_stop,
2711 ExpressionPathEndResultType* final_value_type,
2712 const GetValueForExpressionPathOptions& options,
2713 ExpressionPathAftermath* final_task_on_target)
2714{
2715 const char* dummy_first_unparsed;
2716 ExpressionPathScanEndReason dummy_reason_to_stop;
2717 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002718 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002719
2720 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2721 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2722 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2723 final_value_type ? final_value_type : &dummy_final_value_type,
2724 options,
2725 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2726
2727 if (!ret_val.get()) // if there are errors, I add nothing to the list
2728 return 0;
2729
Enrico Granata86ea8d82012-03-29 01:34:34 +00002730 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002731 {
2732 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002733 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002734 {
2735 list->Append(ret_val);
2736 return 1;
2737 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002738 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 +00002739 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002740 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002741 {
2742 Error error;
2743 ValueObjectSP final_value = ret_val->Dereference(error);
2744 if (error.Fail() || !final_value.get())
2745 {
Greg Clayton23f59502012-07-17 03:23:13 +00002746 if (reason_to_stop)
2747 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2748 if (final_value_type)
2749 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002750 return 0;
2751 }
2752 else
2753 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002754 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002755 list->Append(final_value);
2756 return 1;
2757 }
2758 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002759 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002760 {
2761 Error error;
2762 ValueObjectSP final_value = ret_val->AddressOf(error);
2763 if (error.Fail() || !final_value.get())
2764 {
Greg Clayton23f59502012-07-17 03:23:13 +00002765 if (reason_to_stop)
2766 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2767 if (final_value_type)
2768 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002769 return 0;
2770 }
2771 else
2772 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002773 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002774 list->Append(final_value);
2775 return 1;
2776 }
2777 }
2778 }
2779 }
2780 else
2781 {
2782 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2783 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2784 ret_val,
2785 list,
2786 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2787 final_value_type ? final_value_type : &dummy_final_value_type,
2788 options,
2789 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2790 }
2791 // in any non-covered case, just do the obviously right thing
2792 list->Append(ret_val);
2793 return 1;
2794}
2795
Greg Claytonafacd142011-09-02 01:15:17 +00002796ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002797ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2798 const char** first_unparsed,
2799 ExpressionPathScanEndReason* reason_to_stop,
2800 ExpressionPathEndResultType* final_result,
2801 const GetValueForExpressionPathOptions& options,
2802 ExpressionPathAftermath* what_next)
2803{
2804 ValueObjectSP root = GetSP();
2805
2806 if (!root.get())
2807 return ValueObjectSP();
2808
2809 *first_unparsed = expression_cstr;
2810
2811 while (true)
2812 {
2813
2814 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2815
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002816 CompilerType root_compiler_type = root->GetCompilerType();
2817 CompilerType pointee_compiler_type;
2818 Flags pointee_compiler_type_info;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002819
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002820 Flags root_compiler_type_info(root_compiler_type.GetTypeInfo(&pointee_compiler_type));
2821 if (pointee_compiler_type)
2822 pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002823
2824 if (!expression_cstr || *expression_cstr == '\0')
2825 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002826 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002827 return root;
2828 }
2829
2830 switch (*expression_cstr)
2831 {
2832 case '-':
2833 {
2834 if (options.m_check_dot_vs_arrow_syntax &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002835 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 +00002836 {
2837 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002838 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2839 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002840 return ValueObjectSP();
2841 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002842 if (root_compiler_type_info.Test(eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2843 root_compiler_type_info.Test(eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002844 options.m_no_fragile_ivar)
2845 {
2846 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002847 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2848 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002849 return ValueObjectSP();
2850 }
2851 if (expression_cstr[1] != '>')
2852 {
2853 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002854 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2855 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002856 return ValueObjectSP();
2857 }
2858 expression_cstr++; // skip the -
2859 }
2860 case '.': // or fallthrough from ->
2861 {
2862 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002863 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 +00002864 {
2865 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002866 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2867 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002868 return ValueObjectSP();
2869 }
2870 expression_cstr++; // skip .
2871 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2872 ConstString child_name;
2873 if (!next_separator) // if no other separator just expand this last layer
2874 {
2875 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002876 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2877
2878 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002879 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002880 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002881 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2882 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002883 return child_valobj_sp;
2884 }
Enrico Granataef238c12015-03-12 22:30:58 +00002885 else
Enrico Granata8c9d3562011-08-11 17:08:01 +00002886 {
Enrico Granataef238c12015-03-12 22:30:58 +00002887 switch (options.m_synthetic_children_traversal)
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002888 {
Enrico Granataef238c12015-03-12 22:30:58 +00002889 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None:
2890 break;
2891 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic:
2892 if (root->IsSynthetic())
2893 {
2894 child_valobj_sp = root->GetNonSyntheticValue();
2895 if (child_valobj_sp.get())
2896 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2897 }
2898 break;
2899 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic:
2900 if (!root->IsSynthetic())
2901 {
2902 child_valobj_sp = root->GetSyntheticValue();
2903 if (child_valobj_sp.get())
2904 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2905 }
2906 break;
2907 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both:
2908 if (root->IsSynthetic())
2909 {
2910 child_valobj_sp = root->GetNonSyntheticValue();
2911 if (child_valobj_sp.get())
2912 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2913 }
2914 else
2915 {
2916 child_valobj_sp = root->GetSyntheticValue();
2917 if (child_valobj_sp.get())
2918 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2919 }
2920 break;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002921 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002922 }
2923
2924 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2925 // so we hit the "else" branch, and return an error
2926 if(child_valobj_sp.get()) // if it worked, just return
2927 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002928 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002929 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2930 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002931 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002932 }
2933 else
2934 {
2935 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002936 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2937 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002938 return ValueObjectSP();
2939 }
2940 }
2941 else // other layers do expand
2942 {
2943 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002944 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2945 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002946 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002947 root = child_valobj_sp;
2948 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002949 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002950 continue;
2951 }
Enrico Granataef238c12015-03-12 22:30:58 +00002952 else
Enrico Granata8c9d3562011-08-11 17:08:01 +00002953 {
Enrico Granataef238c12015-03-12 22:30:58 +00002954 switch (options.m_synthetic_children_traversal)
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002955 {
Enrico Granataef238c12015-03-12 22:30:58 +00002956 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None:
2957 break;
2958 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic:
2959 if (root->IsSynthetic())
2960 {
2961 child_valobj_sp = root->GetNonSyntheticValue();
2962 if (child_valobj_sp.get())
2963 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2964 }
2965 break;
2966 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic:
2967 if (!root->IsSynthetic())
2968 {
2969 child_valobj_sp = root->GetSyntheticValue();
2970 if (child_valobj_sp.get())
2971 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2972 }
2973 break;
2974 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both:
2975 if (root->IsSynthetic())
2976 {
2977 child_valobj_sp = root->GetNonSyntheticValue();
2978 if (child_valobj_sp.get())
2979 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2980 }
2981 else
2982 {
2983 child_valobj_sp = root->GetSyntheticValue();
2984 if (child_valobj_sp.get())
2985 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2986 }
2987 break;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002988 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002989 }
2990
2991 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2992 // so we hit the "else" branch, and return an error
2993 if(child_valobj_sp.get()) // if it worked, move on
2994 {
2995 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002996 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002997 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002998 continue;
2999 }
3000 else
3001 {
3002 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003003 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3004 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003005 return ValueObjectSP();
3006 }
3007 }
3008 break;
3009 }
3010 case '[':
3011 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003012 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 +00003013 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003014 if (!root_compiler_type_info.Test(eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003015 {
Enrico Granataef238c12015-03-12 22:30:58 +00003016 if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None) // ...only chance left is synthetic
Enrico Granata27b625e2011-08-09 01:04:56 +00003017 {
3018 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003019 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3020 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003021 return ValueObjectSP();
3022 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003023 }
3024 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3025 {
3026 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003027 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3028 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003029 return ValueObjectSP();
3030 }
3031 }
3032 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3033 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003034 if (!root_compiler_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003035 {
3036 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003037 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3038 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003039 return ValueObjectSP();
3040 }
3041 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
3042 {
3043 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003044 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3045 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003046 return root;
3047 }
3048 }
3049 const char *separator_position = ::strchr(expression_cstr+1,'-');
3050 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3051 if (!close_bracket_position) // if there is no ], this is a syntax error
3052 {
3053 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003054 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3055 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003056 return ValueObjectSP();
3057 }
3058 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3059 {
3060 char *end = NULL;
3061 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3062 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3063 {
3064 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003065 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3066 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003067 return ValueObjectSP();
3068 }
3069 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3070 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003071 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003072 {
3073 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003074 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3075 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003076 return root;
3077 }
3078 else
3079 {
3080 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003081 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3082 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003083 return ValueObjectSP();
3084 }
3085 }
3086 // from here on we do have a valid index
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003087 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003088 {
Greg Claytondaf515f2011-07-09 20:12:33 +00003089 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
3090 if (!child_valobj_sp)
Bruce Mitchener11d86362015-02-26 23:55:39 +00003091 child_valobj_sp = root->GetSyntheticArrayMember(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003092 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00003093 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
3094 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00003095 if (child_valobj_sp)
3096 {
3097 root = child_valobj_sp;
3098 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003099 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00003100 continue;
3101 }
3102 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003103 {
3104 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003105 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3106 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003107 return ValueObjectSP();
3108 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003109 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003110 else if (root_compiler_type_info.Test(eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003111 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003112 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 +00003113 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003114 {
3115 Error error;
3116 root = root->Dereference(error);
3117 if (error.Fail() || !root.get())
3118 {
3119 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003120 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3121 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003122 return ValueObjectSP();
3123 }
3124 else
3125 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003126 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003127 continue;
3128 }
3129 }
3130 else
3131 {
Greg Clayton99558cc42015-08-24 23:46:31 +00003132 if (root->GetCompilerType().GetMinimumLanguage() == eLanguageTypeObjC
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003133 && pointee_compiler_type_info.AllClear(eTypeIsPointer)
Greg Clayton84db9102012-03-26 23:03:23 +00003134 && root->HasSyntheticValue()
Enrico Granataef238c12015-03-12 22:30:58 +00003135 && (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic ||
3136 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both))
Enrico Granata27b625e2011-08-09 01:04:56 +00003137 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003138 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003139 }
3140 else
Bruce Mitchener11d86362015-02-26 23:55:39 +00003141 root = root->GetSyntheticArrayMember(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003142 if (!root.get())
3143 {
3144 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003145 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3146 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003147 return ValueObjectSP();
3148 }
3149 else
3150 {
3151 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003152 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003153 continue;
3154 }
3155 }
3156 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003157 else if (root_compiler_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003158 {
3159 root = root->GetSyntheticBitFieldChild(index, index, true);
3160 if (!root.get())
3161 {
3162 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003163 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3164 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003165 return ValueObjectSP();
3166 }
3167 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3168 {
3169 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003170 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3171 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003172 return root;
3173 }
3174 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003175 else if (root_compiler_type_info.Test(eTypeIsVector))
Enrico Granata08a1bb82013-06-19 00:00:45 +00003176 {
3177 root = root->GetChildAtIndex(index, true);
3178 if (!root.get())
3179 {
3180 *first_unparsed = expression_cstr;
3181 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3182 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3183 return ValueObjectSP();
3184 }
3185 else
3186 {
3187 *first_unparsed = end+1; // skip ]
3188 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3189 continue;
3190 }
3191 }
Enrico Granataef238c12015-03-12 22:30:58 +00003192 else if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic ||
3193 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both)
Enrico Granata27b625e2011-08-09 01:04:56 +00003194 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003195 if (root->HasSyntheticValue())
3196 root = root->GetSyntheticValue();
3197 else if (!root->IsSynthetic())
3198 {
3199 *first_unparsed = expression_cstr;
3200 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3201 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3202 return ValueObjectSP();
3203 }
3204 // if we are here, then root itself is a synthetic VO.. should be good to go
3205
Enrico Granata27b625e2011-08-09 01:04:56 +00003206 if (!root.get())
3207 {
3208 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003209 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3210 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3211 return ValueObjectSP();
3212 }
3213 root = root->GetChildAtIndex(index, true);
3214 if (!root.get())
3215 {
3216 *first_unparsed = expression_cstr;
3217 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3218 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003219 return ValueObjectSP();
3220 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00003221 else
3222 {
3223 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003224 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00003225 continue;
3226 }
Enrico Granata27b625e2011-08-09 01:04:56 +00003227 }
3228 else
3229 {
3230 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003231 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3232 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003233 return ValueObjectSP();
3234 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003235 }
3236 else // we have a low and a high index
3237 {
3238 char *end = NULL;
3239 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3240 if (!end || end != separator_position) // if something weird is in our way return an error
3241 {
3242 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003243 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3244 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003245 return ValueObjectSP();
3246 }
3247 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3248 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3249 {
3250 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003251 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3252 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003253 return ValueObjectSP();
3254 }
3255 if (index_lower > index_higher) // swap indices if required
3256 {
3257 unsigned long temp = index_lower;
3258 index_lower = index_higher;
3259 index_higher = temp;
3260 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003261 if (root_compiler_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003262 {
3263 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3264 if (!root.get())
3265 {
3266 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003267 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3268 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003269 return ValueObjectSP();
3270 }
3271 else
3272 {
3273 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003274 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3275 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003276 return root;
3277 }
3278 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003279 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 +00003280 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003281 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003282 {
3283 Error error;
3284 root = root->Dereference(error);
3285 if (error.Fail() || !root.get())
3286 {
3287 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003288 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3289 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003290 return ValueObjectSP();
3291 }
3292 else
3293 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003294 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003295 continue;
3296 }
3297 }
3298 else
3299 {
3300 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003301 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3302 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003303 return root;
3304 }
3305 }
3306 break;
3307 }
3308 default: // some non-separator is in the way
3309 {
3310 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003311 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3312 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003313 return ValueObjectSP();
3314 break;
3315 }
3316 }
3317 }
3318}
3319
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003320int
3321ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3322 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00003323 ValueObjectSP root,
3324 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003325 ExpressionPathScanEndReason* reason_to_stop,
3326 ExpressionPathEndResultType* final_result,
3327 const GetValueForExpressionPathOptions& options,
3328 ExpressionPathAftermath* what_next)
3329{
3330 if (!root.get())
3331 return 0;
3332
3333 *first_unparsed = expression_cstr;
3334
3335 while (true)
3336 {
3337
3338 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3339
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003340 CompilerType root_compiler_type = root->GetCompilerType();
3341 CompilerType pointee_compiler_type;
3342 Flags pointee_compiler_type_info;
3343 Flags root_compiler_type_info(root_compiler_type.GetTypeInfo(&pointee_compiler_type));
3344 if (pointee_compiler_type)
3345 pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003346
3347 if (!expression_cstr || *expression_cstr == '\0')
3348 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003349 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003350 list->Append(root);
3351 return 1;
3352 }
3353
3354 switch (*expression_cstr)
3355 {
3356 case '[':
3357 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003358 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 +00003359 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003360 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 +00003361 {
3362 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003363 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3364 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003365 return 0;
3366 }
3367 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3368 {
3369 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003370 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3371 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003372 return 0;
3373 }
3374 }
3375 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3376 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003377 if (!root_compiler_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003378 {
3379 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003380 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3381 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003382 return 0;
3383 }
3384 else // expand this into list
3385 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003386 const size_t max_index = root->GetNumChildren() - 1;
3387 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003388 {
3389 ValueObjectSP child =
3390 root->GetChildAtIndex(index, true);
3391 list->Append(child);
3392 }
3393 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003394 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3395 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003396 return max_index; // tell me number of items I added to the VOList
3397 }
3398 }
3399 const char *separator_position = ::strchr(expression_cstr+1,'-');
3400 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3401 if (!close_bracket_position) // if there is no ], this is a syntax error
3402 {
3403 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003404 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3405 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003406 return 0;
3407 }
3408 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3409 {
3410 char *end = NULL;
3411 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3412 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3413 {
3414 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003415 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3416 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003417 return 0;
3418 }
3419 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3420 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003421 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003422 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003423 const size_t max_index = root->GetNumChildren() - 1;
3424 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003425 {
3426 ValueObjectSP child =
3427 root->GetChildAtIndex(index, true);
3428 list->Append(child);
3429 }
3430 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003431 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3432 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003433 return max_index; // tell me number of items I added to the VOList
3434 }
3435 else
3436 {
3437 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003438 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3439 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003440 return 0;
3441 }
3442 }
3443 // from here on we do have a valid index
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003444 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003445 {
3446 root = root->GetChildAtIndex(index, true);
3447 if (!root.get())
3448 {
3449 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003450 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3451 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003452 return 0;
3453 }
3454 else
3455 {
3456 list->Append(root);
3457 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003458 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3459 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003460 return 1;
3461 }
3462 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003463 else if (root_compiler_type_info.Test(eTypeIsPointer))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003464 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003465 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 +00003466 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003467 {
3468 Error error;
3469 root = root->Dereference(error);
3470 if (error.Fail() || !root.get())
3471 {
3472 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003473 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3474 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003475 return 0;
3476 }
3477 else
3478 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003479 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003480 continue;
3481 }
3482 }
3483 else
3484 {
Bruce Mitchener11d86362015-02-26 23:55:39 +00003485 root = root->GetSyntheticArrayMember(index, true);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003486 if (!root.get())
3487 {
3488 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003489 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3490 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003491 return 0;
3492 }
3493 else
3494 {
3495 list->Append(root);
3496 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003497 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3498 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003499 return 1;
3500 }
3501 }
3502 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003503 else /*if (ClangASTContext::IsScalarType(root_compiler_type))*/
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003504 {
3505 root = root->GetSyntheticBitFieldChild(index, index, true);
3506 if (!root.get())
3507 {
3508 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003509 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3510 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003511 return 0;
3512 }
3513 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3514 {
3515 list->Append(root);
3516 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003517 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3518 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003519 return 1;
3520 }
3521 }
3522 }
3523 else // we have a low and a high index
3524 {
3525 char *end = NULL;
3526 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3527 if (!end || end != separator_position) // if something weird is in our way return an error
3528 {
3529 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003530 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3531 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003532 return 0;
3533 }
3534 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3535 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3536 {
3537 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003538 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3539 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003540 return 0;
3541 }
3542 if (index_lower > index_higher) // swap indices if required
3543 {
3544 unsigned long temp = index_lower;
3545 index_lower = index_higher;
3546 index_higher = temp;
3547 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003548 if (root_compiler_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003549 {
3550 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3551 if (!root.get())
3552 {
3553 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003554 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3555 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003556 return 0;
3557 }
3558 else
3559 {
3560 list->Append(root);
3561 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003562 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3563 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003564 return 1;
3565 }
3566 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003567 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 +00003568 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003569 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003570 {
3571 Error error;
3572 root = root->Dereference(error);
3573 if (error.Fail() || !root.get())
3574 {
3575 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003576 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3577 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003578 return 0;
3579 }
3580 else
3581 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003582 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003583 continue;
3584 }
3585 }
3586 else
3587 {
Johnny Chen44805302011-07-19 19:48:13 +00003588 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003589 index <= index_higher; index++)
3590 {
3591 ValueObjectSP child =
3592 root->GetChildAtIndex(index, true);
3593 list->Append(child);
3594 }
3595 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003596 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3597 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003598 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3599 }
3600 }
3601 break;
3602 }
3603 default: // some non-[ separator, or something entirely wrong, is in the way
3604 {
3605 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003606 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3607 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003608 return 0;
3609 break;
3610 }
3611 }
3612 }
3613}
3614
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003615void
3616ValueObject::LogValueObject (Log *log)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003617{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003618 if (log)
Enrico Granatad5957332015-06-03 20:43:54 +00003619 return LogValueObject (log, DumpValueObjectOptions(*this));
Greg Clayton1d3afba2010-10-05 00:00:42 +00003620}
3621
Enrico Granata0c489f52012-03-01 04:24:26 +00003622void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003623ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003624{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003625 if (log)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003626 {
3627 StreamString s;
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003628 Dump (s, options);
Greg Claytonf830dbb2012-03-22 18:15:37 +00003629 if (s.GetSize())
3630 log->PutCString(s.GetData());
3631 }
3632}
3633
3634void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003635ValueObject::Dump (Stream &s)
Enrico Granata0c489f52012-03-01 04:24:26 +00003636{
Enrico Granatad5957332015-06-03 20:43:54 +00003637 Dump (s, DumpValueObjectOptions(*this));
Enrico Granata0c489f52012-03-01 04:24:26 +00003638}
3639
3640void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003641ValueObject::Dump (Stream &s,
3642 const DumpValueObjectOptions& options)
Enrico Granata0c489f52012-03-01 04:24:26 +00003643{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003644 ValueObjectPrinter printer(this,&s,options);
3645 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003646}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003647
3648ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003649ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003650{
3651 ValueObjectSP valobj_sp;
3652
Enrico Granatac3e320a2011-08-02 17:27:39 +00003653 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003654 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003655 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003656
3657 DataExtractor data;
3658 data.SetByteOrder (m_data.GetByteOrder());
3659 data.SetAddressByteSize(m_data.GetAddressByteSize());
3660
Enrico Granata9f1e2042012-04-24 22:15:37 +00003661 if (IsBitfield())
3662 {
3663 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
Greg Clayton57ee3062013-07-11 22:46:58 +00003664 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Enrico Granata9f1e2042012-04-24 22:15:37 +00003665 }
3666 else
Greg Clayton57ee3062013-07-11 22:46:58 +00003667 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003668
3669 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton99558cc42015-08-24 23:46:31 +00003670 GetCompilerType(),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003671 name,
3672 data,
3673 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003674 }
Jim Ingham6035b672011-03-31 00:19:25 +00003675
3676 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003677 {
Greg Claytoneeb15652013-12-10 23:16:40 +00003678 ExecutionContext exe_ctx (GetExecutionContextRef());
3679 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003680 }
3681 return valobj_sp;
3682}
3683
Enrico Granata538a88a2014-10-09 18:24:30 +00003684ValueObjectSP
3685ValueObject::GetQualifiedRepresentationIfAvailable (lldb::DynamicValueType dynValue,
3686 bool synthValue)
3687{
3688 ValueObjectSP result_sp(GetSP());
3689
3690 switch (dynValue)
3691 {
3692 case lldb::eDynamicCanRunTarget:
3693 case lldb::eDynamicDontRunTarget:
3694 {
3695 if (!result_sp->IsDynamic())
3696 {
3697 if (result_sp->GetDynamicValue(dynValue))
3698 result_sp = result_sp->GetDynamicValue(dynValue);
3699 }
3700 }
3701 break;
3702 case lldb::eNoDynamicValues:
Enrico Granata538a88a2014-10-09 18:24:30 +00003703 {
3704 if (result_sp->IsDynamic())
3705 {
3706 if (result_sp->GetStaticValue())
3707 result_sp = result_sp->GetStaticValue();
3708 }
3709 }
3710 break;
3711 }
3712
3713 if (synthValue)
3714 {
3715 if (!result_sp->IsSynthetic())
3716 {
3717 if (result_sp->GetSyntheticValue())
3718 result_sp = result_sp->GetSyntheticValue();
3719 }
3720 }
3721 else
3722 {
3723 if (result_sp->IsSynthetic())
3724 {
3725 if (result_sp->GetNonSyntheticValue())
3726 result_sp = result_sp->GetNonSyntheticValue();
3727 }
3728 }
3729
3730 return result_sp;
3731}
3732
Greg Clayton759e7442014-07-19 00:12:57 +00003733lldb::addr_t
3734ValueObject::GetCPPVTableAddress (AddressType &address_type)
3735{
Greg Claytona1e5dc82015-08-11 22:53:00 +00003736 CompilerType pointee_type;
Greg Clayton99558cc42015-08-24 23:46:31 +00003737 CompilerType this_type(GetCompilerType());
Greg Clayton759e7442014-07-19 00:12:57 +00003738 uint32_t type_info = this_type.GetTypeInfo(&pointee_type);
3739 if (type_info)
3740 {
3741 bool ptr_or_ref = false;
Enrico Granata622be232014-10-21 20:52:14 +00003742 if (type_info & (eTypeIsPointer | eTypeIsReference))
Greg Clayton759e7442014-07-19 00:12:57 +00003743 {
3744 ptr_or_ref = true;
3745 type_info = pointee_type.GetTypeInfo();
3746 }
3747
Enrico Granata622be232014-10-21 20:52:14 +00003748 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus;
Greg Clayton759e7442014-07-19 00:12:57 +00003749 if ((type_info & cpp_class) == cpp_class)
3750 {
3751 if (ptr_or_ref)
3752 {
3753 address_type = GetAddressTypeOfChildren();
3754 return GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
3755 }
3756 else
3757 return GetAddressOf (false, &address_type);
3758 }
3759 }
3760
3761 address_type = eAddressTypeInvalid;
3762 return LLDB_INVALID_ADDRESS;
3763}
3764
Greg Claytonafacd142011-09-02 01:15:17 +00003765ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003766ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003767{
Jim Ingham58b59f92011-04-22 23:53:53 +00003768 if (m_deref_valobj)
3769 return m_deref_valobj->GetSP();
Chaoren Lind7bdc272015-07-31 00:35:40 +00003770
3771 const bool is_pointer_or_reference_type = IsPointerOrReferenceType();
3772 if (is_pointer_or_reference_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003773 {
3774 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003775 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003776
3777 std::string child_name_str;
3778 uint32_t child_byte_size = 0;
3779 int32_t child_byte_offset = 0;
3780 uint32_t child_bitfield_bit_size = 0;
3781 uint32_t child_bitfield_bit_offset = 0;
3782 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003783 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003784 const bool transparent_pointers = false;
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003785 CompilerType compiler_type = GetCompilerType();
3786 CompilerType child_compiler_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003787
Greg Claytoncc4d0142012-02-17 07:49:44 +00003788 ExecutionContext exe_ctx (GetExecutionContextRef());
Chaoren Lind7bdc272015-07-31 00:35:40 +00003789
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003790 child_compiler_type = compiler_type.GetChildCompilerTypeAtIndex (&exe_ctx,
3791 0,
3792 transparent_pointers,
3793 omit_empty_base_classes,
3794 ignore_array_bounds,
3795 child_name_str,
3796 child_byte_size,
3797 child_byte_offset,
3798 child_bitfield_bit_size,
3799 child_bitfield_bit_offset,
3800 child_is_base_class,
3801 child_is_deref_of_parent,
3802 this);
3803 if (child_compiler_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003804 {
3805 ConstString child_name;
3806 if (!child_name_str.empty())
3807 child_name.SetCString (child_name_str.c_str());
3808
Jim Ingham58b59f92011-04-22 23:53:53 +00003809 m_deref_valobj = new ValueObjectChild (*this,
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003810 child_compiler_type,
Jim Ingham58b59f92011-04-22 23:53:53 +00003811 child_name,
3812 child_byte_size,
3813 child_byte_offset,
3814 child_bitfield_bit_size,
3815 child_bitfield_bit_offset,
3816 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003817 child_is_deref_of_parent,
3818 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003819 }
3820 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003821
Jim Ingham58b59f92011-04-22 23:53:53 +00003822 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003823 {
3824 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003825 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003826 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003827 else
3828 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003829 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003830 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003831
Chaoren Lind7bdc272015-07-31 00:35:40 +00003832 if (is_pointer_or_reference_type)
Greg Clayton54979cd2010-12-15 05:08:08 +00003833 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3834 else
Chaoren Lind7bdc272015-07-31 00:35:40 +00003835 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 +00003836 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003837 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003838}
3839
Greg Claytonafacd142011-09-02 01:15:17 +00003840ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003841ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003842{
Jim Ingham78a685a2011-04-16 00:01:13 +00003843 if (m_addr_of_valobj_sp)
3844 return m_addr_of_valobj_sp;
3845
Greg Claytone0d378b2011-03-24 21:19:54 +00003846 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003847 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003848 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003849 error.Clear();
Siva Chandraa3747a92015-05-04 19:43:34 +00003850 if (addr != LLDB_INVALID_ADDRESS && address_type != eAddressTypeHost)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003851 {
3852 switch (address_type)
3853 {
3854 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003855 {
3856 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003857 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003858 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3859 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003860 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003861
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003862 case eAddressTypeFile:
3863 case eAddressTypeLoad:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003864 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003865 CompilerType compiler_type = GetCompilerType();
3866 if (compiler_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003867 {
3868 std::string name (1, '&');
3869 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003870 ExecutionContext exe_ctx (GetExecutionContextRef());
3871 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003872 compiler_type.GetPointerType(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003873 ConstString (name.c_str()),
3874 addr,
3875 eAddressTypeInvalid,
3876 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003877 }
3878 }
3879 break;
Siva Chandraa3747a92015-05-04 19:43:34 +00003880 default:
3881 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003882 }
3883 }
Sean Callananed185ab2013-04-19 19:47:32 +00003884 else
3885 {
3886 StreamString expr_path_strm;
3887 GetExpressionPath(expr_path_strm, true);
3888 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3889 }
3890
Jim Ingham78a685a2011-04-16 00:01:13 +00003891 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003892}
3893
Greg Clayton9a142cf2012-02-03 05:34:10 +00003894ValueObjectSP
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003895ValueObject::Cast (const CompilerType &compiler_type)
Greg Clayton9a142cf2012-02-03 05:34:10 +00003896{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003897 return ValueObjectCast::Create (*this, GetName(), compiler_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003898}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003899
Greg Claytonafacd142011-09-02 01:15:17 +00003900ValueObjectSP
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003901ValueObject::CastPointerType (const char *name, CompilerType &compiler_type)
Greg Claytonb2dcc362011-05-05 23:32:56 +00003902{
Greg Claytonafacd142011-09-02 01:15:17 +00003903 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003904 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003905 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003906
3907 if (ptr_value != LLDB_INVALID_ADDRESS)
3908 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003909 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003910 ExecutionContext exe_ctx (GetExecutionContextRef());
3911 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003912 name,
3913 ptr_addr,
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003914 compiler_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003915 }
3916 return valobj_sp;
3917}
3918
Greg Claytonafacd142011-09-02 01:15:17 +00003919ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003920ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3921{
Greg Claytonafacd142011-09-02 01:15:17 +00003922 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003923 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003924 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003925
3926 if (ptr_value != LLDB_INVALID_ADDRESS)
3927 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003928 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003929 ExecutionContext exe_ctx (GetExecutionContextRef());
3930 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003931 name,
3932 ptr_addr,
3933 type_sp);
3934 }
3935 return valobj_sp;
3936}
3937
Jim Ingham6035b672011-03-31 00:19:25 +00003938ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003939 m_mod_id(),
3940 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003941 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003942{
3943}
3944
3945ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003946 m_mod_id(),
3947 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003948 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003949{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003950 ExecutionContext exe_ctx(exe_scope);
3951 TargetSP target_sp (exe_ctx.GetTargetSP());
3952 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003953 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003954 m_exe_ctx_ref.SetTargetSP (target_sp);
3955 ProcessSP process_sp (exe_ctx.GetProcessSP());
3956 if (!process_sp)
3957 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003958
Greg Claytoncc4d0142012-02-17 07:49:44 +00003959 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003960 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003961 m_mod_id = process_sp->GetModID();
3962 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003963
Greg Claytoncc4d0142012-02-17 07:49:44 +00003964 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003965
Greg Claytoncc4d0142012-02-17 07:49:44 +00003966 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003967 {
3968 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003969 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003970 }
Jim Ingham6035b672011-03-31 00:19:25 +00003971
Greg Claytoncc4d0142012-02-17 07:49:44 +00003972 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003973 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003974 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003975
Jason Molendab57e4a12013-11-04 09:33:30 +00003976 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003977 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003978 {
3979 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003980 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003981 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003982 if (frame_sp)
3983 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003984 }
3985 }
3986 }
Jim Ingham6035b672011-03-31 00:19:25 +00003987}
3988
3989ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003990 m_mod_id(),
3991 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003992 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003993{
3994}
3995
3996ValueObject::EvaluationPoint::~EvaluationPoint ()
3997{
3998}
3999
Jim Ingham6035b672011-03-31 00:19:25 +00004000// This function checks the EvaluationPoint against the current process state. If the current
4001// state matches the evaluation point, or the evaluation point is already invalid, then we return
4002// false, meaning "no change". If the current state is different, we update our state, and return
4003// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
4004// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00004005// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00004006
4007bool
Enrico Granatabb642e52015-05-16 01:27:00 +00004008ValueObject::EvaluationPoint::SyncWithProcessState(bool accept_invalid_exe_ctx)
Jim Ingham6035b672011-03-31 00:19:25 +00004009{
Jim Ingham73ca05a2011-12-17 01:35:57 +00004010 // 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 +00004011 const bool thread_and_frame_only_if_stopped = true;
4012 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
Jim Ingham73ca05a2011-12-17 01:35:57 +00004013
Greg Claytoncc4d0142012-02-17 07:49:44 +00004014 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00004015 return false;
4016
Jim Ingham6035b672011-03-31 00:19:25 +00004017 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00004018 Process *process = exe_ctx.GetProcessPtr();
4019 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00004020 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00004021
Jim Ingham6035b672011-03-31 00:19:25 +00004022 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00004023 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00004024
Jim Ingham78a685a2011-04-16 00:01:13 +00004025 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
4026 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00004027 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00004028 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00004029
Greg Clayton23f59502012-07-17 03:23:13 +00004030 bool changed = false;
4031 const bool was_valid = m_mod_id.IsValid();
4032 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004033 {
4034 if (m_mod_id == current_mod_id)
4035 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00004036 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004037 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00004038 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004039 }
Jim Ingham9ee01152011-12-10 01:49:43 +00004040 else
4041 {
4042 m_mod_id = current_mod_id;
4043 m_needs_update = true;
4044 changed = true;
4045 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004046 }
Jim Ingham6035b672011-03-31 00:19:25 +00004047
Jim Ingham73ca05a2011-12-17 01:35:57 +00004048 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
4049 // That way we'll be sure to return a valid exe_scope.
4050 // 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 +00004051
Enrico Granatabb642e52015-05-16 01:27:00 +00004052 if (!accept_invalid_exe_ctx)
Jim Ingham6035b672011-03-31 00:19:25 +00004053 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004054 if (m_exe_ctx_ref.HasThreadRef())
Greg Clayton262f80d2011-07-06 16:49:27 +00004055 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004056 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
4057 if (thread_sp)
Greg Claytoncc4d0142012-02-17 07:49:44 +00004058 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004059 if (m_exe_ctx_ref.HasFrameRef())
Greg Claytoncc4d0142012-02-17 07:49:44 +00004060 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004061 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
4062 if (!frame_sp)
4063 {
4064 // We used to have a frame, but now it is gone
4065 SetInvalid();
4066 changed = was_valid;
4067 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00004068 }
4069 }
Enrico Granatabb642e52015-05-16 01:27:00 +00004070 else
4071 {
4072 // We used to have a thread, but now it is gone
4073 SetInvalid();
4074 changed = was_valid;
4075 }
Greg Clayton262f80d2011-07-06 16:49:27 +00004076 }
Jim Ingham6035b672011-03-31 00:19:25 +00004077 }
Enrico Granatabb642e52015-05-16 01:27:00 +00004078
Jim Ingham9ee01152011-12-10 01:49:43 +00004079 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00004080}
4081
Jim Ingham61be0902011-05-02 18:13:59 +00004082void
4083ValueObject::EvaluationPoint::SetUpdated ()
4084{
Greg Claytoncc4d0142012-02-17 07:49:44 +00004085 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
4086 if (process_sp)
4087 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00004088 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00004089}
4090
4091
Enrico Granataf2bbf712011-07-15 02:26:42 +00004092
4093void
Enrico Granata86cc9822012-03-19 22:58:49 +00004094ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004095{
Enrico Granata86cc9822012-03-19 22:58:49 +00004096 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4097 m_value_str.clear();
4098
4099 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4100 m_location_str.clear();
4101
4102 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
Enrico Granata86cc9822012-03-19 22:58:49 +00004103 m_summary_str.clear();
Enrico Granata86cc9822012-03-19 22:58:49 +00004104
4105 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4106 m_object_desc_str.clear();
4107
4108 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4109 {
4110 if (m_synthetic_value)
4111 m_synthetic_value = NULL;
4112 }
Enrico Granata744794a2014-09-05 21:46:22 +00004113
4114 if ((clear_mask & eClearUserVisibleDataItemsValidator) == eClearUserVisibleDataItemsValidator)
4115 m_validation_result.reset();
Johnny Chen44805302011-07-19 19:48:13 +00004116}
Enrico Granata9128ee22011-09-06 19:20:51 +00004117
4118SymbolContextScope *
4119ValueObject::GetSymbolContextScope()
4120{
4121 if (m_parent)
4122 {
4123 if (!m_parent->IsPointerOrReferenceType())
4124 return m_parent->GetSymbolContextScope();
4125 }
4126 return NULL;
4127}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004128
4129lldb::ValueObjectSP
4130ValueObject::CreateValueObjectFromExpression (const char* name,
4131 const char* expression,
4132 const ExecutionContext& exe_ctx)
4133{
Enrico Granata972be532014-12-17 21:18:43 +00004134 return CreateValueObjectFromExpression(name, expression, exe_ctx, EvaluateExpressionOptions());
4135}
4136
4137
4138lldb::ValueObjectSP
4139ValueObject::CreateValueObjectFromExpression (const char* name,
4140 const char* expression,
4141 const ExecutionContext& exe_ctx,
4142 const EvaluateExpressionOptions& options)
4143{
Enrico Granatab2698cd2012-09-13 18:27:09 +00004144 lldb::ValueObjectSP retval_sp;
4145 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4146 if (!target_sp)
4147 return retval_sp;
4148 if (!expression || !*expression)
4149 return retval_sp;
4150 target_sp->EvaluateExpression (expression,
4151 exe_ctx.GetFrameSP().get(),
Enrico Granata972be532014-12-17 21:18:43 +00004152 retval_sp,
4153 options);
Enrico Granatab2698cd2012-09-13 18:27:09 +00004154 if (retval_sp && name && *name)
4155 retval_sp->SetName(ConstString(name));
4156 return retval_sp;
4157}
4158
4159lldb::ValueObjectSP
4160ValueObject::CreateValueObjectFromAddress (const char* name,
4161 uint64_t address,
4162 const ExecutionContext& exe_ctx,
Greg Claytona1e5dc82015-08-11 22:53:00 +00004163 CompilerType type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004164{
Greg Clayton57ee3062013-07-11 22:46:58 +00004165 if (type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004166 {
Greg Claytona1e5dc82015-08-11 22:53:00 +00004167 CompilerType pointer_type(type.GetPointerType());
Greg Clayton57ee3062013-07-11 22:46:58 +00004168 if (pointer_type)
4169 {
4170 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4171 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4172 pointer_type,
4173 ConstString(name),
4174 buffer,
Enrico Granata972be532014-12-17 21:18:43 +00004175 exe_ctx.GetByteOrder(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004176 exe_ctx.GetAddressByteSize()));
4177 if (ptr_result_valobj_sp)
4178 {
4179 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4180 Error err;
4181 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4182 if (ptr_result_valobj_sp && name && *name)
4183 ptr_result_valobj_sp->SetName(ConstString(name));
4184 }
4185 return ptr_result_valobj_sp;
4186 }
Enrico Granatab2698cd2012-09-13 18:27:09 +00004187 }
Greg Clayton57ee3062013-07-11 22:46:58 +00004188 return lldb::ValueObjectSP();
Enrico Granatab2698cd2012-09-13 18:27:09 +00004189}
4190
4191lldb::ValueObjectSP
4192ValueObject::CreateValueObjectFromData (const char* name,
Enrico Granata7ca1c762014-03-31 23:02:25 +00004193 const DataExtractor& data,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004194 const ExecutionContext& exe_ctx,
Greg Claytona1e5dc82015-08-11 22:53:00 +00004195 CompilerType type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004196{
4197 lldb::ValueObjectSP new_value_sp;
4198 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004199 type,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004200 ConstString(name),
4201 data,
4202 LLDB_INVALID_ADDRESS);
4203 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4204 if (new_value_sp && name && *name)
4205 new_value_sp->SetName(ConstString(name));
4206 return new_value_sp;
4207}
Enrico Granata4873e522013-04-11 22:48:58 +00004208
4209ModuleSP
4210ValueObject::GetModule ()
4211{
4212 ValueObject* root(GetRoot());
4213 if (root != this)
4214 return root->GetModule();
4215 return lldb::ModuleSP();
4216}
4217
4218ValueObject*
4219ValueObject::GetRoot ()
4220{
4221 if (m_root)
4222 return m_root;
Enrico Granatade61eba2015-01-22 03:07:34 +00004223 return (m_root = FollowParentChain( [] (ValueObject* vo) -> bool {
4224 return (vo->m_parent != nullptr);
4225 }));
4226}
4227
4228ValueObject*
4229ValueObject::FollowParentChain (std::function<bool(ValueObject*)> f)
4230{
4231 ValueObject* vo = this;
4232 while (vo)
Enrico Granata4873e522013-04-11 22:48:58 +00004233 {
Enrico Granatade61eba2015-01-22 03:07:34 +00004234 if (f(vo) == false)
4235 break;
4236 vo = vo->m_parent;
Enrico Granata4873e522013-04-11 22:48:58 +00004237 }
Enrico Granatade61eba2015-01-22 03:07:34 +00004238 return vo;
Enrico Granata4873e522013-04-11 22:48:58 +00004239}
4240
4241AddressType
4242ValueObject::GetAddressTypeOfChildren()
4243{
4244 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
4245 {
4246 ValueObject* root(GetRoot());
4247 if (root != this)
4248 return root->GetAddressTypeOfChildren();
4249 }
4250 return m_address_type_of_ptr_or_ref_children;
4251}
4252
4253lldb::DynamicValueType
4254ValueObject::GetDynamicValueType ()
4255{
4256 ValueObject* with_dv_info = this;
4257 while (with_dv_info)
4258 {
4259 if (with_dv_info->HasDynamicValueTypeInfo())
4260 return with_dv_info->GetDynamicValueTypeImpl();
4261 with_dv_info = with_dv_info->m_parent;
4262 }
4263 return lldb::eNoDynamicValues;
4264}
Enrico Granata39d51412013-05-31 17:43:40 +00004265
Enrico Granata4873e522013-04-11 22:48:58 +00004266lldb::Format
4267ValueObject::GetFormat () const
4268{
4269 const ValueObject* with_fmt_info = this;
4270 while (with_fmt_info)
4271 {
4272 if (with_fmt_info->m_format != lldb::eFormatDefault)
4273 return with_fmt_info->m_format;
4274 with_fmt_info = with_fmt_info->m_parent;
4275 }
4276 return m_format;
4277}
Enrico Granatad07cfd32014-10-08 18:27:36 +00004278
Enrico Granatac1247f52014-11-06 21:23:20 +00004279lldb::LanguageType
4280ValueObject::GetPreferredDisplayLanguage ()
4281{
Enrico Granataed3228a2015-01-21 01:47:13 +00004282 lldb::LanguageType type = m_preferred_display_language;
4283 if (m_preferred_display_language == lldb::eLanguageTypeUnknown)
Enrico Granatac1247f52014-11-06 21:23:20 +00004284 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004285 if (GetRoot())
Enrico Granatac1247f52014-11-06 21:23:20 +00004286 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004287 if (GetRoot() == this)
Enrico Granatac1247f52014-11-06 21:23:20 +00004288 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004289 if (StackFrameSP frame_sp = GetFrameSP())
4290 {
4291 const SymbolContext& sc(frame_sp->GetSymbolContext(eSymbolContextCompUnit));
4292 if (CompileUnit* cu = sc.comp_unit)
4293 type = cu->GetLanguage();
4294 }
4295 }
4296 else
4297 {
4298 type = GetRoot()->GetPreferredDisplayLanguage();
Enrico Granatac1247f52014-11-06 21:23:20 +00004299 }
4300 }
Enrico Granatac1247f52014-11-06 21:23:20 +00004301 }
Enrico Granataed3228a2015-01-21 01:47:13 +00004302 return (m_preferred_display_language = type); // only compute it once
4303}
4304
4305void
4306ValueObject::SetPreferredDisplayLanguage (lldb::LanguageType lt)
4307{
4308 m_preferred_display_language = lt;
Enrico Granatac1247f52014-11-06 21:23:20 +00004309}
4310
Enrico Granata73e8c4d2015-10-07 02:36:35 +00004311void
4312ValueObject::SetPreferredDisplayLanguageIfNeeded (lldb::LanguageType lt)
4313{
4314 if (m_preferred_display_language == lldb::eLanguageTypeUnknown)
4315 SetPreferredDisplayLanguage(lt);
4316}
4317
Enrico Granatad07cfd32014-10-08 18:27:36 +00004318bool
4319ValueObject::CanProvideValue ()
4320{
Sean Callanan7375f3e2014-12-09 21:18:59 +00004321 // we need to support invalid types as providers of values because some bare-board
4322 // debugging scenarios have no notion of types, but still manage to have raw numeric
4323 // values for things like registers. sigh.
Greg Clayton99558cc42015-08-24 23:46:31 +00004324 const CompilerType &type(GetCompilerType());
Sean Callanan7375f3e2014-12-09 21:18:59 +00004325 return (false == type.IsValid()) || (0 != (type.GetTypeInfo() & eTypeHasValue));
4326}
4327
4328bool
4329ValueObject::IsChecksumEmpty ()
4330{
4331 return m_value_checksum.empty();
Enrico Granatad07cfd32014-10-08 18:27:36 +00004332}
Enrico Granata0c10a852014-12-08 23:13:56 +00004333
4334ValueObjectSP
4335ValueObject::Persist ()
4336{
4337 if (!UpdateValueIfNeeded())
4338 return nullptr;
4339
4340 TargetSP target_sp(GetTargetSP());
4341 if (!target_sp)
4342 return nullptr;
4343
Sean Callananb92bd752015-10-01 16:28:02 +00004344 PersistentExpressionState *persistent_state = target_sp->GetPersistentExpressionStateForLanguage(GetPreferredDisplayLanguage());
Sean Callanan8f1f9a12015-09-30 19:57:57 +00004345
4346 if (!persistent_state)
4347 return nullptr;
4348
4349 ConstString name(persistent_state->GetNextPersistentVariableName());
Enrico Granata0c10a852014-12-08 23:13:56 +00004350
Sean Callanan9301ec12015-10-01 23:07:06 +00004351 ValueObjectSP const_result_sp = ValueObjectConstResult::Create (target_sp.get(), GetValue(), name);
4352
4353 ExpressionVariableSP clang_var_sp = persistent_state->CreatePersistentVariable(const_result_sp);
4354 clang_var_sp->m_live_sp = clang_var_sp->m_frozen_sp;
4355 clang_var_sp->m_flags |= ExpressionVariable::EVIsProgramReference;
Enrico Granata0c10a852014-12-08 23:13:56 +00004356
4357 return clang_var_sp->GetValueObject();
4358}
Enrico Granatae29df232014-12-09 19:51:20 +00004359
4360bool
4361ValueObject::IsSyntheticChildrenGenerated ()
4362{
4363 return m_is_synthetic_children_generated;
4364}
4365
4366void
4367ValueObject::SetSyntheticChildrenGenerated (bool b)
4368{
4369 m_is_synthetic_children_generated = b;
4370}