blob: 75135554f65f7e7bcad1c267794da980d431cfb4 [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),
Enrico Granatadc62ffd2015-11-09 19:27:34 +0000100 m_language_flags(0),
Greg Clayton288bdf92010-09-02 02:59:18 +0000101 m_value_is_valid (false),
102 m_value_did_change (false),
103 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000104 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000105 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000106 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000107 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000108 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000109 m_is_getting_summary(false),
Enrico Granatae29df232014-12-09 19:51:20 +0000110 m_did_calculate_complete_objc_class_type(false),
111 m_is_synthetic_children_generated(parent.m_is_synthetic_children_generated)
Jim Ingham6035b672011-03-31 00:19:25 +0000112{
Jim Ingham58b59f92011-04-22 23:53:53 +0000113 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000114}
115
116//----------------------------------------------------------------------
117// ValueObject constructor
118//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000119ValueObject::ValueObject (ExecutionContextScope *exe_scope,
120 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000121 UserID (++g_value_obj_uid), // Unique identifier for every value object
122 m_parent (NULL),
Enrico Granata4873e522013-04-11 22:48:58 +0000123 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000124 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000125 m_name (),
126 m_data (),
127 m_value (),
128 m_error (),
129 m_value_str (),
130 m_old_value_str (),
131 m_location_str (),
132 m_summary_str (),
133 m_object_desc_str (),
Enrico Granata744794a2014-09-05 21:46:22 +0000134 m_validation_result(),
Jim Ingham58b59f92011-04-22 23:53:53 +0000135 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000136 m_children (),
137 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000138 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000139 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000140 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000141 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +0000142 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000143 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +0000144 m_type_summary_sp(),
145 m_type_format_sp(),
146 m_synthetic_children_sp(),
Enrico Granata744794a2014-09-05 21:46:22 +0000147 m_type_validator_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000148 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000149 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Sean Callanan7375f3e2014-12-09 21:18:59 +0000150 m_value_checksum(),
Enrico Granataed3228a2015-01-21 01:47:13 +0000151 m_preferred_display_language(lldb::eLanguageTypeUnknown),
Enrico Granatadc62ffd2015-11-09 19:27:34 +0000152 m_language_flags(0),
Jim Ingham6035b672011-03-31 00:19:25 +0000153 m_value_is_valid (false),
154 m_value_did_change (false),
155 m_children_count_valid (false),
156 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000157 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000158 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000159 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000160 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000161 m_is_getting_summary(false),
Enrico Granatae29df232014-12-09 19:51:20 +0000162 m_did_calculate_complete_objc_class_type(false),
163 m_is_synthetic_children_generated(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000164{
Jim Ingham58b59f92011-04-22 23:53:53 +0000165 m_manager = new ValueObjectManager();
166 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000167}
168
169//----------------------------------------------------------------------
170// Destructor
171//----------------------------------------------------------------------
172ValueObject::~ValueObject ()
173{
174}
175
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000176bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000177ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000178{
Enrico Granata4becb372011-06-29 22:27:15 +0000179
Enrico Granata9128ee22011-09-06 19:20:51 +0000180 bool did_change_formats = false;
181
Enrico Granata0a3958e2011-07-02 00:25:22 +0000182 if (update_format)
Enrico Granata5548cb52013-01-28 23:47:25 +0000183 did_change_formats = UpdateFormatsIfNeeded();
Enrico Granata4becb372011-06-29 22:27:15 +0000184
Greg Claytonb71f3842010-10-05 03:13:51 +0000185 // If this is a constant value, then our success is predicated on whether
186 // we have an error or not
187 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000188 {
Enrico Granatab1c6c482013-10-09 00:33:55 +0000189 // if you are constant, things might still have changed behind your back
190 // (e.g. you are a frozen object and things have changed deeper than you cared to freeze-dry yourself)
191 // in this case, your value has not changed, but "computed" entries might have, so you might now have
192 // a different summary, or a different object description. clear these so we will recompute them
Enrico Granata9128ee22011-09-06 19:20:51 +0000193 if (update_format && !did_change_formats)
Enrico Granatab1c6c482013-10-09 00:33:55 +0000194 ClearUserVisibleData(eClearUserVisibleDataItemsSummary | eClearUserVisibleDataItemsDescription);
Greg Claytonb71f3842010-10-05 03:13:51 +0000195 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000196 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000197
Sean Callanan7375f3e2014-12-09 21:18:59 +0000198 bool first_update = IsChecksumEmpty();
Jim Ingham6035b672011-03-31 00:19:25 +0000199
Enrico Granatabb642e52015-05-16 01:27:00 +0000200 if (NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000201 {
Jim Ingham6035b672011-03-31 00:19:25 +0000202 m_update_point.SetUpdated();
203
204 // Save the old value using swap to avoid a string copy which
205 // also will clear our m_value_str
206 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000207 {
Jim Ingham6035b672011-03-31 00:19:25 +0000208 m_old_value_valid = false;
209 }
210 else
211 {
212 m_old_value_valid = true;
213 m_old_value_str.swap (m_value_str);
Enrico Granata86cc9822012-03-19 22:58:49 +0000214 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham6035b672011-03-31 00:19:25 +0000215 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000216
Enrico Granataf2bbf712011-07-15 02:26:42 +0000217 ClearUserVisibleData();
218
Greg Claytonefbc7d22012-03-09 04:23:44 +0000219 if (IsInScope())
Jim Ingham6035b672011-03-31 00:19:25 +0000220 {
Greg Claytonefbc7d22012-03-09 04:23:44 +0000221 const bool value_was_valid = GetValueIsValid();
222 SetValueDidChange (false);
223
224 m_error.Clear();
225
226 // Call the pure virtual function to update the value
Sean Callanan7375f3e2014-12-09 21:18:59 +0000227
228 bool need_compare_checksums = false;
229 llvm::SmallVector<uint8_t, 16> old_checksum;
230
231 if (!first_update && CanProvideValue())
232 {
233 need_compare_checksums = true;
234 old_checksum.resize(m_value_checksum.size());
235 std::copy(m_value_checksum.begin(), m_value_checksum.end(), old_checksum.begin());
236 }
237
Greg Claytonefbc7d22012-03-09 04:23:44 +0000238 bool success = UpdateValue ();
239
240 SetValueIsValid (success);
241
Sean Callanan7375f3e2014-12-09 21:18:59 +0000242 if (success)
243 {
244 const uint64_t max_checksum_size = 128;
245 m_data.Checksum(m_value_checksum,
246 max_checksum_size);
247 }
248 else
249 {
250 need_compare_checksums = false;
251 m_value_checksum.clear();
252 }
253
Enrico Granata20c321c2015-01-08 19:11:43 +0000254 assert (!need_compare_checksums || (!old_checksum.empty() && !m_value_checksum.empty()));
255
Greg Claytonefbc7d22012-03-09 04:23:44 +0000256 if (first_update)
257 SetValueDidChange (false);
258 else if (!m_value_did_change && success == false)
259 {
260 // The value wasn't gotten successfully, so we mark this
261 // as changed if the value used to be valid and now isn't
262 SetValueDidChange (value_was_valid);
263 }
Sean Callanan7375f3e2014-12-09 21:18:59 +0000264 else if (need_compare_checksums)
265 {
266 SetValueDidChange(memcmp(&old_checksum[0], &m_value_checksum[0], m_value_checksum.size()));
267 }
268
Greg Claytonefbc7d22012-03-09 04:23:44 +0000269 }
270 else
271 {
272 m_error.SetErrorString("out of scope");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000273 }
274 }
275 return m_error.Success();
276}
277
Enrico Granata9128ee22011-09-06 19:20:51 +0000278bool
Enrico Granata5548cb52013-01-28 23:47:25 +0000279ValueObject::UpdateFormatsIfNeeded()
Enrico Granata4becb372011-06-29 22:27:15 +0000280{
Enrico Granata4edfef42015-10-06 17:55:14 +0000281 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_DATAFORMATTERS));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000282 if (log)
Enrico Granatad2284832012-10-17 22:23:56 +0000283 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000284 GetName().GetCString(), static_cast<void*>(this),
285 m_last_format_mgr_revision,
286 DataVisualization::GetCurrentRevision());
287
Enrico Granata9128ee22011-09-06 19:20:51 +0000288 bool any_change = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000289
Enrico Granata5548cb52013-01-28 23:47:25 +0000290 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()))
Enrico Granata4becb372011-06-29 22:27:15 +0000291 {
Enrico Granataa0db6ed2014-04-09 21:06:11 +0000292 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
293 any_change = true;
294
Enrico Granata852cc952013-10-08 19:03:22 +0000295 SetValueFormat(DataVisualization::GetFormat (*this, eNoDynamicValues));
Enrico Granata5548cb52013-01-28 23:47:25 +0000296 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000297#ifndef LLDB_DISABLE_PYTHON
Enrico Granata5548cb52013-01-28 23:47:25 +0000298 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000299#endif
Enrico Granata744794a2014-09-05 21:46:22 +0000300 SetValidator(DataVisualization::GetValidator(*this, GetDynamicValueType()));
Enrico Granata4becb372011-06-29 22:27:15 +0000301 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000302
Enrico Granata9128ee22011-09-06 19:20:51 +0000303 return any_change;
Enrico Granata4becb372011-06-29 22:27:15 +0000304}
305
Jim Ingham16e0c682011-08-12 23:34:31 +0000306void
307ValueObject::SetNeedsUpdate ()
308{
309 m_update_point.SetNeedsUpdate();
310 // We have to clear the value string here so ConstResult children will notice if their values are
311 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000312 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000313}
314
Enrico Granata13ac0e22012-10-17 19:03:34 +0000315void
Enrico Granatae3e91512012-10-22 18:18:36 +0000316ValueObject::ClearDynamicTypeInformation ()
Enrico Granata13ac0e22012-10-17 19:03:34 +0000317{
Enrico Granata38c54632013-10-30 00:04:29 +0000318 m_children_count_valid = false;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000319 m_did_calculate_complete_objc_class_type = false;
Enrico Granatae3e91512012-10-22 18:18:36 +0000320 m_last_format_mgr_revision = 0;
Greg Claytona1e5dc82015-08-11 22:53:00 +0000321 m_override_type = CompilerType();
Enrico Granatae3e91512012-10-22 18:18:36 +0000322 SetValueFormat(lldb::TypeFormatImplSP());
323 SetSummaryFormat(lldb::TypeSummaryImplSP());
324 SetSyntheticChildren(lldb::SyntheticChildrenSP());
Enrico Granata13ac0e22012-10-17 19:03:34 +0000325}
326
Greg Claytona1e5dc82015-08-11 22:53:00 +0000327CompilerType
Sean Callanan72772842012-02-22 23:57:45 +0000328ValueObject::MaybeCalculateCompleteType ()
329{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000330 CompilerType compiler_type(GetCompilerTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000331
Sean Callanan72772842012-02-22 23:57:45 +0000332 if (m_did_calculate_complete_objc_class_type)
333 {
334 if (m_override_type.IsValid())
335 return m_override_type;
336 else
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000337 return compiler_type;
Sean Callanan72772842012-02-22 23:57:45 +0000338 }
339
Greg Claytona1e5dc82015-08-11 22:53:00 +0000340 CompilerType class_type;
Greg Clayton57ee3062013-07-11 22:46:58 +0000341 bool is_pointer_type = false;
Sean Callanan72772842012-02-22 23:57:45 +0000342
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000343 if (ClangASTContext::IsObjCObjectPointerType(compiler_type, &class_type))
Sean Callanan72772842012-02-22 23:57:45 +0000344 {
345 is_pointer_type = true;
346 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000347 else if (ClangASTContext::IsObjCObjectOrInterfaceType(compiler_type))
Sean Callanan72772842012-02-22 23:57:45 +0000348 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000349 class_type = compiler_type;
Sean Callanan72772842012-02-22 23:57:45 +0000350 }
351 else
352 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000353 return compiler_type;
Sean Callanan72772842012-02-22 23:57:45 +0000354 }
355
356 m_did_calculate_complete_objc_class_type = true;
357
Greg Clayton57ee3062013-07-11 22:46:58 +0000358 if (class_type)
Sean Callanan72772842012-02-22 23:57:45 +0000359 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000360 ConstString class_name (class_type.GetConstTypeName());
Sean Callanan72772842012-02-22 23:57:45 +0000361
Greg Clayton57ee3062013-07-11 22:46:58 +0000362 if (class_name)
363 {
364 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
365
366 if (process_sp)
367 {
368 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
369
370 if (objc_language_runtime)
371 {
372 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name);
373
374 if (complete_objc_class_type_sp)
375 {
Greg Clayton99558cc42015-08-24 23:46:31 +0000376 CompilerType complete_class(complete_objc_class_type_sp->GetFullCompilerType ());
Greg Clayton57ee3062013-07-11 22:46:58 +0000377
378 if (complete_class.GetCompleteType())
379 {
380 if (is_pointer_type)
381 {
382 m_override_type = complete_class.GetPointerType();
383 }
384 else
385 {
386 m_override_type = complete_class;
387 }
388
389 if (m_override_type.IsValid())
390 return m_override_type;
391 }
392 }
393 }
394 }
395 }
Sean Callanan72772842012-02-22 23:57:45 +0000396 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000397 return compiler_type;
Sean Callanan72772842012-02-22 23:57:45 +0000398}
399
Greg Claytona1e5dc82015-08-11 22:53:00 +0000400CompilerType
Greg Clayton99558cc42015-08-24 23:46:31 +0000401ValueObject::GetCompilerType ()
Sean Callanan72772842012-02-22 23:57:45 +0000402{
Greg Clayton57ee3062013-07-11 22:46:58 +0000403 return MaybeCalculateCompleteType();
Sean Callanan72772842012-02-22 23:57:45 +0000404}
405
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000406TypeImpl
407ValueObject::GetTypeImpl ()
408{
Greg Clayton99558cc42015-08-24 23:46:31 +0000409 return TypeImpl(GetCompilerType());
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000410}
411
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000412DataExtractor &
413ValueObject::GetDataExtractor ()
414{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000415 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000416 return m_data;
417}
418
419const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000420ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000421{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000422 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000423 return m_error;
424}
425
426const ConstString &
427ValueObject::GetName() const
428{
429 return m_name;
430}
431
432const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000433ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000434{
Enrico Granata82fabf82013-04-30 20:45:04 +0000435 return GetLocationAsCStringImpl(m_value,
436 m_data);
437}
438
439const char *
440ValueObject::GetLocationAsCStringImpl (const Value& value,
441 const DataExtractor& data)
442{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000443 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000444 {
445 if (m_location_str.empty())
446 {
447 StreamString sstr;
Enrico Granata82fabf82013-04-30 20:45:04 +0000448
449 Value::ValueType value_type = value.GetValueType();
450
451 switch (value_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000452 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000453 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +0000454 case Value::eValueTypeVector:
Enrico Granata82fabf82013-04-30 20:45:04 +0000455 if (value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000456 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000457 RegisterInfo *reg_info = value.GetRegisterInfo();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000458 if (reg_info)
459 {
460 if (reg_info->name)
461 m_location_str = reg_info->name;
462 else if (reg_info->alt_name)
463 m_location_str = reg_info->alt_name;
Enrico Granata82fabf82013-04-30 20:45:04 +0000464 if (m_location_str.empty())
465 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000466 }
467 }
Enrico Granata82fabf82013-04-30 20:45:04 +0000468 if (m_location_str.empty())
469 m_location_str = (value_type == Value::eValueTypeVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000470 break;
471
472 case Value::eValueTypeLoadAddress:
473 case Value::eValueTypeFileAddress:
474 case Value::eValueTypeHostAddress:
475 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000476 uint32_t addr_nibble_size = data.GetAddressByteSize() * 2;
477 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000478 m_location_str.swap(sstr.GetString());
479 }
480 break;
481 }
482 }
483 }
484 return m_location_str.c_str();
485}
486
487Value &
488ValueObject::GetValue()
489{
490 return m_value;
491}
492
493const Value &
494ValueObject::GetValue() const
495{
496 return m_value;
497}
498
499bool
Jim Ingham6035b672011-03-31 00:19:25 +0000500ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000501{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000502 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
503 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000504 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000505 Value tmp_value(m_value);
Greg Clayton57ee3062013-07-11 22:46:58 +0000506 scalar = tmp_value.ResolveValue(&exe_ctx);
Greg Claytondcad5022011-12-29 01:26:56 +0000507 if (scalar.IsValid())
508 {
509 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
510 if (bitfield_bit_size)
511 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
512 return true;
513 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000514 }
Greg Claytondcad5022011-12-29 01:26:56 +0000515 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000516}
517
518bool
Jim Ingham98e6daf2015-10-31 00:02:18 +0000519ValueObject::IsLogicalTrue (Error& error)
520{
Enrico Granata407b5c62015-11-02 21:52:05 +0000521 if (Language *language = Language::FindPlugin(GetObjectRuntimeLanguage()))
522 {
523 LazyBool is_logical_true = language->IsLogicalTrue(*this, error);
524 switch (is_logical_true)
525 {
526 case eLazyBoolYes:
527 case eLazyBoolNo:
528 return (is_logical_true == true);
529 case eLazyBoolCalculate:
Enrico Granata407b5c62015-11-02 21:52:05 +0000530 break;
531 }
532 }
533
Jim Ingham98e6daf2015-10-31 00:02:18 +0000534 Scalar scalar_value;
535
536 if (!ResolveValue (scalar_value))
537 {
538 error.SetErrorString("failed to get a scalar result");
539 return false;
540 }
541
542 bool ret;
543 if (scalar_value.ULongLong(1) == 0)
544 ret = false;
545 else
546 ret = true;
547 error.Clear();
548 return ret;
549}
550
551bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000552ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000553{
Greg Clayton288bdf92010-09-02 02:59:18 +0000554 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000555}
556
557
558void
559ValueObject::SetValueIsValid (bool b)
560{
Greg Clayton288bdf92010-09-02 02:59:18 +0000561 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000562}
563
564bool
Jim Ingham6035b672011-03-31 00:19:25 +0000565ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000566{
Greg Clayton288bdf92010-09-02 02:59:18 +0000567 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000568}
569
570void
571ValueObject::SetValueDidChange (bool value_changed)
572{
Greg Clayton288bdf92010-09-02 02:59:18 +0000573 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000574}
575
576ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000577ValueObject::GetChildAtIndex (size_t idx, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000578{
579 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000580 // We may need to update our value if we are dynamic
581 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000582 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000583 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000584 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000585 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000586 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000587 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000588 // No we haven't created the child at this index, so lets have our
589 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000590 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000591 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000592
Enrico Granata9d60f602012-03-09 03:09:58 +0000593 ValueObject* child = m_children.GetChildAtIndex(idx);
594 if (child != NULL)
595 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000596 }
597 return child_sp;
598}
599
Enrico Granata3309d882013-01-12 01:00:22 +0000600ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000601ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
602 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000603{
604 if (idxs.size() == 0)
605 return GetSP();
606 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000607 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000608 {
609 root = root->GetChildAtIndex(idx, true);
610 if (!root)
611 {
612 if (index_of_error)
613 *index_of_error = idx;
614 return root;
615 }
616 }
617 return root;
618}
619
620ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000621ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
622 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000623{
624 if (idxs.size() == 0)
625 return GetSP();
626 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000627 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000628 {
629 root = root->GetChildAtIndex(idx.first, idx.second);
630 if (!root)
631 {
632 if (index_of_error)
633 *index_of_error = idx.first;
634 return root;
635 }
636 }
637 return root;
638}
639
640lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000641ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
642 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000643{
644 if (idxs.size() == 0)
645 return GetSP();
646 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000647 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000648 {
649 root = root->GetChildAtIndex(idx, true);
650 if (!root)
651 {
652 if (index_of_error)
653 *index_of_error = idx;
654 return root;
655 }
656 }
657 return root;
658}
659
660lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000661ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
662 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000663{
664 if (idxs.size() == 0)
665 return GetSP();
666 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000667 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000668 {
669 root = root->GetChildAtIndex(idx.first, idx.second);
670 if (!root)
671 {
672 if (index_of_error)
673 *index_of_error = idx.first;
674 return root;
675 }
676 }
677 return root;
678}
679
Enrico Granatae2e220a2013-09-12 00:48:47 +0000680lldb::ValueObjectSP
681ValueObject::GetChildAtNamePath (const std::initializer_list<ConstString> &names,
682 ConstString* name_of_error)
683{
684 if (names.size() == 0)
685 return GetSP();
686 ValueObjectSP root(GetSP());
687 for (ConstString name : names)
688 {
689 root = root->GetChildMemberWithName(name, true);
690 if (!root)
691 {
692 if (name_of_error)
693 *name_of_error = name;
694 return root;
695 }
696 }
697 return root;
698}
699
700lldb::ValueObjectSP
701ValueObject::GetChildAtNamePath (const std::vector<ConstString> &names,
702 ConstString* name_of_error)
703{
704 if (names.size() == 0)
705 return GetSP();
706 ValueObjectSP root(GetSP());
707 for (ConstString name : names)
708 {
709 root = root->GetChildMemberWithName(name, true);
710 if (!root)
711 {
712 if (name_of_error)
713 *name_of_error = name;
714 return root;
715 }
716 }
717 return root;
718}
719
720lldb::ValueObjectSP
721ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names,
722 ConstString* name_of_error)
723{
724 if (names.size() == 0)
725 return GetSP();
726 ValueObjectSP root(GetSP());
727 for (std::pair<ConstString, bool> name : names)
728 {
729 root = root->GetChildMemberWithName(name.first, name.second);
730 if (!root)
731 {
732 if (name_of_error)
733 *name_of_error = name.first;
734 return root;
735 }
736 }
737 return root;
738}
739
740lldb::ValueObjectSP
741ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names,
742 ConstString* name_of_error)
743{
744 if (names.size() == 0)
745 return GetSP();
746 ValueObjectSP root(GetSP());
747 for (std::pair<ConstString, bool> name : names)
748 {
749 root = root->GetChildMemberWithName(name.first, name.second);
750 if (!root)
751 {
752 if (name_of_error)
753 *name_of_error = name.first;
754 return root;
755 }
756 }
757 return root;
758}
759
Greg Claytonc7bece562013-01-25 18:06:21 +0000760size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000761ValueObject::GetIndexOfChildWithName (const ConstString &name)
762{
763 bool omit_empty_base_classes = true;
Greg Clayton99558cc42015-08-24 23:46:31 +0000764 return GetCompilerType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000765}
766
767ValueObjectSP
768ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
769{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000770 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000771 // classes (which really aren't part of the expression path), so we
772 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000773 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000774
Greg Claytondea8cb42011-06-29 22:09:02 +0000775 // We may need to update our value if we are dynamic
776 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000777 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000778
779 std::vector<uint32_t> child_indexes;
Greg Claytondea8cb42011-06-29 22:09:02 +0000780 bool omit_empty_base_classes = true;
Greg Clayton99558cc42015-08-24 23:46:31 +0000781 const size_t num_child_indexes = GetCompilerType().GetIndexOfChildMemberWithName (name.GetCString(),
Greg Clayton57ee3062013-07-11 22:46:58 +0000782 omit_empty_base_classes,
783 child_indexes);
Greg Claytondea8cb42011-06-29 22:09:02 +0000784 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000785 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000786 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
787 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
788
789 child_sp = GetChildAtIndex(*pos, can_create);
790 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000791 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000792 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000793 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000794 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
795 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000796 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000797 else
798 {
799 child_sp.reset();
800 }
801
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000802 }
803 }
804 return child_sp;
805}
806
807
Greg Claytonc7bece562013-01-25 18:06:21 +0000808size_t
Siva Chandra9ac7a6c2015-10-21 19:28:08 +0000809ValueObject::GetNumChildren (uint32_t max)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000810{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000811 UpdateValueIfNeeded();
Siva Chandra9ac7a6c2015-10-21 19:28:08 +0000812
813 if (max < UINT32_MAX)
814 {
815 if (m_children_count_valid)
816 {
817 size_t children_count = m_children.GetChildrenCount();
818 return children_count <= max ? children_count : max;
819 }
820 else
821 return CalculateNumChildren(max);
822 }
823
Greg Clayton288bdf92010-09-02 02:59:18 +0000824 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000825 {
826 SetNumChildren (CalculateNumChildren());
827 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000828 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000829}
Greg Clayton4a792072012-10-23 01:50:10 +0000830
831bool
832ValueObject::MightHaveChildren()
833{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000834 bool has_children = false;
Greg Clayton2452ab72013-02-08 22:02:02 +0000835 const uint32_t type_info = GetTypeInfo();
836 if (type_info)
Greg Clayton4a792072012-10-23 01:50:10 +0000837 {
Enrico Granata622be232014-10-21 20:52:14 +0000838 if (type_info & (eTypeHasChildren |
839 eTypeIsPointer |
840 eTypeIsReference))
Greg Clayton4a792072012-10-23 01:50:10 +0000841 has_children = true;
842 }
843 else
844 {
845 has_children = GetNumChildren () > 0;
846 }
847 return has_children;
848}
849
850// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000851void
Greg Claytonc7bece562013-01-25 18:06:21 +0000852ValueObject::SetNumChildren (size_t num_children)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000853{
Greg Clayton288bdf92010-09-02 02:59:18 +0000854 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000855 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000856}
857
858void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000859ValueObject::SetName (const ConstString &name)
860{
861 m_name = name;
862}
863
Jim Ingham58b59f92011-04-22 23:53:53 +0000864ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000865ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000866{
Jim Ingham2eec4872011-05-07 00:10:58 +0000867 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000868
Greg Claytondea8cb42011-06-29 22:09:02 +0000869 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000870 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000871 std::string child_name_str;
872 uint32_t child_byte_size = 0;
873 int32_t child_byte_offset = 0;
874 uint32_t child_bitfield_bit_size = 0;
875 uint32_t child_bitfield_bit_offset = 0;
876 bool child_is_base_class = false;
877 bool child_is_deref_of_parent = false;
Enrico Granatadc62ffd2015-11-09 19:27:34 +0000878 uint64_t language_flags = 0;
Greg Claytondea8cb42011-06-29 22:09:02 +0000879
880 const bool transparent_pointers = synthetic_array_member == false;
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000881 CompilerType child_compiler_type;
Greg Claytondea8cb42011-06-29 22:09:02 +0000882
Greg Claytoncc4d0142012-02-17 07:49:44 +0000883 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000884
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000885 child_compiler_type = GetCompilerType().GetChildCompilerTypeAtIndex (&exe_ctx,
886 idx,
887 transparent_pointers,
888 omit_empty_base_classes,
889 ignore_array_bounds,
890 child_name_str,
891 child_byte_size,
892 child_byte_offset,
893 child_bitfield_bit_size,
894 child_bitfield_bit_offset,
895 child_is_base_class,
896 child_is_deref_of_parent,
Enrico Granatadc62ffd2015-11-09 19:27:34 +0000897 this,
898 language_flags);
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000899 if (child_compiler_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000900 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000901 if (synthetic_index)
902 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000903
Greg Claytondea8cb42011-06-29 22:09:02 +0000904 ConstString child_name;
905 if (!child_name_str.empty())
906 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000907
Greg Claytondea8cb42011-06-29 22:09:02 +0000908 valobj = new ValueObjectChild (*this,
Bruce Mitchener4ad83342015-09-21 16:48:48 +0000909 child_compiler_type,
Greg Claytondea8cb42011-06-29 22:09:02 +0000910 child_name,
911 child_byte_size,
912 child_byte_offset,
913 child_bitfield_bit_size,
914 child_bitfield_bit_offset,
915 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000916 child_is_deref_of_parent,
Enrico Granatadc62ffd2015-11-09 19:27:34 +0000917 eAddressTypeInvalid,
918 language_flags);
Enrico Granata9128ee22011-09-06 19:20:51 +0000919 //if (valobj)
920 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
921 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000922
Jim Ingham58b59f92011-04-22 23:53:53 +0000923 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000924}
925
Enrico Granata0c489f52012-03-01 04:24:26 +0000926bool
927ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
Enrico Granata31fda932015-10-07 01:41:23 +0000928 std::string& destination,
929 lldb::LanguageType lang)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000930{
Enrico Granata31fda932015-10-07 01:41:23 +0000931 return GetSummaryAsCString(summary_ptr, destination, TypeSummaryOptions().SetLanguage(lang));
Enrico Granatac1247f52014-11-06 21:23:20 +0000932}
933
934bool
935ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
936 std::string& destination,
937 const TypeSummaryOptions& options)
938{
Enrico Granata0c489f52012-03-01 04:24:26 +0000939 destination.clear();
Enrico Granata31fda932015-10-07 01:41:23 +0000940
Enrico Granata0c489f52012-03-01 04:24:26 +0000941 // ideally we would like to bail out if passing NULL, but if we do so
942 // we end up not providing the summary for function pointers anymore
943 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
944 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000945
946 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000947
Enrico Granata31fda932015-10-07 01:41:23 +0000948 TypeSummaryOptions actual_options(options);
949
950 if (actual_options.GetLanguage() == lldb::eLanguageTypeUnknown)
951 actual_options.SetLanguage(GetPreferredDisplayLanguage());
952
Enrico Granataf18c03e2012-04-04 17:34:10 +0000953 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
954 // information that we might care to see in a crash log. might be useful in very specific situations though.
955 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
Enrico Granata31fda932015-10-07 01:41:23 +0000956 GetTypeName().GetCString(),
957 GetName().GetCString(),
958 summary_ptr->GetDescription().c_str());*/
Enrico Granataf18c03e2012-04-04 17:34:10 +0000959
Enrico Granataff0f23d2014-12-10 02:00:45 +0000960 if (UpdateValueIfNeeded (false) && summary_ptr)
Enrico Granata0c489f52012-03-01 04:24:26 +0000961 {
Enrico Granataff0f23d2014-12-10 02:00:45 +0000962 if (HasSyntheticValue())
963 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 +0000964 summary_ptr->FormatObject(this, destination, actual_options);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000965 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000966 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000967 return !destination.empty();
968}
969
970const char *
Enrico Granata31fda932015-10-07 01:41:23 +0000971ValueObject::GetSummaryAsCString (lldb::LanguageType lang)
Enrico Granata0c489f52012-03-01 04:24:26 +0000972{
973 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
974 {
Enrico Granata31fda932015-10-07 01:41:23 +0000975 TypeSummaryOptions summary_options;
976 summary_options.SetLanguage(lang);
Enrico Granata0c489f52012-03-01 04:24:26 +0000977 GetSummaryAsCString(GetSummaryFormat().get(),
Enrico Granatac1247f52014-11-06 21:23:20 +0000978 m_summary_str,
Enrico Granata31fda932015-10-07 01:41:23 +0000979 summary_options);
Enrico Granata0c489f52012-03-01 04:24:26 +0000980 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000981 if (m_summary_str.empty())
982 return NULL;
983 return m_summary_str.c_str();
984}
985
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000986bool
Enrico Granata49bfafb2014-11-18 23:36:25 +0000987ValueObject::GetSummaryAsCString (std::string& destination,
988 const TypeSummaryOptions& options)
989{
990 return GetSummaryAsCString(GetSummaryFormat().get(),
Enrico Granata31fda932015-10-07 01:41:23 +0000991 destination,
992 options);
Enrico Granata49bfafb2014-11-18 23:36:25 +0000993}
994
995bool
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000996ValueObject::IsCStringContainer(bool check_pointer)
997{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +0000998 CompilerType pointee_or_element_compiler_type;
999 const Flags type_flags (GetTypeInfo (&pointee_or_element_compiler_type));
Enrico Granata622be232014-10-21 20:52:14 +00001000 bool is_char_arr_ptr (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001001 pointee_or_element_compiler_type.IsCharType ());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001002 if (!is_char_arr_ptr)
1003 return false;
1004 if (!check_pointer)
1005 return true;
Enrico Granata622be232014-10-21 20:52:14 +00001006 if (type_flags.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001007 return true;
Greg Claytonafacd142011-09-02 01:15:17 +00001008 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001009 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +00001010 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001011 return (cstr_address != LLDB_INVALID_ADDRESS);
1012}
1013
Enrico Granata9128ee22011-09-06 19:20:51 +00001014size_t
1015ValueObject::GetPointeeData (DataExtractor& data,
1016 uint32_t item_idx,
1017 uint32_t item_count)
1018{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001019 CompilerType pointee_or_element_compiler_type;
1020 const uint32_t type_info = GetTypeInfo (&pointee_or_element_compiler_type);
Enrico Granata622be232014-10-21 20:52:14 +00001021 const bool is_pointer_type = type_info & eTypeIsPointer;
1022 const bool is_array_type = type_info & eTypeIsArray;
Greg Clayton2452ab72013-02-08 22:02:02 +00001023 if (!(is_pointer_type || is_array_type))
Enrico Granata9128ee22011-09-06 19:20:51 +00001024 return 0;
1025
1026 if (item_count == 0)
1027 return 0;
1028
Enrico Granata951bdd52015-01-28 01:09:45 +00001029 ExecutionContext exe_ctx (GetExecutionContextRef());
1030
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001031 const uint64_t item_type_size = pointee_or_element_compiler_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
Enrico Granata9128ee22011-09-06 19:20:51 +00001032 const uint64_t bytes = item_count * item_type_size;
Enrico Granata9128ee22011-09-06 19:20:51 +00001033 const uint64_t offset = item_idx * item_type_size;
1034
1035 if (item_idx == 0 && item_count == 1) // simply a deref
1036 {
Greg Clayton2452ab72013-02-08 22:02:02 +00001037 if (is_pointer_type)
Enrico Granata9128ee22011-09-06 19:20:51 +00001038 {
1039 Error error;
1040 ValueObjectSP pointee_sp = Dereference(error);
1041 if (error.Fail() || pointee_sp.get() == NULL)
1042 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +00001043 return pointee_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +00001044 }
1045 else
1046 {
1047 ValueObjectSP child_sp = GetChildAtIndex(0, true);
1048 if (child_sp.get() == NULL)
1049 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +00001050 Error error;
1051 return child_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +00001052 }
1053 return true;
1054 }
1055 else /* (items > 1) */
1056 {
1057 Error error;
1058 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
1059 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
1060
1061 AddressType addr_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001062 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001063
Enrico Granata9128ee22011-09-06 19:20:51 +00001064 switch (addr_type)
1065 {
1066 case eAddressTypeFile:
1067 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001068 ModuleSP module_sp (GetModule());
1069 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001070 {
Enrico Granata9c2efe32012-08-07 01:49:34 +00001071 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +00001072 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001073 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001074 ExecutionContext exe_ctx (GetExecutionContextRef());
1075 Target* target = exe_ctx.GetTargetPtr();
1076 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +00001077 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001078 heap_buf_ptr->SetByteSize(bytes);
1079 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
1080 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +00001081 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001082 data.SetData(data_sp);
1083 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +00001084 }
1085 }
1086 }
1087 }
1088 break;
1089 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +00001090 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001091 ExecutionContext exe_ctx (GetExecutionContextRef());
1092 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +00001093 if (process)
1094 {
1095 heap_buf_ptr->SetByteSize(bytes);
1096 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
Enrico Granata5e1480c2013-10-30 17:52:44 +00001097 if (error.Success() || bytes_read > 0)
Enrico Granata9128ee22011-09-06 19:20:51 +00001098 {
1099 data.SetData(data_sp);
1100 return bytes_read;
1101 }
1102 }
1103 }
1104 break;
1105 case eAddressTypeHost:
1106 {
Greg Clayton99558cc42015-08-24 23:46:31 +00001107 const uint64_t max_bytes = GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope());
Greg Clayton2452ab72013-02-08 22:02:02 +00001108 if (max_bytes > offset)
1109 {
1110 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
Siva Chandrae32f2b52015-05-05 00:41:35 +00001111 addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Enrico Granata7339b9d2015-11-03 02:34:43 +00001112 if (addr == 0 || addr == LLDB_INVALID_ADDRESS)
Siva Chandrae32f2b52015-05-05 00:41:35 +00001113 break;
Greg Clayton2452ab72013-02-08 22:02:02 +00001114 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
1115 data.SetData(data_sp);
1116 return bytes_read;
1117 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001118 }
1119 break;
1120 case eAddressTypeInvalid:
Enrico Granata9128ee22011-09-06 19:20:51 +00001121 break;
1122 }
1123 }
1124 return 0;
1125}
1126
Greg Claytonfaac1112013-03-14 18:31:44 +00001127uint64_t
Sean Callanan866e91c2014-02-28 22:27:53 +00001128ValueObject::GetData (DataExtractor& data, Error &error)
Enrico Granata9128ee22011-09-06 19:20:51 +00001129{
1130 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001131 ExecutionContext exe_ctx (GetExecutionContextRef());
Sean Callanan866e91c2014-02-28 22:27:53 +00001132 error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001133 if (error.Fail())
Sean Callananed185ab2013-04-19 19:47:32 +00001134 {
1135 if (m_data.GetByteSize())
1136 {
1137 data = m_data;
1138 return data.GetByteSize();
1139 }
1140 else
1141 {
1142 return 0;
1143 }
1144 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001145 data.SetAddressByteSize(m_data.GetAddressByteSize());
1146 data.SetByteOrder(m_data.GetByteOrder());
1147 return data.GetByteSize();
1148}
1149
Sean Callanan389823e2013-04-13 01:21:23 +00001150bool
1151ValueObject::SetData (DataExtractor &data, Error &error)
1152{
1153 error.Clear();
1154 // Make sure our value is up to date first so that our location and location
1155 // type is valid.
1156 if (!UpdateValueIfNeeded(false))
1157 {
1158 error.SetErrorString("unable to read value");
1159 return false;
1160 }
1161
1162 uint64_t count = 0;
Greg Clayton99558cc42015-08-24 23:46:31 +00001163 const Encoding encoding = GetCompilerType().GetEncoding(count);
Sean Callanan389823e2013-04-13 01:21:23 +00001164
1165 const size_t byte_size = GetByteSize();
1166
1167 Value::ValueType value_type = m_value.GetValueType();
1168
1169 switch (value_type)
1170 {
1171 case Value::eValueTypeScalar:
1172 {
1173 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1174
1175 if (!set_error.Success())
1176 {
1177 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1178 return false;
1179 }
1180 }
1181 break;
1182 case Value::eValueTypeLoadAddress:
1183 {
1184 // If it is a load address, then the scalar value is the storage location
1185 // of the data, and we have to shove this value down to that load location.
1186 ExecutionContext exe_ctx (GetExecutionContextRef());
1187 Process *process = exe_ctx.GetProcessPtr();
1188 if (process)
1189 {
1190 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1191 size_t bytes_written = process->WriteMemory(target_addr,
1192 data.GetDataStart(),
1193 byte_size,
1194 error);
1195 if (!error.Success())
1196 return false;
1197 if (bytes_written != byte_size)
1198 {
1199 error.SetErrorString("unable to write value to memory");
1200 return false;
1201 }
1202 }
1203 }
1204 break;
1205 case Value::eValueTypeHostAddress:
1206 {
1207 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1208 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1209 m_data.SetData(buffer_sp, 0);
1210 data.CopyByteOrderedData (0,
1211 byte_size,
1212 const_cast<uint8_t *>(m_data.GetDataStart()),
1213 byte_size,
1214 m_data.GetByteOrder());
1215 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1216 }
1217 break;
1218 case Value::eValueTypeFileAddress:
1219 case Value::eValueTypeVector:
1220 break;
1221 }
1222
1223 // If we have reached this point, then we have successfully changed the value.
1224 SetNeedsUpdate();
1225 return true;
1226}
1227
Enrico Granata9128ee22011-09-06 19:20:51 +00001228// will compute strlen(str), but without consuming more than
1229// maxlen bytes out of str (this serves the purpose of reading
1230// chunks of a string without having to worry about
1231// missing NULL terminators in the chunk)
1232// of course, if strlen(str) > maxlen, the function will return
1233// maxlen_value (which should be != maxlen, because that allows you
1234// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1235static uint32_t
1236strlen_or_inf (const char* str,
1237 uint32_t maxlen,
1238 uint32_t maxlen_value)
1239{
1240 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +00001241 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +00001242 {
Greg Clayton8dd5c172011-10-05 22:19:51 +00001243 while(*str)
1244 {
1245 len++;str++;
Greg Clayton2452ab72013-02-08 22:02:02 +00001246 if (len >= maxlen)
Greg Clayton8dd5c172011-10-05 22:19:51 +00001247 return maxlen_value;
1248 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001249 }
1250 return len;
1251}
1252
Enrico Granata2206b482014-10-30 18:27:31 +00001253static bool
1254CopyStringDataToBufferSP(const StreamString& source,
1255 lldb::DataBufferSP& destination)
1256{
1257 destination.reset(new DataBufferHeap(source.GetSize()+1,0));
1258 memcpy(destination->GetBytes(), source.GetString().c_str(), source.GetSize());
1259 return true;
1260}
1261
Enrico Granatab7662922015-11-04 00:02:08 +00001262std::pair<size_t,bool>
Enrico Granata2206b482014-10-30 18:27:31 +00001263ValueObject::ReadPointedString (lldb::DataBufferSP& buffer_sp,
Greg Claytoncc4d0142012-02-17 07:49:44 +00001264 Error& error,
1265 uint32_t max_length,
1266 bool honor_array,
1267 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001268{
Enrico Granatab7662922015-11-04 00:02:08 +00001269 bool was_capped = false;
Enrico Granata2206b482014-10-30 18:27:31 +00001270 StreamString s;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001271 ExecutionContext exe_ctx (GetExecutionContextRef());
1272 Target* target = exe_ctx.GetTargetPtr();
Enrico Granata2206b482014-10-30 18:27:31 +00001273
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001274 if (!target)
1275 {
1276 s << "<no target to read from>";
1277 error.SetErrorString("no target to read from");
Enrico Granata2206b482014-10-30 18:27:31 +00001278 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granatab7662922015-11-04 00:02:08 +00001279 return {0,was_capped};
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001280 }
1281
1282 if (max_length == 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001283 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001284
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001285 size_t bytes_read = 0;
1286 size_t total_bytes_read = 0;
1287
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001288 CompilerType compiler_type = GetCompilerType();
1289 CompilerType elem_or_pointee_compiler_type;
1290 const Flags type_flags (GetTypeInfo (&elem_or_pointee_compiler_type));
Enrico Granata622be232014-10-21 20:52:14 +00001291 if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001292 elem_or_pointee_compiler_type.IsCharType ())
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001293 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001294 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1295 AddressType cstr_address_type = eAddressTypeInvalid;
1296
1297 size_t cstr_len = 0;
1298 bool capped_data = false;
Enrico Granata622be232014-10-21 20:52:14 +00001299 if (type_flags.Test (eTypeIsArray))
Greg Claytoncc4d0142012-02-17 07:49:44 +00001300 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001301 // We have an array
Greg Clayton57ee3062013-07-11 22:46:58 +00001302 uint64_t array_size = 0;
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001303 if (compiler_type.IsArrayType(NULL, &array_size, NULL))
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001304 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001305 cstr_len = array_size;
1306 if (cstr_len > max_length)
1307 {
1308 capped_data = true;
1309 cstr_len = max_length;
1310 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001311 }
1312 cstr_address = GetAddressOf (true, &cstr_address_type);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001313 }
1314 else
1315 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001316 // We have a pointer
1317 cstr_address = GetPointerValue (&cstr_address_type);
1318 }
1319
1320 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1321 {
1322 s << "<invalid address>";
1323 error.SetErrorString("invalid address");
Enrico Granata2206b482014-10-30 18:27:31 +00001324 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granatab7662922015-11-04 00:02:08 +00001325 return {0,was_capped};
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001326 }
Enrico Granata2206b482014-10-30 18:27:31 +00001327
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001328 Address cstr_so_addr (cstr_address);
1329 DataExtractor data;
1330 if (cstr_len > 0 && honor_array)
1331 {
1332 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1333 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1334 GetPointeeData(data, 0, cstr_len);
Enrico Granata2206b482014-10-30 18:27:31 +00001335
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001336 if ((bytes_read = data.GetByteSize()) > 0)
1337 {
1338 total_bytes_read = bytes_read;
Enrico Granata2206b482014-10-30 18:27:31 +00001339 for (size_t offset = 0; offset < bytes_read; offset++)
1340 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001341 if (capped_data)
Enrico Granatab7662922015-11-04 00:02:08 +00001342 was_capped = true;
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001343 }
1344 }
1345 else
1346 {
1347 cstr_len = max_length;
1348 const size_t k_max_buf_size = 64;
Enrico Granata2206b482014-10-30 18:27:31 +00001349
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001350 size_t offset = 0;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001351
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001352 int cstr_len_displayed = -1;
1353 bool capped_cstr = false;
1354 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1355 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1356 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001357 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001358 total_bytes_read += bytes_read;
1359 const char *cstr = data.PeekCStr(0);
1360 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1361 if (len > k_max_buf_size)
1362 len = k_max_buf_size;
Enrico Granata2206b482014-10-30 18:27:31 +00001363
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001364 if (cstr_len_displayed < 0)
1365 cstr_len_displayed = len;
Enrico Granata2206b482014-10-30 18:27:31 +00001366
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001367 if (len == 0)
1368 break;
1369 cstr_len_displayed += len;
1370 if (len > bytes_read)
1371 len = bytes_read;
1372 if (len > cstr_len)
1373 len = cstr_len;
1374
Enrico Granata2206b482014-10-30 18:27:31 +00001375 for (size_t offset = 0; offset < bytes_read; offset++)
1376 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001377
1378 if (len < k_max_buf_size)
1379 break;
1380
1381 if (len >= cstr_len)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001382 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001383 capped_cstr = true;
1384 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001385 }
Enrico Granata2206b482014-10-30 18:27:31 +00001386
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001387 cstr_len -= len;
1388 offset += len;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001389 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001390
1391 if (cstr_len_displayed >= 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001392 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001393 if (capped_cstr)
Enrico Granatab7662922015-11-04 00:02:08 +00001394 was_capped = true;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001395 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001396 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001397 }
1398 else
1399 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001400 error.SetErrorString("not a string object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001401 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001402 }
Enrico Granata2206b482014-10-30 18:27:31 +00001403 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granatab7662922015-11-04 00:02:08 +00001404 return {total_bytes_read,was_capped};
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001405}
1406
Enrico Granata744794a2014-09-05 21:46:22 +00001407std::pair<TypeValidatorResult, std::string>
1408ValueObject::GetValidationStatus ()
1409{
1410 if (!UpdateValueIfNeeded(true))
1411 return {TypeValidatorResult::Success,""}; // not the validator's job to discuss update problems
1412
1413 if (m_validation_result.hasValue())
1414 return m_validation_result.getValue();
1415
1416 if (!m_type_validator_sp)
1417 return {TypeValidatorResult::Success,""}; // no validator no failure
1418
1419 auto outcome = m_type_validator_sp->FormatObject(this);
1420
1421 return (m_validation_result = {outcome.m_result,outcome.m_message}).getValue();
1422}
1423
Jim Ingham53c47f12010-09-10 23:12:17 +00001424const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001425ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001426{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001427
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001428 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001429 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001430
1431 if (!m_object_desc_str.empty())
1432 return m_object_desc_str.c_str();
1433
Greg Claytoncc4d0142012-02-17 07:49:44 +00001434 ExecutionContext exe_ctx (GetExecutionContextRef());
1435 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001436 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001437 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001438
Jim Ingham53c47f12010-09-10 23:12:17 +00001439 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001440
Greg Claytonafacd142011-09-02 01:15:17 +00001441 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001442 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1443
Jim Inghama2cf2632010-12-23 02:29:54 +00001444 if (runtime == NULL)
1445 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001446 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001447 CompilerType compiler_type = GetCompilerType();
1448 if (compiler_type)
Jim Inghama2cf2632010-12-23 02:29:54 +00001449 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001450 bool is_signed;
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00001451 if (compiler_type.IsIntegerType (is_signed) || compiler_type.IsPointerType ())
Jim Inghamb7603bb2011-03-18 00:05:18 +00001452 {
Greg Claytonafacd142011-09-02 01:15:17 +00001453 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001454 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001455 }
1456 }
1457
Jim Ingham8d543de2011-03-31 23:01:21 +00001458 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001459 {
1460 m_object_desc_str.append (s.GetData());
1461 }
Sean Callanan672ad942010-10-23 00:18:49 +00001462
1463 if (m_object_desc_str.empty())
1464 return NULL;
1465 else
1466 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001467}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001468
Enrico Granata0c489f52012-03-01 04:24:26 +00001469bool
Enrico Granata4939b982013-12-22 09:24:22 +00001470ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format,
1471 std::string& destination)
1472{
1473 if (UpdateValueIfNeeded(false))
1474 return format.FormatObject(this,destination);
1475 else
1476 return false;
1477}
1478
1479bool
Enrico Granata0c489f52012-03-01 04:24:26 +00001480ValueObject::GetValueAsCString (lldb::Format format,
1481 std::string& destination)
1482{
Enrico Granata30f287f2013-12-28 08:44:02 +00001483 return GetValueAsCString(TypeFormatImpl_Format(format),destination);
Enrico Granata0c489f52012-03-01 04:24:26 +00001484}
1485
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001486const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001487ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001488{
Enrico Granatab294fd22013-05-31 19:18:19 +00001489 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001490 {
Enrico Granata4939b982013-12-22 09:24:22 +00001491 lldb::TypeFormatImplSP format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001492 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001493 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001494 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001495 if (m_type_format_sp)
Enrico Granata4939b982013-12-22 09:24:22 +00001496 format_sp = m_type_format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001497 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001498 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001499 if (m_is_bitfield_for_scalar)
1500 my_format = eFormatUnsigned;
1501 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001502 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001503 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001504 {
1505 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1506 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001507 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001508 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001509 else
1510 {
Greg Clayton99558cc42015-08-24 23:46:31 +00001511 my_format = GetValue().GetCompilerType().GetFormat();
Enrico Granata0c489f52012-03-01 04:24:26 +00001512 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001513 }
1514 }
1515 }
Enrico Granatab294fd22013-05-31 19:18:19 +00001516 if (my_format != m_last_format || m_value_str.empty())
Enrico Granata297e69f2012-03-06 23:21:16 +00001517 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001518 m_last_format = my_format;
Enrico Granata4939b982013-12-22 09:24:22 +00001519 if (!format_sp)
Enrico Granata30f287f2013-12-28 08:44:02 +00001520 format_sp.reset(new TypeFormatImpl_Format(my_format));
Enrico Granata4939b982013-12-22 09:24:22 +00001521 if (GetValueAsCString(*format_sp.get(), m_value_str))
Enrico Granata297e69f2012-03-06 23:21:16 +00001522 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001523 if (!m_value_did_change && m_old_value_valid)
1524 {
1525 // The value was gotten successfully, so we consider the
1526 // value as changed if the value string differs
1527 SetValueDidChange (m_old_value_str != m_value_str);
1528 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001529 }
1530 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001531 }
1532 if (m_value_str.empty())
1533 return NULL;
1534 return m_value_str.c_str();
1535}
1536
Enrico Granatac3e320a2011-08-02 17:27:39 +00001537// if > 8bytes, 0 is returned. this method should mostly be used
1538// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001539uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001540ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001541{
1542 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001543 if (CanProvideValue())
Enrico Granatac3e320a2011-08-02 17:27:39 +00001544 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001545 Scalar scalar;
1546 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001547 {
1548 if (success)
1549 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001550 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001551 }
1552 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001553 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001554
1555 if (success)
1556 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001557 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001558}
1559
Enrico Granatad7373f62013-10-31 18:57:50 +00001560int64_t
1561ValueObject::GetValueAsSigned (int64_t fail_value, bool *success)
1562{
1563 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001564 if (CanProvideValue())
Enrico Granatad7373f62013-10-31 18:57:50 +00001565 {
1566 Scalar scalar;
1567 if (ResolveValue (scalar))
1568 {
1569 if (success)
1570 *success = true;
Tamas Berghammer5a9919f2015-01-23 10:54:21 +00001571 return scalar.SLongLong(fail_value);
Enrico Granatad7373f62013-10-31 18:57:50 +00001572 }
1573 // fallthrough, otherwise...
1574 }
1575
1576 if (success)
1577 *success = false;
Tamas Berghammer5a9919f2015-01-23 10:54:21 +00001578 return fail_value;
Enrico Granatad7373f62013-10-31 18:57:50 +00001579}
1580
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001581// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1582// this call up to date by returning true for your new special cases. We will eventually move
1583// to checking this call result before trying to display special cases
1584bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001585ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1586 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001587{
Greg Clayton57ee3062013-07-11 22:46:58 +00001588 Flags flags(GetTypeInfo());
Enrico Granata622be232014-10-21 20:52:14 +00001589 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001590 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001591 {
1592 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001593 (custom_format == eFormatCString ||
1594 custom_format == eFormatCharArray ||
1595 custom_format == eFormatChar ||
1596 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001597 return true;
1598
Enrico Granata622be232014-10-21 20:52:14 +00001599 if (flags.Test(eTypeIsArray))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001600 {
Greg Claytonafacd142011-09-02 01:15:17 +00001601 if ((custom_format == eFormatBytes) ||
1602 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001603 return true;
1604
Greg Claytonafacd142011-09-02 01:15:17 +00001605 if ((custom_format == eFormatVectorOfChar) ||
1606 (custom_format == eFormatVectorOfFloat32) ||
1607 (custom_format == eFormatVectorOfFloat64) ||
1608 (custom_format == eFormatVectorOfSInt16) ||
1609 (custom_format == eFormatVectorOfSInt32) ||
1610 (custom_format == eFormatVectorOfSInt64) ||
1611 (custom_format == eFormatVectorOfSInt8) ||
1612 (custom_format == eFormatVectorOfUInt128) ||
1613 (custom_format == eFormatVectorOfUInt16) ||
1614 (custom_format == eFormatVectorOfUInt32) ||
1615 (custom_format == eFormatVectorOfUInt64) ||
1616 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001617 return true;
1618 }
1619 }
1620 return false;
1621}
1622
Enrico Granata9fc19442011-07-06 02:13:41 +00001623bool
1624ValueObject::DumpPrintableRepresentation(Stream& s,
1625 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001626 Format custom_format,
Enrico Granata0dba9b32014-01-08 01:36:59 +00001627 PrintableRepresentationSpecialCases special,
1628 bool do_dump_error)
Enrico Granata9fc19442011-07-06 02:13:41 +00001629{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001630
Greg Clayton57ee3062013-07-11 22:46:58 +00001631 Flags flags(GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001632
Enrico Granata86cc9822012-03-19 22:58:49 +00001633 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1634 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1635
1636 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001637 {
Enrico Granata622be232014-10-21 20:52:14 +00001638 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001639 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001640 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001641 // when being asked to get a printable display an array or pointer type directly,
1642 // try to "do the right thing"
1643
1644 if (IsCStringContainer(true) &&
1645 (custom_format == eFormatCString ||
1646 custom_format == eFormatCharArray ||
1647 custom_format == eFormatChar ||
1648 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001649 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001650 Error error;
Enrico Granata2206b482014-10-30 18:27:31 +00001651 lldb::DataBufferSP buffer_sp;
Enrico Granatab7662922015-11-04 00:02:08 +00001652 std::pair<size_t, bool> read_string = ReadPointedString(buffer_sp,
1653 error,
1654 0,
1655 (custom_format == eFormatVectorOfChar) ||
1656 (custom_format == eFormatCharArray));
Enrico Granataac494532015-09-09 22:30:24 +00001657 lldb_private::formatters::StringPrinter::ReadBufferAndDumpToStreamOptions options(*this);
Enrico Granata2206b482014-10-30 18:27:31 +00001658 options.SetData(DataExtractor(buffer_sp, lldb::eByteOrderInvalid, 8)); // none of this matters for a string - pass some defaults
1659 options.SetStream(&s);
1660 options.SetPrefixToken(0);
1661 options.SetQuote('"');
1662 options.SetSourceSize(buffer_sp->GetByteSize());
Enrico Granatab7662922015-11-04 00:02:08 +00001663 options.SetIsTruncated(read_string.second);
Enrico Granataac494532015-09-09 22:30:24 +00001664 formatters::StringPrinter::ReadBufferAndDumpToStream<lldb_private::formatters::StringPrinter::StringElementType::ASCII>(options);
Enrico Granata86cc9822012-03-19 22:58:49 +00001665 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001666 }
1667
Enrico Granata86cc9822012-03-19 22:58:49 +00001668 if (custom_format == eFormatEnum)
1669 return false;
1670
1671 // this only works for arrays, because I have no way to know when
1672 // the pointed memory ends, and no special \0 end of data marker
Enrico Granata622be232014-10-21 20:52:14 +00001673 if (flags.Test(eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001674 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001675 if ((custom_format == eFormatBytes) ||
1676 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001677 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001678 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001679
1680 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001681 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001682 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001683
1684 if (low)
1685 s << ',';
1686
1687 ValueObjectSP child = GetChildAtIndex(low,true);
1688 if (!child.get())
1689 {
1690 s << "<invalid child>";
1691 continue;
1692 }
1693 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1694 }
1695
1696 s << ']';
1697
1698 return true;
1699 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001700
Enrico Granata86cc9822012-03-19 22:58:49 +00001701 if ((custom_format == eFormatVectorOfChar) ||
1702 (custom_format == eFormatVectorOfFloat32) ||
1703 (custom_format == eFormatVectorOfFloat64) ||
1704 (custom_format == eFormatVectorOfSInt16) ||
1705 (custom_format == eFormatVectorOfSInt32) ||
1706 (custom_format == eFormatVectorOfSInt64) ||
1707 (custom_format == eFormatVectorOfSInt8) ||
1708 (custom_format == eFormatVectorOfUInt128) ||
1709 (custom_format == eFormatVectorOfUInt16) ||
1710 (custom_format == eFormatVectorOfUInt32) ||
1711 (custom_format == eFormatVectorOfUInt64) ||
1712 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1713 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001714 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001715
1716 Format format = FormatManager::GetSingleItemFormat(custom_format);
1717
1718 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001719 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001720 {
1721
1722 if (low)
1723 s << ',';
1724
1725 ValueObjectSP child = GetChildAtIndex(low,true);
1726 if (!child.get())
1727 {
1728 s << "<invalid child>";
1729 continue;
1730 }
1731 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1732 }
1733
1734 s << ']';
1735
1736 return true;
1737 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001738 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001739
1740 if ((custom_format == eFormatBoolean) ||
1741 (custom_format == eFormatBinary) ||
1742 (custom_format == eFormatChar) ||
1743 (custom_format == eFormatCharPrintable) ||
1744 (custom_format == eFormatComplexFloat) ||
1745 (custom_format == eFormatDecimal) ||
1746 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001747 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001748 (custom_format == eFormatFloat) ||
1749 (custom_format == eFormatOctal) ||
1750 (custom_format == eFormatOSType) ||
1751 (custom_format == eFormatUnicode16) ||
1752 (custom_format == eFormatUnicode32) ||
1753 (custom_format == eFormatUnsigned) ||
1754 (custom_format == eFormatPointer) ||
1755 (custom_format == eFormatComplexInteger) ||
1756 (custom_format == eFormatComplex) ||
1757 (custom_format == eFormatDefault)) // use the [] operator
1758 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001759 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001760 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001761
1762 if (only_special)
1763 return false;
1764
Enrico Granata86cc9822012-03-19 22:58:49 +00001765 bool var_success = false;
1766
1767 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001768 const char *cstr = NULL;
Enrico Granata2c75f112013-06-21 00:04:51 +00001769
1770 // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1771 // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1772 // area for cases where our desired output is not backed by some other longer-term storage
Greg Claytonc7bece562013-01-25 18:06:21 +00001773 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001774
Enrico Granata465f4bc2014-02-15 01:24:44 +00001775 if (custom_format != eFormatInvalid)
Enrico Granata86cc9822012-03-19 22:58:49 +00001776 SetFormat(custom_format);
1777
1778 switch(val_obj_display)
1779 {
1780 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001781 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001782 break;
1783
1784 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001785 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001786 break;
1787
1788 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001789 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001790 break;
1791
1792 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001793 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001794 break;
1795
1796 case eValueObjectRepresentationStyleChildrenCount:
Deepak Panickal99fbc072014-03-03 15:39:47 +00001797 strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren());
Greg Claytonc7bece562013-01-25 18:06:21 +00001798 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001799 break;
1800
1801 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001802 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001803 break;
Enrico Granata2c75f112013-06-21 00:04:51 +00001804
1805 case eValueObjectRepresentationStyleName:
1806 cstr = GetName().AsCString();
1807 break;
1808
1809 case eValueObjectRepresentationStyleExpressionPath:
1810 GetExpressionPath(strm, false);
1811 cstr = strm.GetString().c_str();
1812 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001813 }
1814
Greg Claytonc7bece562013-01-25 18:06:21 +00001815 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001816 {
1817 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001818 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001819 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1820 {
Enrico Granatad07cfd32014-10-08 18:27:36 +00001821 if (!CanProvideValue())
Enrico Granata86cc9822012-03-19 22:58:49 +00001822 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001823 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1824 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001825 }
1826 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001827 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001828 }
1829 }
1830
Greg Claytonc7bece562013-01-25 18:06:21 +00001831 if (cstr)
1832 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001833 else
1834 {
1835 if (m_error.Fail())
Enrico Granata0dba9b32014-01-08 01:36:59 +00001836 {
1837 if (do_dump_error)
1838 s.Printf("<%s>", m_error.AsCString());
1839 else
1840 return false;
1841 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001842 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1843 s.PutCString("<no summary available>");
1844 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1845 s.PutCString("<no value available>");
1846 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1847 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1848 else
1849 s.PutCString("<no printable representation>");
1850 }
1851
1852 // we should only return false here if we could not do *anything*
1853 // even if we have an error message as output, that's a success
1854 // from our callers' perspective, so return true
1855 var_success = true;
Enrico Granata465f4bc2014-02-15 01:24:44 +00001856
1857 if (custom_format != eFormatInvalid)
1858 SetFormat(eFormatDefault);
Enrico Granata86cc9822012-03-19 22:58:49 +00001859 }
1860
Enrico Granataf4efecd2011-07-12 22:56:10 +00001861 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001862}
1863
Greg Clayton737b9322010-09-13 03:32:57 +00001864addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001865ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001866{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001867 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001868 return LLDB_INVALID_ADDRESS;
1869
Greg Clayton73b472d2010-10-27 03:32:59 +00001870 switch (m_value.GetValueType())
1871 {
1872 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001873 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001874 if (scalar_is_load_address)
1875 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001876 if(address_type)
1877 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001878 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1879 }
1880 break;
1881
1882 case Value::eValueTypeLoadAddress:
1883 case Value::eValueTypeFileAddress:
Greg Clayton73b472d2010-10-27 03:32:59 +00001884 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001885 if(address_type)
1886 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001887 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1888 }
1889 break;
Siva Chandraa3747a92015-05-04 19:43:34 +00001890 case Value::eValueTypeHostAddress:
Siva Chandrae32f2b52015-05-05 00:41:35 +00001891 {
1892 if(address_type)
1893 *address_type = m_value.GetValueAddressType ();
1894 return LLDB_INVALID_ADDRESS;
1895 }
Siva Chandraa3747a92015-05-04 19:43:34 +00001896 break;
Greg Clayton73b472d2010-10-27 03:32:59 +00001897 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001898 if (address_type)
1899 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001900 return LLDB_INVALID_ADDRESS;
1901}
1902
1903addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001904ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001905{
Greg Claytonafacd142011-09-02 01:15:17 +00001906 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001907 if(address_type)
1908 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001909
Enrico Granatac3e320a2011-08-02 17:27:39 +00001910 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001911 return address;
1912
Greg Clayton73b472d2010-10-27 03:32:59 +00001913 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001914 {
1915 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001916 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001917 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001918 break;
1919
Enrico Granata9128ee22011-09-06 19:20:51 +00001920 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001921 case Value::eValueTypeLoadAddress:
1922 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001923 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001924 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001925 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001926 }
1927 break;
1928 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001929
Enrico Granata9128ee22011-09-06 19:20:51 +00001930 if (address_type)
1931 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001932
Greg Clayton737b9322010-09-13 03:32:57 +00001933 return address;
1934}
1935
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001936bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001937ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001938{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001939 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001940 // Make sure our value is up to date first so that our location and location
1941 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001942 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001943 {
1944 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001945 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001946 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001947
Greg Claytonfaac1112013-03-14 18:31:44 +00001948 uint64_t count = 0;
Greg Clayton99558cc42015-08-24 23:46:31 +00001949 const Encoding encoding = GetCompilerType().GetEncoding (count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001950
Greg Claytonb1320972010-07-14 00:18:15 +00001951 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001952
Jim Ingham16e0c682011-08-12 23:34:31 +00001953 Value::ValueType value_type = m_value.GetValueType();
1954
1955 if (value_type == Value::eValueTypeScalar)
1956 {
1957 // If the value is already a scalar, then let the scalar change itself:
1958 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1959 }
Sagar Thakur8536fd12015-08-20 09:12:46 +00001960 else if (byte_size <= 16)
Jim Ingham16e0c682011-08-12 23:34:31 +00001961 {
1962 // If the value fits in a scalar, then make a new scalar and again let the
1963 // scalar code do the conversion, then figure out where to put the new value.
1964 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001965 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1966 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001967 {
Jim Ingham4b536182011-08-09 02:12:22 +00001968 switch (value_type)
1969 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001970 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001971 {
1972 // If it is a load address, then the scalar value is the storage location
1973 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001974 ExecutionContext exe_ctx (GetExecutionContextRef());
1975 Process *process = exe_ctx.GetProcessPtr();
1976 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001977 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001978 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001979 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1980 new_scalar,
1981 byte_size,
1982 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001983 if (!error.Success())
1984 return false;
1985 if (bytes_written != byte_size)
1986 {
1987 error.SetErrorString("unable to write value to memory");
1988 return false;
1989 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001990 }
1991 }
Jim Ingham4b536182011-08-09 02:12:22 +00001992 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001993 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001994 {
1995 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1996 DataExtractor new_data;
1997 new_data.SetByteOrder (m_data.GetByteOrder());
1998
1999 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
2000 m_data.SetData(buffer_sp, 0);
2001 bool success = new_scalar.GetData(new_data);
2002 if (success)
2003 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002004 new_data.CopyByteOrderedData (0,
2005 byte_size,
2006 const_cast<uint8_t *>(m_data.GetDataStart()),
2007 byte_size,
2008 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00002009 }
2010 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
2011
2012 }
Jim Ingham4b536182011-08-09 02:12:22 +00002013 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00002014 case Value::eValueTypeFileAddress:
2015 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00002016 case Value::eValueTypeVector:
2017 break;
Jim Ingham4b536182011-08-09 02:12:22 +00002018 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002019 }
2020 else
2021 {
Jim Ingham16e0c682011-08-12 23:34:31 +00002022 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002023 }
Jim Ingham16e0c682011-08-12 23:34:31 +00002024 }
2025 else
2026 {
2027 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00002028 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002029 return false;
2030 }
Jim Ingham16e0c682011-08-12 23:34:31 +00002031
2032 // If we have reached this point, then we have successfully changed the value.
2033 SetNeedsUpdate();
2034 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002035}
2036
Greg Clayton81e871e2012-02-04 02:27:34 +00002037bool
2038ValueObject::GetDeclaration (Declaration &decl)
2039{
2040 decl.Clear();
2041 return false;
2042}
2043
Greg Clayton84db9102012-03-26 23:03:23 +00002044ConstString
2045ValueObject::GetTypeName()
2046{
Greg Clayton99558cc42015-08-24 23:46:31 +00002047 return GetCompilerType().GetConstTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00002048}
2049
2050ConstString
Enrico Granatae8daa2f2014-05-17 19:14:17 +00002051ValueObject::GetDisplayTypeName()
2052{
2053 return GetTypeName();
2054}
2055
2056ConstString
Greg Clayton84db9102012-03-26 23:03:23 +00002057ValueObject::GetQualifiedTypeName()
2058{
Greg Clayton99558cc42015-08-24 23:46:31 +00002059 return GetCompilerType().GetConstQualifiedTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00002060}
2061
2062
Greg Claytonafacd142011-09-02 01:15:17 +00002063LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00002064ValueObject::GetObjectRuntimeLanguage ()
2065{
Greg Clayton99558cc42015-08-24 23:46:31 +00002066 return GetCompilerType().GetMinimumLanguage ();
Jim Ingham5a369122010-09-28 01:25:32 +00002067}
2068
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002069void
Jim Ingham58b59f92011-04-22 23:53:53 +00002070ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002071{
Jim Ingham58b59f92011-04-22 23:53:53 +00002072 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002073}
2074
2075ValueObjectSP
2076ValueObject::GetSyntheticChild (const ConstString &key) const
2077{
2078 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00002079 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002080 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00002081 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002082 return synthetic_child_sp;
2083}
2084
Greg Clayton2452ab72013-02-08 22:02:02 +00002085uint32_t
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002086ValueObject::GetTypeInfo (CompilerType *pointee_or_element_compiler_type)
Greg Clayton2452ab72013-02-08 22:02:02 +00002087{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002088 return GetCompilerType().GetTypeInfo (pointee_or_element_compiler_type);
Greg Clayton2452ab72013-02-08 22:02:02 +00002089}
2090
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002091bool
2092ValueObject::IsPointerType ()
2093{
Greg Clayton99558cc42015-08-24 23:46:31 +00002094 return GetCompilerType().IsPointerType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002095}
2096
Jim Inghamb7603bb2011-03-18 00:05:18 +00002097bool
Greg Claytondaf515f2011-07-09 20:12:33 +00002098ValueObject::IsArrayType ()
2099{
Greg Clayton99558cc42015-08-24 23:46:31 +00002100 return GetCompilerType().IsArrayType (NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00002101}
2102
2103bool
Enrico Granata9fc19442011-07-06 02:13:41 +00002104ValueObject::IsScalarType ()
2105{
Greg Clayton99558cc42015-08-24 23:46:31 +00002106 return GetCompilerType().IsScalarType ();
Enrico Granata9fc19442011-07-06 02:13:41 +00002107}
2108
2109bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00002110ValueObject::IsIntegerType (bool &is_signed)
2111{
Greg Clayton99558cc42015-08-24 23:46:31 +00002112 return GetCompilerType().IsIntegerType (is_signed);
Jim Inghamb7603bb2011-03-18 00:05:18 +00002113}
Greg Clayton73b472d2010-10-27 03:32:59 +00002114
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002115bool
2116ValueObject::IsPointerOrReferenceType ()
2117{
Greg Clayton99558cc42015-08-24 23:46:31 +00002118 return GetCompilerType().IsPointerOrReferenceType ();
Greg Clayton007d5be2011-05-30 00:49:24 +00002119}
2120
2121bool
Greg Claytondea8cb42011-06-29 22:09:02 +00002122ValueObject::IsPossibleDynamicType ()
2123{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002124 ExecutionContext exe_ctx (GetExecutionContextRef());
2125 Process *process = exe_ctx.GetProcessPtr();
2126 if (process)
2127 return process->IsPossibleDynamicValue(*this);
2128 else
Greg Clayton99558cc42015-08-24 23:46:31 +00002129 return GetCompilerType().IsPossibleDynamicType (NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00002130}
2131
Enrico Granata9e7b3882012-12-13 23:50:33 +00002132bool
Enrico Granata560558e2015-02-11 02:35:39 +00002133ValueObject::IsRuntimeSupportValue ()
2134{
2135 Process *process(GetProcessSP().get());
2136 if (process)
2137 {
2138 LanguageRuntime *runtime = process->GetLanguageRuntime(GetObjectRuntimeLanguage());
2139 if (!runtime)
2140 runtime = process->GetObjCLanguageRuntime();
2141 if (runtime)
2142 return runtime->IsRuntimeSupportValue(*this);
2143 }
2144 return false;
2145}
2146
2147bool
Enrico Granata9e7b3882012-12-13 23:50:33 +00002148ValueObject::IsObjCNil ()
2149{
Enrico Granata622be232014-10-21 20:52:14 +00002150 const uint32_t mask = eTypeIsObjC | eTypeIsPointer;
Greg Clayton99558cc42015-08-24 23:46:31 +00002151 bool isObjCpointer = (((GetCompilerType().GetTypeInfo(NULL)) & mask) == mask);
Enrico Granata7277d202013-03-15 23:33:15 +00002152 if (!isObjCpointer)
2153 return false;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002154 bool canReadValue = true;
2155 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
Enrico Granata7277d202013-03-15 23:33:15 +00002156 return canReadValue && isZero;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002157}
2158
Greg Claytondaf515f2011-07-09 20:12:33 +00002159// This allows you to create an array member using and index
2160// that doesn't not fall in the normal bounds of the array.
2161// Many times structure can be defined as:
2162// struct Collection
2163// {
2164// uint32_t item_count;
2165// Item item_array[0];
2166// };
2167// The size of the "item_array" is 1, but many times in practice
2168// there are more items in "item_array".
2169
2170ValueObjectSP
Bruce Mitchener11d86362015-02-26 23:55:39 +00002171ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00002172{
2173 ValueObjectSP synthetic_child_sp;
Bruce Mitchener11d86362015-02-26 23:55:39 +00002174 if (IsPointerType () || IsArrayType())
Greg Claytondaf515f2011-07-09 20:12:33 +00002175 {
2176 char index_str[64];
Deepak Panickal99fbc072014-03-03 15:39:47 +00002177 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
Greg Claytondaf515f2011-07-09 20:12:33 +00002178 ConstString index_const_str(index_str);
2179 // Check if we have already created a synthetic array member in this
2180 // valid object. If we have we will re-use it.
2181 synthetic_child_sp = GetSyntheticChild (index_const_str);
2182 if (!synthetic_child_sp)
2183 {
2184 ValueObject *synthetic_child;
2185 // We haven't made a synthetic array member for INDEX yet, so
2186 // lets make one and cache it for any future reference.
2187 synthetic_child = CreateChildAtIndex(0, true, index);
Bruce Mitchener11d86362015-02-26 23:55:39 +00002188
Greg Claytondaf515f2011-07-09 20:12:33 +00002189 // Cache the value if we got one back...
2190 if (synthetic_child)
2191 {
2192 AddSyntheticChild(index_const_str, synthetic_child);
2193 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002194 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00002195 synthetic_child_sp->m_is_array_item_for_pointer = true;
2196 }
2197 }
2198 }
2199 return synthetic_child_sp;
2200}
2201
Enrico Granata9fc19442011-07-06 02:13:41 +00002202ValueObjectSP
2203ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2204{
2205 ValueObjectSP synthetic_child_sp;
2206 if (IsScalarType ())
2207 {
2208 char index_str[64];
2209 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2210 ConstString index_const_str(index_str);
2211 // Check if we have already created a synthetic array member in this
2212 // valid object. If we have we will re-use it.
2213 synthetic_child_sp = GetSyntheticChild (index_const_str);
2214 if (!synthetic_child_sp)
2215 {
Enrico Granata9fc19442011-07-06 02:13:41 +00002216 // We haven't made a synthetic array member for INDEX yet, so
2217 // lets make one and cache it for any future reference.
Greg Clayton57ee3062013-07-11 22:46:58 +00002218 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
Greg Clayton99558cc42015-08-24 23:46:31 +00002219 GetCompilerType(),
Greg Clayton57ee3062013-07-11 22:46:58 +00002220 index_const_str,
2221 GetByteSize(),
2222 0,
2223 to-from+1,
2224 from,
2225 false,
2226 false,
Enrico Granatadc62ffd2015-11-09 19:27:34 +00002227 eAddressTypeInvalid,
2228 0);
Enrico Granata9fc19442011-07-06 02:13:41 +00002229
2230 // Cache the value if we got one back...
2231 if (synthetic_child)
2232 {
2233 AddSyntheticChild(index_const_str, synthetic_child);
2234 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002235 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002236 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2237 }
2238 }
2239 }
2240 return synthetic_child_sp;
2241}
2242
Greg Claytonafacd142011-09-02 01:15:17 +00002243ValueObjectSP
Greg Claytona1e5dc82015-08-11 22:53:00 +00002244ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const CompilerType& type, bool can_create)
Enrico Granata6f3533f2011-07-29 19:53:35 +00002245{
2246
2247 ValueObjectSP synthetic_child_sp;
2248
2249 char name_str[64];
2250 snprintf(name_str, sizeof(name_str), "@%i", offset);
2251 ConstString name_const_str(name_str);
2252
2253 // Check if we have already created a synthetic array member in this
2254 // valid object. If we have we will re-use it.
2255 synthetic_child_sp = GetSyntheticChild (name_const_str);
2256
2257 if (synthetic_child_sp.get())
2258 return synthetic_child_sp;
2259
2260 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002261 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002262
Enrico Granata951bdd52015-01-28 01:09:45 +00002263 ExecutionContext exe_ctx (GetExecutionContextRef());
2264
Enrico Granata6f3533f2011-07-29 19:53:35 +00002265 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
Greg Clayton57ee3062013-07-11 22:46:58 +00002266 type,
Enrico Granata6f3533f2011-07-29 19:53:35 +00002267 name_const_str,
Greg Clayton526ae042015-02-12 00:34:25 +00002268 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
Enrico Granata6f3533f2011-07-29 19:53:35 +00002269 offset,
2270 0,
2271 0,
2272 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002273 false,
Enrico Granatadc62ffd2015-11-09 19:27:34 +00002274 eAddressTypeInvalid,
2275 0);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002276 if (synthetic_child)
2277 {
2278 AddSyntheticChild(name_const_str, synthetic_child);
2279 synthetic_child_sp = synthetic_child->GetSP();
2280 synthetic_child_sp->SetName(name_const_str);
2281 synthetic_child_sp->m_is_child_at_offset = true;
2282 }
2283 return synthetic_child_sp;
2284}
2285
Enrico Granata32556cd2014-08-26 20:54:04 +00002286ValueObjectSP
Greg Claytona1e5dc82015-08-11 22:53:00 +00002287ValueObject::GetSyntheticBase (uint32_t offset, const CompilerType& type, bool can_create)
Enrico Granata32556cd2014-08-26 20:54:04 +00002288{
2289 ValueObjectSP synthetic_child_sp;
2290
2291 char name_str[64];
2292 snprintf(name_str, sizeof(name_str), "%s", type.GetTypeName().AsCString("<unknown>"));
2293 ConstString name_const_str(name_str);
2294
2295 // Check if we have already created a synthetic array member in this
2296 // valid object. If we have we will re-use it.
2297 synthetic_child_sp = GetSyntheticChild (name_const_str);
2298
2299 if (synthetic_child_sp.get())
2300 return synthetic_child_sp;
2301
2302 if (!can_create)
2303 return ValueObjectSP();
2304
Enrico Granata32556cd2014-08-26 20:54:04 +00002305 const bool is_base_class = true;
2306
Enrico Granata951bdd52015-01-28 01:09:45 +00002307 ExecutionContext exe_ctx (GetExecutionContextRef());
2308
Enrico Granata32556cd2014-08-26 20:54:04 +00002309 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2310 type,
2311 name_const_str,
Greg Clayton526ae042015-02-12 00:34:25 +00002312 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()),
Enrico Granata32556cd2014-08-26 20:54:04 +00002313 offset,
2314 0,
2315 0,
2316 is_base_class,
2317 false,
Enrico Granatadc62ffd2015-11-09 19:27:34 +00002318 eAddressTypeInvalid,
2319 0);
Enrico Granata32556cd2014-08-26 20:54:04 +00002320 if (synthetic_child)
2321 {
2322 AddSyntheticChild(name_const_str, synthetic_child);
2323 synthetic_child_sp = synthetic_child->GetSP();
2324 synthetic_child_sp->SetName(name_const_str);
2325 }
2326 return synthetic_child_sp;
2327}
2328
2329
Enrico Granatad55546b2011-07-22 00:16:08 +00002330// your expression path needs to have a leading . or ->
2331// (unless it somehow "looks like" an array, in which case it has
2332// a leading [ symbol). while the [ is meaningful and should be shown
2333// to the user, . and -> are just parser design, but by no means
2334// added information for the user.. strip them off
2335static const char*
2336SkipLeadingExpressionPathSeparators(const char* expression)
2337{
2338 if (!expression || !expression[0])
2339 return expression;
2340 if (expression[0] == '.')
2341 return expression+1;
2342 if (expression[0] == '-' && expression[1] == '>')
2343 return expression+2;
2344 return expression;
2345}
2346
Greg Claytonafacd142011-09-02 01:15:17 +00002347ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002348ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2349{
2350 ValueObjectSP synthetic_child_sp;
2351 ConstString name_const_string(expression);
2352 // Check if we have already created a synthetic array member in this
2353 // valid object. If we have we will re-use it.
2354 synthetic_child_sp = GetSyntheticChild (name_const_string);
2355 if (!synthetic_child_sp)
2356 {
2357 // We haven't made a synthetic array member for expression yet, so
2358 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002359 synthetic_child_sp = GetValueForExpressionPath(expression,
2360 NULL, NULL, NULL,
Enrico Granataef238c12015-03-12 22:30:58 +00002361 GetValueForExpressionPathOptions().SetSyntheticChildrenTraversal(GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None));
Enrico Granatad55546b2011-07-22 00:16:08 +00002362
2363 // Cache the value if we got one back...
2364 if (synthetic_child_sp.get())
2365 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002366 // 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 +00002367 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002368 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002369 }
2370 }
2371 return synthetic_child_sp;
2372}
2373
2374void
Enrico Granata86cc9822012-03-19 22:58:49 +00002375ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002376{
Enrico Granata86cc9822012-03-19 22:58:49 +00002377 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002378 return;
2379
Enrico Granatac5bc4122012-03-27 02:35:13 +00002380 TargetSP target_sp(GetTargetSP());
Enrico Granata5d5f60c2013-09-24 22:58:37 +00002381 if (target_sp && target_sp->GetEnableSyntheticValue() == false)
Enrico Granatac5bc4122012-03-27 02:35:13 +00002382 {
2383 m_synthetic_value = NULL;
2384 return;
2385 }
2386
Enrico Granatae3e91512012-10-22 18:18:36 +00002387 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2388
Enrico Granata5548cb52013-01-28 23:47:25 +00002389 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002390 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002391
Enrico Granata0c489f52012-03-01 04:24:26 +00002392 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002393 return;
2394
Enrico Granatae3e91512012-10-22 18:18:36 +00002395 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2396 return;
2397
Enrico Granata86cc9822012-03-19 22:58:49 +00002398 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002399}
2400
Jim Ingham78a685a2011-04-16 00:01:13 +00002401void
Greg Claytonafacd142011-09-02 01:15:17 +00002402ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002403{
Greg Claytonafacd142011-09-02 01:15:17 +00002404 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002405 return;
2406
Jim Ingham58b59f92011-04-22 23:53:53 +00002407 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002408 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002409 ExecutionContext exe_ctx (GetExecutionContextRef());
2410 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002411 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002412 {
2413 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002414 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002415 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002416 }
2417}
2418
Jim Ingham58b59f92011-04-22 23:53:53 +00002419ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002420ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002421{
Greg Claytonafacd142011-09-02 01:15:17 +00002422 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002423 return ValueObjectSP();
2424
2425 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002426 {
Jim Ingham2837b762011-05-04 03:43:18 +00002427 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002428 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002429 if (m_dynamic_value)
2430 return m_dynamic_value->GetSP();
2431 else
2432 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002433}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002434
Jim Ingham60dbabb2011-12-08 19:44:08 +00002435ValueObjectSP
2436ValueObject::GetStaticValue()
2437{
2438 return GetSP();
2439}
2440
Enrico Granata886147f2012-05-08 18:47:08 +00002441lldb::ValueObjectSP
2442ValueObject::GetNonSyntheticValue ()
2443{
2444 return GetSP();
2445}
2446
Enrico Granatad55546b2011-07-22 00:16:08 +00002447ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002448ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002449{
Enrico Granata86cc9822012-03-19 22:58:49 +00002450 if (use_synthetic == false)
2451 return ValueObjectSP();
2452
Enrico Granatad55546b2011-07-22 00:16:08 +00002453 CalculateSyntheticValue(use_synthetic);
2454
2455 if (m_synthetic_value)
2456 return m_synthetic_value->GetSP();
2457 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002458 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002459}
2460
Greg Claytone221f822011-01-21 01:59:00 +00002461bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002462ValueObject::HasSyntheticValue()
2463{
Enrico Granata5548cb52013-01-28 23:47:25 +00002464 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002465
Enrico Granata0c489f52012-03-01 04:24:26 +00002466 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002467 return false;
2468
Enrico Granata86cc9822012-03-19 22:58:49 +00002469 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002470
2471 if (m_synthetic_value)
2472 return true;
2473 else
2474 return false;
2475}
2476
2477bool
Greg Claytone221f822011-01-21 01:59:00 +00002478ValueObject::GetBaseClassPath (Stream &s)
2479{
2480 if (IsBaseClass())
2481 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002482 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002483 CompilerType compiler_type = GetCompilerType();
Greg Claytone221f822011-01-21 01:59:00 +00002484 std::string cxx_class_name;
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002485 bool this_had_base_class = ClangASTContext::GetCXXClassName (compiler_type, cxx_class_name);
Greg Claytone221f822011-01-21 01:59:00 +00002486 if (this_had_base_class)
2487 {
2488 if (parent_had_base_class)
2489 s.PutCString("::");
2490 s.PutCString(cxx_class_name.c_str());
2491 }
2492 return parent_had_base_class || this_had_base_class;
2493 }
2494 return false;
2495}
2496
2497
2498ValueObject *
2499ValueObject::GetNonBaseClassParent()
2500{
Jim Ingham78a685a2011-04-16 00:01:13 +00002501 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002502 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002503 if (GetParent()->IsBaseClass())
2504 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002505 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002506 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002507 }
2508 return NULL;
2509}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002510
Enrico Granataa3c8f042014-08-19 22:29:08 +00002511
2512bool
2513ValueObject::IsBaseClass (uint32_t& depth)
2514{
2515 if (!IsBaseClass())
2516 {
2517 depth = 0;
2518 return false;
2519 }
2520 if (GetParent())
2521 {
2522 GetParent()->IsBaseClass(depth);
2523 depth = depth + 1;
2524 return true;
2525 }
2526 // TODO: a base of no parent? weird..
2527 depth = 1;
2528 return true;
2529}
2530
Greg Clayton1d3afba2010-10-05 00:00:42 +00002531void
Enrico Granata4becb372011-06-29 22:27:15 +00002532ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002533{
Enrico Granata986fa5f2014-12-09 21:41:16 +00002534 // synthetic children do not actually "exist" as part of the hierarchy, and sometimes they are consed up in ways
2535 // that don't make sense from an underlying language/API standpoint. So, use a special code path here to return
2536 // something that can hopefully be used in expression
2537 if (m_is_synthetic_children_generated)
2538 {
2539 UpdateValueIfNeeded();
2540
2541 if (m_value.GetValueType() == Value::eValueTypeLoadAddress)
2542 {
2543 if (IsPointerOrReferenceType())
2544 {
2545 s.Printf("((%s)0x%" PRIx64 ")",
2546 GetTypeName().AsCString("void"),
2547 GetValueAsUnsigned(0));
2548 return;
2549 }
2550 else
2551 {
2552 uint64_t load_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
2553 if (load_addr != LLDB_INVALID_ADDRESS)
2554 {
2555 s.Printf("(*( (%s *)0x%" PRIx64 "))",
2556 GetTypeName().AsCString("void"),
2557 load_addr);
2558 return;
2559 }
2560 }
2561 }
2562
2563 if (CanProvideValue())
2564 {
2565 s.Printf("((%s)%s)",
2566 GetTypeName().AsCString("void"),
2567 GetValueAsCString());
2568 return;
2569 }
2570
2571 return;
2572 }
2573
Greg Claytone221f822011-01-21 01:59:00 +00002574 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002575
Enrico Granata86cc9822012-03-19 22:58:49 +00002576 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002577 {
Enrico Granata4becb372011-06-29 22:27:15 +00002578 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2579 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2580 // the eHonorPointers mode is meant to produce strings in this latter format
2581 s.PutCString("*(");
2582 }
Greg Claytone221f822011-01-21 01:59:00 +00002583
Enrico Granata4becb372011-06-29 22:27:15 +00002584 ValueObject* parent = GetParent();
2585
2586 if (parent)
2587 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002588
2589 // if we are a deref_of_parent just because we are synthetic array
2590 // members made up to allow ptr[%d] syntax to work in variable
2591 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002592 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002593 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002594
Greg Claytone221f822011-01-21 01:59:00 +00002595 if (!IsBaseClass())
2596 {
2597 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002598 {
Greg Claytone221f822011-01-21 01:59:00 +00002599 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2600 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002601 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002602 CompilerType non_base_class_parent_compiler_type = non_base_class_parent->GetCompilerType();
2603 if (non_base_class_parent_compiler_type)
Greg Claytone221f822011-01-21 01:59:00 +00002604 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002605 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002606 {
2607 s.PutCString("->");
2608 }
Enrico Granata4becb372011-06-29 22:27:15 +00002609 else
2610 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002611 const uint32_t non_base_class_parent_type_info = non_base_class_parent_compiler_type.GetTypeInfo();
Greg Clayton57ee3062013-07-11 22:46:58 +00002612
Enrico Granata622be232014-10-21 20:52:14 +00002613 if (non_base_class_parent_type_info & eTypeIsPointer)
Enrico Granata4becb372011-06-29 22:27:15 +00002614 {
2615 s.PutCString("->");
2616 }
Enrico Granata622be232014-10-21 20:52:14 +00002617 else if ((non_base_class_parent_type_info & eTypeHasChildren) &&
2618 !(non_base_class_parent_type_info & eTypeIsArray))
Enrico Granata4becb372011-06-29 22:27:15 +00002619 {
2620 s.PutChar('.');
2621 }
Greg Claytone221f822011-01-21 01:59:00 +00002622 }
2623 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002624 }
Greg Claytone221f822011-01-21 01:59:00 +00002625
2626 const char *name = GetName().GetCString();
2627 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002628 {
Greg Claytone221f822011-01-21 01:59:00 +00002629 if (qualify_cxx_base_classes)
2630 {
2631 if (GetBaseClassPath (s))
2632 s.PutCString("::");
2633 }
2634 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002635 }
2636 }
2637 }
2638
Enrico Granata86cc9822012-03-19 22:58:49 +00002639 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002640 {
Greg Claytone221f822011-01-21 01:59:00 +00002641 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002642 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002643}
2644
Greg Claytonafacd142011-09-02 01:15:17 +00002645ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002646ValueObject::GetValueForExpressionPath(const char* expression,
2647 const char** first_unparsed,
2648 ExpressionPathScanEndReason* reason_to_stop,
2649 ExpressionPathEndResultType* final_value_type,
2650 const GetValueForExpressionPathOptions& options,
2651 ExpressionPathAftermath* final_task_on_target)
2652{
2653
2654 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002655 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2656 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002657 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002658
2659 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2660 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2661 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2662 final_value_type ? final_value_type : &dummy_final_value_type,
2663 options,
2664 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2665
Enrico Granata86cc9822012-03-19 22:58:49 +00002666 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002667 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002668
Enrico Granata86cc9822012-03-19 22:58:49 +00002669 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 +00002670 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002671 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002672 {
2673 Error error;
2674 ValueObjectSP final_value = ret_val->Dereference(error);
2675 if (error.Fail() || !final_value.get())
2676 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002677 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002678 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002679 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002680 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002681 return ValueObjectSP();
2682 }
2683 else
2684 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002685 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002686 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002687 return final_value;
2688 }
2689 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002690 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002691 {
2692 Error error;
2693 ValueObjectSP final_value = ret_val->AddressOf(error);
2694 if (error.Fail() || !final_value.get())
2695 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002696 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002697 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002698 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002699 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002700 return ValueObjectSP();
2701 }
2702 else
2703 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002704 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002705 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002706 return final_value;
2707 }
2708 }
2709 }
2710 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2711}
2712
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002713int
2714ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002715 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002716 const char** first_unparsed,
2717 ExpressionPathScanEndReason* reason_to_stop,
2718 ExpressionPathEndResultType* final_value_type,
2719 const GetValueForExpressionPathOptions& options,
2720 ExpressionPathAftermath* final_task_on_target)
2721{
2722 const char* dummy_first_unparsed;
2723 ExpressionPathScanEndReason dummy_reason_to_stop;
2724 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002725 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002726
2727 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2728 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2729 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2730 final_value_type ? final_value_type : &dummy_final_value_type,
2731 options,
2732 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2733
2734 if (!ret_val.get()) // if there are errors, I add nothing to the list
2735 return 0;
2736
Enrico Granata86ea8d82012-03-29 01:34:34 +00002737 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002738 {
2739 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002740 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002741 {
2742 list->Append(ret_val);
2743 return 1;
2744 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002745 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 +00002746 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002747 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002748 {
2749 Error error;
2750 ValueObjectSP final_value = ret_val->Dereference(error);
2751 if (error.Fail() || !final_value.get())
2752 {
Greg Clayton23f59502012-07-17 03:23:13 +00002753 if (reason_to_stop)
2754 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2755 if (final_value_type)
2756 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002757 return 0;
2758 }
2759 else
2760 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002761 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002762 list->Append(final_value);
2763 return 1;
2764 }
2765 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002766 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002767 {
2768 Error error;
2769 ValueObjectSP final_value = ret_val->AddressOf(error);
2770 if (error.Fail() || !final_value.get())
2771 {
Greg Clayton23f59502012-07-17 03:23:13 +00002772 if (reason_to_stop)
2773 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2774 if (final_value_type)
2775 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002776 return 0;
2777 }
2778 else
2779 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002780 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002781 list->Append(final_value);
2782 return 1;
2783 }
2784 }
2785 }
2786 }
2787 else
2788 {
2789 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2790 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2791 ret_val,
2792 list,
2793 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2794 final_value_type ? final_value_type : &dummy_final_value_type,
2795 options,
2796 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2797 }
2798 // in any non-covered case, just do the obviously right thing
2799 list->Append(ret_val);
2800 return 1;
2801}
2802
Greg Claytonafacd142011-09-02 01:15:17 +00002803ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002804ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2805 const char** first_unparsed,
2806 ExpressionPathScanEndReason* reason_to_stop,
2807 ExpressionPathEndResultType* final_result,
2808 const GetValueForExpressionPathOptions& options,
2809 ExpressionPathAftermath* what_next)
2810{
2811 ValueObjectSP root = GetSP();
2812
2813 if (!root.get())
2814 return ValueObjectSP();
2815
2816 *first_unparsed = expression_cstr;
2817
2818 while (true)
2819 {
2820
2821 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2822
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002823 CompilerType root_compiler_type = root->GetCompilerType();
2824 CompilerType pointee_compiler_type;
2825 Flags pointee_compiler_type_info;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002826
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002827 Flags root_compiler_type_info(root_compiler_type.GetTypeInfo(&pointee_compiler_type));
2828 if (pointee_compiler_type)
2829 pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002830
2831 if (!expression_cstr || *expression_cstr == '\0')
2832 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002833 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002834 return root;
2835 }
2836
2837 switch (*expression_cstr)
2838 {
2839 case '-':
2840 {
2841 if (options.m_check_dot_vs_arrow_syntax &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002842 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 +00002843 {
2844 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002845 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2846 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002847 return ValueObjectSP();
2848 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002849 if (root_compiler_type_info.Test(eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2850 root_compiler_type_info.Test(eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002851 options.m_no_fragile_ivar)
2852 {
2853 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002854 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2855 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002856 return ValueObjectSP();
2857 }
2858 if (expression_cstr[1] != '>')
2859 {
2860 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002861 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2862 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002863 return ValueObjectSP();
2864 }
2865 expression_cstr++; // skip the -
2866 }
2867 case '.': // or fallthrough from ->
2868 {
2869 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00002870 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 +00002871 {
2872 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002873 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2874 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002875 return ValueObjectSP();
2876 }
2877 expression_cstr++; // skip .
2878 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2879 ConstString child_name;
2880 if (!next_separator) // if no other separator just expand this last layer
2881 {
2882 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002883 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2884
2885 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002886 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002887 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002888 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2889 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002890 return child_valobj_sp;
2891 }
Enrico Granataef238c12015-03-12 22:30:58 +00002892 else
Enrico Granata8c9d3562011-08-11 17:08:01 +00002893 {
Enrico Granataef238c12015-03-12 22:30:58 +00002894 switch (options.m_synthetic_children_traversal)
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002895 {
Enrico Granataef238c12015-03-12 22:30:58 +00002896 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None:
2897 break;
2898 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic:
2899 if (root->IsSynthetic())
2900 {
2901 child_valobj_sp = root->GetNonSyntheticValue();
2902 if (child_valobj_sp.get())
2903 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2904 }
2905 break;
2906 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic:
2907 if (!root->IsSynthetic())
2908 {
2909 child_valobj_sp = root->GetSyntheticValue();
2910 if (child_valobj_sp.get())
2911 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2912 }
2913 break;
2914 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both:
2915 if (root->IsSynthetic())
2916 {
2917 child_valobj_sp = root->GetNonSyntheticValue();
2918 if (child_valobj_sp.get())
2919 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2920 }
2921 else
2922 {
2923 child_valobj_sp = root->GetSyntheticValue();
2924 if (child_valobj_sp.get())
2925 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2926 }
2927 break;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002928 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002929 }
2930
2931 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2932 // so we hit the "else" branch, and return an error
2933 if(child_valobj_sp.get()) // if it worked, just return
2934 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002935 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002936 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2937 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002938 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002939 }
2940 else
2941 {
2942 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002943 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2944 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002945 return ValueObjectSP();
2946 }
2947 }
2948 else // other layers do expand
2949 {
2950 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002951 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2952 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002953 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002954 root = child_valobj_sp;
2955 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002956 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002957 continue;
2958 }
Enrico Granataef238c12015-03-12 22:30:58 +00002959 else
Enrico Granata8c9d3562011-08-11 17:08:01 +00002960 {
Enrico Granataef238c12015-03-12 22:30:58 +00002961 switch (options.m_synthetic_children_traversal)
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002962 {
Enrico Granataef238c12015-03-12 22:30:58 +00002963 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None:
2964 break;
2965 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::FromSynthetic:
2966 if (root->IsSynthetic())
2967 {
2968 child_valobj_sp = root->GetNonSyntheticValue();
2969 if (child_valobj_sp.get())
2970 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2971 }
2972 break;
2973 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic:
2974 if (!root->IsSynthetic())
2975 {
2976 child_valobj_sp = root->GetSyntheticValue();
2977 if (child_valobj_sp.get())
2978 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2979 }
2980 break;
2981 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both:
2982 if (root->IsSynthetic())
2983 {
2984 child_valobj_sp = root->GetNonSyntheticValue();
2985 if (child_valobj_sp.get())
2986 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2987 }
2988 else
2989 {
2990 child_valobj_sp = root->GetSyntheticValue();
2991 if (child_valobj_sp.get())
2992 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
2993 }
2994 break;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002995 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002996 }
2997
2998 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2999 // so we hit the "else" branch, and return an error
3000 if(child_valobj_sp.get()) // if it worked, move on
3001 {
3002 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003003 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00003004 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003005 continue;
3006 }
3007 else
3008 {
3009 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003010 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3011 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003012 return ValueObjectSP();
3013 }
3014 }
3015 break;
3016 }
3017 case '[':
3018 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003019 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 +00003020 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003021 if (!root_compiler_type_info.Test(eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003022 {
Enrico Granataef238c12015-03-12 22:30:58 +00003023 if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::None) // ...only chance left is synthetic
Enrico Granata27b625e2011-08-09 01:04:56 +00003024 {
3025 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003026 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3027 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003028 return ValueObjectSP();
3029 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003030 }
3031 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3032 {
3033 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003034 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3035 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003036 return ValueObjectSP();
3037 }
3038 }
3039 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3040 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003041 if (!root_compiler_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003042 {
3043 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003044 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3045 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003046 return ValueObjectSP();
3047 }
3048 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
3049 {
3050 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003051 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3052 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003053 return root;
3054 }
3055 }
3056 const char *separator_position = ::strchr(expression_cstr+1,'-');
3057 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3058 if (!close_bracket_position) // if there is no ], this is a syntax error
3059 {
3060 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003061 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3062 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003063 return ValueObjectSP();
3064 }
3065 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3066 {
3067 char *end = NULL;
3068 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3069 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3070 {
3071 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003072 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3073 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003074 return ValueObjectSP();
3075 }
3076 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3077 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003078 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003079 {
3080 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003081 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3082 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003083 return root;
3084 }
3085 else
3086 {
3087 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003088 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3089 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003090 return ValueObjectSP();
3091 }
3092 }
3093 // from here on we do have a valid index
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003094 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003095 {
Greg Claytondaf515f2011-07-09 20:12:33 +00003096 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
3097 if (!child_valobj_sp)
Bruce Mitchener11d86362015-02-26 23:55:39 +00003098 child_valobj_sp = root->GetSyntheticArrayMember(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003099 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00003100 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
3101 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00003102 if (child_valobj_sp)
3103 {
3104 root = child_valobj_sp;
3105 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003106 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00003107 continue;
3108 }
3109 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003110 {
3111 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003112 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3113 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003114 return ValueObjectSP();
3115 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003116 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003117 else if (root_compiler_type_info.Test(eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003118 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003119 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 +00003120 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003121 {
3122 Error error;
3123 root = root->Dereference(error);
3124 if (error.Fail() || !root.get())
3125 {
3126 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003127 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3128 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003129 return ValueObjectSP();
3130 }
3131 else
3132 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003133 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003134 continue;
3135 }
3136 }
3137 else
3138 {
Greg Clayton99558cc42015-08-24 23:46:31 +00003139 if (root->GetCompilerType().GetMinimumLanguage() == eLanguageTypeObjC
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003140 && pointee_compiler_type_info.AllClear(eTypeIsPointer)
Greg Clayton84db9102012-03-26 23:03:23 +00003141 && root->HasSyntheticValue()
Enrico Granataef238c12015-03-12 22:30:58 +00003142 && (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic ||
3143 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both))
Enrico Granata27b625e2011-08-09 01:04:56 +00003144 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003145 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003146 }
3147 else
Bruce Mitchener11d86362015-02-26 23:55:39 +00003148 root = root->GetSyntheticArrayMember(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003149 if (!root.get())
3150 {
3151 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003152 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3153 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003154 return ValueObjectSP();
3155 }
3156 else
3157 {
3158 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003159 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003160 continue;
3161 }
3162 }
3163 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003164 else if (root_compiler_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003165 {
3166 root = root->GetSyntheticBitFieldChild(index, index, true);
3167 if (!root.get())
3168 {
3169 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003170 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3171 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003172 return ValueObjectSP();
3173 }
3174 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3175 {
3176 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003177 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3178 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003179 return root;
3180 }
3181 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003182 else if (root_compiler_type_info.Test(eTypeIsVector))
Enrico Granata08a1bb82013-06-19 00:00:45 +00003183 {
3184 root = root->GetChildAtIndex(index, true);
3185 if (!root.get())
3186 {
3187 *first_unparsed = expression_cstr;
3188 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3189 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3190 return ValueObjectSP();
3191 }
3192 else
3193 {
3194 *first_unparsed = end+1; // skip ]
3195 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3196 continue;
3197 }
3198 }
Enrico Granataef238c12015-03-12 22:30:58 +00003199 else if (options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::ToSynthetic ||
3200 options.m_synthetic_children_traversal == GetValueForExpressionPathOptions::SyntheticChildrenTraversal::Both)
Enrico Granata27b625e2011-08-09 01:04:56 +00003201 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003202 if (root->HasSyntheticValue())
3203 root = root->GetSyntheticValue();
3204 else if (!root->IsSynthetic())
3205 {
3206 *first_unparsed = expression_cstr;
3207 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3208 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3209 return ValueObjectSP();
3210 }
3211 // if we are here, then root itself is a synthetic VO.. should be good to go
3212
Enrico Granata27b625e2011-08-09 01:04:56 +00003213 if (!root.get())
3214 {
3215 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003216 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3217 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3218 return ValueObjectSP();
3219 }
3220 root = root->GetChildAtIndex(index, true);
3221 if (!root.get())
3222 {
3223 *first_unparsed = expression_cstr;
3224 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3225 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003226 return ValueObjectSP();
3227 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00003228 else
3229 {
3230 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003231 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00003232 continue;
3233 }
Enrico Granata27b625e2011-08-09 01:04:56 +00003234 }
3235 else
3236 {
3237 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003238 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3239 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003240 return ValueObjectSP();
3241 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003242 }
3243 else // we have a low and a high index
3244 {
3245 char *end = NULL;
3246 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3247 if (!end || end != separator_position) // if something weird is in our way return an error
3248 {
3249 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003250 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3251 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003252 return ValueObjectSP();
3253 }
3254 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3255 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3256 {
3257 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003258 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3259 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003260 return ValueObjectSP();
3261 }
3262 if (index_lower > index_higher) // swap indices if required
3263 {
3264 unsigned long temp = index_lower;
3265 index_lower = index_higher;
3266 index_higher = temp;
3267 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003268 if (root_compiler_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003269 {
3270 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3271 if (!root.get())
3272 {
3273 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003274 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3275 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003276 return ValueObjectSP();
3277 }
3278 else
3279 {
3280 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003281 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3282 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003283 return root;
3284 }
3285 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003286 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 +00003287 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003288 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003289 {
3290 Error error;
3291 root = root->Dereference(error);
3292 if (error.Fail() || !root.get())
3293 {
3294 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003295 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3296 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003297 return ValueObjectSP();
3298 }
3299 else
3300 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003301 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003302 continue;
3303 }
3304 }
3305 else
3306 {
3307 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003308 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3309 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003310 return root;
3311 }
3312 }
3313 break;
3314 }
3315 default: // some non-separator is in the way
3316 {
3317 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003318 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3319 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003320 return ValueObjectSP();
3321 break;
3322 }
3323 }
3324 }
3325}
3326
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003327int
3328ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3329 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00003330 ValueObjectSP root,
3331 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003332 ExpressionPathScanEndReason* reason_to_stop,
3333 ExpressionPathEndResultType* final_result,
3334 const GetValueForExpressionPathOptions& options,
3335 ExpressionPathAftermath* what_next)
3336{
3337 if (!root.get())
3338 return 0;
3339
3340 *first_unparsed = expression_cstr;
3341
3342 while (true)
3343 {
3344
3345 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3346
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003347 CompilerType root_compiler_type = root->GetCompilerType();
3348 CompilerType pointee_compiler_type;
3349 Flags pointee_compiler_type_info;
3350 Flags root_compiler_type_info(root_compiler_type.GetTypeInfo(&pointee_compiler_type));
3351 if (pointee_compiler_type)
3352 pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003353
3354 if (!expression_cstr || *expression_cstr == '\0')
3355 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003356 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003357 list->Append(root);
3358 return 1;
3359 }
3360
3361 switch (*expression_cstr)
3362 {
3363 case '[':
3364 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003365 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 +00003366 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003367 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 +00003368 {
3369 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003370 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3371 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003372 return 0;
3373 }
3374 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3375 {
3376 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003377 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3378 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003379 return 0;
3380 }
3381 }
3382 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3383 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003384 if (!root_compiler_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003385 {
3386 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003387 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3388 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003389 return 0;
3390 }
3391 else // expand this into list
3392 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003393 const size_t max_index = root->GetNumChildren() - 1;
3394 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003395 {
3396 ValueObjectSP child =
3397 root->GetChildAtIndex(index, true);
3398 list->Append(child);
3399 }
3400 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003401 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3402 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003403 return max_index; // tell me number of items I added to the VOList
3404 }
3405 }
3406 const char *separator_position = ::strchr(expression_cstr+1,'-');
3407 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3408 if (!close_bracket_position) // if there is no ], this is a syntax error
3409 {
3410 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003411 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3412 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003413 return 0;
3414 }
3415 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3416 {
3417 char *end = NULL;
3418 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3419 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3420 {
3421 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003422 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3423 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003424 return 0;
3425 }
3426 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3427 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003428 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003429 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003430 const size_t max_index = root->GetNumChildren() - 1;
3431 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003432 {
3433 ValueObjectSP child =
3434 root->GetChildAtIndex(index, true);
3435 list->Append(child);
3436 }
3437 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003438 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3439 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003440 return max_index; // tell me number of items I added to the VOList
3441 }
3442 else
3443 {
3444 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003445 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3446 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003447 return 0;
3448 }
3449 }
3450 // from here on we do have a valid index
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003451 if (root_compiler_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003452 {
3453 root = root->GetChildAtIndex(index, true);
3454 if (!root.get())
3455 {
3456 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003457 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3458 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003459 return 0;
3460 }
3461 else
3462 {
3463 list->Append(root);
3464 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003465 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3466 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003467 return 1;
3468 }
3469 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003470 else if (root_compiler_type_info.Test(eTypeIsPointer))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003471 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003472 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 +00003473 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003474 {
3475 Error error;
3476 root = root->Dereference(error);
3477 if (error.Fail() || !root.get())
3478 {
3479 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003480 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3481 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003482 return 0;
3483 }
3484 else
3485 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003486 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003487 continue;
3488 }
3489 }
3490 else
3491 {
Bruce Mitchener11d86362015-02-26 23:55:39 +00003492 root = root->GetSyntheticArrayMember(index, true);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003493 if (!root.get())
3494 {
3495 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003496 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3497 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003498 return 0;
3499 }
3500 else
3501 {
3502 list->Append(root);
3503 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003504 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3505 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003506 return 1;
3507 }
3508 }
3509 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003510 else /*if (ClangASTContext::IsScalarType(root_compiler_type))*/
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003511 {
3512 root = root->GetSyntheticBitFieldChild(index, index, true);
3513 if (!root.get())
3514 {
3515 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003516 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3517 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003518 return 0;
3519 }
3520 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3521 {
3522 list->Append(root);
3523 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003524 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3525 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003526 return 1;
3527 }
3528 }
3529 }
3530 else // we have a low and a high index
3531 {
3532 char *end = NULL;
3533 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3534 if (!end || end != separator_position) // if something weird is in our way return an error
3535 {
3536 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003537 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3538 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003539 return 0;
3540 }
3541 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3542 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3543 {
3544 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003545 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3546 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003547 return 0;
3548 }
3549 if (index_lower > index_higher) // swap indices if required
3550 {
3551 unsigned long temp = index_lower;
3552 index_lower = index_higher;
3553 index_higher = temp;
3554 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003555 if (root_compiler_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003556 {
3557 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3558 if (!root.get())
3559 {
3560 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003561 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3562 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003563 return 0;
3564 }
3565 else
3566 {
3567 list->Append(root);
3568 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003569 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3570 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003571 return 1;
3572 }
3573 }
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003574 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 +00003575 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003576 pointee_compiler_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003577 {
3578 Error error;
3579 root = root->Dereference(error);
3580 if (error.Fail() || !root.get())
3581 {
3582 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003583 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3584 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003585 return 0;
3586 }
3587 else
3588 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003589 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003590 continue;
3591 }
3592 }
3593 else
3594 {
Johnny Chen44805302011-07-19 19:48:13 +00003595 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003596 index <= index_higher; index++)
3597 {
3598 ValueObjectSP child =
3599 root->GetChildAtIndex(index, true);
3600 list->Append(child);
3601 }
3602 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003603 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3604 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003605 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3606 }
3607 }
3608 break;
3609 }
3610 default: // some non-[ separator, or something entirely wrong, is in the way
3611 {
3612 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003613 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3614 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003615 return 0;
3616 break;
3617 }
3618 }
3619 }
3620}
3621
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003622void
3623ValueObject::LogValueObject (Log *log)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003624{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003625 if (log)
Enrico Granatad5957332015-06-03 20:43:54 +00003626 return LogValueObject (log, DumpValueObjectOptions(*this));
Greg Clayton1d3afba2010-10-05 00:00:42 +00003627}
3628
Enrico Granata0c489f52012-03-01 04:24:26 +00003629void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003630ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003631{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003632 if (log)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003633 {
3634 StreamString s;
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003635 Dump (s, options);
Greg Claytonf830dbb2012-03-22 18:15:37 +00003636 if (s.GetSize())
3637 log->PutCString(s.GetData());
3638 }
3639}
3640
3641void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003642ValueObject::Dump (Stream &s)
Enrico Granata0c489f52012-03-01 04:24:26 +00003643{
Enrico Granatad5957332015-06-03 20:43:54 +00003644 Dump (s, DumpValueObjectOptions(*this));
Enrico Granata0c489f52012-03-01 04:24:26 +00003645}
3646
3647void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003648ValueObject::Dump (Stream &s,
3649 const DumpValueObjectOptions& options)
Enrico Granata0c489f52012-03-01 04:24:26 +00003650{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003651 ValueObjectPrinter printer(this,&s,options);
3652 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003653}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003654
3655ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003656ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003657{
3658 ValueObjectSP valobj_sp;
3659
Enrico Granatac3e320a2011-08-02 17:27:39 +00003660 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003661 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003662 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003663
3664 DataExtractor data;
3665 data.SetByteOrder (m_data.GetByteOrder());
3666 data.SetAddressByteSize(m_data.GetAddressByteSize());
3667
Enrico Granata9f1e2042012-04-24 22:15:37 +00003668 if (IsBitfield())
3669 {
3670 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
Greg Clayton57ee3062013-07-11 22:46:58 +00003671 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Enrico Granata9f1e2042012-04-24 22:15:37 +00003672 }
3673 else
Greg Clayton57ee3062013-07-11 22:46:58 +00003674 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003675
3676 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton99558cc42015-08-24 23:46:31 +00003677 GetCompilerType(),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003678 name,
3679 data,
3680 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003681 }
Jim Ingham6035b672011-03-31 00:19:25 +00003682
3683 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003684 {
Greg Claytoneeb15652013-12-10 23:16:40 +00003685 ExecutionContext exe_ctx (GetExecutionContextRef());
3686 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003687 }
3688 return valobj_sp;
3689}
3690
Enrico Granata538a88a2014-10-09 18:24:30 +00003691ValueObjectSP
3692ValueObject::GetQualifiedRepresentationIfAvailable (lldb::DynamicValueType dynValue,
3693 bool synthValue)
3694{
3695 ValueObjectSP result_sp(GetSP());
3696
3697 switch (dynValue)
3698 {
3699 case lldb::eDynamicCanRunTarget:
3700 case lldb::eDynamicDontRunTarget:
3701 {
3702 if (!result_sp->IsDynamic())
3703 {
3704 if (result_sp->GetDynamicValue(dynValue))
3705 result_sp = result_sp->GetDynamicValue(dynValue);
3706 }
3707 }
3708 break;
3709 case lldb::eNoDynamicValues:
Enrico Granata538a88a2014-10-09 18:24:30 +00003710 {
3711 if (result_sp->IsDynamic())
3712 {
3713 if (result_sp->GetStaticValue())
3714 result_sp = result_sp->GetStaticValue();
3715 }
3716 }
3717 break;
3718 }
3719
3720 if (synthValue)
3721 {
3722 if (!result_sp->IsSynthetic())
3723 {
3724 if (result_sp->GetSyntheticValue())
3725 result_sp = result_sp->GetSyntheticValue();
3726 }
3727 }
3728 else
3729 {
3730 if (result_sp->IsSynthetic())
3731 {
3732 if (result_sp->GetNonSyntheticValue())
3733 result_sp = result_sp->GetNonSyntheticValue();
3734 }
3735 }
3736
3737 return result_sp;
3738}
3739
Greg Clayton759e7442014-07-19 00:12:57 +00003740lldb::addr_t
3741ValueObject::GetCPPVTableAddress (AddressType &address_type)
3742{
Greg Claytona1e5dc82015-08-11 22:53:00 +00003743 CompilerType pointee_type;
Greg Clayton99558cc42015-08-24 23:46:31 +00003744 CompilerType this_type(GetCompilerType());
Greg Clayton759e7442014-07-19 00:12:57 +00003745 uint32_t type_info = this_type.GetTypeInfo(&pointee_type);
3746 if (type_info)
3747 {
3748 bool ptr_or_ref = false;
Enrico Granata622be232014-10-21 20:52:14 +00003749 if (type_info & (eTypeIsPointer | eTypeIsReference))
Greg Clayton759e7442014-07-19 00:12:57 +00003750 {
3751 ptr_or_ref = true;
3752 type_info = pointee_type.GetTypeInfo();
3753 }
3754
Enrico Granata622be232014-10-21 20:52:14 +00003755 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus;
Greg Clayton759e7442014-07-19 00:12:57 +00003756 if ((type_info & cpp_class) == cpp_class)
3757 {
3758 if (ptr_or_ref)
3759 {
3760 address_type = GetAddressTypeOfChildren();
3761 return GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
3762 }
3763 else
3764 return GetAddressOf (false, &address_type);
3765 }
3766 }
3767
3768 address_type = eAddressTypeInvalid;
3769 return LLDB_INVALID_ADDRESS;
3770}
3771
Greg Claytonafacd142011-09-02 01:15:17 +00003772ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003773ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003774{
Jim Ingham58b59f92011-04-22 23:53:53 +00003775 if (m_deref_valobj)
3776 return m_deref_valobj->GetSP();
Chaoren Lind7bdc272015-07-31 00:35:40 +00003777
3778 const bool is_pointer_or_reference_type = IsPointerOrReferenceType();
3779 if (is_pointer_or_reference_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003780 {
3781 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003782 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003783
3784 std::string child_name_str;
3785 uint32_t child_byte_size = 0;
3786 int32_t child_byte_offset = 0;
3787 uint32_t child_bitfield_bit_size = 0;
3788 uint32_t child_bitfield_bit_offset = 0;
3789 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003790 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003791 const bool transparent_pointers = false;
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003792 CompilerType compiler_type = GetCompilerType();
3793 CompilerType child_compiler_type;
Enrico Granatadc62ffd2015-11-09 19:27:34 +00003794 uint64_t language_flags;
Jim Inghamd555bac2011-06-24 22:03:24 +00003795
Greg Claytoncc4d0142012-02-17 07:49:44 +00003796 ExecutionContext exe_ctx (GetExecutionContextRef());
Chaoren Lind7bdc272015-07-31 00:35:40 +00003797
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003798 child_compiler_type = compiler_type.GetChildCompilerTypeAtIndex (&exe_ctx,
3799 0,
3800 transparent_pointers,
3801 omit_empty_base_classes,
3802 ignore_array_bounds,
3803 child_name_str,
3804 child_byte_size,
3805 child_byte_offset,
3806 child_bitfield_bit_size,
3807 child_bitfield_bit_offset,
3808 child_is_base_class,
3809 child_is_deref_of_parent,
Enrico Granatadc62ffd2015-11-09 19:27:34 +00003810 this,
3811 language_flags);
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003812 if (child_compiler_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003813 {
3814 ConstString child_name;
3815 if (!child_name_str.empty())
3816 child_name.SetCString (child_name_str.c_str());
3817
Jim Ingham58b59f92011-04-22 23:53:53 +00003818 m_deref_valobj = new ValueObjectChild (*this,
Bruce Mitchener4ad83342015-09-21 16:48:48 +00003819 child_compiler_type,
Jim Ingham58b59f92011-04-22 23:53:53 +00003820 child_name,
3821 child_byte_size,
3822 child_byte_offset,
3823 child_bitfield_bit_size,
3824 child_bitfield_bit_offset,
3825 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003826 child_is_deref_of_parent,
Enrico Granatadc62ffd2015-11-09 19:27:34 +00003827 eAddressTypeInvalid,
3828 language_flags);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003829 }
3830 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003831
Jim Ingham58b59f92011-04-22 23:53:53 +00003832 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003833 {
3834 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003835 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003836 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003837 else
3838 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003839 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003840 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003841
Chaoren Lind7bdc272015-07-31 00:35:40 +00003842 if (is_pointer_or_reference_type)
Greg Clayton54979cd2010-12-15 05:08:08 +00003843 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3844 else
Chaoren Lind7bdc272015-07-31 00:35:40 +00003845 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 +00003846 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003847 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003848}
3849
Greg Claytonafacd142011-09-02 01:15:17 +00003850ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003851ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003852{
Jim Ingham78a685a2011-04-16 00:01:13 +00003853 if (m_addr_of_valobj_sp)
3854 return m_addr_of_valobj_sp;
3855
Greg Claytone0d378b2011-03-24 21:19:54 +00003856 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003857 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003858 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003859 error.Clear();
Siva Chandraa3747a92015-05-04 19:43:34 +00003860 if (addr != LLDB_INVALID_ADDRESS && address_type != eAddressTypeHost)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003861 {
3862 switch (address_type)
3863 {
3864 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003865 {
3866 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003867 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003868 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3869 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003870 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003871
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003872 case eAddressTypeFile:
3873 case eAddressTypeLoad:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003874 {
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003875 CompilerType compiler_type = GetCompilerType();
3876 if (compiler_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003877 {
3878 std::string name (1, '&');
3879 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003880 ExecutionContext exe_ctx (GetExecutionContextRef());
3881 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003882 compiler_type.GetPointerType(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003883 ConstString (name.c_str()),
3884 addr,
3885 eAddressTypeInvalid,
3886 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003887 }
3888 }
3889 break;
Siva Chandraa3747a92015-05-04 19:43:34 +00003890 default:
3891 break;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003892 }
3893 }
Sean Callananed185ab2013-04-19 19:47:32 +00003894 else
3895 {
3896 StreamString expr_path_strm;
3897 GetExpressionPath(expr_path_strm, true);
3898 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3899 }
3900
Jim Ingham78a685a2011-04-16 00:01:13 +00003901 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003902}
3903
Greg Clayton9a142cf2012-02-03 05:34:10 +00003904ValueObjectSP
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003905ValueObject::Cast (const CompilerType &compiler_type)
Greg Clayton9a142cf2012-02-03 05:34:10 +00003906{
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003907 return ValueObjectCast::Create (*this, GetName(), compiler_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003908}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003909
Greg Claytonafacd142011-09-02 01:15:17 +00003910ValueObjectSP
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003911ValueObject::CastPointerType (const char *name, CompilerType &compiler_type)
Greg Claytonb2dcc362011-05-05 23:32:56 +00003912{
Greg Claytonafacd142011-09-02 01:15:17 +00003913 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003914 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003915 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003916
3917 if (ptr_value != LLDB_INVALID_ADDRESS)
3918 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003919 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003920 ExecutionContext exe_ctx (GetExecutionContextRef());
3921 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003922 name,
3923 ptr_addr,
Bruce Mitchener3ad353f2015-09-24 03:54:50 +00003924 compiler_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003925 }
3926 return valobj_sp;
3927}
3928
Greg Claytonafacd142011-09-02 01:15:17 +00003929ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003930ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3931{
Greg Claytonafacd142011-09-02 01:15:17 +00003932 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003933 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003934 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003935
3936 if (ptr_value != LLDB_INVALID_ADDRESS)
3937 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003938 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003939 ExecutionContext exe_ctx (GetExecutionContextRef());
3940 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003941 name,
3942 ptr_addr,
3943 type_sp);
3944 }
3945 return valobj_sp;
3946}
3947
Jim Ingham6035b672011-03-31 00:19:25 +00003948ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003949 m_mod_id(),
3950 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003951 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003952{
3953}
3954
3955ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003956 m_mod_id(),
3957 m_exe_ctx_ref(),
Sean Callanan7375f3e2014-12-09 21:18:59 +00003958 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003959{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003960 ExecutionContext exe_ctx(exe_scope);
3961 TargetSP target_sp (exe_ctx.GetTargetSP());
3962 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003963 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003964 m_exe_ctx_ref.SetTargetSP (target_sp);
3965 ProcessSP process_sp (exe_ctx.GetProcessSP());
3966 if (!process_sp)
3967 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003968
Greg Claytoncc4d0142012-02-17 07:49:44 +00003969 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003970 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003971 m_mod_id = process_sp->GetModID();
3972 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003973
Greg Claytoncc4d0142012-02-17 07:49:44 +00003974 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003975
Greg Claytoncc4d0142012-02-17 07:49:44 +00003976 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003977 {
3978 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003979 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003980 }
Jim Ingham6035b672011-03-31 00:19:25 +00003981
Greg Claytoncc4d0142012-02-17 07:49:44 +00003982 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003983 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003984 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003985
Jason Molendab57e4a12013-11-04 09:33:30 +00003986 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003987 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003988 {
3989 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003990 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003991 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003992 if (frame_sp)
3993 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003994 }
3995 }
3996 }
Jim Ingham6035b672011-03-31 00:19:25 +00003997}
3998
3999ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00004000 m_mod_id(),
4001 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
Sean Callanan7375f3e2014-12-09 21:18:59 +00004002 m_needs_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00004003{
4004}
4005
4006ValueObject::EvaluationPoint::~EvaluationPoint ()
4007{
4008}
4009
Jim Ingham6035b672011-03-31 00:19:25 +00004010// This function checks the EvaluationPoint against the current process state. If the current
4011// state matches the evaluation point, or the evaluation point is already invalid, then we return
4012// false, meaning "no change". If the current state is different, we update our state, and return
4013// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
4014// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00004015// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00004016
4017bool
Enrico Granatabb642e52015-05-16 01:27:00 +00004018ValueObject::EvaluationPoint::SyncWithProcessState(bool accept_invalid_exe_ctx)
Jim Ingham6035b672011-03-31 00:19:25 +00004019{
Jim Ingham73ca05a2011-12-17 01:35:57 +00004020 // 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 +00004021 const bool thread_and_frame_only_if_stopped = true;
4022 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
Jim Ingham73ca05a2011-12-17 01:35:57 +00004023
Greg Claytoncc4d0142012-02-17 07:49:44 +00004024 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00004025 return false;
4026
Jim Ingham6035b672011-03-31 00:19:25 +00004027 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00004028 Process *process = exe_ctx.GetProcessPtr();
4029 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00004030 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00004031
Jim Ingham6035b672011-03-31 00:19:25 +00004032 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00004033 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00004034
Jim Ingham78a685a2011-04-16 00:01:13 +00004035 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
4036 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00004037 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00004038 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00004039
Greg Clayton23f59502012-07-17 03:23:13 +00004040 bool changed = false;
4041 const bool was_valid = m_mod_id.IsValid();
4042 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004043 {
4044 if (m_mod_id == current_mod_id)
4045 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00004046 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004047 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00004048 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004049 }
Jim Ingham9ee01152011-12-10 01:49:43 +00004050 else
4051 {
4052 m_mod_id = current_mod_id;
4053 m_needs_update = true;
4054 changed = true;
4055 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004056 }
Jim Ingham6035b672011-03-31 00:19:25 +00004057
Jim Ingham73ca05a2011-12-17 01:35:57 +00004058 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
4059 // That way we'll be sure to return a valid exe_scope.
4060 // 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 +00004061
Enrico Granatabb642e52015-05-16 01:27:00 +00004062 if (!accept_invalid_exe_ctx)
Jim Ingham6035b672011-03-31 00:19:25 +00004063 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004064 if (m_exe_ctx_ref.HasThreadRef())
Greg Clayton262f80d2011-07-06 16:49:27 +00004065 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004066 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
4067 if (thread_sp)
Greg Claytoncc4d0142012-02-17 07:49:44 +00004068 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004069 if (m_exe_ctx_ref.HasFrameRef())
Greg Claytoncc4d0142012-02-17 07:49:44 +00004070 {
Enrico Granatabb642e52015-05-16 01:27:00 +00004071 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
4072 if (!frame_sp)
4073 {
4074 // We used to have a frame, but now it is gone
4075 SetInvalid();
4076 changed = was_valid;
4077 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00004078 }
4079 }
Enrico Granatabb642e52015-05-16 01:27:00 +00004080 else
4081 {
4082 // We used to have a thread, but now it is gone
4083 SetInvalid();
4084 changed = was_valid;
4085 }
Greg Clayton262f80d2011-07-06 16:49:27 +00004086 }
Jim Ingham6035b672011-03-31 00:19:25 +00004087 }
Enrico Granatabb642e52015-05-16 01:27:00 +00004088
Jim Ingham9ee01152011-12-10 01:49:43 +00004089 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00004090}
4091
Jim Ingham61be0902011-05-02 18:13:59 +00004092void
4093ValueObject::EvaluationPoint::SetUpdated ()
4094{
Greg Claytoncc4d0142012-02-17 07:49:44 +00004095 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
4096 if (process_sp)
4097 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00004098 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00004099}
4100
4101
Enrico Granataf2bbf712011-07-15 02:26:42 +00004102
4103void
Enrico Granata86cc9822012-03-19 22:58:49 +00004104ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004105{
Enrico Granata86cc9822012-03-19 22:58:49 +00004106 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4107 m_value_str.clear();
4108
4109 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4110 m_location_str.clear();
4111
4112 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
Enrico Granata86cc9822012-03-19 22:58:49 +00004113 m_summary_str.clear();
Enrico Granata86cc9822012-03-19 22:58:49 +00004114
4115 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4116 m_object_desc_str.clear();
4117
4118 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4119 {
4120 if (m_synthetic_value)
4121 m_synthetic_value = NULL;
4122 }
Enrico Granata744794a2014-09-05 21:46:22 +00004123
4124 if ((clear_mask & eClearUserVisibleDataItemsValidator) == eClearUserVisibleDataItemsValidator)
4125 m_validation_result.reset();
Johnny Chen44805302011-07-19 19:48:13 +00004126}
Enrico Granata9128ee22011-09-06 19:20:51 +00004127
4128SymbolContextScope *
4129ValueObject::GetSymbolContextScope()
4130{
4131 if (m_parent)
4132 {
4133 if (!m_parent->IsPointerOrReferenceType())
4134 return m_parent->GetSymbolContextScope();
4135 }
4136 return NULL;
4137}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004138
4139lldb::ValueObjectSP
4140ValueObject::CreateValueObjectFromExpression (const char* name,
4141 const char* expression,
4142 const ExecutionContext& exe_ctx)
4143{
Enrico Granata972be532014-12-17 21:18:43 +00004144 return CreateValueObjectFromExpression(name, expression, exe_ctx, EvaluateExpressionOptions());
4145}
4146
4147
4148lldb::ValueObjectSP
4149ValueObject::CreateValueObjectFromExpression (const char* name,
4150 const char* expression,
4151 const ExecutionContext& exe_ctx,
4152 const EvaluateExpressionOptions& options)
4153{
Enrico Granatab2698cd2012-09-13 18:27:09 +00004154 lldb::ValueObjectSP retval_sp;
4155 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4156 if (!target_sp)
4157 return retval_sp;
4158 if (!expression || !*expression)
4159 return retval_sp;
4160 target_sp->EvaluateExpression (expression,
4161 exe_ctx.GetFrameSP().get(),
Enrico Granata972be532014-12-17 21:18:43 +00004162 retval_sp,
4163 options);
Enrico Granatab2698cd2012-09-13 18:27:09 +00004164 if (retval_sp && name && *name)
4165 retval_sp->SetName(ConstString(name));
4166 return retval_sp;
4167}
4168
4169lldb::ValueObjectSP
4170ValueObject::CreateValueObjectFromAddress (const char* name,
4171 uint64_t address,
4172 const ExecutionContext& exe_ctx,
Greg Claytona1e5dc82015-08-11 22:53:00 +00004173 CompilerType type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004174{
Greg Clayton57ee3062013-07-11 22:46:58 +00004175 if (type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004176 {
Greg Claytona1e5dc82015-08-11 22:53:00 +00004177 CompilerType pointer_type(type.GetPointerType());
Greg Clayton57ee3062013-07-11 22:46:58 +00004178 if (pointer_type)
4179 {
4180 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4181 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4182 pointer_type,
4183 ConstString(name),
4184 buffer,
Enrico Granata972be532014-12-17 21:18:43 +00004185 exe_ctx.GetByteOrder(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004186 exe_ctx.GetAddressByteSize()));
4187 if (ptr_result_valobj_sp)
4188 {
4189 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4190 Error err;
4191 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4192 if (ptr_result_valobj_sp && name && *name)
4193 ptr_result_valobj_sp->SetName(ConstString(name));
4194 }
4195 return ptr_result_valobj_sp;
4196 }
Enrico Granatab2698cd2012-09-13 18:27:09 +00004197 }
Greg Clayton57ee3062013-07-11 22:46:58 +00004198 return lldb::ValueObjectSP();
Enrico Granatab2698cd2012-09-13 18:27:09 +00004199}
4200
4201lldb::ValueObjectSP
4202ValueObject::CreateValueObjectFromData (const char* name,
Enrico Granata7ca1c762014-03-31 23:02:25 +00004203 const DataExtractor& data,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004204 const ExecutionContext& exe_ctx,
Greg Claytona1e5dc82015-08-11 22:53:00 +00004205 CompilerType type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004206{
4207 lldb::ValueObjectSP new_value_sp;
4208 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004209 type,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004210 ConstString(name),
4211 data,
4212 LLDB_INVALID_ADDRESS);
4213 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4214 if (new_value_sp && name && *name)
4215 new_value_sp->SetName(ConstString(name));
4216 return new_value_sp;
4217}
Enrico Granata4873e522013-04-11 22:48:58 +00004218
4219ModuleSP
4220ValueObject::GetModule ()
4221{
4222 ValueObject* root(GetRoot());
4223 if (root != this)
4224 return root->GetModule();
4225 return lldb::ModuleSP();
4226}
4227
4228ValueObject*
4229ValueObject::GetRoot ()
4230{
4231 if (m_root)
4232 return m_root;
Enrico Granatade61eba2015-01-22 03:07:34 +00004233 return (m_root = FollowParentChain( [] (ValueObject* vo) -> bool {
4234 return (vo->m_parent != nullptr);
4235 }));
4236}
4237
4238ValueObject*
4239ValueObject::FollowParentChain (std::function<bool(ValueObject*)> f)
4240{
4241 ValueObject* vo = this;
4242 while (vo)
Enrico Granata4873e522013-04-11 22:48:58 +00004243 {
Enrico Granatade61eba2015-01-22 03:07:34 +00004244 if (f(vo) == false)
4245 break;
4246 vo = vo->m_parent;
Enrico Granata4873e522013-04-11 22:48:58 +00004247 }
Enrico Granatade61eba2015-01-22 03:07:34 +00004248 return vo;
Enrico Granata4873e522013-04-11 22:48:58 +00004249}
4250
4251AddressType
4252ValueObject::GetAddressTypeOfChildren()
4253{
4254 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
4255 {
4256 ValueObject* root(GetRoot());
4257 if (root != this)
4258 return root->GetAddressTypeOfChildren();
4259 }
4260 return m_address_type_of_ptr_or_ref_children;
4261}
4262
4263lldb::DynamicValueType
4264ValueObject::GetDynamicValueType ()
4265{
4266 ValueObject* with_dv_info = this;
4267 while (with_dv_info)
4268 {
4269 if (with_dv_info->HasDynamicValueTypeInfo())
4270 return with_dv_info->GetDynamicValueTypeImpl();
4271 with_dv_info = with_dv_info->m_parent;
4272 }
4273 return lldb::eNoDynamicValues;
4274}
Enrico Granata39d51412013-05-31 17:43:40 +00004275
Enrico Granata4873e522013-04-11 22:48:58 +00004276lldb::Format
4277ValueObject::GetFormat () const
4278{
4279 const ValueObject* with_fmt_info = this;
4280 while (with_fmt_info)
4281 {
4282 if (with_fmt_info->m_format != lldb::eFormatDefault)
4283 return with_fmt_info->m_format;
4284 with_fmt_info = with_fmt_info->m_parent;
4285 }
4286 return m_format;
4287}
Enrico Granatad07cfd32014-10-08 18:27:36 +00004288
Enrico Granatac1247f52014-11-06 21:23:20 +00004289lldb::LanguageType
4290ValueObject::GetPreferredDisplayLanguage ()
4291{
Enrico Granataed3228a2015-01-21 01:47:13 +00004292 lldb::LanguageType type = m_preferred_display_language;
4293 if (m_preferred_display_language == lldb::eLanguageTypeUnknown)
Enrico Granatac1247f52014-11-06 21:23:20 +00004294 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004295 if (GetRoot())
Enrico Granatac1247f52014-11-06 21:23:20 +00004296 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004297 if (GetRoot() == this)
Enrico Granatac1247f52014-11-06 21:23:20 +00004298 {
Enrico Granataed3228a2015-01-21 01:47:13 +00004299 if (StackFrameSP frame_sp = GetFrameSP())
4300 {
4301 const SymbolContext& sc(frame_sp->GetSymbolContext(eSymbolContextCompUnit));
4302 if (CompileUnit* cu = sc.comp_unit)
4303 type = cu->GetLanguage();
4304 }
4305 }
4306 else
4307 {
4308 type = GetRoot()->GetPreferredDisplayLanguage();
Enrico Granatac1247f52014-11-06 21:23:20 +00004309 }
4310 }
Enrico Granatac1247f52014-11-06 21:23:20 +00004311 }
Enrico Granataed3228a2015-01-21 01:47:13 +00004312 return (m_preferred_display_language = type); // only compute it once
4313}
4314
4315void
4316ValueObject::SetPreferredDisplayLanguage (lldb::LanguageType lt)
4317{
4318 m_preferred_display_language = lt;
Enrico Granatac1247f52014-11-06 21:23:20 +00004319}
4320
Enrico Granata73e8c4d2015-10-07 02:36:35 +00004321void
4322ValueObject::SetPreferredDisplayLanguageIfNeeded (lldb::LanguageType lt)
4323{
4324 if (m_preferred_display_language == lldb::eLanguageTypeUnknown)
4325 SetPreferredDisplayLanguage(lt);
4326}
4327
Enrico Granatad07cfd32014-10-08 18:27:36 +00004328bool
4329ValueObject::CanProvideValue ()
4330{
Sean Callanan7375f3e2014-12-09 21:18:59 +00004331 // we need to support invalid types as providers of values because some bare-board
4332 // debugging scenarios have no notion of types, but still manage to have raw numeric
4333 // values for things like registers. sigh.
Greg Clayton99558cc42015-08-24 23:46:31 +00004334 const CompilerType &type(GetCompilerType());
Sean Callanan7375f3e2014-12-09 21:18:59 +00004335 return (false == type.IsValid()) || (0 != (type.GetTypeInfo() & eTypeHasValue));
4336}
4337
4338bool
4339ValueObject::IsChecksumEmpty ()
4340{
4341 return m_value_checksum.empty();
Enrico Granatad07cfd32014-10-08 18:27:36 +00004342}
Enrico Granata0c10a852014-12-08 23:13:56 +00004343
4344ValueObjectSP
4345ValueObject::Persist ()
4346{
4347 if (!UpdateValueIfNeeded())
4348 return nullptr;
4349
4350 TargetSP target_sp(GetTargetSP());
4351 if (!target_sp)
4352 return nullptr;
4353
Sean Callananb92bd752015-10-01 16:28:02 +00004354 PersistentExpressionState *persistent_state = target_sp->GetPersistentExpressionStateForLanguage(GetPreferredDisplayLanguage());
Sean Callanan8f1f9a12015-09-30 19:57:57 +00004355
4356 if (!persistent_state)
4357 return nullptr;
4358
4359 ConstString name(persistent_state->GetNextPersistentVariableName());
Enrico Granata0c10a852014-12-08 23:13:56 +00004360
Sean Callanan9301ec12015-10-01 23:07:06 +00004361 ValueObjectSP const_result_sp = ValueObjectConstResult::Create (target_sp.get(), GetValue(), name);
4362
4363 ExpressionVariableSP clang_var_sp = persistent_state->CreatePersistentVariable(const_result_sp);
4364 clang_var_sp->m_live_sp = clang_var_sp->m_frozen_sp;
4365 clang_var_sp->m_flags |= ExpressionVariable::EVIsProgramReference;
Enrico Granata0c10a852014-12-08 23:13:56 +00004366
4367 return clang_var_sp->GetValueObject();
4368}
Enrico Granatae29df232014-12-09 19:51:20 +00004369
4370bool
4371ValueObject::IsSyntheticChildrenGenerated ()
4372{
4373 return m_is_synthetic_children_generated;
4374}
4375
4376void
4377ValueObject::SetSyntheticChildrenGenerated (bool b)
4378{
4379 m_is_synthetic_children_generated = b;
4380}
Enrico Granatadc62ffd2015-11-09 19:27:34 +00004381
4382uint64_t
4383ValueObject::GetLanguageFlags ()
4384{
4385 return m_language_flags;
4386}
4387
4388void
4389ValueObject::SetLanguageFlags (uint64_t flags)
4390{
4391 m_language_flags = flags;
4392}