blob: 8bb285db05d90fd952b7b25268bdec70f5bd23c0 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- ValueObject.cpp -----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "lldb/Core/ValueObject.h"
13
14// C Includes
Greg Claytonf5e56de2010-09-14 23:36:40 +000015#include <stdlib.h>
16
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017// C++ Includes
18// Other libraries and framework includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "llvm/Support/raw_ostream.h"
Jim Ingham5a369122010-09-28 01:25:32 +000020#include "clang/AST/Type.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021
22// Project includes
23#include "lldb/Core/DataBufferHeap.h"
Enrico Granata4becb372011-06-29 22:27:15 +000024#include "lldb/Core/Debugger.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000025#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000026#include "lldb/Core/Module.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Core/StreamString.h"
Enrico Granata21fd13f2012-10-27 02:05:48 +000028#include "lldb/Core/ValueObjectCast.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Core/ValueObjectChild.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000030#include "lldb/Core/ValueObjectConstResult.h"
Jim Ingham78a685a2011-04-16 00:01:13 +000031#include "lldb/Core/ValueObjectDynamicValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032#include "lldb/Core/ValueObjectList.h"
Greg Claytonb2dcc362011-05-05 23:32:56 +000033#include "lldb/Core/ValueObjectMemory.h"
Enrico Granatad55546b2011-07-22 00:16:08 +000034#include "lldb/Core/ValueObjectSyntheticFilter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035
Enrico Granata5548cb52013-01-28 23:47:25 +000036#include "lldb/DataFormatters/DataVisualization.h"
37
Greg Clayton7fb56d02011-02-01 01:31:41 +000038#include "lldb/Host/Endian.h"
39
Enrico Granata61a80ba2011-08-12 16:42:31 +000040#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granataf2bbf712011-07-15 02:26:42 +000041#include "lldb/Interpreter/ScriptInterpreterPython.h"
42
Greg Claytone1a916a2010-07-21 22:12:05 +000043#include "lldb/Symbol/ClangASTType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000044#include "lldb/Symbol/ClangASTContext.h"
45#include "lldb/Symbol/Type.h"
46
Jim Ingham53c47f12010-09-10 23:12:17 +000047#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000048#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000049#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000050#include "lldb/Target/Process.h"
51#include "lldb/Target/RegisterContext.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000052#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054
55using namespace lldb;
56using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000057using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058
Greg Claytonafacd142011-09-02 01:15:17 +000059static user_id_t g_value_obj_uid = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060
61//----------------------------------------------------------------------
62// ValueObject constructor
63//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000064ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000066 m_parent (&parent),
Enrico Granata4873e522013-04-11 22:48:58 +000067 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +000068 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000069 m_name (),
70 m_data (),
71 m_value (),
72 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000073 m_value_str (),
74 m_old_value_str (),
75 m_location_str (),
76 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000077 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +000078 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000079 m_children (),
80 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000081 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000082 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000083 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000084 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +000085 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000086 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +000087 m_type_summary_sp(),
88 m_type_format_sp(),
89 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +000090 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +000091 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
Greg Clayton288bdf92010-09-02 02:59:18 +000092 m_value_is_valid (false),
93 m_value_did_change (false),
94 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000095 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +000096 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +000097 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +000098 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +000099 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000100 m_is_getting_summary(false),
101 m_did_calculate_complete_objc_class_type(false)
Jim Ingham6035b672011-03-31 00:19:25 +0000102{
Jim Ingham58b59f92011-04-22 23:53:53 +0000103 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000104}
105
106//----------------------------------------------------------------------
107// ValueObject constructor
108//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000109ValueObject::ValueObject (ExecutionContextScope *exe_scope,
110 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000111 UserID (++g_value_obj_uid), // Unique identifier for every value object
112 m_parent (NULL),
Enrico Granata4873e522013-04-11 22:48:58 +0000113 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000114 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000115 m_name (),
116 m_data (),
117 m_value (),
118 m_error (),
119 m_value_str (),
120 m_old_value_str (),
121 m_location_str (),
122 m_summary_str (),
123 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000124 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000125 m_children (),
126 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000127 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000128 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000129 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000130 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +0000131 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000132 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +0000133 m_type_summary_sp(),
134 m_type_format_sp(),
135 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000136 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000137 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Jim Ingham6035b672011-03-31 00:19:25 +0000138 m_value_is_valid (false),
139 m_value_did_change (false),
140 m_children_count_valid (false),
141 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000142 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000143 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000144 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000145 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000146 m_is_getting_summary(false),
147 m_did_calculate_complete_objc_class_type(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000148{
Jim Ingham58b59f92011-04-22 23:53:53 +0000149 m_manager = new ValueObjectManager();
150 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000151}
152
153//----------------------------------------------------------------------
154// Destructor
155//----------------------------------------------------------------------
156ValueObject::~ValueObject ()
157{
158}
159
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000160bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000161ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000162{
Enrico Granata4becb372011-06-29 22:27:15 +0000163
Enrico Granata9128ee22011-09-06 19:20:51 +0000164 bool did_change_formats = false;
165
Enrico Granata0a3958e2011-07-02 00:25:22 +0000166 if (update_format)
Enrico Granata5548cb52013-01-28 23:47:25 +0000167 did_change_formats = UpdateFormatsIfNeeded();
Enrico Granata4becb372011-06-29 22:27:15 +0000168
Greg Claytonb71f3842010-10-05 03:13:51 +0000169 // If this is a constant value, then our success is predicated on whether
170 // we have an error or not
171 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000172 {
173 // if you were asked to update your formatters, but did not get a chance to do it
174 // clear your own values (this serves the purpose of faking a stop-id for frozen
175 // objects (which are regarded as constant, but could have changes behind their backs
176 // because of the frozen-pointer depth limit)
177 // TODO: decouple summary from value and then remove this code and only force-clear the summary
178 if (update_format && !did_change_formats)
Enrico Granata86cc9822012-03-19 22:58:49 +0000179 ClearUserVisibleData(eClearUserVisibleDataItemsSummary);
Greg Claytonb71f3842010-10-05 03:13:51 +0000180 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000181 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000182
Jim Ingham6035b672011-03-31 00:19:25 +0000183 bool first_update = m_update_point.IsFirstEvaluation();
184
185 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000186 {
Jim Ingham6035b672011-03-31 00:19:25 +0000187 m_update_point.SetUpdated();
188
189 // Save the old value using swap to avoid a string copy which
190 // also will clear our m_value_str
191 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000192 {
Jim Ingham6035b672011-03-31 00:19:25 +0000193 m_old_value_valid = false;
194 }
195 else
196 {
197 m_old_value_valid = true;
198 m_old_value_str.swap (m_value_str);
Enrico Granata86cc9822012-03-19 22:58:49 +0000199 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham6035b672011-03-31 00:19:25 +0000200 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000201
Enrico Granataf2bbf712011-07-15 02:26:42 +0000202 ClearUserVisibleData();
203
Greg Claytonefbc7d22012-03-09 04:23:44 +0000204 if (IsInScope())
Jim Ingham6035b672011-03-31 00:19:25 +0000205 {
Greg Claytonefbc7d22012-03-09 04:23:44 +0000206 const bool value_was_valid = GetValueIsValid();
207 SetValueDidChange (false);
208
209 m_error.Clear();
210
211 // Call the pure virtual function to update the value
212 bool success = UpdateValue ();
213
214 SetValueIsValid (success);
215
216 if (first_update)
217 SetValueDidChange (false);
218 else if (!m_value_did_change && success == false)
219 {
220 // The value wasn't gotten successfully, so we mark this
221 // as changed if the value used to be valid and now isn't
222 SetValueDidChange (value_was_valid);
223 }
224 }
225 else
226 {
227 m_error.SetErrorString("out of scope");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000228 }
229 }
230 return m_error.Success();
231}
232
Enrico Granata9128ee22011-09-06 19:20:51 +0000233bool
Enrico Granata5548cb52013-01-28 23:47:25 +0000234ValueObject::UpdateFormatsIfNeeded()
Enrico Granata4becb372011-06-29 22:27:15 +0000235{
Greg Clayton5160ce52013-03-27 23:08:40 +0000236 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000237 if (log)
Enrico Granatad2284832012-10-17 22:23:56 +0000238 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
Enrico Granata6f3533f2011-07-29 19:53:35 +0000239 GetName().GetCString(),
Enrico Granatad2284832012-10-17 22:23:56 +0000240 this,
Enrico Granata4becb372011-06-29 22:27:15 +0000241 m_last_format_mgr_revision,
Enrico Granata85933ed2011-08-18 16:38:26 +0000242 DataVisualization::GetCurrentRevision());
Enrico Granata9128ee22011-09-06 19:20:51 +0000243
244 bool any_change = false;
245
Enrico Granata5548cb52013-01-28 23:47:25 +0000246 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()))
Enrico Granata4becb372011-06-29 22:27:15 +0000247 {
Enrico Granata78d06382011-09-09 23:33:14 +0000248 SetValueFormat(DataVisualization::ValueFormats::GetFormat (*this, eNoDynamicValues));
Enrico Granata5548cb52013-01-28 23:47:25 +0000249 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000250#ifndef LLDB_DISABLE_PYTHON
Enrico Granata5548cb52013-01-28 23:47:25 +0000251 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000252#endif
Enrico Granata1490c6f2011-07-19 02:34:21 +0000253
Enrico Granata85933ed2011-08-18 16:38:26 +0000254 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
Enrico Granata855cd902011-09-06 22:59:55 +0000255
256 any_change = true;
Enrico Granata4becb372011-06-29 22:27:15 +0000257 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000258
259 return any_change;
260
Enrico Granata4becb372011-06-29 22:27:15 +0000261}
262
Jim Ingham16e0c682011-08-12 23:34:31 +0000263void
264ValueObject::SetNeedsUpdate ()
265{
266 m_update_point.SetNeedsUpdate();
267 // We have to clear the value string here so ConstResult children will notice if their values are
268 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000269 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000270}
271
Enrico Granata13ac0e22012-10-17 19:03:34 +0000272void
Enrico Granatae3e91512012-10-22 18:18:36 +0000273ValueObject::ClearDynamicTypeInformation ()
Enrico Granata13ac0e22012-10-17 19:03:34 +0000274{
275 m_did_calculate_complete_objc_class_type = false;
Enrico Granatae3e91512012-10-22 18:18:36 +0000276 m_last_format_mgr_revision = 0;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000277 m_override_type = ClangASTType();
Enrico Granatae3e91512012-10-22 18:18:36 +0000278 SetValueFormat(lldb::TypeFormatImplSP());
279 SetSummaryFormat(lldb::TypeSummaryImplSP());
280 SetSyntheticChildren(lldb::SyntheticChildrenSP());
Enrico Granata13ac0e22012-10-17 19:03:34 +0000281}
282
Sean Callanan72772842012-02-22 23:57:45 +0000283ClangASTType
284ValueObject::MaybeCalculateCompleteType ()
285{
Greg Clayton57ee3062013-07-11 22:46:58 +0000286 ClangASTType clang_type(GetClangTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000287
Sean Callanan72772842012-02-22 23:57:45 +0000288 if (m_did_calculate_complete_objc_class_type)
289 {
290 if (m_override_type.IsValid())
291 return m_override_type;
292 else
Greg Clayton57ee3062013-07-11 22:46:58 +0000293 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000294 }
295
Greg Clayton57ee3062013-07-11 22:46:58 +0000296 ClangASTType class_type;
297 bool is_pointer_type = false;
Sean Callanan72772842012-02-22 23:57:45 +0000298
Greg Clayton57ee3062013-07-11 22:46:58 +0000299 if (clang_type.IsObjCObjectPointerType(&class_type))
Sean Callanan72772842012-02-22 23:57:45 +0000300 {
301 is_pointer_type = true;
302 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000303 else if (clang_type.IsObjCObjectOrInterfaceType())
Sean Callanan72772842012-02-22 23:57:45 +0000304 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000305 class_type = clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000306 }
307 else
308 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000309 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000310 }
311
312 m_did_calculate_complete_objc_class_type = true;
313
Greg Clayton57ee3062013-07-11 22:46:58 +0000314 if (class_type)
Sean Callanan72772842012-02-22 23:57:45 +0000315 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000316 ConstString class_name (class_type.GetConstTypeName());
Sean Callanan72772842012-02-22 23:57:45 +0000317
Greg Clayton57ee3062013-07-11 22:46:58 +0000318 if (class_name)
319 {
320 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
321
322 if (process_sp)
323 {
324 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
325
326 if (objc_language_runtime)
327 {
328 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name);
329
330 if (complete_objc_class_type_sp)
331 {
332 ClangASTType complete_class(complete_objc_class_type_sp->GetClangFullType());
333
334 if (complete_class.GetCompleteType())
335 {
336 if (is_pointer_type)
337 {
338 m_override_type = complete_class.GetPointerType();
339 }
340 else
341 {
342 m_override_type = complete_class;
343 }
344
345 if (m_override_type.IsValid())
346 return m_override_type;
347 }
348 }
349 }
350 }
351 }
Sean Callanan72772842012-02-22 23:57:45 +0000352 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000353 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000354}
355
Greg Clayton57ee3062013-07-11 22:46:58 +0000356ClangASTType
Sean Callanan72772842012-02-22 23:57:45 +0000357ValueObject::GetClangType ()
358{
Greg Clayton57ee3062013-07-11 22:46:58 +0000359 return MaybeCalculateCompleteType();
Sean Callanan72772842012-02-22 23:57:45 +0000360}
361
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000362DataExtractor &
363ValueObject::GetDataExtractor ()
364{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000365 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000366 return m_data;
367}
368
369const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000370ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000371{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000372 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000373 return m_error;
374}
375
376const ConstString &
377ValueObject::GetName() const
378{
379 return m_name;
380}
381
382const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000383ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000384{
Enrico Granata82fabf82013-04-30 20:45:04 +0000385 return GetLocationAsCStringImpl(m_value,
386 m_data);
387}
388
389const char *
390ValueObject::GetLocationAsCStringImpl (const Value& value,
391 const DataExtractor& data)
392{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000393 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000394 {
395 if (m_location_str.empty())
396 {
397 StreamString sstr;
Enrico Granata82fabf82013-04-30 20:45:04 +0000398
399 Value::ValueType value_type = value.GetValueType();
400
401 switch (value_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000402 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000403 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +0000404 case Value::eValueTypeVector:
Enrico Granata82fabf82013-04-30 20:45:04 +0000405 if (value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000406 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000407 RegisterInfo *reg_info = value.GetRegisterInfo();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000408 if (reg_info)
409 {
410 if (reg_info->name)
411 m_location_str = reg_info->name;
412 else if (reg_info->alt_name)
413 m_location_str = reg_info->alt_name;
Enrico Granata82fabf82013-04-30 20:45:04 +0000414 if (m_location_str.empty())
415 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000416 }
417 }
Enrico Granata82fabf82013-04-30 20:45:04 +0000418 if (m_location_str.empty())
419 m_location_str = (value_type == Value::eValueTypeVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000420 break;
421
422 case Value::eValueTypeLoadAddress:
423 case Value::eValueTypeFileAddress:
424 case Value::eValueTypeHostAddress:
425 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000426 uint32_t addr_nibble_size = data.GetAddressByteSize() * 2;
427 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000428 m_location_str.swap(sstr.GetString());
429 }
430 break;
431 }
432 }
433 }
434 return m_location_str.c_str();
435}
436
437Value &
438ValueObject::GetValue()
439{
440 return m_value;
441}
442
443const Value &
444ValueObject::GetValue() const
445{
446 return m_value;
447}
448
449bool
Jim Ingham6035b672011-03-31 00:19:25 +0000450ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000451{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000452 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
453 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000454 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000455 Value tmp_value(m_value);
Greg Clayton57ee3062013-07-11 22:46:58 +0000456 scalar = tmp_value.ResolveValue(&exe_ctx);
Greg Claytondcad5022011-12-29 01:26:56 +0000457 if (scalar.IsValid())
458 {
459 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
460 if (bitfield_bit_size)
461 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
462 return true;
463 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000464 }
Greg Claytondcad5022011-12-29 01:26:56 +0000465 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000466}
467
468bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000469ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000470{
Greg Clayton288bdf92010-09-02 02:59:18 +0000471 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000472}
473
474
475void
476ValueObject::SetValueIsValid (bool b)
477{
Greg Clayton288bdf92010-09-02 02:59:18 +0000478 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000479}
480
481bool
Jim Ingham6035b672011-03-31 00:19:25 +0000482ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000483{
Jim Ingham6035b672011-03-31 00:19:25 +0000484 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000485 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000486}
487
488void
489ValueObject::SetValueDidChange (bool value_changed)
490{
Greg Clayton288bdf92010-09-02 02:59:18 +0000491 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000492}
493
494ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000495ValueObject::GetChildAtIndex (size_t idx, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000496{
497 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000498 // We may need to update our value if we are dynamic
499 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000500 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000501 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000502 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000503 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000504 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000505 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000506 // No we haven't created the child at this index, so lets have our
507 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000508 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000509 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000510
Enrico Granata9d60f602012-03-09 03:09:58 +0000511 ValueObject* child = m_children.GetChildAtIndex(idx);
512 if (child != NULL)
513 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000514 }
515 return child_sp;
516}
517
Enrico Granata3309d882013-01-12 01:00:22 +0000518ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000519ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
520 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000521{
522 if (idxs.size() == 0)
523 return GetSP();
524 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000525 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000526 {
527 root = root->GetChildAtIndex(idx, true);
528 if (!root)
529 {
530 if (index_of_error)
531 *index_of_error = idx;
532 return root;
533 }
534 }
535 return root;
536}
537
538ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000539ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
540 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000541{
542 if (idxs.size() == 0)
543 return GetSP();
544 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000545 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000546 {
547 root = root->GetChildAtIndex(idx.first, idx.second);
548 if (!root)
549 {
550 if (index_of_error)
551 *index_of_error = idx.first;
552 return root;
553 }
554 }
555 return root;
556}
557
558lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000559ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
560 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000561{
562 if (idxs.size() == 0)
563 return GetSP();
564 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000565 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000566 {
567 root = root->GetChildAtIndex(idx, true);
568 if (!root)
569 {
570 if (index_of_error)
571 *index_of_error = idx;
572 return root;
573 }
574 }
575 return root;
576}
577
578lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000579ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
580 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000581{
582 if (idxs.size() == 0)
583 return GetSP();
584 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000585 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000586 {
587 root = root->GetChildAtIndex(idx.first, idx.second);
588 if (!root)
589 {
590 if (index_of_error)
591 *index_of_error = idx.first;
592 return root;
593 }
594 }
595 return root;
596}
597
Enrico Granatae2e220a2013-09-12 00:48:47 +0000598lldb::ValueObjectSP
599ValueObject::GetChildAtNamePath (const std::initializer_list<ConstString> &names,
600 ConstString* name_of_error)
601{
602 if (names.size() == 0)
603 return GetSP();
604 ValueObjectSP root(GetSP());
605 for (ConstString name : names)
606 {
607 root = root->GetChildMemberWithName(name, true);
608 if (!root)
609 {
610 if (name_of_error)
611 *name_of_error = name;
612 return root;
613 }
614 }
615 return root;
616}
617
618lldb::ValueObjectSP
619ValueObject::GetChildAtNamePath (const std::vector<ConstString> &names,
620 ConstString* name_of_error)
621{
622 if (names.size() == 0)
623 return GetSP();
624 ValueObjectSP root(GetSP());
625 for (ConstString name : names)
626 {
627 root = root->GetChildMemberWithName(name, true);
628 if (!root)
629 {
630 if (name_of_error)
631 *name_of_error = name;
632 return root;
633 }
634 }
635 return root;
636}
637
638lldb::ValueObjectSP
639ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names,
640 ConstString* name_of_error)
641{
642 if (names.size() == 0)
643 return GetSP();
644 ValueObjectSP root(GetSP());
645 for (std::pair<ConstString, bool> name : names)
646 {
647 root = root->GetChildMemberWithName(name.first, name.second);
648 if (!root)
649 {
650 if (name_of_error)
651 *name_of_error = name.first;
652 return root;
653 }
654 }
655 return root;
656}
657
658lldb::ValueObjectSP
659ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names,
660 ConstString* name_of_error)
661{
662 if (names.size() == 0)
663 return GetSP();
664 ValueObjectSP root(GetSP());
665 for (std::pair<ConstString, bool> name : names)
666 {
667 root = root->GetChildMemberWithName(name.first, name.second);
668 if (!root)
669 {
670 if (name_of_error)
671 *name_of_error = name.first;
672 return root;
673 }
674 }
675 return root;
676}
677
Greg Claytonc7bece562013-01-25 18:06:21 +0000678size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000679ValueObject::GetIndexOfChildWithName (const ConstString &name)
680{
681 bool omit_empty_base_classes = true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000682 return GetClangType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000683}
684
685ValueObjectSP
686ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
687{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000688 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000689 // classes (which really aren't part of the expression path), so we
690 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000691 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000692
Greg Claytondea8cb42011-06-29 22:09:02 +0000693 // We may need to update our value if we are dynamic
694 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000695 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000696
697 std::vector<uint32_t> child_indexes;
Greg Claytondea8cb42011-06-29 22:09:02 +0000698 bool omit_empty_base_classes = true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000699 const size_t num_child_indexes = GetClangType().GetIndexOfChildMemberWithName (name.GetCString(),
700 omit_empty_base_classes,
701 child_indexes);
Greg Claytondea8cb42011-06-29 22:09:02 +0000702 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000703 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000704 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
705 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
706
707 child_sp = GetChildAtIndex(*pos, can_create);
708 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000709 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000710 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000711 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000712 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
713 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000714 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000715 else
716 {
717 child_sp.reset();
718 }
719
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000720 }
721 }
722 return child_sp;
723}
724
725
Greg Claytonc7bece562013-01-25 18:06:21 +0000726size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000727ValueObject::GetNumChildren ()
728{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000729 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000730 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000731 {
732 SetNumChildren (CalculateNumChildren());
733 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000734 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000735}
Greg Clayton4a792072012-10-23 01:50:10 +0000736
737bool
738ValueObject::MightHaveChildren()
739{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000740 bool has_children = false;
Greg Clayton2452ab72013-02-08 22:02:02 +0000741 const uint32_t type_info = GetTypeInfo();
742 if (type_info)
Greg Clayton4a792072012-10-23 01:50:10 +0000743 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000744 if (type_info & (ClangASTType::eTypeHasChildren |
745 ClangASTType::eTypeIsPointer |
746 ClangASTType::eTypeIsReference))
Greg Clayton4a792072012-10-23 01:50:10 +0000747 has_children = true;
748 }
749 else
750 {
751 has_children = GetNumChildren () > 0;
752 }
753 return has_children;
754}
755
756// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000757void
Greg Claytonc7bece562013-01-25 18:06:21 +0000758ValueObject::SetNumChildren (size_t num_children)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000759{
Greg Clayton288bdf92010-09-02 02:59:18 +0000760 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000761 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000762}
763
764void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000765ValueObject::SetName (const ConstString &name)
766{
767 m_name = name;
768}
769
Jim Ingham58b59f92011-04-22 23:53:53 +0000770ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000771ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000772{
Jim Ingham2eec4872011-05-07 00:10:58 +0000773 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000774
Greg Claytondea8cb42011-06-29 22:09:02 +0000775 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000776 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000777 std::string child_name_str;
778 uint32_t child_byte_size = 0;
779 int32_t child_byte_offset = 0;
780 uint32_t child_bitfield_bit_size = 0;
781 uint32_t child_bitfield_bit_offset = 0;
782 bool child_is_base_class = false;
783 bool child_is_deref_of_parent = false;
784
785 const bool transparent_pointers = synthetic_array_member == false;
Greg Clayton57ee3062013-07-11 22:46:58 +0000786 ClangASTType child_clang_type;
Greg Claytondea8cb42011-06-29 22:09:02 +0000787
Greg Claytoncc4d0142012-02-17 07:49:44 +0000788 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000789
Greg Clayton57ee3062013-07-11 22:46:58 +0000790 child_clang_type = GetClangType().GetChildClangTypeAtIndex (&exe_ctx,
791 GetName().GetCString(),
792 idx,
793 transparent_pointers,
794 omit_empty_base_classes,
795 ignore_array_bounds,
796 child_name_str,
797 child_byte_size,
798 child_byte_offset,
799 child_bitfield_bit_size,
800 child_bitfield_bit_offset,
801 child_is_base_class,
802 child_is_deref_of_parent);
Greg Clayton4ef877f2012-12-06 02:33:54 +0000803 if (child_clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000804 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000805 if (synthetic_index)
806 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000807
Greg Claytondea8cb42011-06-29 22:09:02 +0000808 ConstString child_name;
809 if (!child_name_str.empty())
810 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000811
Greg Claytondea8cb42011-06-29 22:09:02 +0000812 valobj = new ValueObjectChild (*this,
Greg Claytondea8cb42011-06-29 22:09:02 +0000813 child_clang_type,
814 child_name,
815 child_byte_size,
816 child_byte_offset,
817 child_bitfield_bit_size,
818 child_bitfield_bit_offset,
819 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000820 child_is_deref_of_parent,
821 eAddressTypeInvalid);
822 //if (valobj)
823 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
824 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000825
Jim Ingham58b59f92011-04-22 23:53:53 +0000826 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000827}
828
Enrico Granata0c489f52012-03-01 04:24:26 +0000829bool
830ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
831 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000832{
Enrico Granata0c489f52012-03-01 04:24:26 +0000833 destination.clear();
834
835 // ideally we would like to bail out if passing NULL, but if we do so
836 // we end up not providing the summary for function pointers anymore
837 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
838 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000839
840 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000841
842 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
843 // information that we might care to see in a crash log. might be useful in very specific situations though.
844 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
845 GetTypeName().GetCString(),
846 GetName().GetCString(),
847 summary_ptr->GetDescription().c_str());*/
848
Enrico Granata0c489f52012-03-01 04:24:26 +0000849 if (UpdateValueIfNeeded (false))
850 {
851 if (summary_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000852 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000853 if (HasSyntheticValue())
854 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
855 summary_ptr->FormatObject(this, destination);
Enrico Granata0c489f52012-03-01 04:24:26 +0000856 }
857 else
858 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000859 ClangASTType clang_type = GetClangType();
Enrico Granata0c489f52012-03-01 04:24:26 +0000860
861 // Do some default printout for function pointers
862 if (clang_type)
Enrico Granata4becb372011-06-29 22:27:15 +0000863 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000864 if (clang_type.IsFunctionPointerType ())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000865 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000866 StreamString sstr;
Enrico Granata0c489f52012-03-01 04:24:26 +0000867 AddressType func_ptr_address_type = eAddressTypeInvalid;
868 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
869 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000870 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000871 switch (func_ptr_address_type)
Jim Ingham6035b672011-03-31 00:19:25 +0000872 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000873 case eAddressTypeInvalid:
874 case eAddressTypeFile:
875 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000876
Greg Claytoncc4d0142012-02-17 07:49:44 +0000877 case eAddressTypeLoad:
Enrico Granata0c489f52012-03-01 04:24:26 +0000878 {
879 ExecutionContext exe_ctx (GetExecutionContextRef());
880
881 Address so_addr;
882 Target *target = exe_ctx.GetTargetPtr();
883 if (target && target->GetSectionLoadList().IsEmpty() == false)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000884 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000885 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000886 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000887 so_addr.Dump (&sstr,
888 exe_ctx.GetBestExecutionContextScope(),
889 Address::DumpStyleResolvedDescription,
890 Address::DumpStyleSectionNameOffset);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000891 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000892 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000893 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000894 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000895
Greg Claytoncc4d0142012-02-17 07:49:44 +0000896 case eAddressTypeHost:
897 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +0000898 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000899 }
900 if (sstr.GetSize() > 0)
901 {
902 destination.assign (1, '(');
903 destination.append (sstr.GetData(), sstr.GetSize());
904 destination.append (1, ')');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000905 }
906 }
907 }
908 }
909 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000910 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000911 return !destination.empty();
912}
913
914const char *
915ValueObject::GetSummaryAsCString ()
916{
917 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
918 {
919 GetSummaryAsCString(GetSummaryFormat().get(),
920 m_summary_str);
921 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000922 if (m_summary_str.empty())
923 return NULL;
924 return m_summary_str.c_str();
925}
926
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000927bool
928ValueObject::IsCStringContainer(bool check_pointer)
929{
Greg Clayton57ee3062013-07-11 22:46:58 +0000930 ClangASTType pointee_or_element_clang_type;
931 const Flags type_flags (GetTypeInfo (&pointee_or_element_clang_type));
932 bool is_char_arr_ptr (type_flags.AnySet (ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer) &&
933 pointee_or_element_clang_type.IsCharType ());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000934 if (!is_char_arr_ptr)
935 return false;
936 if (!check_pointer)
937 return true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000938 if (type_flags.Test(ClangASTType::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000939 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000940 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000941 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000942 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000943 return (cstr_address != LLDB_INVALID_ADDRESS);
944}
945
Enrico Granata9128ee22011-09-06 19:20:51 +0000946size_t
947ValueObject::GetPointeeData (DataExtractor& data,
948 uint32_t item_idx,
949 uint32_t item_count)
950{
Greg Clayton57ee3062013-07-11 22:46:58 +0000951 ClangASTType pointee_or_element_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +0000952 const uint32_t type_info = GetTypeInfo (&pointee_or_element_clang_type);
Greg Clayton57ee3062013-07-11 22:46:58 +0000953 const bool is_pointer_type = type_info & ClangASTType::eTypeIsPointer;
954 const bool is_array_type = type_info & ClangASTType::eTypeIsArray;
Greg Clayton2452ab72013-02-08 22:02:02 +0000955 if (!(is_pointer_type || is_array_type))
Enrico Granata9128ee22011-09-06 19:20:51 +0000956 return 0;
957
958 if (item_count == 0)
959 return 0;
960
Greg Clayton57ee3062013-07-11 22:46:58 +0000961 const uint64_t item_type_size = pointee_or_element_clang_type.GetByteSize();
Enrico Granata9128ee22011-09-06 19:20:51 +0000962 const uint64_t bytes = item_count * item_type_size;
Enrico Granata9128ee22011-09-06 19:20:51 +0000963 const uint64_t offset = item_idx * item_type_size;
964
965 if (item_idx == 0 && item_count == 1) // simply a deref
966 {
Greg Clayton2452ab72013-02-08 22:02:02 +0000967 if (is_pointer_type)
Enrico Granata9128ee22011-09-06 19:20:51 +0000968 {
969 Error error;
970 ValueObjectSP pointee_sp = Dereference(error);
971 if (error.Fail() || pointee_sp.get() == NULL)
972 return 0;
973 return pointee_sp->GetDataExtractor().Copy(data);
974 }
975 else
976 {
977 ValueObjectSP child_sp = GetChildAtIndex(0, true);
978 if (child_sp.get() == NULL)
979 return 0;
980 return child_sp->GetDataExtractor().Copy(data);
981 }
982 return true;
983 }
984 else /* (items > 1) */
985 {
986 Error error;
987 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
988 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
989
990 AddressType addr_type;
Greg Clayton2452ab72013-02-08 22:02:02 +0000991 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +0000992
Enrico Granata9128ee22011-09-06 19:20:51 +0000993 switch (addr_type)
994 {
995 case eAddressTypeFile:
996 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000997 ModuleSP module_sp (GetModule());
998 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000999 {
Enrico Granata9c2efe32012-08-07 01:49:34 +00001000 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +00001001 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001002 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001003 ExecutionContext exe_ctx (GetExecutionContextRef());
1004 Target* target = exe_ctx.GetTargetPtr();
1005 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +00001006 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001007 heap_buf_ptr->SetByteSize(bytes);
1008 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
1009 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +00001010 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001011 data.SetData(data_sp);
1012 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +00001013 }
1014 }
1015 }
1016 }
1017 break;
1018 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +00001019 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001020 ExecutionContext exe_ctx (GetExecutionContextRef());
1021 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +00001022 if (process)
1023 {
1024 heap_buf_ptr->SetByteSize(bytes);
1025 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
1026 if (error.Success())
1027 {
1028 data.SetData(data_sp);
1029 return bytes_read;
1030 }
1031 }
1032 }
1033 break;
1034 case eAddressTypeHost:
1035 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001036 const uint64_t max_bytes = GetClangType().GetByteSize();
Greg Clayton2452ab72013-02-08 22:02:02 +00001037 if (max_bytes > offset)
1038 {
1039 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
1040 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
1041 data.SetData(data_sp);
1042 return bytes_read;
1043 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001044 }
1045 break;
1046 case eAddressTypeInvalid:
Enrico Granata9128ee22011-09-06 19:20:51 +00001047 break;
1048 }
1049 }
1050 return 0;
1051}
1052
Greg Claytonfaac1112013-03-14 18:31:44 +00001053uint64_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001054ValueObject::GetData (DataExtractor& data)
1055{
1056 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001057 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Clayton57ee3062013-07-11 22:46:58 +00001058 Error error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001059 if (error.Fail())
Sean Callananed185ab2013-04-19 19:47:32 +00001060 {
1061 if (m_data.GetByteSize())
1062 {
1063 data = m_data;
1064 return data.GetByteSize();
1065 }
1066 else
1067 {
1068 return 0;
1069 }
1070 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001071 data.SetAddressByteSize(m_data.GetAddressByteSize());
1072 data.SetByteOrder(m_data.GetByteOrder());
1073 return data.GetByteSize();
1074}
1075
Sean Callanan389823e2013-04-13 01:21:23 +00001076bool
1077ValueObject::SetData (DataExtractor &data, Error &error)
1078{
1079 error.Clear();
1080 // Make sure our value is up to date first so that our location and location
1081 // type is valid.
1082 if (!UpdateValueIfNeeded(false))
1083 {
1084 error.SetErrorString("unable to read value");
1085 return false;
1086 }
1087
1088 uint64_t count = 0;
Greg Clayton57ee3062013-07-11 22:46:58 +00001089 const Encoding encoding = GetClangType().GetEncoding(count);
Sean Callanan389823e2013-04-13 01:21:23 +00001090
1091 const size_t byte_size = GetByteSize();
1092
1093 Value::ValueType value_type = m_value.GetValueType();
1094
1095 switch (value_type)
1096 {
1097 case Value::eValueTypeScalar:
1098 {
1099 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1100
1101 if (!set_error.Success())
1102 {
1103 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1104 return false;
1105 }
1106 }
1107 break;
1108 case Value::eValueTypeLoadAddress:
1109 {
1110 // If it is a load address, then the scalar value is the storage location
1111 // of the data, and we have to shove this value down to that load location.
1112 ExecutionContext exe_ctx (GetExecutionContextRef());
1113 Process *process = exe_ctx.GetProcessPtr();
1114 if (process)
1115 {
1116 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1117 size_t bytes_written = process->WriteMemory(target_addr,
1118 data.GetDataStart(),
1119 byte_size,
1120 error);
1121 if (!error.Success())
1122 return false;
1123 if (bytes_written != byte_size)
1124 {
1125 error.SetErrorString("unable to write value to memory");
1126 return false;
1127 }
1128 }
1129 }
1130 break;
1131 case Value::eValueTypeHostAddress:
1132 {
1133 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1134 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1135 m_data.SetData(buffer_sp, 0);
1136 data.CopyByteOrderedData (0,
1137 byte_size,
1138 const_cast<uint8_t *>(m_data.GetDataStart()),
1139 byte_size,
1140 m_data.GetByteOrder());
1141 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1142 }
1143 break;
1144 case Value::eValueTypeFileAddress:
1145 case Value::eValueTypeVector:
1146 break;
1147 }
1148
1149 // If we have reached this point, then we have successfully changed the value.
1150 SetNeedsUpdate();
1151 return true;
1152}
1153
Enrico Granata9128ee22011-09-06 19:20:51 +00001154// will compute strlen(str), but without consuming more than
1155// maxlen bytes out of str (this serves the purpose of reading
1156// chunks of a string without having to worry about
1157// missing NULL terminators in the chunk)
1158// of course, if strlen(str) > maxlen, the function will return
1159// maxlen_value (which should be != maxlen, because that allows you
1160// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1161static uint32_t
1162strlen_or_inf (const char* str,
1163 uint32_t maxlen,
1164 uint32_t maxlen_value)
1165{
1166 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +00001167 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +00001168 {
Greg Clayton8dd5c172011-10-05 22:19:51 +00001169 while(*str)
1170 {
1171 len++;str++;
Greg Clayton2452ab72013-02-08 22:02:02 +00001172 if (len >= maxlen)
Greg Clayton8dd5c172011-10-05 22:19:51 +00001173 return maxlen_value;
1174 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001175 }
1176 return len;
1177}
1178
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001179size_t
Greg Claytoncc4d0142012-02-17 07:49:44 +00001180ValueObject::ReadPointedString (Stream& s,
1181 Error& error,
1182 uint32_t max_length,
1183 bool honor_array,
1184 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001185{
Greg Claytoncc4d0142012-02-17 07:49:44 +00001186 ExecutionContext exe_ctx (GetExecutionContextRef());
1187 Target* target = exe_ctx.GetTargetPtr();
1188
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001189 if (!target)
1190 {
1191 s << "<no target to read from>";
1192 error.SetErrorString("no target to read from");
1193 return 0;
1194 }
1195
1196 if (max_length == 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001197 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001198
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001199 size_t bytes_read = 0;
1200 size_t total_bytes_read = 0;
1201
Greg Clayton57ee3062013-07-11 22:46:58 +00001202 ClangASTType clang_type = GetClangType();
1203 ClangASTType elem_or_pointee_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001204 const Flags type_flags (GetTypeInfo (&elem_or_pointee_clang_type));
Greg Clayton57ee3062013-07-11 22:46:58 +00001205 if (type_flags.AnySet (ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer) &&
1206 elem_or_pointee_clang_type.IsCharType ())
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001207 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001208 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1209 AddressType cstr_address_type = eAddressTypeInvalid;
1210
1211 size_t cstr_len = 0;
1212 bool capped_data = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00001213 if (type_flags.Test (ClangASTType::eTypeIsArray))
Greg Claytoncc4d0142012-02-17 07:49:44 +00001214 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001215 // We have an array
Greg Clayton57ee3062013-07-11 22:46:58 +00001216 uint64_t array_size = 0;
1217 if (clang_type.IsArrayType(NULL, &array_size, NULL))
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001218 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001219 cstr_len = array_size;
1220 if (cstr_len > max_length)
1221 {
1222 capped_data = true;
1223 cstr_len = max_length;
1224 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001225 }
1226 cstr_address = GetAddressOf (true, &cstr_address_type);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001227 }
1228 else
1229 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001230 // We have a pointer
1231 cstr_address = GetPointerValue (&cstr_address_type);
1232 }
1233
1234 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1235 {
1236 s << "<invalid address>";
1237 error.SetErrorString("invalid address");
1238 return 0;
1239 }
1240
1241 Address cstr_so_addr (cstr_address);
1242 DataExtractor data;
1243 if (cstr_len > 0 && honor_array)
1244 {
1245 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1246 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1247 GetPointeeData(data, 0, cstr_len);
1248
1249 if ((bytes_read = data.GetByteSize()) > 0)
1250 {
1251 total_bytes_read = bytes_read;
1252 s << '"';
1253 data.Dump (&s,
1254 0, // Start offset in "data"
1255 item_format,
1256 1, // Size of item (1 byte for a char!)
1257 bytes_read, // How many bytes to print?
1258 UINT32_MAX, // num per line
1259 LLDB_INVALID_ADDRESS,// base address
1260 0, // bitfield bit size
1261 0); // bitfield bit offset
1262 if (capped_data)
1263 s << "...";
1264 s << '"';
1265 }
1266 }
1267 else
1268 {
1269 cstr_len = max_length;
1270 const size_t k_max_buf_size = 64;
1271
1272 size_t offset = 0;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001273
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001274 int cstr_len_displayed = -1;
1275 bool capped_cstr = false;
1276 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1277 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1278 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001279 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001280 total_bytes_read += bytes_read;
1281 const char *cstr = data.PeekCStr(0);
1282 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1283 if (len > k_max_buf_size)
1284 len = k_max_buf_size;
1285 if (cstr && cstr_len_displayed < 0)
1286 s << '"';
1287
1288 if (cstr_len_displayed < 0)
1289 cstr_len_displayed = len;
1290
1291 if (len == 0)
1292 break;
1293 cstr_len_displayed += len;
1294 if (len > bytes_read)
1295 len = bytes_read;
1296 if (len > cstr_len)
1297 len = cstr_len;
1298
1299 data.Dump (&s,
1300 0, // Start offset in "data"
1301 item_format,
1302 1, // Size of item (1 byte for a char!)
1303 len, // How many bytes to print?
1304 UINT32_MAX, // num per line
1305 LLDB_INVALID_ADDRESS,// base address
1306 0, // bitfield bit size
1307 0); // bitfield bit offset
1308
1309 if (len < k_max_buf_size)
1310 break;
1311
1312 if (len >= cstr_len)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001313 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001314 capped_cstr = true;
1315 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001316 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001317
1318 cstr_len -= len;
1319 offset += len;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001320 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001321
1322 if (cstr_len_displayed >= 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001323 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001324 s << '"';
1325 if (capped_cstr)
1326 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001327 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001328 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001329 }
1330 else
1331 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001332 error.SetErrorString("not a string object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001333 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001334 }
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001335 return total_bytes_read;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001336}
1337
Jim Ingham53c47f12010-09-10 23:12:17 +00001338const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001339ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001340{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001341
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001342 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001343 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001344
1345 if (!m_object_desc_str.empty())
1346 return m_object_desc_str.c_str();
1347
Greg Claytoncc4d0142012-02-17 07:49:44 +00001348 ExecutionContext exe_ctx (GetExecutionContextRef());
1349 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001350 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001351 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001352
Jim Ingham53c47f12010-09-10 23:12:17 +00001353 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001354
Greg Claytonafacd142011-09-02 01:15:17 +00001355 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001356 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1357
Jim Inghama2cf2632010-12-23 02:29:54 +00001358 if (runtime == NULL)
1359 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001360 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Greg Clayton57ee3062013-07-11 22:46:58 +00001361 ClangASTType clang_type = GetClangType();
1362 if (clang_type)
Jim Inghama2cf2632010-12-23 02:29:54 +00001363 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001364 bool is_signed;
Greg Clayton57ee3062013-07-11 22:46:58 +00001365 if (clang_type.IsIntegerType (is_signed) || clang_type.IsPointerType ())
Jim Inghamb7603bb2011-03-18 00:05:18 +00001366 {
Greg Claytonafacd142011-09-02 01:15:17 +00001367 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001368 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001369 }
1370 }
1371
Jim Ingham8d543de2011-03-31 23:01:21 +00001372 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001373 {
1374 m_object_desc_str.append (s.GetData());
1375 }
Sean Callanan672ad942010-10-23 00:18:49 +00001376
1377 if (m_object_desc_str.empty())
1378 return NULL;
1379 else
1380 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001381}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001382
Enrico Granata0c489f52012-03-01 04:24:26 +00001383bool
1384ValueObject::GetValueAsCString (lldb::Format format,
1385 std::string& destination)
1386{
Greg Clayton57ee3062013-07-11 22:46:58 +00001387 if (GetClangType().IsAggregateType () == false && UpdateValueIfNeeded(false))
Enrico Granata0c489f52012-03-01 04:24:26 +00001388 {
1389 const Value::ContextType context_type = m_value.GetContextType();
1390
Greg Clayton57ee3062013-07-11 22:46:58 +00001391 if (context_type == Value::eContextTypeRegisterInfo)
Enrico Granata0c489f52012-03-01 04:24:26 +00001392 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001393 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1394 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001395 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001396 ExecutionContext exe_ctx (GetExecutionContextRef());
1397
1398 StreamString reg_sstr;
1399 m_data.Dump (&reg_sstr,
1400 0,
1401 format,
1402 reg_info->byte_size,
1403 1,
1404 UINT32_MAX,
1405 LLDB_INVALID_ADDRESS,
1406 0,
1407 0,
1408 exe_ctx.GetBestExecutionContextScope());
1409 destination.swap(reg_sstr.GetString());
1410 }
1411 }
1412 else
1413 {
1414 ClangASTType clang_type = GetClangType ();
1415 if (clang_type)
1416 {
1417 // put custom bytes to display in this DataExtractor to override the default value logic
1418 lldb_private::DataExtractor special_format_data;
1419 if (format == eFormatCString)
Enrico Granata0c489f52012-03-01 04:24:26 +00001420 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001421 Flags type_flags(clang_type.GetTypeInfo(NULL));
1422 if (type_flags.Test(ClangASTType::eTypeIsPointer) && !type_flags.Test(ClangASTType::eTypeIsObjC))
Enrico Granata852cce72013-03-23 01:12:38 +00001423 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001424 // if we are dumping a pointer as a c-string, get the pointee data as a string
1425 TargetSP target_sp(GetTargetSP());
1426 if (target_sp)
Enrico Granata852cce72013-03-23 01:12:38 +00001427 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001428 size_t max_len = target_sp->GetMaximumSizeOfStringSummary();
1429 Error error;
1430 DataBufferSP buffer_sp(new DataBufferHeap(max_len+1,0));
1431 Address address(GetPointerValue());
1432 if (target_sp->ReadCStringFromMemory(address, (char*)buffer_sp->GetBytes(), max_len, error) && error.Success())
1433 special_format_data.SetData(buffer_sp);
Enrico Granata852cce72013-03-23 01:12:38 +00001434 }
1435 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001436 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001437
Greg Clayton57ee3062013-07-11 22:46:58 +00001438 StreamString sstr;
1439 ExecutionContext exe_ctx (GetExecutionContextRef());
1440 clang_type.DumpTypeValue (&sstr, // The stream to use for display
1441 format, // Format to display this type with
1442 special_format_data.GetByteSize() ?
1443 special_format_data: m_data, // Data to extract from
1444 0, // Byte offset into "m_data"
1445 GetByteSize(), // Byte size of item in "m_data"
1446 GetBitfieldBitSize(), // Bitfield bit size
1447 GetBitfieldBitOffset(), // Bitfield bit offset
1448 exe_ctx.GetBestExecutionContextScope());
1449 // Don't set the m_error to anything here otherwise
1450 // we won't be able to re-format as anything else. The
1451 // code for ClangASTType::DumpTypeValue() should always
1452 // return something, even if that something contains
1453 // an error messsage. "m_error" is used to detect errors
1454 // when reading the valid object, not for formatting errors.
1455 if (sstr.GetString().empty())
1456 destination.clear();
1457 else
1458 destination.swap(sstr.GetString());
Enrico Granata0c489f52012-03-01 04:24:26 +00001459 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001460 }
1461 return !destination.empty();
1462 }
1463 else
1464 return false;
1465}
1466
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001467const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001468ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001469{
Enrico Granatab294fd22013-05-31 19:18:19 +00001470 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001471 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001472 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001473 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001474 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001475 if (m_type_format_sp)
1476 my_format = m_type_format_sp->GetFormat();
1477 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001478 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001479 if (m_is_bitfield_for_scalar)
1480 my_format = eFormatUnsigned;
1481 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001482 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001483 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001484 {
1485 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1486 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001487 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001488 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001489 else
1490 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001491 my_format = GetClangType().GetFormat();
Enrico Granata0c489f52012-03-01 04:24:26 +00001492 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001493 }
1494 }
1495 }
Enrico Granatab294fd22013-05-31 19:18:19 +00001496 if (my_format != m_last_format || m_value_str.empty())
Enrico Granata297e69f2012-03-06 23:21:16 +00001497 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001498 m_last_format = my_format;
1499 if (GetValueAsCString(my_format, m_value_str))
Enrico Granata297e69f2012-03-06 23:21:16 +00001500 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001501 if (!m_value_did_change && m_old_value_valid)
1502 {
1503 // The value was gotten successfully, so we consider the
1504 // value as changed if the value string differs
1505 SetValueDidChange (m_old_value_str != m_value_str);
1506 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001507 }
1508 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001509 }
1510 if (m_value_str.empty())
1511 return NULL;
1512 return m_value_str.c_str();
1513}
1514
Enrico Granatac3e320a2011-08-02 17:27:39 +00001515// if > 8bytes, 0 is returned. this method should mostly be used
1516// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001517uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001518ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001519{
1520 // If our byte size is zero this is an aggregate type that has children
Greg Clayton57ee3062013-07-11 22:46:58 +00001521 if (!GetClangType().IsAggregateType())
Enrico Granatac3e320a2011-08-02 17:27:39 +00001522 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001523 Scalar scalar;
1524 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001525 {
1526 if (success)
1527 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001528 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001529 }
1530 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001531 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001532
1533 if (success)
1534 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001535 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001536}
1537
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001538// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1539// this call up to date by returning true for your new special cases. We will eventually move
1540// to checking this call result before trying to display special cases
1541bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001542ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1543 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001544{
Greg Clayton57ee3062013-07-11 22:46:58 +00001545 Flags flags(GetTypeInfo());
1546 if (flags.AnySet(ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001547 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001548 {
1549 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001550 (custom_format == eFormatCString ||
1551 custom_format == eFormatCharArray ||
1552 custom_format == eFormatChar ||
1553 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001554 return true;
1555
Greg Clayton57ee3062013-07-11 22:46:58 +00001556 if (flags.Test(ClangASTType::eTypeIsArray))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001557 {
Greg Claytonafacd142011-09-02 01:15:17 +00001558 if ((custom_format == eFormatBytes) ||
1559 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001560 return true;
1561
Greg Claytonafacd142011-09-02 01:15:17 +00001562 if ((custom_format == eFormatVectorOfChar) ||
1563 (custom_format == eFormatVectorOfFloat32) ||
1564 (custom_format == eFormatVectorOfFloat64) ||
1565 (custom_format == eFormatVectorOfSInt16) ||
1566 (custom_format == eFormatVectorOfSInt32) ||
1567 (custom_format == eFormatVectorOfSInt64) ||
1568 (custom_format == eFormatVectorOfSInt8) ||
1569 (custom_format == eFormatVectorOfUInt128) ||
1570 (custom_format == eFormatVectorOfUInt16) ||
1571 (custom_format == eFormatVectorOfUInt32) ||
1572 (custom_format == eFormatVectorOfUInt64) ||
1573 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001574 return true;
1575 }
1576 }
1577 return false;
1578}
1579
Enrico Granata9fc19442011-07-06 02:13:41 +00001580bool
1581ValueObject::DumpPrintableRepresentation(Stream& s,
1582 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001583 Format custom_format,
Enrico Granata86cc9822012-03-19 22:58:49 +00001584 PrintableRepresentationSpecialCases special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001585{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001586
Greg Clayton57ee3062013-07-11 22:46:58 +00001587 Flags flags(GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001588
Enrico Granata86cc9822012-03-19 22:58:49 +00001589 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1590 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1591
1592 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001593 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001594 if (flags.AnySet(ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001595 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001596 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001597 // when being asked to get a printable display an array or pointer type directly,
1598 // try to "do the right thing"
1599
1600 if (IsCStringContainer(true) &&
1601 (custom_format == eFormatCString ||
1602 custom_format == eFormatCharArray ||
1603 custom_format == eFormatChar ||
1604 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001605 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001606 Error error;
1607 ReadPointedString(s,
1608 error,
1609 0,
1610 (custom_format == eFormatVectorOfChar) ||
1611 (custom_format == eFormatCharArray));
1612 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001613 }
1614
Enrico Granata86cc9822012-03-19 22:58:49 +00001615 if (custom_format == eFormatEnum)
1616 return false;
1617
1618 // this only works for arrays, because I have no way to know when
1619 // the pointed memory ends, and no special \0 end of data marker
Greg Clayton57ee3062013-07-11 22:46:58 +00001620 if (flags.Test(ClangASTType::eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001621 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001622 if ((custom_format == eFormatBytes) ||
1623 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001624 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001625 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001626
1627 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001628 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001629 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001630
1631 if (low)
1632 s << ',';
1633
1634 ValueObjectSP child = GetChildAtIndex(low,true);
1635 if (!child.get())
1636 {
1637 s << "<invalid child>";
1638 continue;
1639 }
1640 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1641 }
1642
1643 s << ']';
1644
1645 return true;
1646 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001647
Enrico Granata86cc9822012-03-19 22:58:49 +00001648 if ((custom_format == eFormatVectorOfChar) ||
1649 (custom_format == eFormatVectorOfFloat32) ||
1650 (custom_format == eFormatVectorOfFloat64) ||
1651 (custom_format == eFormatVectorOfSInt16) ||
1652 (custom_format == eFormatVectorOfSInt32) ||
1653 (custom_format == eFormatVectorOfSInt64) ||
1654 (custom_format == eFormatVectorOfSInt8) ||
1655 (custom_format == eFormatVectorOfUInt128) ||
1656 (custom_format == eFormatVectorOfUInt16) ||
1657 (custom_format == eFormatVectorOfUInt32) ||
1658 (custom_format == eFormatVectorOfUInt64) ||
1659 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1660 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001661 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001662
1663 Format format = FormatManager::GetSingleItemFormat(custom_format);
1664
1665 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001666 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001667 {
1668
1669 if (low)
1670 s << ',';
1671
1672 ValueObjectSP child = GetChildAtIndex(low,true);
1673 if (!child.get())
1674 {
1675 s << "<invalid child>";
1676 continue;
1677 }
1678 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1679 }
1680
1681 s << ']';
1682
1683 return true;
1684 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001685 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001686
1687 if ((custom_format == eFormatBoolean) ||
1688 (custom_format == eFormatBinary) ||
1689 (custom_format == eFormatChar) ||
1690 (custom_format == eFormatCharPrintable) ||
1691 (custom_format == eFormatComplexFloat) ||
1692 (custom_format == eFormatDecimal) ||
1693 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001694 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001695 (custom_format == eFormatFloat) ||
1696 (custom_format == eFormatOctal) ||
1697 (custom_format == eFormatOSType) ||
1698 (custom_format == eFormatUnicode16) ||
1699 (custom_format == eFormatUnicode32) ||
1700 (custom_format == eFormatUnsigned) ||
1701 (custom_format == eFormatPointer) ||
1702 (custom_format == eFormatComplexInteger) ||
1703 (custom_format == eFormatComplex) ||
1704 (custom_format == eFormatDefault)) // use the [] operator
1705 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001706 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001707 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001708
1709 if (only_special)
1710 return false;
1711
Enrico Granata86cc9822012-03-19 22:58:49 +00001712 bool var_success = false;
1713
1714 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001715 const char *cstr = NULL;
Enrico Granata2c75f112013-06-21 00:04:51 +00001716
1717 // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1718 // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1719 // area for cases where our desired output is not backed by some other longer-term storage
Greg Claytonc7bece562013-01-25 18:06:21 +00001720 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001721
1722 if (custom_format != eFormatInvalid)
1723 SetFormat(custom_format);
1724
1725 switch(val_obj_display)
1726 {
1727 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001728 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001729 break;
1730
1731 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001732 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001733 break;
1734
1735 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001736 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001737 break;
1738
1739 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001740 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001741 break;
1742
1743 case eValueObjectRepresentationStyleChildrenCount:
Greg Claytonc7bece562013-01-25 18:06:21 +00001744 strm.Printf("%zu", GetNumChildren());
1745 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001746 break;
1747
1748 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001749 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001750 break;
Enrico Granata2c75f112013-06-21 00:04:51 +00001751
1752 case eValueObjectRepresentationStyleName:
1753 cstr = GetName().AsCString();
1754 break;
1755
1756 case eValueObjectRepresentationStyleExpressionPath:
1757 GetExpressionPath(strm, false);
1758 cstr = strm.GetString().c_str();
1759 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001760 }
1761
Greg Claytonc7bece562013-01-25 18:06:21 +00001762 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001763 {
1764 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001765 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001766 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1767 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001768 if (GetClangType().IsAggregateType())
Enrico Granata86cc9822012-03-19 22:58:49 +00001769 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001770 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1771 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001772 }
1773 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001774 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001775 }
1776 }
1777
Greg Claytonc7bece562013-01-25 18:06:21 +00001778 if (cstr)
1779 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001780 else
1781 {
1782 if (m_error.Fail())
1783 s.Printf("<%s>", m_error.AsCString());
1784 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1785 s.PutCString("<no summary available>");
1786 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1787 s.PutCString("<no value available>");
1788 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1789 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1790 else
1791 s.PutCString("<no printable representation>");
1792 }
1793
1794 // we should only return false here if we could not do *anything*
1795 // even if we have an error message as output, that's a success
1796 // from our callers' perspective, so return true
1797 var_success = true;
1798
1799 if (custom_format != eFormatInvalid)
1800 SetFormat(eFormatDefault);
1801 }
1802
Enrico Granataf4efecd2011-07-12 22:56:10 +00001803 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001804}
1805
Greg Clayton737b9322010-09-13 03:32:57 +00001806addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001807ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001808{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001809 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001810 return LLDB_INVALID_ADDRESS;
1811
Greg Clayton73b472d2010-10-27 03:32:59 +00001812 switch (m_value.GetValueType())
1813 {
1814 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001815 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001816 if (scalar_is_load_address)
1817 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001818 if(address_type)
1819 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001820 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1821 }
1822 break;
1823
1824 case Value::eValueTypeLoadAddress:
1825 case Value::eValueTypeFileAddress:
1826 case Value::eValueTypeHostAddress:
1827 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001828 if(address_type)
1829 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001830 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1831 }
1832 break;
1833 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001834 if (address_type)
1835 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001836 return LLDB_INVALID_ADDRESS;
1837}
1838
1839addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001840ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001841{
Greg Claytonafacd142011-09-02 01:15:17 +00001842 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001843 if(address_type)
1844 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001845
Enrico Granatac3e320a2011-08-02 17:27:39 +00001846 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001847 return address;
1848
Greg Clayton73b472d2010-10-27 03:32:59 +00001849 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001850 {
1851 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001852 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001853 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001854 break;
1855
Enrico Granata9128ee22011-09-06 19:20:51 +00001856 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001857 case Value::eValueTypeLoadAddress:
1858 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001859 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001860 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001861 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001862 }
1863 break;
1864 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001865
Enrico Granata9128ee22011-09-06 19:20:51 +00001866 if (address_type)
1867 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001868
Greg Clayton737b9322010-09-13 03:32:57 +00001869 return address;
1870}
1871
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001872bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001873ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001874{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001875 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001876 // Make sure our value is up to date first so that our location and location
1877 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001878 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001879 {
1880 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001881 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001882 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001883
Greg Claytonfaac1112013-03-14 18:31:44 +00001884 uint64_t count = 0;
Greg Clayton57ee3062013-07-11 22:46:58 +00001885 const Encoding encoding = GetClangType().GetEncoding (count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001886
Greg Claytonb1320972010-07-14 00:18:15 +00001887 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001888
Jim Ingham16e0c682011-08-12 23:34:31 +00001889 Value::ValueType value_type = m_value.GetValueType();
1890
1891 if (value_type == Value::eValueTypeScalar)
1892 {
1893 // If the value is already a scalar, then let the scalar change itself:
1894 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1895 }
1896 else if (byte_size <= Scalar::GetMaxByteSize())
1897 {
1898 // If the value fits in a scalar, then make a new scalar and again let the
1899 // scalar code do the conversion, then figure out where to put the new value.
1900 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001901 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1902 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001903 {
Jim Ingham4b536182011-08-09 02:12:22 +00001904 switch (value_type)
1905 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001906 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001907 {
1908 // If it is a load address, then the scalar value is the storage location
1909 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001910 ExecutionContext exe_ctx (GetExecutionContextRef());
1911 Process *process = exe_ctx.GetProcessPtr();
1912 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001913 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001914 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001915 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1916 new_scalar,
1917 byte_size,
1918 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001919 if (!error.Success())
1920 return false;
1921 if (bytes_written != byte_size)
1922 {
1923 error.SetErrorString("unable to write value to memory");
1924 return false;
1925 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001926 }
1927 }
Jim Ingham4b536182011-08-09 02:12:22 +00001928 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001929 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001930 {
1931 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1932 DataExtractor new_data;
1933 new_data.SetByteOrder (m_data.GetByteOrder());
1934
1935 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1936 m_data.SetData(buffer_sp, 0);
1937 bool success = new_scalar.GetData(new_data);
1938 if (success)
1939 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001940 new_data.CopyByteOrderedData (0,
1941 byte_size,
1942 const_cast<uint8_t *>(m_data.GetDataStart()),
1943 byte_size,
1944 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001945 }
1946 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1947
1948 }
Jim Ingham4b536182011-08-09 02:12:22 +00001949 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001950 case Value::eValueTypeFileAddress:
1951 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001952 case Value::eValueTypeVector:
1953 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001954 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001955 }
1956 else
1957 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001958 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001959 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001960 }
1961 else
1962 {
1963 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001964 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001965 return false;
1966 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001967
1968 // If we have reached this point, then we have successfully changed the value.
1969 SetNeedsUpdate();
1970 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001971}
1972
Greg Clayton81e871e2012-02-04 02:27:34 +00001973bool
1974ValueObject::GetDeclaration (Declaration &decl)
1975{
1976 decl.Clear();
1977 return false;
1978}
1979
Greg Clayton84db9102012-03-26 23:03:23 +00001980ConstString
1981ValueObject::GetTypeName()
1982{
Greg Clayton57ee3062013-07-11 22:46:58 +00001983 return GetClangType().GetConstTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00001984}
1985
1986ConstString
1987ValueObject::GetQualifiedTypeName()
1988{
Greg Clayton57ee3062013-07-11 22:46:58 +00001989 return GetClangType().GetConstQualifiedTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00001990}
1991
1992
Greg Claytonafacd142011-09-02 01:15:17 +00001993LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001994ValueObject::GetObjectRuntimeLanguage ()
1995{
Greg Clayton57ee3062013-07-11 22:46:58 +00001996 return GetClangType().GetMinimumLanguage ();
Jim Ingham5a369122010-09-28 01:25:32 +00001997}
1998
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001999void
Jim Ingham58b59f92011-04-22 23:53:53 +00002000ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002001{
Jim Ingham58b59f92011-04-22 23:53:53 +00002002 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002003}
2004
2005ValueObjectSP
2006ValueObject::GetSyntheticChild (const ConstString &key) const
2007{
2008 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00002009 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002010 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00002011 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002012 return synthetic_child_sp;
2013}
2014
Greg Clayton2452ab72013-02-08 22:02:02 +00002015uint32_t
Greg Clayton57ee3062013-07-11 22:46:58 +00002016ValueObject::GetTypeInfo (ClangASTType *pointee_or_element_clang_type)
Greg Clayton2452ab72013-02-08 22:02:02 +00002017{
Greg Clayton57ee3062013-07-11 22:46:58 +00002018 return GetClangType().GetTypeInfo (pointee_or_element_clang_type);
Greg Clayton2452ab72013-02-08 22:02:02 +00002019}
2020
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002021bool
2022ValueObject::IsPointerType ()
2023{
Greg Clayton57ee3062013-07-11 22:46:58 +00002024 return GetClangType().IsPointerType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002025}
2026
Jim Inghamb7603bb2011-03-18 00:05:18 +00002027bool
Greg Claytondaf515f2011-07-09 20:12:33 +00002028ValueObject::IsArrayType ()
2029{
Greg Clayton57ee3062013-07-11 22:46:58 +00002030 return GetClangType().IsArrayType (NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00002031}
2032
2033bool
Enrico Granata9fc19442011-07-06 02:13:41 +00002034ValueObject::IsScalarType ()
2035{
Greg Clayton57ee3062013-07-11 22:46:58 +00002036 return GetClangType().IsScalarType ();
Enrico Granata9fc19442011-07-06 02:13:41 +00002037}
2038
2039bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00002040ValueObject::IsIntegerType (bool &is_signed)
2041{
Greg Clayton57ee3062013-07-11 22:46:58 +00002042 return GetClangType().IsIntegerType (is_signed);
Jim Inghamb7603bb2011-03-18 00:05:18 +00002043}
Greg Clayton73b472d2010-10-27 03:32:59 +00002044
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002045bool
2046ValueObject::IsPointerOrReferenceType ()
2047{
Greg Clayton57ee3062013-07-11 22:46:58 +00002048 return GetClangType().IsPointerOrReferenceType ();
Greg Clayton007d5be2011-05-30 00:49:24 +00002049}
2050
2051bool
Greg Claytondea8cb42011-06-29 22:09:02 +00002052ValueObject::IsPossibleDynamicType ()
2053{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002054 ExecutionContext exe_ctx (GetExecutionContextRef());
2055 Process *process = exe_ctx.GetProcessPtr();
2056 if (process)
2057 return process->IsPossibleDynamicValue(*this);
2058 else
Greg Clayton57ee3062013-07-11 22:46:58 +00002059 return GetClangType().IsPossibleDynamicType (NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00002060}
2061
Enrico Granata9e7b3882012-12-13 23:50:33 +00002062bool
2063ValueObject::IsObjCNil ()
2064{
Greg Clayton57ee3062013-07-11 22:46:58 +00002065 const uint32_t mask = ClangASTType::eTypeIsObjC | ClangASTType::eTypeIsPointer;
2066 bool isObjCpointer = (((GetClangType().GetTypeInfo(NULL)) & mask) == mask);
Enrico Granata7277d202013-03-15 23:33:15 +00002067 if (!isObjCpointer)
2068 return false;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002069 bool canReadValue = true;
2070 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
Enrico Granata7277d202013-03-15 23:33:15 +00002071 return canReadValue && isZero;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002072}
2073
Greg Claytonafacd142011-09-02 01:15:17 +00002074ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002075ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002076{
Greg Clayton2452ab72013-02-08 22:02:02 +00002077 const uint32_t type_info = GetTypeInfo ();
Greg Clayton57ee3062013-07-11 22:46:58 +00002078 if (type_info & ClangASTType::eTypeIsArray)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002079 return GetSyntheticArrayMemberFromArray(index, can_create);
2080
Greg Clayton57ee3062013-07-11 22:46:58 +00002081 if (type_info & ClangASTType::eTypeIsPointer)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002082 return GetSyntheticArrayMemberFromPointer(index, can_create);
2083
2084 return ValueObjectSP();
2085
2086}
2087
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002088ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002089ValueObject::GetSyntheticArrayMemberFromPointer (size_t index, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002090{
2091 ValueObjectSP synthetic_child_sp;
2092 if (IsPointerType ())
2093 {
2094 char index_str[64];
Greg Claytonc7bece562013-01-25 18:06:21 +00002095 snprintf(index_str, sizeof(index_str), "[%zu]", index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002096 ConstString index_const_str(index_str);
2097 // Check if we have already created a synthetic array member in this
2098 // valid object. If we have we will re-use it.
2099 synthetic_child_sp = GetSyntheticChild (index_const_str);
2100 if (!synthetic_child_sp)
2101 {
Jim Ingham58b59f92011-04-22 23:53:53 +00002102 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002103 // We haven't made a synthetic array member for INDEX yet, so
2104 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00002105 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002106
2107 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00002108 if (synthetic_child)
2109 {
2110 AddSyntheticChild(index_const_str, synthetic_child);
2111 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002112 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00002113 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00002114 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002115 }
2116 }
2117 return synthetic_child_sp;
2118}
Jim Ingham22777012010-09-23 02:01:19 +00002119
Greg Claytondaf515f2011-07-09 20:12:33 +00002120// This allows you to create an array member using and index
2121// that doesn't not fall in the normal bounds of the array.
2122// Many times structure can be defined as:
2123// struct Collection
2124// {
2125// uint32_t item_count;
2126// Item item_array[0];
2127// };
2128// The size of the "item_array" is 1, but many times in practice
2129// there are more items in "item_array".
2130
2131ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002132ValueObject::GetSyntheticArrayMemberFromArray (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00002133{
2134 ValueObjectSP synthetic_child_sp;
2135 if (IsArrayType ())
2136 {
2137 char index_str[64];
Greg Claytonc7bece562013-01-25 18:06:21 +00002138 snprintf(index_str, sizeof(index_str), "[%zu]", index);
Greg Claytondaf515f2011-07-09 20:12:33 +00002139 ConstString index_const_str(index_str);
2140 // Check if we have already created a synthetic array member in this
2141 // valid object. If we have we will re-use it.
2142 synthetic_child_sp = GetSyntheticChild (index_const_str);
2143 if (!synthetic_child_sp)
2144 {
2145 ValueObject *synthetic_child;
2146 // We haven't made a synthetic array member for INDEX yet, so
2147 // lets make one and cache it for any future reference.
2148 synthetic_child = CreateChildAtIndex(0, true, index);
2149
2150 // Cache the value if we got one back...
2151 if (synthetic_child)
2152 {
2153 AddSyntheticChild(index_const_str, synthetic_child);
2154 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002155 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00002156 synthetic_child_sp->m_is_array_item_for_pointer = true;
2157 }
2158 }
2159 }
2160 return synthetic_child_sp;
2161}
2162
Enrico Granata9fc19442011-07-06 02:13:41 +00002163ValueObjectSP
2164ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2165{
2166 ValueObjectSP synthetic_child_sp;
2167 if (IsScalarType ())
2168 {
2169 char index_str[64];
2170 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2171 ConstString index_const_str(index_str);
2172 // Check if we have already created a synthetic array member in this
2173 // valid object. If we have we will re-use it.
2174 synthetic_child_sp = GetSyntheticChild (index_const_str);
2175 if (!synthetic_child_sp)
2176 {
Enrico Granata9fc19442011-07-06 02:13:41 +00002177 // We haven't made a synthetic array member for INDEX yet, so
2178 // lets make one and cache it for any future reference.
Greg Clayton57ee3062013-07-11 22:46:58 +00002179 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
2180 GetClangType(),
2181 index_const_str,
2182 GetByteSize(),
2183 0,
2184 to-from+1,
2185 from,
2186 false,
2187 false,
2188 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002189
2190 // Cache the value if we got one back...
2191 if (synthetic_child)
2192 {
2193 AddSyntheticChild(index_const_str, synthetic_child);
2194 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002195 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002196 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2197 }
2198 }
2199 }
2200 return synthetic_child_sp;
2201}
2202
Greg Claytonafacd142011-09-02 01:15:17 +00002203ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00002204ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
2205{
2206
2207 ValueObjectSP synthetic_child_sp;
2208
2209 char name_str[64];
2210 snprintf(name_str, sizeof(name_str), "@%i", offset);
2211 ConstString name_const_str(name_str);
2212
2213 // Check if we have already created a synthetic array member in this
2214 // valid object. If we have we will re-use it.
2215 synthetic_child_sp = GetSyntheticChild (name_const_str);
2216
2217 if (synthetic_child_sp.get())
2218 return synthetic_child_sp;
2219
2220 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002221 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002222
2223 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
Greg Clayton57ee3062013-07-11 22:46:58 +00002224 type,
Enrico Granata6f3533f2011-07-29 19:53:35 +00002225 name_const_str,
Greg Clayton57ee3062013-07-11 22:46:58 +00002226 type.GetByteSize(),
Enrico Granata6f3533f2011-07-29 19:53:35 +00002227 offset,
2228 0,
2229 0,
2230 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002231 false,
2232 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002233 if (synthetic_child)
2234 {
2235 AddSyntheticChild(name_const_str, synthetic_child);
2236 synthetic_child_sp = synthetic_child->GetSP();
2237 synthetic_child_sp->SetName(name_const_str);
2238 synthetic_child_sp->m_is_child_at_offset = true;
2239 }
2240 return synthetic_child_sp;
2241}
2242
Enrico Granatad55546b2011-07-22 00:16:08 +00002243// your expression path needs to have a leading . or ->
2244// (unless it somehow "looks like" an array, in which case it has
2245// a leading [ symbol). while the [ is meaningful and should be shown
2246// to the user, . and -> are just parser design, but by no means
2247// added information for the user.. strip them off
2248static const char*
2249SkipLeadingExpressionPathSeparators(const char* expression)
2250{
2251 if (!expression || !expression[0])
2252 return expression;
2253 if (expression[0] == '.')
2254 return expression+1;
2255 if (expression[0] == '-' && expression[1] == '>')
2256 return expression+2;
2257 return expression;
2258}
2259
Greg Claytonafacd142011-09-02 01:15:17 +00002260ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002261ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2262{
2263 ValueObjectSP synthetic_child_sp;
2264 ConstString name_const_string(expression);
2265 // Check if we have already created a synthetic array member in this
2266 // valid object. If we have we will re-use it.
2267 synthetic_child_sp = GetSyntheticChild (name_const_string);
2268 if (!synthetic_child_sp)
2269 {
2270 // We haven't made a synthetic array member for expression yet, so
2271 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002272 synthetic_child_sp = GetValueForExpressionPath(expression,
2273 NULL, NULL, NULL,
2274 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
Enrico Granatad55546b2011-07-22 00:16:08 +00002275
2276 // Cache the value if we got one back...
2277 if (synthetic_child_sp.get())
2278 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002279 // 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 +00002280 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002281 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002282 }
2283 }
2284 return synthetic_child_sp;
2285}
2286
2287void
Enrico Granata86cc9822012-03-19 22:58:49 +00002288ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002289{
Enrico Granata86cc9822012-03-19 22:58:49 +00002290 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002291 return;
2292
Enrico Granatac5bc4122012-03-27 02:35:13 +00002293 TargetSP target_sp(GetTargetSP());
2294 if (target_sp && (target_sp->GetEnableSyntheticValue() == false || target_sp->GetSuppressSyntheticValue() == true))
2295 {
2296 m_synthetic_value = NULL;
2297 return;
2298 }
2299
Enrico Granatae3e91512012-10-22 18:18:36 +00002300 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2301
Enrico Granata5548cb52013-01-28 23:47:25 +00002302 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002303 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002304
Enrico Granata0c489f52012-03-01 04:24:26 +00002305 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002306 return;
2307
Enrico Granatae3e91512012-10-22 18:18:36 +00002308 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2309 return;
2310
Enrico Granata86cc9822012-03-19 22:58:49 +00002311 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002312}
2313
Jim Ingham78a685a2011-04-16 00:01:13 +00002314void
Greg Claytonafacd142011-09-02 01:15:17 +00002315ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002316{
Greg Claytonafacd142011-09-02 01:15:17 +00002317 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002318 return;
2319
Jim Ingham58b59f92011-04-22 23:53:53 +00002320 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002321 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002322 ExecutionContext exe_ctx (GetExecutionContextRef());
2323 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002324 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002325 {
2326 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002327 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002328 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002329 }
2330}
2331
Jim Ingham58b59f92011-04-22 23:53:53 +00002332ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002333ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002334{
Greg Claytonafacd142011-09-02 01:15:17 +00002335 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002336 return ValueObjectSP();
2337
2338 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002339 {
Jim Ingham2837b762011-05-04 03:43:18 +00002340 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002341 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002342 if (m_dynamic_value)
2343 return m_dynamic_value->GetSP();
2344 else
2345 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002346}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002347
Jim Ingham60dbabb2011-12-08 19:44:08 +00002348ValueObjectSP
2349ValueObject::GetStaticValue()
2350{
2351 return GetSP();
2352}
2353
Enrico Granata886147f2012-05-08 18:47:08 +00002354lldb::ValueObjectSP
2355ValueObject::GetNonSyntheticValue ()
2356{
2357 return GetSP();
2358}
2359
Enrico Granatad55546b2011-07-22 00:16:08 +00002360ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002361ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002362{
Enrico Granata86cc9822012-03-19 22:58:49 +00002363 if (use_synthetic == false)
2364 return ValueObjectSP();
2365
Enrico Granatad55546b2011-07-22 00:16:08 +00002366 CalculateSyntheticValue(use_synthetic);
2367
2368 if (m_synthetic_value)
2369 return m_synthetic_value->GetSP();
2370 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002371 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002372}
2373
Greg Claytone221f822011-01-21 01:59:00 +00002374bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002375ValueObject::HasSyntheticValue()
2376{
Enrico Granata5548cb52013-01-28 23:47:25 +00002377 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002378
Enrico Granata0c489f52012-03-01 04:24:26 +00002379 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002380 return false;
2381
Enrico Granata86cc9822012-03-19 22:58:49 +00002382 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002383
2384 if (m_synthetic_value)
2385 return true;
2386 else
2387 return false;
2388}
2389
2390bool
Greg Claytone221f822011-01-21 01:59:00 +00002391ValueObject::GetBaseClassPath (Stream &s)
2392{
2393 if (IsBaseClass())
2394 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002395 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Clayton57ee3062013-07-11 22:46:58 +00002396 ClangASTType clang_type = GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002397 std::string cxx_class_name;
Greg Clayton57ee3062013-07-11 22:46:58 +00002398 bool this_had_base_class = clang_type.GetCXXClassName (cxx_class_name);
Greg Claytone221f822011-01-21 01:59:00 +00002399 if (this_had_base_class)
2400 {
2401 if (parent_had_base_class)
2402 s.PutCString("::");
2403 s.PutCString(cxx_class_name.c_str());
2404 }
2405 return parent_had_base_class || this_had_base_class;
2406 }
2407 return false;
2408}
2409
2410
2411ValueObject *
2412ValueObject::GetNonBaseClassParent()
2413{
Jim Ingham78a685a2011-04-16 00:01:13 +00002414 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002415 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002416 if (GetParent()->IsBaseClass())
2417 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002418 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002419 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002420 }
2421 return NULL;
2422}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002423
2424void
Enrico Granata4becb372011-06-29 22:27:15 +00002425ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002426{
Greg Claytone221f822011-01-21 01:59:00 +00002427 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002428
Enrico Granata86cc9822012-03-19 22:58:49 +00002429 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002430 {
Enrico Granata4becb372011-06-29 22:27:15 +00002431 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2432 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2433 // the eHonorPointers mode is meant to produce strings in this latter format
2434 s.PutCString("*(");
2435 }
Greg Claytone221f822011-01-21 01:59:00 +00002436
Enrico Granata4becb372011-06-29 22:27:15 +00002437 ValueObject* parent = GetParent();
2438
2439 if (parent)
2440 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002441
2442 // if we are a deref_of_parent just because we are synthetic array
2443 // members made up to allow ptr[%d] syntax to work in variable
2444 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002445 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002446 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002447
Greg Claytone221f822011-01-21 01:59:00 +00002448 if (!IsBaseClass())
2449 {
2450 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002451 {
Greg Claytone221f822011-01-21 01:59:00 +00002452 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2453 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002454 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002455 ClangASTType non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002456 if (non_base_class_parent_clang_type)
2457 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002458 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002459 {
2460 s.PutCString("->");
2461 }
Enrico Granata4becb372011-06-29 22:27:15 +00002462 else
2463 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002464 const uint32_t non_base_class_parent_type_info = non_base_class_parent_clang_type.GetTypeInfo();
2465
2466 if (non_base_class_parent_type_info & ClangASTType::eTypeIsPointer)
Enrico Granata4becb372011-06-29 22:27:15 +00002467 {
2468 s.PutCString("->");
2469 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002470 else if ((non_base_class_parent_type_info & ClangASTType::eTypeHasChildren) &&
2471 !(non_base_class_parent_type_info & ClangASTType::eTypeIsArray))
Enrico Granata4becb372011-06-29 22:27:15 +00002472 {
2473 s.PutChar('.');
2474 }
Greg Claytone221f822011-01-21 01:59:00 +00002475 }
2476 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002477 }
Greg Claytone221f822011-01-21 01:59:00 +00002478
2479 const char *name = GetName().GetCString();
2480 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002481 {
Greg Claytone221f822011-01-21 01:59:00 +00002482 if (qualify_cxx_base_classes)
2483 {
2484 if (GetBaseClassPath (s))
2485 s.PutCString("::");
2486 }
2487 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002488 }
2489 }
2490 }
2491
Enrico Granata86cc9822012-03-19 22:58:49 +00002492 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002493 {
Greg Claytone221f822011-01-21 01:59:00 +00002494 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002495 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002496}
2497
Greg Claytonafacd142011-09-02 01:15:17 +00002498ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002499ValueObject::GetValueForExpressionPath(const char* expression,
2500 const char** first_unparsed,
2501 ExpressionPathScanEndReason* reason_to_stop,
2502 ExpressionPathEndResultType* final_value_type,
2503 const GetValueForExpressionPathOptions& options,
2504 ExpressionPathAftermath* final_task_on_target)
2505{
2506
2507 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002508 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2509 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002510 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002511
2512 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2513 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2514 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2515 final_value_type ? final_value_type : &dummy_final_value_type,
2516 options,
2517 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2518
Enrico Granata86cc9822012-03-19 22:58:49 +00002519 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002520 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002521
Enrico Granata86cc9822012-03-19 22:58:49 +00002522 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 +00002523 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002524 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002525 {
2526 Error error;
2527 ValueObjectSP final_value = ret_val->Dereference(error);
2528 if (error.Fail() || !final_value.get())
2529 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002530 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002531 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002532 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002533 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002534 return ValueObjectSP();
2535 }
2536 else
2537 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002538 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002539 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002540 return final_value;
2541 }
2542 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002543 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002544 {
2545 Error error;
2546 ValueObjectSP final_value = ret_val->AddressOf(error);
2547 if (error.Fail() || !final_value.get())
2548 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002549 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002550 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002551 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002552 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002553 return ValueObjectSP();
2554 }
2555 else
2556 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002557 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002558 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002559 return final_value;
2560 }
2561 }
2562 }
2563 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2564}
2565
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002566int
2567ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002568 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002569 const char** first_unparsed,
2570 ExpressionPathScanEndReason* reason_to_stop,
2571 ExpressionPathEndResultType* final_value_type,
2572 const GetValueForExpressionPathOptions& options,
2573 ExpressionPathAftermath* final_task_on_target)
2574{
2575 const char* dummy_first_unparsed;
2576 ExpressionPathScanEndReason dummy_reason_to_stop;
2577 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002578 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002579
2580 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2581 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2582 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2583 final_value_type ? final_value_type : &dummy_final_value_type,
2584 options,
2585 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2586
2587 if (!ret_val.get()) // if there are errors, I add nothing to the list
2588 return 0;
2589
Enrico Granata86ea8d82012-03-29 01:34:34 +00002590 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002591 {
2592 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002593 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002594 {
2595 list->Append(ret_val);
2596 return 1;
2597 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002598 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 +00002599 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002600 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002601 {
2602 Error error;
2603 ValueObjectSP final_value = ret_val->Dereference(error);
2604 if (error.Fail() || !final_value.get())
2605 {
Greg Clayton23f59502012-07-17 03:23:13 +00002606 if (reason_to_stop)
2607 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2608 if (final_value_type)
2609 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002610 return 0;
2611 }
2612 else
2613 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002614 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002615 list->Append(final_value);
2616 return 1;
2617 }
2618 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002619 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002620 {
2621 Error error;
2622 ValueObjectSP final_value = ret_val->AddressOf(error);
2623 if (error.Fail() || !final_value.get())
2624 {
Greg Clayton23f59502012-07-17 03:23:13 +00002625 if (reason_to_stop)
2626 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2627 if (final_value_type)
2628 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002629 return 0;
2630 }
2631 else
2632 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002633 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002634 list->Append(final_value);
2635 return 1;
2636 }
2637 }
2638 }
2639 }
2640 else
2641 {
2642 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2643 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2644 ret_val,
2645 list,
2646 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2647 final_value_type ? final_value_type : &dummy_final_value_type,
2648 options,
2649 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2650 }
2651 // in any non-covered case, just do the obviously right thing
2652 list->Append(ret_val);
2653 return 1;
2654}
2655
Greg Claytonafacd142011-09-02 01:15:17 +00002656ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002657ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2658 const char** first_unparsed,
2659 ExpressionPathScanEndReason* reason_to_stop,
2660 ExpressionPathEndResultType* final_result,
2661 const GetValueForExpressionPathOptions& options,
2662 ExpressionPathAftermath* what_next)
2663{
2664 ValueObjectSP root = GetSP();
2665
2666 if (!root.get())
2667 return ValueObjectSP();
2668
2669 *first_unparsed = expression_cstr;
2670
2671 while (true)
2672 {
2673
2674 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2675
Greg Clayton57ee3062013-07-11 22:46:58 +00002676 ClangASTType root_clang_type = root->GetClangType();
2677 ClangASTType pointee_clang_type;
2678 Flags pointee_clang_type_info;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002679
Greg Clayton57ee3062013-07-11 22:46:58 +00002680 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002681 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00002682 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002683
2684 if (!expression_cstr || *expression_cstr == '\0')
2685 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002686 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002687 return root;
2688 }
2689
2690 switch (*expression_cstr)
2691 {
2692 case '-':
2693 {
2694 if (options.m_check_dot_vs_arrow_syntax &&
Greg Clayton57ee3062013-07-11 22:46:58 +00002695 root_clang_type_info.Test(ClangASTType::eTypeIsPointer) ) // if you are trying to use -> on a non-pointer and I must catch the error
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002696 {
2697 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002698 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2699 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002700 return ValueObjectSP();
2701 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002702 if (root_clang_type_info.Test(ClangASTType::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2703 root_clang_type_info.Test(ClangASTType::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002704 options.m_no_fragile_ivar)
2705 {
2706 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002707 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2708 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002709 return ValueObjectSP();
2710 }
2711 if (expression_cstr[1] != '>')
2712 {
2713 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002714 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2715 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002716 return ValueObjectSP();
2717 }
2718 expression_cstr++; // skip the -
2719 }
2720 case '.': // or fallthrough from ->
2721 {
2722 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Greg Clayton57ee3062013-07-11 22:46:58 +00002723 root_clang_type_info.Test(ClangASTType::eTypeIsPointer)) // if you are trying to use . on a pointer and I must catch the error
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002724 {
2725 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002726 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2727 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002728 return ValueObjectSP();
2729 }
2730 expression_cstr++; // skip .
2731 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2732 ConstString child_name;
2733 if (!next_separator) // if no other separator just expand this last layer
2734 {
2735 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002736 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2737
2738 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002739 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002740 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002741 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2742 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002743 return child_valobj_sp;
2744 }
2745 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2746 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002747 if (root->IsSynthetic())
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002748 {
2749 *first_unparsed = expression_cstr;
2750 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2751 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2752 return ValueObjectSP();
2753 }
2754
2755 child_valobj_sp = root->GetSyntheticValue();
Enrico Granata86cc9822012-03-19 22:58:49 +00002756 if (child_valobj_sp.get())
2757 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002758 }
2759
2760 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2761 // so we hit the "else" branch, and return an error
2762 if(child_valobj_sp.get()) // if it worked, just return
2763 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002764 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002765 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2766 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002767 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002768 }
2769 else
2770 {
2771 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002772 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2773 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002774 return ValueObjectSP();
2775 }
2776 }
2777 else // other layers do expand
2778 {
2779 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002780 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2781 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002782 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002783 root = child_valobj_sp;
2784 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002785 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002786 continue;
2787 }
2788 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2789 {
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002790 if (root->IsSynthetic())
2791 {
2792 *first_unparsed = expression_cstr;
2793 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2794 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2795 return ValueObjectSP();
2796 }
2797
Enrico Granata86cc9822012-03-19 22:58:49 +00002798 child_valobj_sp = root->GetSyntheticValue(true);
2799 if (child_valobj_sp)
2800 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002801 }
2802
2803 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2804 // so we hit the "else" branch, and return an error
2805 if(child_valobj_sp.get()) // if it worked, move on
2806 {
2807 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002808 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002809 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002810 continue;
2811 }
2812 else
2813 {
2814 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002815 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2816 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002817 return ValueObjectSP();
2818 }
2819 }
2820 break;
2821 }
2822 case '[':
2823 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002824 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray) && !root_clang_type_info.Test(ClangASTType::eTypeIsPointer) && !root_clang_type_info.Test(ClangASTType::eTypeIsVector)) // if this is not a T[] nor a T*
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002825 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002826 if (!root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002827 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002828 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2829 {
2830 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002831 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2832 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002833 return ValueObjectSP();
2834 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002835 }
2836 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2837 {
2838 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002839 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2840 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002841 return ValueObjectSP();
2842 }
2843 }
2844 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2845 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002846 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002847 {
2848 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002849 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2850 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002851 return ValueObjectSP();
2852 }
2853 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2854 {
2855 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002856 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2857 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002858 return root;
2859 }
2860 }
2861 const char *separator_position = ::strchr(expression_cstr+1,'-');
2862 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2863 if (!close_bracket_position) // if there is no ], this is a syntax error
2864 {
2865 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002866 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2867 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002868 return ValueObjectSP();
2869 }
2870 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2871 {
2872 char *end = NULL;
2873 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2874 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2875 {
2876 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002877 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2878 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002879 return ValueObjectSP();
2880 }
2881 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2882 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002883 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002884 {
2885 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002886 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2887 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002888 return root;
2889 }
2890 else
2891 {
2892 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002893 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2894 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002895 return ValueObjectSP();
2896 }
2897 }
2898 // from here on we do have a valid index
Greg Clayton57ee3062013-07-11 22:46:58 +00002899 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002900 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002901 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2902 if (!child_valobj_sp)
2903 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002904 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002905 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2906 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002907 if (child_valobj_sp)
2908 {
2909 root = child_valobj_sp;
2910 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002911 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002912 continue;
2913 }
2914 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002915 {
2916 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002917 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2918 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002919 return ValueObjectSP();
2920 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002921 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002922 else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002923 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002924 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
Greg Clayton57ee3062013-07-11 22:46:58 +00002925 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002926 {
2927 Error error;
2928 root = root->Dereference(error);
2929 if (error.Fail() || !root.get())
2930 {
2931 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002932 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2933 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002934 return ValueObjectSP();
2935 }
2936 else
2937 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002938 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002939 continue;
2940 }
2941 }
2942 else
2943 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002944 if (root->GetClangType().GetMinimumLanguage() == eLanguageTypeObjC
2945 && pointee_clang_type_info.AllClear(ClangASTType::eTypeIsPointer)
Greg Clayton84db9102012-03-26 23:03:23 +00002946 && root->HasSyntheticValue()
2947 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002948 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002949 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002950 }
2951 else
2952 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002953 if (!root.get())
2954 {
2955 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002956 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2957 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002958 return ValueObjectSP();
2959 }
2960 else
2961 {
2962 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002963 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002964 continue;
2965 }
2966 }
2967 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002968 else if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002969 {
2970 root = root->GetSyntheticBitFieldChild(index, index, true);
2971 if (!root.get())
2972 {
2973 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002974 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2975 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002976 return ValueObjectSP();
2977 }
2978 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2979 {
2980 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002981 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2982 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002983 return root;
2984 }
2985 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002986 else if (root_clang_type_info.Test(ClangASTType::eTypeIsVector))
Enrico Granata08a1bb82013-06-19 00:00:45 +00002987 {
2988 root = root->GetChildAtIndex(index, true);
2989 if (!root.get())
2990 {
2991 *first_unparsed = expression_cstr;
2992 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2993 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2994 return ValueObjectSP();
2995 }
2996 else
2997 {
2998 *first_unparsed = end+1; // skip ]
2999 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3000 continue;
3001 }
3002 }
Enrico Granata86cc9822012-03-19 22:58:49 +00003003 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00003004 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003005 if (root->HasSyntheticValue())
3006 root = root->GetSyntheticValue();
3007 else if (!root->IsSynthetic())
3008 {
3009 *first_unparsed = expression_cstr;
3010 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3011 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3012 return ValueObjectSP();
3013 }
3014 // if we are here, then root itself is a synthetic VO.. should be good to go
3015
Enrico Granata27b625e2011-08-09 01:04:56 +00003016 if (!root.get())
3017 {
3018 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003019 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3020 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3021 return ValueObjectSP();
3022 }
3023 root = root->GetChildAtIndex(index, true);
3024 if (!root.get())
3025 {
3026 *first_unparsed = expression_cstr;
3027 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3028 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003029 return ValueObjectSP();
3030 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00003031 else
3032 {
3033 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003034 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00003035 continue;
3036 }
Enrico Granata27b625e2011-08-09 01:04:56 +00003037 }
3038 else
3039 {
3040 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003041 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3042 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003043 return ValueObjectSP();
3044 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003045 }
3046 else // we have a low and a high index
3047 {
3048 char *end = NULL;
3049 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3050 if (!end || end != separator_position) // if something weird is in our way return an error
3051 {
3052 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003053 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3054 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003055 return ValueObjectSP();
3056 }
3057 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3058 if (!end || end != close_bracket_position) // if something weird is in our way return an 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 (index_lower > index_higher) // swap indices if required
3066 {
3067 unsigned long temp = index_lower;
3068 index_lower = index_higher;
3069 index_higher = temp;
3070 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003071 if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003072 {
3073 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3074 if (!root.get())
3075 {
3076 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003077 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3078 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003079 return ValueObjectSP();
3080 }
3081 else
3082 {
3083 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003084 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3085 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003086 return root;
3087 }
3088 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003089 else if (root_clang_type_info.Test(ClangASTType::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 +00003090 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Greg Clayton57ee3062013-07-11 22:46:58 +00003091 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003092 {
3093 Error error;
3094 root = root->Dereference(error);
3095 if (error.Fail() || !root.get())
3096 {
3097 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003098 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3099 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003100 return ValueObjectSP();
3101 }
3102 else
3103 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003104 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003105 continue;
3106 }
3107 }
3108 else
3109 {
3110 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003111 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3112 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003113 return root;
3114 }
3115 }
3116 break;
3117 }
3118 default: // some non-separator is in the way
3119 {
3120 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003121 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3122 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003123 return ValueObjectSP();
3124 break;
3125 }
3126 }
3127 }
3128}
3129
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003130int
3131ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3132 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00003133 ValueObjectSP root,
3134 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003135 ExpressionPathScanEndReason* reason_to_stop,
3136 ExpressionPathEndResultType* final_result,
3137 const GetValueForExpressionPathOptions& options,
3138 ExpressionPathAftermath* what_next)
3139{
3140 if (!root.get())
3141 return 0;
3142
3143 *first_unparsed = expression_cstr;
3144
3145 while (true)
3146 {
3147
3148 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3149
Greg Clayton57ee3062013-07-11 22:46:58 +00003150 ClangASTType root_clang_type = root->GetClangType();
3151 ClangASTType pointee_clang_type;
3152 Flags pointee_clang_type_info;
3153 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003154 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00003155 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003156
3157 if (!expression_cstr || *expression_cstr == '\0')
3158 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003159 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003160 list->Append(root);
3161 return 1;
3162 }
3163
3164 switch (*expression_cstr)
3165 {
3166 case '[':
3167 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003168 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray) && !root_clang_type_info.Test(ClangASTType::eTypeIsPointer)) // if this is not a T[] nor a T*
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003169 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003170 if (!root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003171 {
3172 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003173 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3174 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003175 return 0;
3176 }
3177 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3178 {
3179 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003180 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3181 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003182 return 0;
3183 }
3184 }
3185 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3186 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003187 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003188 {
3189 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003190 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3191 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003192 return 0;
3193 }
3194 else // expand this into list
3195 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003196 const size_t max_index = root->GetNumChildren() - 1;
3197 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003198 {
3199 ValueObjectSP child =
3200 root->GetChildAtIndex(index, true);
3201 list->Append(child);
3202 }
3203 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003204 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3205 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003206 return max_index; // tell me number of items I added to the VOList
3207 }
3208 }
3209 const char *separator_position = ::strchr(expression_cstr+1,'-');
3210 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3211 if (!close_bracket_position) // if there is no ], this is a syntax error
3212 {
3213 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003214 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3215 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003216 return 0;
3217 }
3218 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3219 {
3220 char *end = NULL;
3221 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3222 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3223 {
3224 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003225 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3226 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003227 return 0;
3228 }
3229 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3230 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003231 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003232 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003233 const size_t max_index = root->GetNumChildren() - 1;
3234 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003235 {
3236 ValueObjectSP child =
3237 root->GetChildAtIndex(index, true);
3238 list->Append(child);
3239 }
3240 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003241 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3242 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003243 return max_index; // tell me number of items I added to the VOList
3244 }
3245 else
3246 {
3247 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003248 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3249 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003250 return 0;
3251 }
3252 }
3253 // from here on we do have a valid index
Greg Clayton57ee3062013-07-11 22:46:58 +00003254 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003255 {
3256 root = root->GetChildAtIndex(index, true);
3257 if (!root.get())
3258 {
3259 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003260 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3261 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003262 return 0;
3263 }
3264 else
3265 {
3266 list->Append(root);
3267 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003268 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3269 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003270 return 1;
3271 }
3272 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003273 else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003274 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003275 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
Greg Clayton57ee3062013-07-11 22:46:58 +00003276 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003277 {
3278 Error error;
3279 root = root->Dereference(error);
3280 if (error.Fail() || !root.get())
3281 {
3282 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003283 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3284 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003285 return 0;
3286 }
3287 else
3288 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003289 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003290 continue;
3291 }
3292 }
3293 else
3294 {
3295 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3296 if (!root.get())
3297 {
3298 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003299 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3300 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003301 return 0;
3302 }
3303 else
3304 {
3305 list->Append(root);
3306 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003307 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3308 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003309 return 1;
3310 }
3311 }
3312 }
3313 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3314 {
3315 root = root->GetSyntheticBitFieldChild(index, index, true);
3316 if (!root.get())
3317 {
3318 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003319 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3320 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003321 return 0;
3322 }
3323 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3324 {
3325 list->Append(root);
3326 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003327 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3328 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003329 return 1;
3330 }
3331 }
3332 }
3333 else // we have a low and a high index
3334 {
3335 char *end = NULL;
3336 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3337 if (!end || end != separator_position) // if something weird is in our way return an error
3338 {
3339 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003340 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3341 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003342 return 0;
3343 }
3344 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3345 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3346 {
3347 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003348 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3349 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003350 return 0;
3351 }
3352 if (index_lower > index_higher) // swap indices if required
3353 {
3354 unsigned long temp = index_lower;
3355 index_lower = index_higher;
3356 index_higher = temp;
3357 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003358 if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // expansion only works for scalars
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003359 {
3360 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3361 if (!root.get())
3362 {
3363 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003364 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3365 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003366 return 0;
3367 }
3368 else
3369 {
3370 list->Append(root);
3371 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003372 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3373 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003374 return 1;
3375 }
3376 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003377 else if (root_clang_type_info.Test(ClangASTType::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 +00003378 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Greg Clayton57ee3062013-07-11 22:46:58 +00003379 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003380 {
3381 Error error;
3382 root = root->Dereference(error);
3383 if (error.Fail() || !root.get())
3384 {
3385 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003386 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3387 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003388 return 0;
3389 }
3390 else
3391 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003392 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003393 continue;
3394 }
3395 }
3396 else
3397 {
Johnny Chen44805302011-07-19 19:48:13 +00003398 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003399 index <= index_higher; index++)
3400 {
3401 ValueObjectSP child =
3402 root->GetChildAtIndex(index, true);
3403 list->Append(child);
3404 }
3405 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003406 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3407 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003408 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3409 }
3410 }
3411 break;
3412 }
3413 default: // some non-[ separator, or something entirely wrong, is in the way
3414 {
3415 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003416 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3417 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003418 return 0;
3419 break;
3420 }
3421 }
3422 }
3423}
3424
Enrico Granata0c489f52012-03-01 04:24:26 +00003425static void
3426DumpValueObject_Impl (Stream &s,
3427 ValueObject *valobj,
3428 const ValueObject::DumpValueObjectOptions& options,
3429 uint32_t ptr_depth,
3430 uint32_t curr_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003431{
Greg Clayton007d5be2011-05-30 00:49:24 +00003432 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003433 {
Enrico Granata5548cb52013-01-28 23:47:25 +00003434 bool update_success = valobj->UpdateValueIfNeeded (true);
Greg Clayton007d5be2011-05-30 00:49:24 +00003435
Enrico Granata0c489f52012-03-01 04:24:26 +00003436 const char *root_valobj_name =
3437 options.m_root_valobj_name.empty() ?
3438 valobj->GetName().AsCString() :
3439 options.m_root_valobj_name.c_str();
3440
3441 if (update_success && options.m_use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00003442 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003443 ValueObject *dynamic_value = valobj->GetDynamicValue(options.m_use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003444 if (dynamic_value)
3445 valobj = dynamic_value;
3446 }
3447
Greg Clayton57ee3062013-07-11 22:46:58 +00003448 ClangASTType clang_type = valobj->GetClangType();
3449 const Flags type_flags (clang_type.GetTypeInfo ());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003450 const char *err_cstr = NULL;
Greg Clayton57ee3062013-07-11 22:46:58 +00003451 const bool has_children = type_flags.Test (ClangASTType::eTypeHasChildren);
3452 const bool has_value = type_flags.Test (ClangASTType::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003453
Enrico Granata0c489f52012-03-01 04:24:26 +00003454 const bool print_valobj = options.m_flat_output == false || has_value;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003455
3456 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003457 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003458 if (options.m_show_location)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003459 {
Jim Ingham6035b672011-03-31 00:19:25 +00003460 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003461 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003462
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003463 s.Indent();
Enrico Granata2b2631c2012-08-09 16:51:25 +00003464
3465 bool show_type = true;
3466 // if we are at the root-level and been asked to hide the root's type, then hide it
3467 if (curr_depth == 0 && options.m_hide_root_type)
3468 show_type = false;
3469 else
3470 // otherwise decide according to the usual rules (asked to show types - always at the root level)
3471 show_type = options.m_show_types || (curr_depth == 0 && !options.m_flat_output);
3472
3473 if (show_type)
Greg Clayton0fa5c972013-04-25 01:05:15 +00003474 {
3475 // Some ValueObjects don't have types (like registers sets). Only print
3476 // the type if there is one to print
3477 ConstString qualified_type_name(valobj->GetQualifiedTypeName());
3478 if (qualified_type_name)
3479 s.Printf("(%s) ", qualified_type_name.GetCString());
3480 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003481
Enrico Granata0c489f52012-03-01 04:24:26 +00003482 if (options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003483 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003484 // If we are showing types, also qualify the C++ base classes
Enrico Granata0c489f52012-03-01 04:24:26 +00003485 const bool qualify_cxx_base_classes = options.m_show_types;
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003486 if (!options.m_hide_name)
3487 {
3488 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
3489 s.PutCString(" =");
3490 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003491 }
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003492 else if (!options.m_hide_name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003493 {
3494 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3495 s.Printf ("%s =", name_cstr);
3496 }
3497
Enrico Granata0c489f52012-03-01 04:24:26 +00003498 if (!options.m_scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003499 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003500 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003501 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003502 }
3503
Enrico Granata0c489f52012-03-01 04:24:26 +00003504 std::string summary_str;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003505 std::string value_str;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003506 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003507 const char *sum_cstr = NULL;
Enrico Granata0c489f52012-03-01 04:24:26 +00003508 TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003509
Enrico Granata0c489f52012-03-01 04:24:26 +00003510 if (options.m_omit_summary_depth > 0)
Enrico Granata0c5ef692011-07-16 01:22:04 +00003511 entry = NULL;
3512
Enrico Granata9e7b3882012-12-13 23:50:33 +00003513 bool is_nil = valobj->IsObjCNil();
3514
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003515 if (err_cstr == NULL)
3516 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003517 if (options.m_format != eFormatDefault && options.m_format != valobj->GetFormat())
Greg Clayton6efba4f2012-01-26 21:08:30 +00003518 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003519 valobj->GetValueAsCString(options.m_format,
3520 value_str);
Greg Clayton6efba4f2012-01-26 21:08:30 +00003521 }
Enrico Granata0c489f52012-03-01 04:24:26 +00003522 else
Greg Clayton6efba4f2012-01-26 21:08:30 +00003523 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003524 val_cstr = valobj->GetValueAsCString();
3525 if (val_cstr)
3526 value_str = val_cstr;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003527 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003528 err_cstr = valobj->GetError().AsCString();
3529 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003530
3531 if (err_cstr)
3532 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003533 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003534 }
3535 else
3536 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003537 const bool is_ref = type_flags.Test (ClangASTType::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003538 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003539 {
Enrico Granata9e7b3882012-12-13 23:50:33 +00003540 if (is_nil)
3541 sum_cstr = "nil";
3542 else if (options.m_omit_summary_depth == 0)
Enrico Granata0c489f52012-03-01 04:24:26 +00003543 {
3544 if (options.m_summary_sp)
3545 {
3546 valobj->GetSummaryAsCString(entry, summary_str);
3547 sum_cstr = summary_str.c_str();
3548 }
3549 else
3550 sum_cstr = valobj->GetSummaryAsCString();
3551 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003552
Greg Clayton6efba4f2012-01-26 21:08:30 +00003553 // Make sure we have a value and make sure the summary didn't
Enrico Granata9e7b3882012-12-13 23:50:33 +00003554 // specify that the value should not be printed - and do not print
3555 // the value if this thing is nil
Enrico Granatac2a58d72013-03-25 19:46:48 +00003556 // (but show the value if the user passes a format explicitly)
3557 if (!is_nil && !value_str.empty() && (entry == NULL || (entry->DoesPrintValue() || options.m_format != eFormatDefault) || sum_cstr == NULL) && !options.m_hide_value)
Greg Clayton6efba4f2012-01-26 21:08:30 +00003558 s.Printf(" %s", value_str.c_str());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003559
Enrico Granata9dd75c82011-07-15 23:30:15 +00003560 if (sum_cstr)
Enrico Granata0c489f52012-03-01 04:24:26 +00003561 s.Printf(" %s", sum_cstr);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003562
Enrico Granata9e7b3882012-12-13 23:50:33 +00003563 // let's avoid the overly verbose no description error for a nil thing
3564 if (options.m_use_objc && !is_nil)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003565 {
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003566 if (!options.m_hide_value || !options.m_hide_name)
3567 s.Printf(" ");
Jim Ingham6035b672011-03-31 00:19:25 +00003568 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003569 if (object_desc)
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003570 s.Printf("%s\n", object_desc);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003571 else
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003572 s.Printf ("[no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003573 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003574 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003575 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003576
Enrico Granata0c489f52012-03-01 04:24:26 +00003577 if (curr_depth < options.m_max_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003578 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003579 // We will show children for all concrete types. We won't show
3580 // pointer contents unless a pointer depth has been specified.
3581 // We won't reference contents unless the reference is the
3582 // root object (depth of zero).
3583 bool print_children = true;
3584
3585 // Use a new temporary pointer depth in case we override the
3586 // current pointer depth below...
3587 uint32_t curr_ptr_depth = ptr_depth;
3588
Greg Clayton57ee3062013-07-11 22:46:58 +00003589 const bool is_ptr = type_flags.Test (ClangASTType::eTypeIsPointer);
Greg Clayton73b472d2010-10-27 03:32:59 +00003590 if (is_ptr || is_ref)
3591 {
3592 // We have a pointer or reference whose value is an address.
3593 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003594 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003595 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003596 print_children = false;
3597
3598 else if (is_ref && curr_depth == 0)
3599 {
3600 // If this is the root object (depth is zero) that we are showing
3601 // and it is a reference, and no pointer depth has been supplied
3602 // print out what it references. Don't do this at deeper depths
3603 // otherwise we can end up with infinite recursion...
3604 curr_ptr_depth = 1;
3605 }
3606
3607 if (curr_ptr_depth == 0)
3608 print_children = false;
3609 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003610
Enrico Granata0a3958e2011-07-02 00:25:22 +00003611 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003612 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003613 ValueObjectSP synth_valobj_sp = valobj->GetSyntheticValue (options.m_use_synthetic);
Greg Clayton0fa5c972013-04-25 01:05:15 +00003614 ValueObject* synth_valobj = (synth_valobj_sp ? synth_valobj_sp.get() : valobj);
Enrico Granatac5bc4122012-03-27 02:35:13 +00003615
Greg Claytonc7bece562013-01-25 18:06:21 +00003616 size_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003617 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003618 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003619 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003620 if (options.m_flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003621 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003622 if (print_valobj)
3623 s.EOL();
3624 }
3625 else
3626 {
3627 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003628 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003629 s.IndentMore();
3630 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003631
Greg Claytonc7bece562013-01-25 18:06:21 +00003632 const size_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00003633
Enrico Granata0c489f52012-03-01 04:24:26 +00003634 if (num_children > max_num_children && !options.m_ignore_cap)
Enrico Granata22c55d12011-08-12 02:00:06 +00003635 {
3636 num_children = max_num_children;
3637 print_dotdotdot = true;
3638 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003639
Enrico Granata0c489f52012-03-01 04:24:26 +00003640 ValueObject::DumpValueObjectOptions child_options(options);
Enrico Granatac953a6a2012-12-11 02:17:22 +00003641 child_options.SetFormat(options.m_format).SetSummary().SetRootValueObjectName();
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003642 child_options.SetScopeChecked(true).SetHideName(options.m_hide_name).SetHideValue(options.m_hide_value)
Enrico Granata0c489f52012-03-01 04:24:26 +00003643 .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0);
Greg Claytonc7bece562013-01-25 18:06:21 +00003644 for (size_t idx=0; idx<num_children; ++idx)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003645 {
Enrico Granatac482a192011-08-17 22:13:59 +00003646 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003647 if (child_sp.get())
3648 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003649 DumpValueObject_Impl (s,
3650 child_sp.get(),
3651 child_options,
3652 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
3653 curr_depth + 1);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003654 }
3655 }
3656
Enrico Granata0c489f52012-03-01 04:24:26 +00003657 if (!options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003658 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003659 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003660 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003661 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3662 Target *target = exe_ctx.GetTargetPtr();
3663 if (target)
3664 target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003665 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003666 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003667 s.IndentLess();
3668 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003669 }
3670 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003671 else if (has_children)
3672 {
3673 // Aggregate, no children...
3674 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003675 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003676 }
3677 else
3678 {
3679 if (print_valobj)
3680 s.EOL();
3681 }
3682
Greg Clayton1d3afba2010-10-05 00:00:42 +00003683 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003684 else
3685 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003686 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003687 }
3688 }
3689 else
3690 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003691 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003692 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003693 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003694 }
3695 }
3696 }
3697 }
3698}
3699
Enrico Granata0c489f52012-03-01 04:24:26 +00003700void
Greg Claytonf830dbb2012-03-22 18:15:37 +00003701ValueObject::LogValueObject (Log *log,
3702 ValueObject *valobj)
3703{
3704 if (log && valobj)
3705 return LogValueObject (log, valobj, DumpValueObjectOptions::DefaultOptions());
3706}
3707
3708void
3709ValueObject::LogValueObject (Log *log,
3710 ValueObject *valobj,
3711 const DumpValueObjectOptions& options)
3712{
3713 if (log && valobj)
3714 {
3715 StreamString s;
3716 ValueObject::DumpValueObject (s, valobj, options);
3717 if (s.GetSize())
3718 log->PutCString(s.GetData());
3719 }
3720}
3721
3722void
Enrico Granata0c489f52012-03-01 04:24:26 +00003723ValueObject::DumpValueObject (Stream &s,
3724 ValueObject *valobj)
3725{
3726
3727 if (!valobj)
3728 return;
3729
3730 DumpValueObject_Impl(s,
3731 valobj,
3732 DumpValueObjectOptions::DefaultOptions(),
3733 0,
3734 0);
3735}
3736
3737void
3738ValueObject::DumpValueObject (Stream &s,
3739 ValueObject *valobj,
3740 const DumpValueObjectOptions& options)
3741{
3742 DumpValueObject_Impl(s,
3743 valobj,
3744 options,
3745 options.m_max_ptr_depth, // max pointer depth allowed, we will go down from here
3746 0 // current object depth is 0 since we are just starting
3747 );
3748}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003749
3750ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003751ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003752{
3753 ValueObjectSP valobj_sp;
3754
Enrico Granatac3e320a2011-08-02 17:27:39 +00003755 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003756 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003757 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003758
3759 DataExtractor data;
3760 data.SetByteOrder (m_data.GetByteOrder());
3761 data.SetAddressByteSize(m_data.GetAddressByteSize());
3762
Enrico Granata9f1e2042012-04-24 22:15:37 +00003763 if (IsBitfield())
3764 {
3765 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
Greg Clayton57ee3062013-07-11 22:46:58 +00003766 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Enrico Granata9f1e2042012-04-24 22:15:37 +00003767 }
3768 else
Greg Clayton57ee3062013-07-11 22:46:58 +00003769 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003770
3771 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003772 GetClangType(),
3773 name,
3774 data,
3775 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003776 }
Jim Ingham6035b672011-03-31 00:19:25 +00003777
3778 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003779 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003780 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003781 }
3782 return valobj_sp;
3783}
3784
Greg Claytonafacd142011-09-02 01:15:17 +00003785ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003786ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003787{
Jim Ingham58b59f92011-04-22 23:53:53 +00003788 if (m_deref_valobj)
3789 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003790
Greg Clayton54979cd2010-12-15 05:08:08 +00003791 const bool is_pointer_type = IsPointerType();
3792 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003793 {
3794 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003795 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003796
3797 std::string child_name_str;
3798 uint32_t child_byte_size = 0;
3799 int32_t child_byte_offset = 0;
3800 uint32_t child_bitfield_bit_size = 0;
3801 uint32_t child_bitfield_bit_offset = 0;
3802 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003803 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003804 const bool transparent_pointers = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00003805 ClangASTType clang_type = GetClangType();
3806 ClangASTType child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003807
Greg Claytoncc4d0142012-02-17 07:49:44 +00003808 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003809
Greg Clayton57ee3062013-07-11 22:46:58 +00003810 child_clang_type = clang_type.GetChildClangTypeAtIndex (&exe_ctx,
3811 GetName().GetCString(),
3812 0,
3813 transparent_pointers,
3814 omit_empty_base_classes,
3815 ignore_array_bounds,
3816 child_name_str,
3817 child_byte_size,
3818 child_byte_offset,
3819 child_bitfield_bit_size,
3820 child_bitfield_bit_offset,
3821 child_is_base_class,
3822 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003823 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003824 {
3825 ConstString child_name;
3826 if (!child_name_str.empty())
3827 child_name.SetCString (child_name_str.c_str());
3828
Jim Ingham58b59f92011-04-22 23:53:53 +00003829 m_deref_valobj = new ValueObjectChild (*this,
Jim Ingham58b59f92011-04-22 23:53:53 +00003830 child_clang_type,
3831 child_name,
3832 child_byte_size,
3833 child_byte_offset,
3834 child_bitfield_bit_size,
3835 child_bitfield_bit_offset,
3836 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003837 child_is_deref_of_parent,
3838 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003839 }
3840 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003841
Jim Ingham58b59f92011-04-22 23:53:53 +00003842 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003843 {
3844 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003845 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003846 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003847 else
3848 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003849 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003850 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003851
3852 if (is_pointer_type)
3853 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3854 else
3855 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003856 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003857 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003858}
3859
Greg Claytonafacd142011-09-02 01:15:17 +00003860ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003861ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003862{
Jim Ingham78a685a2011-04-16 00:01:13 +00003863 if (m_addr_of_valobj_sp)
3864 return m_addr_of_valobj_sp;
3865
Greg Claytone0d378b2011-03-24 21:19:54 +00003866 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003867 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003868 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003869 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003870 if (addr != LLDB_INVALID_ADDRESS)
3871 {
3872 switch (address_type)
3873 {
3874 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003875 {
3876 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003877 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003878 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3879 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003880 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003881
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003882 case eAddressTypeFile:
3883 case eAddressTypeLoad:
3884 case eAddressTypeHost:
3885 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003886 ClangASTType clang_type = GetClangType();
3887 if (clang_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003888 {
3889 std::string name (1, '&');
3890 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003891 ExecutionContext exe_ctx (GetExecutionContextRef());
3892 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00003893 clang_type.GetPointerType(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003894 ConstString (name.c_str()),
3895 addr,
3896 eAddressTypeInvalid,
3897 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003898 }
3899 }
3900 break;
3901 }
3902 }
Sean Callananed185ab2013-04-19 19:47:32 +00003903 else
3904 {
3905 StreamString expr_path_strm;
3906 GetExpressionPath(expr_path_strm, true);
3907 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3908 }
3909
Jim Ingham78a685a2011-04-16 00:01:13 +00003910 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003911}
3912
Greg Clayton9a142cf2012-02-03 05:34:10 +00003913ValueObjectSP
3914ValueObject::Cast (const ClangASTType &clang_ast_type)
3915{
Greg Clayton81e871e2012-02-04 02:27:34 +00003916 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003917}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003918
Greg Claytonafacd142011-09-02 01:15:17 +00003919ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003920ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3921{
Greg Claytonafacd142011-09-02 01:15:17 +00003922 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003923 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003924 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003925
3926 if (ptr_value != LLDB_INVALID_ADDRESS)
3927 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003928 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003929 ExecutionContext exe_ctx (GetExecutionContextRef());
3930 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003931 name,
3932 ptr_addr,
3933 clang_ast_type);
3934 }
3935 return valobj_sp;
3936}
3937
Greg Claytonafacd142011-09-02 01:15:17 +00003938ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003939ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3940{
Greg Claytonafacd142011-09-02 01:15:17 +00003941 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003942 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003943 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003944
3945 if (ptr_value != LLDB_INVALID_ADDRESS)
3946 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003947 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003948 ExecutionContext exe_ctx (GetExecutionContextRef());
3949 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003950 name,
3951 ptr_addr,
3952 type_sp);
3953 }
3954 return valobj_sp;
3955}
3956
Jim Ingham6035b672011-03-31 00:19:25 +00003957ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003958 m_mod_id(),
3959 m_exe_ctx_ref(),
3960 m_needs_update (true),
3961 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003962{
3963}
3964
3965ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003966 m_mod_id(),
3967 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003968 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003969 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003970{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003971 ExecutionContext exe_ctx(exe_scope);
3972 TargetSP target_sp (exe_ctx.GetTargetSP());
3973 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003974 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003975 m_exe_ctx_ref.SetTargetSP (target_sp);
3976 ProcessSP process_sp (exe_ctx.GetProcessSP());
3977 if (!process_sp)
3978 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003979
Greg Claytoncc4d0142012-02-17 07:49:44 +00003980 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003981 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003982 m_mod_id = process_sp->GetModID();
3983 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003984
Greg Claytoncc4d0142012-02-17 07:49:44 +00003985 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003986
Greg Claytoncc4d0142012-02-17 07:49:44 +00003987 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003988 {
3989 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003990 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003991 }
Jim Ingham6035b672011-03-31 00:19:25 +00003992
Greg Claytoncc4d0142012-02-17 07:49:44 +00003993 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003994 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003995 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003996
Greg Claytoncc4d0142012-02-17 07:49:44 +00003997 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3998 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003999 {
4000 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00004001 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00004002 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00004003 if (frame_sp)
4004 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00004005 }
4006 }
4007 }
Jim Ingham6035b672011-03-31 00:19:25 +00004008}
4009
4010ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00004011 m_mod_id(),
4012 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
4013 m_needs_update (true),
4014 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00004015{
4016}
4017
4018ValueObject::EvaluationPoint::~EvaluationPoint ()
4019{
4020}
4021
Jim Ingham6035b672011-03-31 00:19:25 +00004022// This function checks the EvaluationPoint against the current process state. If the current
4023// state matches the evaluation point, or the evaluation point is already invalid, then we return
4024// false, meaning "no change". If the current state is different, we update our state, and return
4025// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
4026// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00004027// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00004028
4029bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00004030ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00004031{
Jim Ingham73ca05a2011-12-17 01:35:57 +00004032
4033 // Start with the target, if it is NULL, then we're obviously not going to get any further:
Greg Claytoncc4d0142012-02-17 07:49:44 +00004034 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00004035
Greg Claytoncc4d0142012-02-17 07:49:44 +00004036 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00004037 return false;
4038
Jim Ingham6035b672011-03-31 00:19:25 +00004039 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00004040 Process *process = exe_ctx.GetProcessPtr();
4041 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00004042 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00004043
Jim Ingham6035b672011-03-31 00:19:25 +00004044 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00004045 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00004046
Jim Ingham78a685a2011-04-16 00:01:13 +00004047 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
4048 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00004049 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00004050 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00004051
Greg Clayton23f59502012-07-17 03:23:13 +00004052 bool changed = false;
4053 const bool was_valid = m_mod_id.IsValid();
4054 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004055 {
4056 if (m_mod_id == current_mod_id)
4057 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00004058 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004059 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00004060 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004061 }
Jim Ingham9ee01152011-12-10 01:49:43 +00004062 else
4063 {
4064 m_mod_id = current_mod_id;
4065 m_needs_update = true;
4066 changed = true;
4067 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00004068 }
Jim Ingham6035b672011-03-31 00:19:25 +00004069
Jim Ingham73ca05a2011-12-17 01:35:57 +00004070 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
4071 // That way we'll be sure to return a valid exe_scope.
4072 // 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 +00004073
Greg Claytoncc4d0142012-02-17 07:49:44 +00004074 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00004075 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00004076 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
4077 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00004078 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00004079 if (m_exe_ctx_ref.HasFrameRef())
4080 {
4081 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
4082 if (!frame_sp)
4083 {
4084 // We used to have a frame, but now it is gone
4085 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00004086 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00004087 }
4088 }
Greg Clayton262f80d2011-07-06 16:49:27 +00004089 }
Jim Ingham6035b672011-03-31 00:19:25 +00004090 else
4091 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00004092 // We used to have a thread, but now it is gone
4093 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00004094 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00004095 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00004096
Jim Ingham6035b672011-03-31 00:19:25 +00004097 }
Jim Ingham9ee01152011-12-10 01:49:43 +00004098 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00004099}
4100
Jim Ingham61be0902011-05-02 18:13:59 +00004101void
4102ValueObject::EvaluationPoint::SetUpdated ()
4103{
Greg Claytoncc4d0142012-02-17 07:49:44 +00004104 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
4105 if (process_sp)
4106 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00004107 m_first_update = false;
4108 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00004109}
4110
4111
Enrico Granataf2bbf712011-07-15 02:26:42 +00004112
4113void
Enrico Granata86cc9822012-03-19 22:58:49 +00004114ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004115{
Enrico Granata86cc9822012-03-19 22:58:49 +00004116 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4117 m_value_str.clear();
4118
4119 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4120 m_location_str.clear();
4121
4122 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
4123 {
Enrico Granata86cc9822012-03-19 22:58:49 +00004124 m_summary_str.clear();
4125 }
4126
4127 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4128 m_object_desc_str.clear();
4129
4130 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4131 {
4132 if (m_synthetic_value)
4133 m_synthetic_value = NULL;
4134 }
Johnny Chen44805302011-07-19 19:48:13 +00004135}
Enrico Granata9128ee22011-09-06 19:20:51 +00004136
4137SymbolContextScope *
4138ValueObject::GetSymbolContextScope()
4139{
4140 if (m_parent)
4141 {
4142 if (!m_parent->IsPointerOrReferenceType())
4143 return m_parent->GetSymbolContextScope();
4144 }
4145 return NULL;
4146}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004147
4148lldb::ValueObjectSP
4149ValueObject::CreateValueObjectFromExpression (const char* name,
4150 const char* expression,
4151 const ExecutionContext& exe_ctx)
4152{
4153 lldb::ValueObjectSP retval_sp;
4154 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4155 if (!target_sp)
4156 return retval_sp;
4157 if (!expression || !*expression)
4158 return retval_sp;
4159 target_sp->EvaluateExpression (expression,
4160 exe_ctx.GetFrameSP().get(),
4161 retval_sp);
4162 if (retval_sp && name && *name)
4163 retval_sp->SetName(ConstString(name));
4164 return retval_sp;
4165}
4166
4167lldb::ValueObjectSP
4168ValueObject::CreateValueObjectFromAddress (const char* name,
4169 uint64_t address,
4170 const ExecutionContext& exe_ctx,
4171 ClangASTType type)
4172{
Greg Clayton57ee3062013-07-11 22:46:58 +00004173 if (type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004174 {
Greg Clayton57ee3062013-07-11 22:46:58 +00004175 ClangASTType pointer_type(type.GetPointerType());
4176 if (pointer_type)
4177 {
4178 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4179 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4180 pointer_type,
4181 ConstString(name),
4182 buffer,
4183 lldb::endian::InlHostByteOrder(),
4184 exe_ctx.GetAddressByteSize()));
4185 if (ptr_result_valobj_sp)
4186 {
4187 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4188 Error err;
4189 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4190 if (ptr_result_valobj_sp && name && *name)
4191 ptr_result_valobj_sp->SetName(ConstString(name));
4192 }
4193 return ptr_result_valobj_sp;
4194 }
Enrico Granatab2698cd2012-09-13 18:27:09 +00004195 }
Greg Clayton57ee3062013-07-11 22:46:58 +00004196 return lldb::ValueObjectSP();
Enrico Granatab2698cd2012-09-13 18:27:09 +00004197}
4198
4199lldb::ValueObjectSP
4200ValueObject::CreateValueObjectFromData (const char* name,
4201 DataExtractor& data,
4202 const ExecutionContext& exe_ctx,
4203 ClangASTType type)
4204{
4205 lldb::ValueObjectSP new_value_sp;
4206 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004207 type,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004208 ConstString(name),
4209 data,
4210 LLDB_INVALID_ADDRESS);
4211 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4212 if (new_value_sp && name && *name)
4213 new_value_sp->SetName(ConstString(name));
4214 return new_value_sp;
4215}
Enrico Granata4873e522013-04-11 22:48:58 +00004216
4217ModuleSP
4218ValueObject::GetModule ()
4219{
4220 ValueObject* root(GetRoot());
4221 if (root != this)
4222 return root->GetModule();
4223 return lldb::ModuleSP();
4224}
4225
4226ValueObject*
4227ValueObject::GetRoot ()
4228{
4229 if (m_root)
4230 return m_root;
4231 ValueObject* parent = m_parent;
4232 if (!parent)
4233 return (m_root = this);
4234 while (parent->m_parent)
4235 {
4236 if (parent->m_root)
4237 return (m_root = parent->m_root);
4238 parent = parent->m_parent;
4239 }
4240 return (m_root = parent);
4241}
4242
4243AddressType
4244ValueObject::GetAddressTypeOfChildren()
4245{
4246 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
4247 {
4248 ValueObject* root(GetRoot());
4249 if (root != this)
4250 return root->GetAddressTypeOfChildren();
4251 }
4252 return m_address_type_of_ptr_or_ref_children;
4253}
4254
4255lldb::DynamicValueType
4256ValueObject::GetDynamicValueType ()
4257{
4258 ValueObject* with_dv_info = this;
4259 while (with_dv_info)
4260 {
4261 if (with_dv_info->HasDynamicValueTypeInfo())
4262 return with_dv_info->GetDynamicValueTypeImpl();
4263 with_dv_info = with_dv_info->m_parent;
4264 }
4265 return lldb::eNoDynamicValues;
4266}
Enrico Granata39d51412013-05-31 17:43:40 +00004267
Enrico Granata4873e522013-04-11 22:48:58 +00004268lldb::Format
4269ValueObject::GetFormat () const
4270{
4271 const ValueObject* with_fmt_info = this;
4272 while (with_fmt_info)
4273 {
4274 if (with_fmt_info->m_format != lldb::eFormatDefault)
4275 return with_fmt_info->m_format;
4276 with_fmt_info = with_fmt_info->m_parent;
4277 }
4278 return m_format;
4279}