blob: f58271c0638d17b07163e4fb7245a64f11f16857 [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"
Enrico Granata4d93b8c2013-09-30 19:11:51 +000037#include "lldb/DataFormatters/ValueObjectPrinter.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000038
Greg Clayton7fb56d02011-02-01 01:31:41 +000039#include "lldb/Host/Endian.h"
40
Enrico Granata61a80ba2011-08-12 16:42:31 +000041#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granataf2bbf712011-07-15 02:26:42 +000042#include "lldb/Interpreter/ScriptInterpreterPython.h"
43
Greg Claytone1a916a2010-07-21 22:12:05 +000044#include "lldb/Symbol/ClangASTType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000045#include "lldb/Symbol/ClangASTContext.h"
46#include "lldb/Symbol/Type.h"
47
Jim Ingham53c47f12010-09-10 23:12:17 +000048#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000049#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000050#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051#include "lldb/Target/Process.h"
52#include "lldb/Target/RegisterContext.h"
Greg Claytond5944cd2013-12-06 01:12:00 +000053#include "lldb/Target/SectionLoadList.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000054#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000055#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056
57using namespace lldb;
58using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000059using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060
Greg Claytonafacd142011-09-02 01:15:17 +000061static user_id_t g_value_obj_uid = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062
63//----------------------------------------------------------------------
64// ValueObject constructor
65//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000066ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000067 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000068 m_parent (&parent),
Enrico Granata4873e522013-04-11 22:48:58 +000069 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +000070 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000071 m_name (),
72 m_data (),
73 m_value (),
74 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000075 m_value_str (),
76 m_old_value_str (),
77 m_location_str (),
78 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000079 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +000080 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000081 m_children (),
82 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000083 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000084 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000085 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000086 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +000087 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000088 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +000089 m_type_summary_sp(),
90 m_type_format_sp(),
91 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +000092 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +000093 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
Greg Clayton288bdf92010-09-02 02:59:18 +000094 m_value_is_valid (false),
95 m_value_did_change (false),
96 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000097 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +000098 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +000099 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000100 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000101 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000102 m_is_getting_summary(false),
103 m_did_calculate_complete_objc_class_type(false)
Jim Ingham6035b672011-03-31 00:19:25 +0000104{
Jim Ingham58b59f92011-04-22 23:53:53 +0000105 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000106}
107
108//----------------------------------------------------------------------
109// ValueObject constructor
110//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000111ValueObject::ValueObject (ExecutionContextScope *exe_scope,
112 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000113 UserID (++g_value_obj_uid), // Unique identifier for every value object
114 m_parent (NULL),
Enrico Granata4873e522013-04-11 22:48:58 +0000115 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000116 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000117 m_name (),
118 m_data (),
119 m_value (),
120 m_error (),
121 m_value_str (),
122 m_old_value_str (),
123 m_location_str (),
124 m_summary_str (),
125 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000126 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000127 m_children (),
128 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000129 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000130 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000131 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000132 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +0000133 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000134 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +0000135 m_type_summary_sp(),
136 m_type_format_sp(),
137 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000138 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000139 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Jim Ingham6035b672011-03-31 00:19:25 +0000140 m_value_is_valid (false),
141 m_value_did_change (false),
142 m_children_count_valid (false),
143 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000144 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000145 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000146 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000147 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000148 m_is_getting_summary(false),
149 m_did_calculate_complete_objc_class_type(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000150{
Jim Ingham58b59f92011-04-22 23:53:53 +0000151 m_manager = new ValueObjectManager();
152 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000153}
154
155//----------------------------------------------------------------------
156// Destructor
157//----------------------------------------------------------------------
158ValueObject::~ValueObject ()
159{
160}
161
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000162bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000163ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000164{
Enrico Granata4becb372011-06-29 22:27:15 +0000165
Enrico Granata9128ee22011-09-06 19:20:51 +0000166 bool did_change_formats = false;
167
Enrico Granata0a3958e2011-07-02 00:25:22 +0000168 if (update_format)
Enrico Granata5548cb52013-01-28 23:47:25 +0000169 did_change_formats = UpdateFormatsIfNeeded();
Enrico Granata4becb372011-06-29 22:27:15 +0000170
Greg Claytonb71f3842010-10-05 03:13:51 +0000171 // If this is a constant value, then our success is predicated on whether
172 // we have an error or not
173 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000174 {
Enrico Granatab1c6c482013-10-09 00:33:55 +0000175 // if you are constant, things might still have changed behind your back
176 // (e.g. you are a frozen object and things have changed deeper than you cared to freeze-dry yourself)
177 // in this case, your value has not changed, but "computed" entries might have, so you might now have
178 // a different summary, or a different object description. clear these so we will recompute them
Enrico Granata9128ee22011-09-06 19:20:51 +0000179 if (update_format && !did_change_formats)
Enrico Granatab1c6c482013-10-09 00:33:55 +0000180 ClearUserVisibleData(eClearUserVisibleDataItemsSummary | eClearUserVisibleDataItemsDescription);
Greg Claytonb71f3842010-10-05 03:13:51 +0000181 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000182 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000183
Jim Ingham6035b672011-03-31 00:19:25 +0000184 bool first_update = m_update_point.IsFirstEvaluation();
185
186 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000187 {
Jim Ingham6035b672011-03-31 00:19:25 +0000188 m_update_point.SetUpdated();
189
190 // Save the old value using swap to avoid a string copy which
191 // also will clear our m_value_str
192 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000193 {
Jim Ingham6035b672011-03-31 00:19:25 +0000194 m_old_value_valid = false;
195 }
196 else
197 {
198 m_old_value_valid = true;
199 m_old_value_str.swap (m_value_str);
Enrico Granata86cc9822012-03-19 22:58:49 +0000200 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham6035b672011-03-31 00:19:25 +0000201 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000202
Enrico Granataf2bbf712011-07-15 02:26:42 +0000203 ClearUserVisibleData();
204
Greg Claytonefbc7d22012-03-09 04:23:44 +0000205 if (IsInScope())
Jim Ingham6035b672011-03-31 00:19:25 +0000206 {
Greg Claytonefbc7d22012-03-09 04:23:44 +0000207 const bool value_was_valid = GetValueIsValid();
208 SetValueDidChange (false);
209
210 m_error.Clear();
211
212 // Call the pure virtual function to update the value
213 bool success = UpdateValue ();
214
215 SetValueIsValid (success);
216
217 if (first_update)
218 SetValueDidChange (false);
219 else if (!m_value_did_change && success == false)
220 {
221 // The value wasn't gotten successfully, so we mark this
222 // as changed if the value used to be valid and now isn't
223 SetValueDidChange (value_was_valid);
224 }
225 }
226 else
227 {
228 m_error.SetErrorString("out of scope");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000229 }
230 }
231 return m_error.Success();
232}
233
Enrico Granata9128ee22011-09-06 19:20:51 +0000234bool
Enrico Granata5548cb52013-01-28 23:47:25 +0000235ValueObject::UpdateFormatsIfNeeded()
Enrico Granata4becb372011-06-29 22:27:15 +0000236{
Greg Clayton5160ce52013-03-27 23:08:40 +0000237 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000238 if (log)
Enrico Granatad2284832012-10-17 22:23:56 +0000239 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
Enrico Granata6f3533f2011-07-29 19:53:35 +0000240 GetName().GetCString(),
Enrico Granatad2284832012-10-17 22:23:56 +0000241 this,
Enrico Granata4becb372011-06-29 22:27:15 +0000242 m_last_format_mgr_revision,
Enrico Granata85933ed2011-08-18 16:38:26 +0000243 DataVisualization::GetCurrentRevision());
Enrico Granata9128ee22011-09-06 19:20:51 +0000244
245 bool any_change = false;
246
Enrico Granata5548cb52013-01-28 23:47:25 +0000247 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()))
Enrico Granata4becb372011-06-29 22:27:15 +0000248 {
Enrico Granata852cc952013-10-08 19:03:22 +0000249 SetValueFormat(DataVisualization::GetFormat (*this, eNoDynamicValues));
Enrico Granata5548cb52013-01-28 23:47:25 +0000250 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000251#ifndef LLDB_DISABLE_PYTHON
Enrico Granata5548cb52013-01-28 23:47:25 +0000252 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000253#endif
Enrico Granata1490c6f2011-07-19 02:34:21 +0000254
Enrico Granata85933ed2011-08-18 16:38:26 +0000255 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
Enrico Granata855cd902011-09-06 22:59:55 +0000256
257 any_change = true;
Enrico Granata4becb372011-06-29 22:27:15 +0000258 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000259
260 return any_change;
261
Enrico Granata4becb372011-06-29 22:27:15 +0000262}
263
Jim Ingham16e0c682011-08-12 23:34:31 +0000264void
265ValueObject::SetNeedsUpdate ()
266{
267 m_update_point.SetNeedsUpdate();
268 // We have to clear the value string here so ConstResult children will notice if their values are
269 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000270 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000271}
272
Enrico Granata13ac0e22012-10-17 19:03:34 +0000273void
Enrico Granatae3e91512012-10-22 18:18:36 +0000274ValueObject::ClearDynamicTypeInformation ()
Enrico Granata13ac0e22012-10-17 19:03:34 +0000275{
Enrico Granata38c54632013-10-30 00:04:29 +0000276 m_children_count_valid = false;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000277 m_did_calculate_complete_objc_class_type = false;
Enrico Granatae3e91512012-10-22 18:18:36 +0000278 m_last_format_mgr_revision = 0;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000279 m_override_type = ClangASTType();
Enrico Granatae3e91512012-10-22 18:18:36 +0000280 SetValueFormat(lldb::TypeFormatImplSP());
281 SetSummaryFormat(lldb::TypeSummaryImplSP());
282 SetSyntheticChildren(lldb::SyntheticChildrenSP());
Enrico Granata13ac0e22012-10-17 19:03:34 +0000283}
284
Sean Callanan72772842012-02-22 23:57:45 +0000285ClangASTType
286ValueObject::MaybeCalculateCompleteType ()
287{
Greg Clayton57ee3062013-07-11 22:46:58 +0000288 ClangASTType clang_type(GetClangTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000289
Sean Callanan72772842012-02-22 23:57:45 +0000290 if (m_did_calculate_complete_objc_class_type)
291 {
292 if (m_override_type.IsValid())
293 return m_override_type;
294 else
Greg Clayton57ee3062013-07-11 22:46:58 +0000295 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000296 }
297
Greg Clayton57ee3062013-07-11 22:46:58 +0000298 ClangASTType class_type;
299 bool is_pointer_type = false;
Sean Callanan72772842012-02-22 23:57:45 +0000300
Greg Clayton57ee3062013-07-11 22:46:58 +0000301 if (clang_type.IsObjCObjectPointerType(&class_type))
Sean Callanan72772842012-02-22 23:57:45 +0000302 {
303 is_pointer_type = true;
304 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000305 else if (clang_type.IsObjCObjectOrInterfaceType())
Sean Callanan72772842012-02-22 23:57:45 +0000306 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000307 class_type = clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000308 }
309 else
310 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000311 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000312 }
313
314 m_did_calculate_complete_objc_class_type = true;
315
Greg Clayton57ee3062013-07-11 22:46:58 +0000316 if (class_type)
Sean Callanan72772842012-02-22 23:57:45 +0000317 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000318 ConstString class_name (class_type.GetConstTypeName());
Sean Callanan72772842012-02-22 23:57:45 +0000319
Greg Clayton57ee3062013-07-11 22:46:58 +0000320 if (class_name)
321 {
322 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
323
324 if (process_sp)
325 {
326 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
327
328 if (objc_language_runtime)
329 {
330 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name);
331
332 if (complete_objc_class_type_sp)
333 {
334 ClangASTType complete_class(complete_objc_class_type_sp->GetClangFullType());
335
336 if (complete_class.GetCompleteType())
337 {
338 if (is_pointer_type)
339 {
340 m_override_type = complete_class.GetPointerType();
341 }
342 else
343 {
344 m_override_type = complete_class;
345 }
346
347 if (m_override_type.IsValid())
348 return m_override_type;
349 }
350 }
351 }
352 }
353 }
Sean Callanan72772842012-02-22 23:57:45 +0000354 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000355 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000356}
357
Greg Clayton57ee3062013-07-11 22:46:58 +0000358ClangASTType
Sean Callanan72772842012-02-22 23:57:45 +0000359ValueObject::GetClangType ()
360{
Greg Clayton57ee3062013-07-11 22:46:58 +0000361 return MaybeCalculateCompleteType();
Sean Callanan72772842012-02-22 23:57:45 +0000362}
363
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000364TypeImpl
365ValueObject::GetTypeImpl ()
366{
367 return TypeImpl(GetClangType());
368}
369
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000370DataExtractor &
371ValueObject::GetDataExtractor ()
372{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000373 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000374 return m_data;
375}
376
377const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000378ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000379{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000380 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000381 return m_error;
382}
383
384const ConstString &
385ValueObject::GetName() const
386{
387 return m_name;
388}
389
390const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000391ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000392{
Enrico Granata82fabf82013-04-30 20:45:04 +0000393 return GetLocationAsCStringImpl(m_value,
394 m_data);
395}
396
397const char *
398ValueObject::GetLocationAsCStringImpl (const Value& value,
399 const DataExtractor& data)
400{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000401 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000402 {
403 if (m_location_str.empty())
404 {
405 StreamString sstr;
Enrico Granata82fabf82013-04-30 20:45:04 +0000406
407 Value::ValueType value_type = value.GetValueType();
408
409 switch (value_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000410 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000411 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +0000412 case Value::eValueTypeVector:
Enrico Granata82fabf82013-04-30 20:45:04 +0000413 if (value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000414 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000415 RegisterInfo *reg_info = value.GetRegisterInfo();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000416 if (reg_info)
417 {
418 if (reg_info->name)
419 m_location_str = reg_info->name;
420 else if (reg_info->alt_name)
421 m_location_str = reg_info->alt_name;
Enrico Granata82fabf82013-04-30 20:45:04 +0000422 if (m_location_str.empty())
423 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000424 }
425 }
Enrico Granata82fabf82013-04-30 20:45:04 +0000426 if (m_location_str.empty())
427 m_location_str = (value_type == Value::eValueTypeVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000428 break;
429
430 case Value::eValueTypeLoadAddress:
431 case Value::eValueTypeFileAddress:
432 case Value::eValueTypeHostAddress:
433 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000434 uint32_t addr_nibble_size = data.GetAddressByteSize() * 2;
435 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000436 m_location_str.swap(sstr.GetString());
437 }
438 break;
439 }
440 }
441 }
442 return m_location_str.c_str();
443}
444
445Value &
446ValueObject::GetValue()
447{
448 return m_value;
449}
450
451const Value &
452ValueObject::GetValue() const
453{
454 return m_value;
455}
456
457bool
Jim Ingham6035b672011-03-31 00:19:25 +0000458ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000459{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000460 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
461 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000462 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000463 Value tmp_value(m_value);
Greg Clayton57ee3062013-07-11 22:46:58 +0000464 scalar = tmp_value.ResolveValue(&exe_ctx);
Greg Claytondcad5022011-12-29 01:26:56 +0000465 if (scalar.IsValid())
466 {
467 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
468 if (bitfield_bit_size)
469 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
470 return true;
471 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000472 }
Greg Claytondcad5022011-12-29 01:26:56 +0000473 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000474}
475
476bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000477ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000478{
Greg Clayton288bdf92010-09-02 02:59:18 +0000479 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000480}
481
482
483void
484ValueObject::SetValueIsValid (bool b)
485{
Greg Clayton288bdf92010-09-02 02:59:18 +0000486 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000487}
488
489bool
Jim Ingham6035b672011-03-31 00:19:25 +0000490ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000491{
Jim Ingham6035b672011-03-31 00:19:25 +0000492 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000493 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000494}
495
496void
497ValueObject::SetValueDidChange (bool value_changed)
498{
Greg Clayton288bdf92010-09-02 02:59:18 +0000499 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000500}
501
502ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000503ValueObject::GetChildAtIndex (size_t idx, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000504{
505 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000506 // We may need to update our value if we are dynamic
507 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000508 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000509 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000510 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000511 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000512 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000513 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000514 // No we haven't created the child at this index, so lets have our
515 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000516 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000517 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000518
Enrico Granata9d60f602012-03-09 03:09:58 +0000519 ValueObject* child = m_children.GetChildAtIndex(idx);
520 if (child != NULL)
521 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000522 }
523 return child_sp;
524}
525
Enrico Granata3309d882013-01-12 01:00:22 +0000526ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000527ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
528 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000529{
530 if (idxs.size() == 0)
531 return GetSP();
532 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000533 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000534 {
535 root = root->GetChildAtIndex(idx, true);
536 if (!root)
537 {
538 if (index_of_error)
539 *index_of_error = idx;
540 return root;
541 }
542 }
543 return root;
544}
545
546ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000547ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
548 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000549{
550 if (idxs.size() == 0)
551 return GetSP();
552 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000553 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000554 {
555 root = root->GetChildAtIndex(idx.first, idx.second);
556 if (!root)
557 {
558 if (index_of_error)
559 *index_of_error = idx.first;
560 return root;
561 }
562 }
563 return root;
564}
565
566lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000567ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
568 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000569{
570 if (idxs.size() == 0)
571 return GetSP();
572 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000573 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000574 {
575 root = root->GetChildAtIndex(idx, true);
576 if (!root)
577 {
578 if (index_of_error)
579 *index_of_error = idx;
580 return root;
581 }
582 }
583 return root;
584}
585
586lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000587ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
588 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000589{
590 if (idxs.size() == 0)
591 return GetSP();
592 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000593 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000594 {
595 root = root->GetChildAtIndex(idx.first, idx.second);
596 if (!root)
597 {
598 if (index_of_error)
599 *index_of_error = idx.first;
600 return root;
601 }
602 }
603 return root;
604}
605
Enrico Granatae2e220a2013-09-12 00:48:47 +0000606lldb::ValueObjectSP
607ValueObject::GetChildAtNamePath (const std::initializer_list<ConstString> &names,
608 ConstString* name_of_error)
609{
610 if (names.size() == 0)
611 return GetSP();
612 ValueObjectSP root(GetSP());
613 for (ConstString name : names)
614 {
615 root = root->GetChildMemberWithName(name, true);
616 if (!root)
617 {
618 if (name_of_error)
619 *name_of_error = name;
620 return root;
621 }
622 }
623 return root;
624}
625
626lldb::ValueObjectSP
627ValueObject::GetChildAtNamePath (const std::vector<ConstString> &names,
628 ConstString* name_of_error)
629{
630 if (names.size() == 0)
631 return GetSP();
632 ValueObjectSP root(GetSP());
633 for (ConstString name : names)
634 {
635 root = root->GetChildMemberWithName(name, true);
636 if (!root)
637 {
638 if (name_of_error)
639 *name_of_error = name;
640 return root;
641 }
642 }
643 return root;
644}
645
646lldb::ValueObjectSP
647ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names,
648 ConstString* name_of_error)
649{
650 if (names.size() == 0)
651 return GetSP();
652 ValueObjectSP root(GetSP());
653 for (std::pair<ConstString, bool> name : names)
654 {
655 root = root->GetChildMemberWithName(name.first, name.second);
656 if (!root)
657 {
658 if (name_of_error)
659 *name_of_error = name.first;
660 return root;
661 }
662 }
663 return root;
664}
665
666lldb::ValueObjectSP
667ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names,
668 ConstString* name_of_error)
669{
670 if (names.size() == 0)
671 return GetSP();
672 ValueObjectSP root(GetSP());
673 for (std::pair<ConstString, bool> name : names)
674 {
675 root = root->GetChildMemberWithName(name.first, name.second);
676 if (!root)
677 {
678 if (name_of_error)
679 *name_of_error = name.first;
680 return root;
681 }
682 }
683 return root;
684}
685
Greg Claytonc7bece562013-01-25 18:06:21 +0000686size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000687ValueObject::GetIndexOfChildWithName (const ConstString &name)
688{
689 bool omit_empty_base_classes = true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000690 return GetClangType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000691}
692
693ValueObjectSP
694ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
695{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000696 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000697 // classes (which really aren't part of the expression path), so we
698 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000699 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000700
Greg Claytondea8cb42011-06-29 22:09:02 +0000701 // We may need to update our value if we are dynamic
702 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000703 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000704
705 std::vector<uint32_t> child_indexes;
Greg Claytondea8cb42011-06-29 22:09:02 +0000706 bool omit_empty_base_classes = true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000707 const size_t num_child_indexes = GetClangType().GetIndexOfChildMemberWithName (name.GetCString(),
708 omit_empty_base_classes,
709 child_indexes);
Greg Claytondea8cb42011-06-29 22:09:02 +0000710 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000711 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000712 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
713 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
714
715 child_sp = GetChildAtIndex(*pos, can_create);
716 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000717 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000718 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000719 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000720 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
721 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000722 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000723 else
724 {
725 child_sp.reset();
726 }
727
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000728 }
729 }
730 return child_sp;
731}
732
733
Greg Claytonc7bece562013-01-25 18:06:21 +0000734size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000735ValueObject::GetNumChildren ()
736{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000737 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000738 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000739 {
740 SetNumChildren (CalculateNumChildren());
741 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000742 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000743}
Greg Clayton4a792072012-10-23 01:50:10 +0000744
745bool
746ValueObject::MightHaveChildren()
747{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000748 bool has_children = false;
Greg Clayton2452ab72013-02-08 22:02:02 +0000749 const uint32_t type_info = GetTypeInfo();
750 if (type_info)
Greg Clayton4a792072012-10-23 01:50:10 +0000751 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000752 if (type_info & (ClangASTType::eTypeHasChildren |
753 ClangASTType::eTypeIsPointer |
754 ClangASTType::eTypeIsReference))
Greg Clayton4a792072012-10-23 01:50:10 +0000755 has_children = true;
756 }
757 else
758 {
759 has_children = GetNumChildren () > 0;
760 }
761 return has_children;
762}
763
764// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000765void
Greg Claytonc7bece562013-01-25 18:06:21 +0000766ValueObject::SetNumChildren (size_t num_children)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000767{
Greg Clayton288bdf92010-09-02 02:59:18 +0000768 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000769 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000770}
771
772void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000773ValueObject::SetName (const ConstString &name)
774{
775 m_name = name;
776}
777
Jim Ingham58b59f92011-04-22 23:53:53 +0000778ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000779ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000780{
Jim Ingham2eec4872011-05-07 00:10:58 +0000781 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000782
Greg Claytondea8cb42011-06-29 22:09:02 +0000783 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000784 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000785 std::string child_name_str;
786 uint32_t child_byte_size = 0;
787 int32_t child_byte_offset = 0;
788 uint32_t child_bitfield_bit_size = 0;
789 uint32_t child_bitfield_bit_offset = 0;
790 bool child_is_base_class = false;
791 bool child_is_deref_of_parent = false;
792
793 const bool transparent_pointers = synthetic_array_member == false;
Greg Clayton57ee3062013-07-11 22:46:58 +0000794 ClangASTType child_clang_type;
Greg Claytondea8cb42011-06-29 22:09:02 +0000795
Greg Claytoncc4d0142012-02-17 07:49:44 +0000796 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000797
Greg Clayton57ee3062013-07-11 22:46:58 +0000798 child_clang_type = GetClangType().GetChildClangTypeAtIndex (&exe_ctx,
799 GetName().GetCString(),
800 idx,
801 transparent_pointers,
802 omit_empty_base_classes,
803 ignore_array_bounds,
804 child_name_str,
805 child_byte_size,
806 child_byte_offset,
807 child_bitfield_bit_size,
808 child_bitfield_bit_offset,
809 child_is_base_class,
810 child_is_deref_of_parent);
Greg Clayton4ef877f2012-12-06 02:33:54 +0000811 if (child_clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000812 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000813 if (synthetic_index)
814 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000815
Greg Claytondea8cb42011-06-29 22:09:02 +0000816 ConstString child_name;
817 if (!child_name_str.empty())
818 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000819
Greg Claytondea8cb42011-06-29 22:09:02 +0000820 valobj = new ValueObjectChild (*this,
Greg Claytondea8cb42011-06-29 22:09:02 +0000821 child_clang_type,
822 child_name,
823 child_byte_size,
824 child_byte_offset,
825 child_bitfield_bit_size,
826 child_bitfield_bit_offset,
827 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000828 child_is_deref_of_parent,
829 eAddressTypeInvalid);
830 //if (valobj)
831 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
832 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000833
Jim Ingham58b59f92011-04-22 23:53:53 +0000834 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000835}
836
Enrico Granata0c489f52012-03-01 04:24:26 +0000837bool
838ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
839 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000840{
Enrico Granata0c489f52012-03-01 04:24:26 +0000841 destination.clear();
842
843 // ideally we would like to bail out if passing NULL, but if we do so
844 // we end up not providing the summary for function pointers anymore
845 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
846 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000847
848 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000849
850 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
851 // information that we might care to see in a crash log. might be useful in very specific situations though.
852 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
853 GetTypeName().GetCString(),
854 GetName().GetCString(),
855 summary_ptr->GetDescription().c_str());*/
856
Enrico Granata0c489f52012-03-01 04:24:26 +0000857 if (UpdateValueIfNeeded (false))
858 {
859 if (summary_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000860 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000861 if (HasSyntheticValue())
862 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
863 summary_ptr->FormatObject(this, destination);
Enrico Granata0c489f52012-03-01 04:24:26 +0000864 }
865 else
866 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000867 ClangASTType clang_type = GetClangType();
Enrico Granata0c489f52012-03-01 04:24:26 +0000868
869 // Do some default printout for function pointers
870 if (clang_type)
Enrico Granata4becb372011-06-29 22:27:15 +0000871 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000872 if (clang_type.IsFunctionPointerType ())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000873 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000874 StreamString sstr;
Enrico Granata0c489f52012-03-01 04:24:26 +0000875 AddressType func_ptr_address_type = eAddressTypeInvalid;
876 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
877 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000878 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000879 switch (func_ptr_address_type)
Jim Ingham6035b672011-03-31 00:19:25 +0000880 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000881 case eAddressTypeInvalid:
882 case eAddressTypeFile:
883 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000884
Greg Claytoncc4d0142012-02-17 07:49:44 +0000885 case eAddressTypeLoad:
Enrico Granata0c489f52012-03-01 04:24:26 +0000886 {
887 ExecutionContext exe_ctx (GetExecutionContextRef());
888
889 Address so_addr;
890 Target *target = exe_ctx.GetTargetPtr();
891 if (target && target->GetSectionLoadList().IsEmpty() == false)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000892 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000893 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000894 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000895 so_addr.Dump (&sstr,
896 exe_ctx.GetBestExecutionContextScope(),
897 Address::DumpStyleResolvedDescription,
898 Address::DumpStyleSectionNameOffset);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000899 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000900 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000901 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000902 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000903
Greg Claytoncc4d0142012-02-17 07:49:44 +0000904 case eAddressTypeHost:
905 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +0000906 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000907 }
908 if (sstr.GetSize() > 0)
909 {
910 destination.assign (1, '(');
911 destination.append (sstr.GetData(), sstr.GetSize());
912 destination.append (1, ')');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000913 }
914 }
915 }
916 }
917 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000918 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000919 return !destination.empty();
920}
921
922const char *
923ValueObject::GetSummaryAsCString ()
924{
925 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
926 {
927 GetSummaryAsCString(GetSummaryFormat().get(),
928 m_summary_str);
929 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000930 if (m_summary_str.empty())
931 return NULL;
932 return m_summary_str.c_str();
933}
934
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000935bool
936ValueObject::IsCStringContainer(bool check_pointer)
937{
Greg Clayton57ee3062013-07-11 22:46:58 +0000938 ClangASTType pointee_or_element_clang_type;
939 const Flags type_flags (GetTypeInfo (&pointee_or_element_clang_type));
940 bool is_char_arr_ptr (type_flags.AnySet (ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer) &&
941 pointee_or_element_clang_type.IsCharType ());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000942 if (!is_char_arr_ptr)
943 return false;
944 if (!check_pointer)
945 return true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000946 if (type_flags.Test(ClangASTType::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000947 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000948 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000949 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000950 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000951 return (cstr_address != LLDB_INVALID_ADDRESS);
952}
953
Enrico Granata9128ee22011-09-06 19:20:51 +0000954size_t
955ValueObject::GetPointeeData (DataExtractor& data,
956 uint32_t item_idx,
957 uint32_t item_count)
958{
Greg Clayton57ee3062013-07-11 22:46:58 +0000959 ClangASTType pointee_or_element_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +0000960 const uint32_t type_info = GetTypeInfo (&pointee_or_element_clang_type);
Greg Clayton57ee3062013-07-11 22:46:58 +0000961 const bool is_pointer_type = type_info & ClangASTType::eTypeIsPointer;
962 const bool is_array_type = type_info & ClangASTType::eTypeIsArray;
Greg Clayton2452ab72013-02-08 22:02:02 +0000963 if (!(is_pointer_type || is_array_type))
Enrico Granata9128ee22011-09-06 19:20:51 +0000964 return 0;
965
966 if (item_count == 0)
967 return 0;
968
Greg Clayton57ee3062013-07-11 22:46:58 +0000969 const uint64_t item_type_size = pointee_or_element_clang_type.GetByteSize();
Enrico Granata9128ee22011-09-06 19:20:51 +0000970 const uint64_t bytes = item_count * item_type_size;
Enrico Granata9128ee22011-09-06 19:20:51 +0000971 const uint64_t offset = item_idx * item_type_size;
972
973 if (item_idx == 0 && item_count == 1) // simply a deref
974 {
Greg Clayton2452ab72013-02-08 22:02:02 +0000975 if (is_pointer_type)
Enrico Granata9128ee22011-09-06 19:20:51 +0000976 {
977 Error error;
978 ValueObjectSP pointee_sp = Dereference(error);
979 if (error.Fail() || pointee_sp.get() == NULL)
980 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +0000981 return pointee_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +0000982 }
983 else
984 {
985 ValueObjectSP child_sp = GetChildAtIndex(0, true);
986 if (child_sp.get() == NULL)
987 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +0000988 Error error;
989 return child_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +0000990 }
991 return true;
992 }
993 else /* (items > 1) */
994 {
995 Error error;
996 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
997 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
998
999 AddressType addr_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001000 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001001
Enrico Granata9128ee22011-09-06 19:20:51 +00001002 switch (addr_type)
1003 {
1004 case eAddressTypeFile:
1005 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001006 ModuleSP module_sp (GetModule());
1007 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001008 {
Enrico Granata9c2efe32012-08-07 01:49:34 +00001009 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +00001010 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001011 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001012 ExecutionContext exe_ctx (GetExecutionContextRef());
1013 Target* target = exe_ctx.GetTargetPtr();
1014 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +00001015 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001016 heap_buf_ptr->SetByteSize(bytes);
1017 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
1018 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +00001019 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001020 data.SetData(data_sp);
1021 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +00001022 }
1023 }
1024 }
1025 }
1026 break;
1027 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +00001028 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001029 ExecutionContext exe_ctx (GetExecutionContextRef());
1030 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +00001031 if (process)
1032 {
1033 heap_buf_ptr->SetByteSize(bytes);
1034 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
Enrico Granata5e1480c2013-10-30 17:52:44 +00001035 if (error.Success() || bytes_read > 0)
Enrico Granata9128ee22011-09-06 19:20:51 +00001036 {
1037 data.SetData(data_sp);
1038 return bytes_read;
1039 }
1040 }
1041 }
1042 break;
1043 case eAddressTypeHost:
1044 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001045 const uint64_t max_bytes = GetClangType().GetByteSize();
Greg Clayton2452ab72013-02-08 22:02:02 +00001046 if (max_bytes > offset)
1047 {
1048 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
1049 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
1050 data.SetData(data_sp);
1051 return bytes_read;
1052 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001053 }
1054 break;
1055 case eAddressTypeInvalid:
Enrico Granata9128ee22011-09-06 19:20:51 +00001056 break;
1057 }
1058 }
1059 return 0;
1060}
1061
Greg Claytonfaac1112013-03-14 18:31:44 +00001062uint64_t
Sean Callanan866e91c2014-02-28 22:27:53 +00001063ValueObject::GetData (DataExtractor& data, Error &error)
Enrico Granata9128ee22011-09-06 19:20:51 +00001064{
1065 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001066 ExecutionContext exe_ctx (GetExecutionContextRef());
Sean Callanan866e91c2014-02-28 22:27:53 +00001067 error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001068 if (error.Fail())
Sean Callananed185ab2013-04-19 19:47:32 +00001069 {
1070 if (m_data.GetByteSize())
1071 {
1072 data = m_data;
1073 return data.GetByteSize();
1074 }
1075 else
1076 {
1077 return 0;
1078 }
1079 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001080 data.SetAddressByteSize(m_data.GetAddressByteSize());
1081 data.SetByteOrder(m_data.GetByteOrder());
1082 return data.GetByteSize();
1083}
1084
Sean Callanan389823e2013-04-13 01:21:23 +00001085bool
1086ValueObject::SetData (DataExtractor &data, Error &error)
1087{
1088 error.Clear();
1089 // Make sure our value is up to date first so that our location and location
1090 // type is valid.
1091 if (!UpdateValueIfNeeded(false))
1092 {
1093 error.SetErrorString("unable to read value");
1094 return false;
1095 }
1096
1097 uint64_t count = 0;
Greg Clayton57ee3062013-07-11 22:46:58 +00001098 const Encoding encoding = GetClangType().GetEncoding(count);
Sean Callanan389823e2013-04-13 01:21:23 +00001099
1100 const size_t byte_size = GetByteSize();
1101
1102 Value::ValueType value_type = m_value.GetValueType();
1103
1104 switch (value_type)
1105 {
1106 case Value::eValueTypeScalar:
1107 {
1108 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1109
1110 if (!set_error.Success())
1111 {
1112 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1113 return false;
1114 }
1115 }
1116 break;
1117 case Value::eValueTypeLoadAddress:
1118 {
1119 // If it is a load address, then the scalar value is the storage location
1120 // of the data, and we have to shove this value down to that load location.
1121 ExecutionContext exe_ctx (GetExecutionContextRef());
1122 Process *process = exe_ctx.GetProcessPtr();
1123 if (process)
1124 {
1125 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1126 size_t bytes_written = process->WriteMemory(target_addr,
1127 data.GetDataStart(),
1128 byte_size,
1129 error);
1130 if (!error.Success())
1131 return false;
1132 if (bytes_written != byte_size)
1133 {
1134 error.SetErrorString("unable to write value to memory");
1135 return false;
1136 }
1137 }
1138 }
1139 break;
1140 case Value::eValueTypeHostAddress:
1141 {
1142 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1143 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1144 m_data.SetData(buffer_sp, 0);
1145 data.CopyByteOrderedData (0,
1146 byte_size,
1147 const_cast<uint8_t *>(m_data.GetDataStart()),
1148 byte_size,
1149 m_data.GetByteOrder());
1150 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1151 }
1152 break;
1153 case Value::eValueTypeFileAddress:
1154 case Value::eValueTypeVector:
1155 break;
1156 }
1157
1158 // If we have reached this point, then we have successfully changed the value.
1159 SetNeedsUpdate();
1160 return true;
1161}
1162
Enrico Granata9128ee22011-09-06 19:20:51 +00001163// will compute strlen(str), but without consuming more than
1164// maxlen bytes out of str (this serves the purpose of reading
1165// chunks of a string without having to worry about
1166// missing NULL terminators in the chunk)
1167// of course, if strlen(str) > maxlen, the function will return
1168// maxlen_value (which should be != maxlen, because that allows you
1169// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1170static uint32_t
1171strlen_or_inf (const char* str,
1172 uint32_t maxlen,
1173 uint32_t maxlen_value)
1174{
1175 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +00001176 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +00001177 {
Greg Clayton8dd5c172011-10-05 22:19:51 +00001178 while(*str)
1179 {
1180 len++;str++;
Greg Clayton2452ab72013-02-08 22:02:02 +00001181 if (len >= maxlen)
Greg Clayton8dd5c172011-10-05 22:19:51 +00001182 return maxlen_value;
1183 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001184 }
1185 return len;
1186}
1187
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001188size_t
Greg Claytoncc4d0142012-02-17 07:49:44 +00001189ValueObject::ReadPointedString (Stream& s,
1190 Error& error,
1191 uint32_t max_length,
1192 bool honor_array,
1193 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001194{
Greg Claytoncc4d0142012-02-17 07:49:44 +00001195 ExecutionContext exe_ctx (GetExecutionContextRef());
1196 Target* target = exe_ctx.GetTargetPtr();
1197
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001198 if (!target)
1199 {
1200 s << "<no target to read from>";
1201 error.SetErrorString("no target to read from");
1202 return 0;
1203 }
1204
1205 if (max_length == 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001206 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001207
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001208 size_t bytes_read = 0;
1209 size_t total_bytes_read = 0;
1210
Greg Clayton57ee3062013-07-11 22:46:58 +00001211 ClangASTType clang_type = GetClangType();
1212 ClangASTType elem_or_pointee_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001213 const Flags type_flags (GetTypeInfo (&elem_or_pointee_clang_type));
Greg Clayton57ee3062013-07-11 22:46:58 +00001214 if (type_flags.AnySet (ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer) &&
1215 elem_or_pointee_clang_type.IsCharType ())
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001216 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001217 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1218 AddressType cstr_address_type = eAddressTypeInvalid;
1219
1220 size_t cstr_len = 0;
1221 bool capped_data = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00001222 if (type_flags.Test (ClangASTType::eTypeIsArray))
Greg Claytoncc4d0142012-02-17 07:49:44 +00001223 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001224 // We have an array
Greg Clayton57ee3062013-07-11 22:46:58 +00001225 uint64_t array_size = 0;
1226 if (clang_type.IsArrayType(NULL, &array_size, NULL))
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001227 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001228 cstr_len = array_size;
1229 if (cstr_len > max_length)
1230 {
1231 capped_data = true;
1232 cstr_len = max_length;
1233 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001234 }
1235 cstr_address = GetAddressOf (true, &cstr_address_type);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001236 }
1237 else
1238 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001239 // We have a pointer
1240 cstr_address = GetPointerValue (&cstr_address_type);
1241 }
1242
1243 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1244 {
1245 s << "<invalid address>";
1246 error.SetErrorString("invalid address");
1247 return 0;
1248 }
1249
1250 Address cstr_so_addr (cstr_address);
1251 DataExtractor data;
1252 if (cstr_len > 0 && honor_array)
1253 {
1254 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1255 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1256 GetPointeeData(data, 0, cstr_len);
1257
1258 if ((bytes_read = data.GetByteSize()) > 0)
1259 {
1260 total_bytes_read = bytes_read;
1261 s << '"';
1262 data.Dump (&s,
1263 0, // Start offset in "data"
1264 item_format,
1265 1, // Size of item (1 byte for a char!)
1266 bytes_read, // How many bytes to print?
1267 UINT32_MAX, // num per line
1268 LLDB_INVALID_ADDRESS,// base address
1269 0, // bitfield bit size
1270 0); // bitfield bit offset
1271 if (capped_data)
1272 s << "...";
1273 s << '"';
1274 }
1275 }
1276 else
1277 {
1278 cstr_len = max_length;
1279 const size_t k_max_buf_size = 64;
1280
1281 size_t offset = 0;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001282
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001283 int cstr_len_displayed = -1;
1284 bool capped_cstr = false;
1285 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1286 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1287 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001288 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001289 total_bytes_read += bytes_read;
1290 const char *cstr = data.PeekCStr(0);
1291 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1292 if (len > k_max_buf_size)
1293 len = k_max_buf_size;
1294 if (cstr && cstr_len_displayed < 0)
1295 s << '"';
1296
1297 if (cstr_len_displayed < 0)
1298 cstr_len_displayed = len;
1299
1300 if (len == 0)
1301 break;
1302 cstr_len_displayed += len;
1303 if (len > bytes_read)
1304 len = bytes_read;
1305 if (len > cstr_len)
1306 len = cstr_len;
1307
1308 data.Dump (&s,
1309 0, // Start offset in "data"
1310 item_format,
1311 1, // Size of item (1 byte for a char!)
1312 len, // How many bytes to print?
1313 UINT32_MAX, // num per line
1314 LLDB_INVALID_ADDRESS,// base address
1315 0, // bitfield bit size
1316 0); // bitfield bit offset
1317
1318 if (len < k_max_buf_size)
1319 break;
1320
1321 if (len >= cstr_len)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001322 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001323 capped_cstr = true;
1324 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001325 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001326
1327 cstr_len -= len;
1328 offset += len;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001329 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001330
1331 if (cstr_len_displayed >= 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001332 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001333 s << '"';
1334 if (capped_cstr)
1335 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001336 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001337 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001338 }
1339 else
1340 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001341 error.SetErrorString("not a string object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001342 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001343 }
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001344 return total_bytes_read;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001345}
1346
Jim Ingham53c47f12010-09-10 23:12:17 +00001347const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001348ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001349{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001350
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001351 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001352 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001353
1354 if (!m_object_desc_str.empty())
1355 return m_object_desc_str.c_str();
1356
Greg Claytoncc4d0142012-02-17 07:49:44 +00001357 ExecutionContext exe_ctx (GetExecutionContextRef());
1358 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001359 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001360 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001361
Jim Ingham53c47f12010-09-10 23:12:17 +00001362 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001363
Greg Claytonafacd142011-09-02 01:15:17 +00001364 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001365 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1366
Jim Inghama2cf2632010-12-23 02:29:54 +00001367 if (runtime == NULL)
1368 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001369 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Greg Clayton57ee3062013-07-11 22:46:58 +00001370 ClangASTType clang_type = GetClangType();
1371 if (clang_type)
Jim Inghama2cf2632010-12-23 02:29:54 +00001372 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001373 bool is_signed;
Greg Clayton57ee3062013-07-11 22:46:58 +00001374 if (clang_type.IsIntegerType (is_signed) || clang_type.IsPointerType ())
Jim Inghamb7603bb2011-03-18 00:05:18 +00001375 {
Greg Claytonafacd142011-09-02 01:15:17 +00001376 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001377 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001378 }
1379 }
1380
Jim Ingham8d543de2011-03-31 23:01:21 +00001381 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001382 {
1383 m_object_desc_str.append (s.GetData());
1384 }
Sean Callanan672ad942010-10-23 00:18:49 +00001385
1386 if (m_object_desc_str.empty())
1387 return NULL;
1388 else
1389 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001390}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001391
Enrico Granata0c489f52012-03-01 04:24:26 +00001392bool
Enrico Granata4939b982013-12-22 09:24:22 +00001393ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format,
1394 std::string& destination)
1395{
1396 if (UpdateValueIfNeeded(false))
1397 return format.FormatObject(this,destination);
1398 else
1399 return false;
1400}
1401
1402bool
Enrico Granata0c489f52012-03-01 04:24:26 +00001403ValueObject::GetValueAsCString (lldb::Format format,
1404 std::string& destination)
1405{
Enrico Granata30f287f2013-12-28 08:44:02 +00001406 return GetValueAsCString(TypeFormatImpl_Format(format),destination);
Enrico Granata0c489f52012-03-01 04:24:26 +00001407}
1408
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001409const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001410ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001411{
Enrico Granatab294fd22013-05-31 19:18:19 +00001412 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001413 {
Enrico Granata4939b982013-12-22 09:24:22 +00001414 lldb::TypeFormatImplSP format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001415 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001416 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001417 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001418 if (m_type_format_sp)
Enrico Granata4939b982013-12-22 09:24:22 +00001419 format_sp = m_type_format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001420 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001421 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001422 if (m_is_bitfield_for_scalar)
1423 my_format = eFormatUnsigned;
1424 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001425 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001426 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001427 {
1428 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1429 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001430 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001431 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001432 else
1433 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001434 my_format = GetClangType().GetFormat();
Enrico Granata0c489f52012-03-01 04:24:26 +00001435 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001436 }
1437 }
1438 }
Enrico Granatab294fd22013-05-31 19:18:19 +00001439 if (my_format != m_last_format || m_value_str.empty())
Enrico Granata297e69f2012-03-06 23:21:16 +00001440 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001441 m_last_format = my_format;
Enrico Granata4939b982013-12-22 09:24:22 +00001442 if (!format_sp)
Enrico Granata30f287f2013-12-28 08:44:02 +00001443 format_sp.reset(new TypeFormatImpl_Format(my_format));
Enrico Granata4939b982013-12-22 09:24:22 +00001444 if (GetValueAsCString(*format_sp.get(), m_value_str))
Enrico Granata297e69f2012-03-06 23:21:16 +00001445 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001446 if (!m_value_did_change && m_old_value_valid)
1447 {
1448 // The value was gotten successfully, so we consider the
1449 // value as changed if the value string differs
1450 SetValueDidChange (m_old_value_str != m_value_str);
1451 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001452 }
1453 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001454 }
1455 if (m_value_str.empty())
1456 return NULL;
1457 return m_value_str.c_str();
1458}
1459
Enrico Granatac3e320a2011-08-02 17:27:39 +00001460// if > 8bytes, 0 is returned. this method should mostly be used
1461// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001462uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001463ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001464{
1465 // If our byte size is zero this is an aggregate type that has children
Greg Clayton57ee3062013-07-11 22:46:58 +00001466 if (!GetClangType().IsAggregateType())
Enrico Granatac3e320a2011-08-02 17:27:39 +00001467 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001468 Scalar scalar;
1469 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001470 {
1471 if (success)
1472 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001473 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001474 }
1475 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001476 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001477
1478 if (success)
1479 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001480 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001481}
1482
Enrico Granatad7373f62013-10-31 18:57:50 +00001483int64_t
1484ValueObject::GetValueAsSigned (int64_t fail_value, bool *success)
1485{
1486 // If our byte size is zero this is an aggregate type that has children
1487 if (!GetClangType().IsAggregateType())
1488 {
1489 Scalar scalar;
1490 if (ResolveValue (scalar))
1491 {
1492 if (success)
1493 *success = true;
1494 return scalar.SLongLong(fail_value);
1495 }
1496 // fallthrough, otherwise...
1497 }
1498
1499 if (success)
1500 *success = false;
1501 return fail_value;
1502}
1503
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001504// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1505// this call up to date by returning true for your new special cases. We will eventually move
1506// to checking this call result before trying to display special cases
1507bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001508ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1509 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001510{
Greg Clayton57ee3062013-07-11 22:46:58 +00001511 Flags flags(GetTypeInfo());
1512 if (flags.AnySet(ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001513 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001514 {
1515 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001516 (custom_format == eFormatCString ||
1517 custom_format == eFormatCharArray ||
1518 custom_format == eFormatChar ||
1519 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001520 return true;
1521
Greg Clayton57ee3062013-07-11 22:46:58 +00001522 if (flags.Test(ClangASTType::eTypeIsArray))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001523 {
Greg Claytonafacd142011-09-02 01:15:17 +00001524 if ((custom_format == eFormatBytes) ||
1525 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001526 return true;
1527
Greg Claytonafacd142011-09-02 01:15:17 +00001528 if ((custom_format == eFormatVectorOfChar) ||
1529 (custom_format == eFormatVectorOfFloat32) ||
1530 (custom_format == eFormatVectorOfFloat64) ||
1531 (custom_format == eFormatVectorOfSInt16) ||
1532 (custom_format == eFormatVectorOfSInt32) ||
1533 (custom_format == eFormatVectorOfSInt64) ||
1534 (custom_format == eFormatVectorOfSInt8) ||
1535 (custom_format == eFormatVectorOfUInt128) ||
1536 (custom_format == eFormatVectorOfUInt16) ||
1537 (custom_format == eFormatVectorOfUInt32) ||
1538 (custom_format == eFormatVectorOfUInt64) ||
1539 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001540 return true;
1541 }
1542 }
1543 return false;
1544}
1545
Enrico Granata9fc19442011-07-06 02:13:41 +00001546bool
1547ValueObject::DumpPrintableRepresentation(Stream& s,
1548 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001549 Format custom_format,
Enrico Granata0dba9b32014-01-08 01:36:59 +00001550 PrintableRepresentationSpecialCases special,
1551 bool do_dump_error)
Enrico Granata9fc19442011-07-06 02:13:41 +00001552{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001553
Greg Clayton57ee3062013-07-11 22:46:58 +00001554 Flags flags(GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001555
Enrico Granata86cc9822012-03-19 22:58:49 +00001556 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1557 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1558
1559 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001560 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001561 if (flags.AnySet(ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001562 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001563 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001564 // when being asked to get a printable display an array or pointer type directly,
1565 // try to "do the right thing"
1566
1567 if (IsCStringContainer(true) &&
1568 (custom_format == eFormatCString ||
1569 custom_format == eFormatCharArray ||
1570 custom_format == eFormatChar ||
1571 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001572 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001573 Error error;
1574 ReadPointedString(s,
1575 error,
1576 0,
1577 (custom_format == eFormatVectorOfChar) ||
1578 (custom_format == eFormatCharArray));
1579 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001580 }
1581
Enrico Granata86cc9822012-03-19 22:58:49 +00001582 if (custom_format == eFormatEnum)
1583 return false;
1584
1585 // this only works for arrays, because I have no way to know when
1586 // the pointed memory ends, and no special \0 end of data marker
Greg Clayton57ee3062013-07-11 22:46:58 +00001587 if (flags.Test(ClangASTType::eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001588 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001589 if ((custom_format == eFormatBytes) ||
1590 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001591 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001592 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001593
1594 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001595 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001596 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001597
1598 if (low)
1599 s << ',';
1600
1601 ValueObjectSP child = GetChildAtIndex(low,true);
1602 if (!child.get())
1603 {
1604 s << "<invalid child>";
1605 continue;
1606 }
1607 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1608 }
1609
1610 s << ']';
1611
1612 return true;
1613 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001614
Enrico Granata86cc9822012-03-19 22:58:49 +00001615 if ((custom_format == eFormatVectorOfChar) ||
1616 (custom_format == eFormatVectorOfFloat32) ||
1617 (custom_format == eFormatVectorOfFloat64) ||
1618 (custom_format == eFormatVectorOfSInt16) ||
1619 (custom_format == eFormatVectorOfSInt32) ||
1620 (custom_format == eFormatVectorOfSInt64) ||
1621 (custom_format == eFormatVectorOfSInt8) ||
1622 (custom_format == eFormatVectorOfUInt128) ||
1623 (custom_format == eFormatVectorOfUInt16) ||
1624 (custom_format == eFormatVectorOfUInt32) ||
1625 (custom_format == eFormatVectorOfUInt64) ||
1626 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1627 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001628 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001629
1630 Format format = FormatManager::GetSingleItemFormat(custom_format);
1631
1632 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001633 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001634 {
1635
1636 if (low)
1637 s << ',';
1638
1639 ValueObjectSP child = GetChildAtIndex(low,true);
1640 if (!child.get())
1641 {
1642 s << "<invalid child>";
1643 continue;
1644 }
1645 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1646 }
1647
1648 s << ']';
1649
1650 return true;
1651 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001652 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001653
1654 if ((custom_format == eFormatBoolean) ||
1655 (custom_format == eFormatBinary) ||
1656 (custom_format == eFormatChar) ||
1657 (custom_format == eFormatCharPrintable) ||
1658 (custom_format == eFormatComplexFloat) ||
1659 (custom_format == eFormatDecimal) ||
1660 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001661 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001662 (custom_format == eFormatFloat) ||
1663 (custom_format == eFormatOctal) ||
1664 (custom_format == eFormatOSType) ||
1665 (custom_format == eFormatUnicode16) ||
1666 (custom_format == eFormatUnicode32) ||
1667 (custom_format == eFormatUnsigned) ||
1668 (custom_format == eFormatPointer) ||
1669 (custom_format == eFormatComplexInteger) ||
1670 (custom_format == eFormatComplex) ||
1671 (custom_format == eFormatDefault)) // use the [] operator
1672 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001673 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001674 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001675
1676 if (only_special)
1677 return false;
1678
Enrico Granata86cc9822012-03-19 22:58:49 +00001679 bool var_success = false;
1680
1681 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001682 const char *cstr = NULL;
Enrico Granata2c75f112013-06-21 00:04:51 +00001683
1684 // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1685 // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1686 // area for cases where our desired output is not backed by some other longer-term storage
Greg Claytonc7bece562013-01-25 18:06:21 +00001687 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001688
Enrico Granata465f4bc2014-02-15 01:24:44 +00001689 if (custom_format != eFormatInvalid)
Enrico Granata86cc9822012-03-19 22:58:49 +00001690 SetFormat(custom_format);
1691
1692 switch(val_obj_display)
1693 {
1694 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001695 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001696 break;
1697
1698 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001699 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001700 break;
1701
1702 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001703 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001704 break;
1705
1706 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001707 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001708 break;
1709
1710 case eValueObjectRepresentationStyleChildrenCount:
Greg Claytonc7bece562013-01-25 18:06:21 +00001711 strm.Printf("%zu", GetNumChildren());
1712 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001713 break;
1714
1715 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001716 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001717 break;
Enrico Granata2c75f112013-06-21 00:04:51 +00001718
1719 case eValueObjectRepresentationStyleName:
1720 cstr = GetName().AsCString();
1721 break;
1722
1723 case eValueObjectRepresentationStyleExpressionPath:
1724 GetExpressionPath(strm, false);
1725 cstr = strm.GetString().c_str();
1726 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001727 }
1728
Greg Claytonc7bece562013-01-25 18:06:21 +00001729 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001730 {
1731 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001732 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001733 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1734 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001735 if (GetClangType().IsAggregateType())
Enrico Granata86cc9822012-03-19 22:58:49 +00001736 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001737 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1738 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001739 }
1740 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001741 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001742 }
1743 }
1744
Greg Claytonc7bece562013-01-25 18:06:21 +00001745 if (cstr)
1746 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001747 else
1748 {
1749 if (m_error.Fail())
Enrico Granata0dba9b32014-01-08 01:36:59 +00001750 {
1751 if (do_dump_error)
1752 s.Printf("<%s>", m_error.AsCString());
1753 else
1754 return false;
1755 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001756 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1757 s.PutCString("<no summary available>");
1758 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1759 s.PutCString("<no value available>");
1760 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1761 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1762 else
1763 s.PutCString("<no printable representation>");
1764 }
1765
1766 // we should only return false here if we could not do *anything*
1767 // even if we have an error message as output, that's a success
1768 // from our callers' perspective, so return true
1769 var_success = true;
Enrico Granata465f4bc2014-02-15 01:24:44 +00001770
1771 if (custom_format != eFormatInvalid)
1772 SetFormat(eFormatDefault);
Enrico Granata86cc9822012-03-19 22:58:49 +00001773 }
1774
Enrico Granataf4efecd2011-07-12 22:56:10 +00001775 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001776}
1777
Greg Clayton737b9322010-09-13 03:32:57 +00001778addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001779ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001780{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001781 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001782 return LLDB_INVALID_ADDRESS;
1783
Greg Clayton73b472d2010-10-27 03:32:59 +00001784 switch (m_value.GetValueType())
1785 {
1786 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001787 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001788 if (scalar_is_load_address)
1789 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001790 if(address_type)
1791 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001792 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1793 }
1794 break;
1795
1796 case Value::eValueTypeLoadAddress:
1797 case Value::eValueTypeFileAddress:
1798 case Value::eValueTypeHostAddress:
1799 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001800 if(address_type)
1801 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001802 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1803 }
1804 break;
1805 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001806 if (address_type)
1807 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001808 return LLDB_INVALID_ADDRESS;
1809}
1810
1811addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001812ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001813{
Greg Claytonafacd142011-09-02 01:15:17 +00001814 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001815 if(address_type)
1816 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001817
Enrico Granatac3e320a2011-08-02 17:27:39 +00001818 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001819 return address;
1820
Greg Clayton73b472d2010-10-27 03:32:59 +00001821 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001822 {
1823 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001824 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001825 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001826 break;
1827
Enrico Granata9128ee22011-09-06 19:20:51 +00001828 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001829 case Value::eValueTypeLoadAddress:
1830 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001831 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001832 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001833 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001834 }
1835 break;
1836 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001837
Enrico Granata9128ee22011-09-06 19:20:51 +00001838 if (address_type)
1839 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001840
Greg Clayton737b9322010-09-13 03:32:57 +00001841 return address;
1842}
1843
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001844bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001845ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001846{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001847 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001848 // Make sure our value is up to date first so that our location and location
1849 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001850 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001851 {
1852 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001853 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001854 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001855
Greg Claytonfaac1112013-03-14 18:31:44 +00001856 uint64_t count = 0;
Greg Clayton57ee3062013-07-11 22:46:58 +00001857 const Encoding encoding = GetClangType().GetEncoding (count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001858
Greg Claytonb1320972010-07-14 00:18:15 +00001859 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001860
Jim Ingham16e0c682011-08-12 23:34:31 +00001861 Value::ValueType value_type = m_value.GetValueType();
1862
1863 if (value_type == Value::eValueTypeScalar)
1864 {
1865 // If the value is already a scalar, then let the scalar change itself:
1866 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1867 }
1868 else if (byte_size <= Scalar::GetMaxByteSize())
1869 {
1870 // If the value fits in a scalar, then make a new scalar and again let the
1871 // scalar code do the conversion, then figure out where to put the new value.
1872 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001873 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1874 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001875 {
Jim Ingham4b536182011-08-09 02:12:22 +00001876 switch (value_type)
1877 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001878 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001879 {
1880 // If it is a load address, then the scalar value is the storage location
1881 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001882 ExecutionContext exe_ctx (GetExecutionContextRef());
1883 Process *process = exe_ctx.GetProcessPtr();
1884 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001885 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001886 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001887 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1888 new_scalar,
1889 byte_size,
1890 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001891 if (!error.Success())
1892 return false;
1893 if (bytes_written != byte_size)
1894 {
1895 error.SetErrorString("unable to write value to memory");
1896 return false;
1897 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001898 }
1899 }
Jim Ingham4b536182011-08-09 02:12:22 +00001900 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001901 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001902 {
1903 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1904 DataExtractor new_data;
1905 new_data.SetByteOrder (m_data.GetByteOrder());
1906
1907 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1908 m_data.SetData(buffer_sp, 0);
1909 bool success = new_scalar.GetData(new_data);
1910 if (success)
1911 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001912 new_data.CopyByteOrderedData (0,
1913 byte_size,
1914 const_cast<uint8_t *>(m_data.GetDataStart()),
1915 byte_size,
1916 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001917 }
1918 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1919
1920 }
Jim Ingham4b536182011-08-09 02:12:22 +00001921 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001922 case Value::eValueTypeFileAddress:
1923 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001924 case Value::eValueTypeVector:
1925 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001926 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001927 }
1928 else
1929 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001930 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001931 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001932 }
1933 else
1934 {
1935 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001936 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001937 return false;
1938 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001939
1940 // If we have reached this point, then we have successfully changed the value.
1941 SetNeedsUpdate();
1942 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001943}
1944
Greg Clayton81e871e2012-02-04 02:27:34 +00001945bool
1946ValueObject::GetDeclaration (Declaration &decl)
1947{
1948 decl.Clear();
1949 return false;
1950}
1951
Greg Clayton84db9102012-03-26 23:03:23 +00001952ConstString
1953ValueObject::GetTypeName()
1954{
Greg Clayton57ee3062013-07-11 22:46:58 +00001955 return GetClangType().GetConstTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00001956}
1957
1958ConstString
1959ValueObject::GetQualifiedTypeName()
1960{
Greg Clayton57ee3062013-07-11 22:46:58 +00001961 return GetClangType().GetConstQualifiedTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00001962}
1963
1964
Greg Claytonafacd142011-09-02 01:15:17 +00001965LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001966ValueObject::GetObjectRuntimeLanguage ()
1967{
Greg Clayton57ee3062013-07-11 22:46:58 +00001968 return GetClangType().GetMinimumLanguage ();
Jim Ingham5a369122010-09-28 01:25:32 +00001969}
1970
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001971void
Jim Ingham58b59f92011-04-22 23:53:53 +00001972ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001973{
Jim Ingham58b59f92011-04-22 23:53:53 +00001974 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001975}
1976
1977ValueObjectSP
1978ValueObject::GetSyntheticChild (const ConstString &key) const
1979{
1980 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001981 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001982 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001983 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001984 return synthetic_child_sp;
1985}
1986
Greg Clayton2452ab72013-02-08 22:02:02 +00001987uint32_t
Greg Clayton57ee3062013-07-11 22:46:58 +00001988ValueObject::GetTypeInfo (ClangASTType *pointee_or_element_clang_type)
Greg Clayton2452ab72013-02-08 22:02:02 +00001989{
Greg Clayton57ee3062013-07-11 22:46:58 +00001990 return GetClangType().GetTypeInfo (pointee_or_element_clang_type);
Greg Clayton2452ab72013-02-08 22:02:02 +00001991}
1992
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001993bool
1994ValueObject::IsPointerType ()
1995{
Greg Clayton57ee3062013-07-11 22:46:58 +00001996 return GetClangType().IsPointerType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001997}
1998
Jim Inghamb7603bb2011-03-18 00:05:18 +00001999bool
Greg Claytondaf515f2011-07-09 20:12:33 +00002000ValueObject::IsArrayType ()
2001{
Greg Clayton57ee3062013-07-11 22:46:58 +00002002 return GetClangType().IsArrayType (NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00002003}
2004
2005bool
Enrico Granata9fc19442011-07-06 02:13:41 +00002006ValueObject::IsScalarType ()
2007{
Greg Clayton57ee3062013-07-11 22:46:58 +00002008 return GetClangType().IsScalarType ();
Enrico Granata9fc19442011-07-06 02:13:41 +00002009}
2010
2011bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00002012ValueObject::IsIntegerType (bool &is_signed)
2013{
Greg Clayton57ee3062013-07-11 22:46:58 +00002014 return GetClangType().IsIntegerType (is_signed);
Jim Inghamb7603bb2011-03-18 00:05:18 +00002015}
Greg Clayton73b472d2010-10-27 03:32:59 +00002016
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002017bool
2018ValueObject::IsPointerOrReferenceType ()
2019{
Greg Clayton57ee3062013-07-11 22:46:58 +00002020 return GetClangType().IsPointerOrReferenceType ();
Greg Clayton007d5be2011-05-30 00:49:24 +00002021}
2022
2023bool
Greg Claytondea8cb42011-06-29 22:09:02 +00002024ValueObject::IsPossibleDynamicType ()
2025{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002026 ExecutionContext exe_ctx (GetExecutionContextRef());
2027 Process *process = exe_ctx.GetProcessPtr();
2028 if (process)
2029 return process->IsPossibleDynamicValue(*this);
2030 else
Greg Clayton57ee3062013-07-11 22:46:58 +00002031 return GetClangType().IsPossibleDynamicType (NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00002032}
2033
Enrico Granata9e7b3882012-12-13 23:50:33 +00002034bool
2035ValueObject::IsObjCNil ()
2036{
Greg Clayton57ee3062013-07-11 22:46:58 +00002037 const uint32_t mask = ClangASTType::eTypeIsObjC | ClangASTType::eTypeIsPointer;
2038 bool isObjCpointer = (((GetClangType().GetTypeInfo(NULL)) & mask) == mask);
Enrico Granata7277d202013-03-15 23:33:15 +00002039 if (!isObjCpointer)
2040 return false;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002041 bool canReadValue = true;
2042 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
Enrico Granata7277d202013-03-15 23:33:15 +00002043 return canReadValue && isZero;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002044}
2045
Greg Claytonafacd142011-09-02 01:15:17 +00002046ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002047ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002048{
Greg Clayton2452ab72013-02-08 22:02:02 +00002049 const uint32_t type_info = GetTypeInfo ();
Greg Clayton57ee3062013-07-11 22:46:58 +00002050 if (type_info & ClangASTType::eTypeIsArray)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002051 return GetSyntheticArrayMemberFromArray(index, can_create);
2052
Greg Clayton57ee3062013-07-11 22:46:58 +00002053 if (type_info & ClangASTType::eTypeIsPointer)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002054 return GetSyntheticArrayMemberFromPointer(index, can_create);
2055
2056 return ValueObjectSP();
2057
2058}
2059
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002060ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002061ValueObject::GetSyntheticArrayMemberFromPointer (size_t index, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002062{
2063 ValueObjectSP synthetic_child_sp;
2064 if (IsPointerType ())
2065 {
2066 char index_str[64];
Greg Claytonc7bece562013-01-25 18:06:21 +00002067 snprintf(index_str, sizeof(index_str), "[%zu]", index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002068 ConstString index_const_str(index_str);
2069 // Check if we have already created a synthetic array member in this
2070 // valid object. If we have we will re-use it.
2071 synthetic_child_sp = GetSyntheticChild (index_const_str);
2072 if (!synthetic_child_sp)
2073 {
Jim Ingham58b59f92011-04-22 23:53:53 +00002074 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002075 // We haven't made a synthetic array member for INDEX yet, so
2076 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00002077 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002078
2079 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00002080 if (synthetic_child)
2081 {
2082 AddSyntheticChild(index_const_str, synthetic_child);
2083 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002084 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00002085 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00002086 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002087 }
2088 }
2089 return synthetic_child_sp;
2090}
Jim Ingham22777012010-09-23 02:01:19 +00002091
Greg Claytondaf515f2011-07-09 20:12:33 +00002092// This allows you to create an array member using and index
2093// that doesn't not fall in the normal bounds of the array.
2094// Many times structure can be defined as:
2095// struct Collection
2096// {
2097// uint32_t item_count;
2098// Item item_array[0];
2099// };
2100// The size of the "item_array" is 1, but many times in practice
2101// there are more items in "item_array".
2102
2103ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002104ValueObject::GetSyntheticArrayMemberFromArray (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00002105{
2106 ValueObjectSP synthetic_child_sp;
2107 if (IsArrayType ())
2108 {
2109 char index_str[64];
Greg Claytonc7bece562013-01-25 18:06:21 +00002110 snprintf(index_str, sizeof(index_str), "[%zu]", index);
Greg Claytondaf515f2011-07-09 20:12:33 +00002111 ConstString index_const_str(index_str);
2112 // Check if we have already created a synthetic array member in this
2113 // valid object. If we have we will re-use it.
2114 synthetic_child_sp = GetSyntheticChild (index_const_str);
2115 if (!synthetic_child_sp)
2116 {
2117 ValueObject *synthetic_child;
2118 // We haven't made a synthetic array member for INDEX yet, so
2119 // lets make one and cache it for any future reference.
2120 synthetic_child = CreateChildAtIndex(0, true, index);
2121
2122 // Cache the value if we got one back...
2123 if (synthetic_child)
2124 {
2125 AddSyntheticChild(index_const_str, synthetic_child);
2126 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002127 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00002128 synthetic_child_sp->m_is_array_item_for_pointer = true;
2129 }
2130 }
2131 }
2132 return synthetic_child_sp;
2133}
2134
Enrico Granata9fc19442011-07-06 02:13:41 +00002135ValueObjectSP
2136ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2137{
2138 ValueObjectSP synthetic_child_sp;
2139 if (IsScalarType ())
2140 {
2141 char index_str[64];
2142 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2143 ConstString index_const_str(index_str);
2144 // Check if we have already created a synthetic array member in this
2145 // valid object. If we have we will re-use it.
2146 synthetic_child_sp = GetSyntheticChild (index_const_str);
2147 if (!synthetic_child_sp)
2148 {
Enrico Granata9fc19442011-07-06 02:13:41 +00002149 // We haven't made a synthetic array member for INDEX yet, so
2150 // lets make one and cache it for any future reference.
Greg Clayton57ee3062013-07-11 22:46:58 +00002151 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
2152 GetClangType(),
2153 index_const_str,
2154 GetByteSize(),
2155 0,
2156 to-from+1,
2157 from,
2158 false,
2159 false,
2160 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002161
2162 // Cache the value if we got one back...
2163 if (synthetic_child)
2164 {
2165 AddSyntheticChild(index_const_str, synthetic_child);
2166 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002167 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002168 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2169 }
2170 }
2171 }
2172 return synthetic_child_sp;
2173}
2174
Greg Claytonafacd142011-09-02 01:15:17 +00002175ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00002176ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
2177{
2178
2179 ValueObjectSP synthetic_child_sp;
2180
2181 char name_str[64];
2182 snprintf(name_str, sizeof(name_str), "@%i", offset);
2183 ConstString name_const_str(name_str);
2184
2185 // Check if we have already created a synthetic array member in this
2186 // valid object. If we have we will re-use it.
2187 synthetic_child_sp = GetSyntheticChild (name_const_str);
2188
2189 if (synthetic_child_sp.get())
2190 return synthetic_child_sp;
2191
2192 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002193 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002194
2195 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
Greg Clayton57ee3062013-07-11 22:46:58 +00002196 type,
Enrico Granata6f3533f2011-07-29 19:53:35 +00002197 name_const_str,
Greg Clayton57ee3062013-07-11 22:46:58 +00002198 type.GetByteSize(),
Enrico Granata6f3533f2011-07-29 19:53:35 +00002199 offset,
2200 0,
2201 0,
2202 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002203 false,
2204 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002205 if (synthetic_child)
2206 {
2207 AddSyntheticChild(name_const_str, synthetic_child);
2208 synthetic_child_sp = synthetic_child->GetSP();
2209 synthetic_child_sp->SetName(name_const_str);
2210 synthetic_child_sp->m_is_child_at_offset = true;
2211 }
2212 return synthetic_child_sp;
2213}
2214
Enrico Granatad55546b2011-07-22 00:16:08 +00002215// your expression path needs to have a leading . or ->
2216// (unless it somehow "looks like" an array, in which case it has
2217// a leading [ symbol). while the [ is meaningful and should be shown
2218// to the user, . and -> are just parser design, but by no means
2219// added information for the user.. strip them off
2220static const char*
2221SkipLeadingExpressionPathSeparators(const char* expression)
2222{
2223 if (!expression || !expression[0])
2224 return expression;
2225 if (expression[0] == '.')
2226 return expression+1;
2227 if (expression[0] == '-' && expression[1] == '>')
2228 return expression+2;
2229 return expression;
2230}
2231
Greg Claytonafacd142011-09-02 01:15:17 +00002232ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002233ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2234{
2235 ValueObjectSP synthetic_child_sp;
2236 ConstString name_const_string(expression);
2237 // Check if we have already created a synthetic array member in this
2238 // valid object. If we have we will re-use it.
2239 synthetic_child_sp = GetSyntheticChild (name_const_string);
2240 if (!synthetic_child_sp)
2241 {
2242 // We haven't made a synthetic array member for expression yet, so
2243 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002244 synthetic_child_sp = GetValueForExpressionPath(expression,
2245 NULL, NULL, NULL,
2246 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
Enrico Granatad55546b2011-07-22 00:16:08 +00002247
2248 // Cache the value if we got one back...
2249 if (synthetic_child_sp.get())
2250 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002251 // 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 +00002252 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002253 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002254 }
2255 }
2256 return synthetic_child_sp;
2257}
2258
2259void
Enrico Granata86cc9822012-03-19 22:58:49 +00002260ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002261{
Enrico Granata86cc9822012-03-19 22:58:49 +00002262 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002263 return;
2264
Enrico Granatac5bc4122012-03-27 02:35:13 +00002265 TargetSP target_sp(GetTargetSP());
Enrico Granata5d5f60c2013-09-24 22:58:37 +00002266 if (target_sp && target_sp->GetEnableSyntheticValue() == false)
Enrico Granatac5bc4122012-03-27 02:35:13 +00002267 {
2268 m_synthetic_value = NULL;
2269 return;
2270 }
2271
Enrico Granatae3e91512012-10-22 18:18:36 +00002272 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2273
Enrico Granata5548cb52013-01-28 23:47:25 +00002274 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002275 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002276
Enrico Granata0c489f52012-03-01 04:24:26 +00002277 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002278 return;
2279
Enrico Granatae3e91512012-10-22 18:18:36 +00002280 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2281 return;
2282
Enrico Granata86cc9822012-03-19 22:58:49 +00002283 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002284}
2285
Jim Ingham78a685a2011-04-16 00:01:13 +00002286void
Greg Claytonafacd142011-09-02 01:15:17 +00002287ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002288{
Greg Claytonafacd142011-09-02 01:15:17 +00002289 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002290 return;
2291
Jim Ingham58b59f92011-04-22 23:53:53 +00002292 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002293 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002294 ExecutionContext exe_ctx (GetExecutionContextRef());
2295 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002296 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002297 {
2298 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002299 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002300 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002301 }
2302}
2303
Jim Ingham58b59f92011-04-22 23:53:53 +00002304ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002305ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002306{
Greg Claytonafacd142011-09-02 01:15:17 +00002307 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002308 return ValueObjectSP();
2309
2310 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002311 {
Jim Ingham2837b762011-05-04 03:43:18 +00002312 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002313 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002314 if (m_dynamic_value)
2315 return m_dynamic_value->GetSP();
2316 else
2317 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002318}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002319
Jim Ingham60dbabb2011-12-08 19:44:08 +00002320ValueObjectSP
2321ValueObject::GetStaticValue()
2322{
2323 return GetSP();
2324}
2325
Enrico Granata886147f2012-05-08 18:47:08 +00002326lldb::ValueObjectSP
2327ValueObject::GetNonSyntheticValue ()
2328{
2329 return GetSP();
2330}
2331
Enrico Granatad55546b2011-07-22 00:16:08 +00002332ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002333ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002334{
Enrico Granata86cc9822012-03-19 22:58:49 +00002335 if (use_synthetic == false)
2336 return ValueObjectSP();
2337
Enrico Granatad55546b2011-07-22 00:16:08 +00002338 CalculateSyntheticValue(use_synthetic);
2339
2340 if (m_synthetic_value)
2341 return m_synthetic_value->GetSP();
2342 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002343 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002344}
2345
Greg Claytone221f822011-01-21 01:59:00 +00002346bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002347ValueObject::HasSyntheticValue()
2348{
Enrico Granata5548cb52013-01-28 23:47:25 +00002349 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002350
Enrico Granata0c489f52012-03-01 04:24:26 +00002351 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002352 return false;
2353
Enrico Granata86cc9822012-03-19 22:58:49 +00002354 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002355
2356 if (m_synthetic_value)
2357 return true;
2358 else
2359 return false;
2360}
2361
2362bool
Greg Claytone221f822011-01-21 01:59:00 +00002363ValueObject::GetBaseClassPath (Stream &s)
2364{
2365 if (IsBaseClass())
2366 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002367 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Clayton57ee3062013-07-11 22:46:58 +00002368 ClangASTType clang_type = GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002369 std::string cxx_class_name;
Greg Clayton57ee3062013-07-11 22:46:58 +00002370 bool this_had_base_class = clang_type.GetCXXClassName (cxx_class_name);
Greg Claytone221f822011-01-21 01:59:00 +00002371 if (this_had_base_class)
2372 {
2373 if (parent_had_base_class)
2374 s.PutCString("::");
2375 s.PutCString(cxx_class_name.c_str());
2376 }
2377 return parent_had_base_class || this_had_base_class;
2378 }
2379 return false;
2380}
2381
2382
2383ValueObject *
2384ValueObject::GetNonBaseClassParent()
2385{
Jim Ingham78a685a2011-04-16 00:01:13 +00002386 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002387 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002388 if (GetParent()->IsBaseClass())
2389 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002390 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002391 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002392 }
2393 return NULL;
2394}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002395
2396void
Enrico Granata4becb372011-06-29 22:27:15 +00002397ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002398{
Greg Claytone221f822011-01-21 01:59:00 +00002399 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002400
Enrico Granata86cc9822012-03-19 22:58:49 +00002401 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002402 {
Enrico Granata4becb372011-06-29 22:27:15 +00002403 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2404 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2405 // the eHonorPointers mode is meant to produce strings in this latter format
2406 s.PutCString("*(");
2407 }
Greg Claytone221f822011-01-21 01:59:00 +00002408
Enrico Granata4becb372011-06-29 22:27:15 +00002409 ValueObject* parent = GetParent();
2410
2411 if (parent)
2412 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002413
2414 // if we are a deref_of_parent just because we are synthetic array
2415 // members made up to allow ptr[%d] syntax to work in variable
2416 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002417 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002418 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002419
Greg Claytone221f822011-01-21 01:59:00 +00002420 if (!IsBaseClass())
2421 {
2422 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002423 {
Greg Claytone221f822011-01-21 01:59:00 +00002424 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2425 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002426 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002427 ClangASTType non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002428 if (non_base_class_parent_clang_type)
2429 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002430 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002431 {
2432 s.PutCString("->");
2433 }
Enrico Granata4becb372011-06-29 22:27:15 +00002434 else
2435 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002436 const uint32_t non_base_class_parent_type_info = non_base_class_parent_clang_type.GetTypeInfo();
2437
2438 if (non_base_class_parent_type_info & ClangASTType::eTypeIsPointer)
Enrico Granata4becb372011-06-29 22:27:15 +00002439 {
2440 s.PutCString("->");
2441 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002442 else if ((non_base_class_parent_type_info & ClangASTType::eTypeHasChildren) &&
2443 !(non_base_class_parent_type_info & ClangASTType::eTypeIsArray))
Enrico Granata4becb372011-06-29 22:27:15 +00002444 {
2445 s.PutChar('.');
2446 }
Greg Claytone221f822011-01-21 01:59:00 +00002447 }
2448 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002449 }
Greg Claytone221f822011-01-21 01:59:00 +00002450
2451 const char *name = GetName().GetCString();
2452 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002453 {
Greg Claytone221f822011-01-21 01:59:00 +00002454 if (qualify_cxx_base_classes)
2455 {
2456 if (GetBaseClassPath (s))
2457 s.PutCString("::");
2458 }
2459 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002460 }
2461 }
2462 }
2463
Enrico Granata86cc9822012-03-19 22:58:49 +00002464 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002465 {
Greg Claytone221f822011-01-21 01:59:00 +00002466 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002467 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002468}
2469
Greg Claytonafacd142011-09-02 01:15:17 +00002470ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002471ValueObject::GetValueForExpressionPath(const char* expression,
2472 const char** first_unparsed,
2473 ExpressionPathScanEndReason* reason_to_stop,
2474 ExpressionPathEndResultType* final_value_type,
2475 const GetValueForExpressionPathOptions& options,
2476 ExpressionPathAftermath* final_task_on_target)
2477{
2478
2479 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002480 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2481 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002482 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002483
2484 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2485 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2486 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2487 final_value_type ? final_value_type : &dummy_final_value_type,
2488 options,
2489 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2490
Enrico Granata86cc9822012-03-19 22:58:49 +00002491 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002492 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002493
Enrico Granata86cc9822012-03-19 22:58:49 +00002494 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 +00002495 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002496 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002497 {
2498 Error error;
2499 ValueObjectSP final_value = ret_val->Dereference(error);
2500 if (error.Fail() || !final_value.get())
2501 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002502 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002503 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002504 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002505 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002506 return ValueObjectSP();
2507 }
2508 else
2509 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002510 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002511 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002512 return final_value;
2513 }
2514 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002515 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002516 {
2517 Error error;
2518 ValueObjectSP final_value = ret_val->AddressOf(error);
2519 if (error.Fail() || !final_value.get())
2520 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002521 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002522 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002523 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002524 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002525 return ValueObjectSP();
2526 }
2527 else
2528 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002529 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002530 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002531 return final_value;
2532 }
2533 }
2534 }
2535 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2536}
2537
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002538int
2539ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002540 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002541 const char** first_unparsed,
2542 ExpressionPathScanEndReason* reason_to_stop,
2543 ExpressionPathEndResultType* final_value_type,
2544 const GetValueForExpressionPathOptions& options,
2545 ExpressionPathAftermath* final_task_on_target)
2546{
2547 const char* dummy_first_unparsed;
2548 ExpressionPathScanEndReason dummy_reason_to_stop;
2549 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002550 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002551
2552 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2553 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2554 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2555 final_value_type ? final_value_type : &dummy_final_value_type,
2556 options,
2557 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2558
2559 if (!ret_val.get()) // if there are errors, I add nothing to the list
2560 return 0;
2561
Enrico Granata86ea8d82012-03-29 01:34:34 +00002562 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002563 {
2564 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002565 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002566 {
2567 list->Append(ret_val);
2568 return 1;
2569 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002570 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 +00002571 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002572 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002573 {
2574 Error error;
2575 ValueObjectSP final_value = ret_val->Dereference(error);
2576 if (error.Fail() || !final_value.get())
2577 {
Greg Clayton23f59502012-07-17 03:23:13 +00002578 if (reason_to_stop)
2579 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2580 if (final_value_type)
2581 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002582 return 0;
2583 }
2584 else
2585 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002586 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002587 list->Append(final_value);
2588 return 1;
2589 }
2590 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002591 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002592 {
2593 Error error;
2594 ValueObjectSP final_value = ret_val->AddressOf(error);
2595 if (error.Fail() || !final_value.get())
2596 {
Greg Clayton23f59502012-07-17 03:23:13 +00002597 if (reason_to_stop)
2598 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2599 if (final_value_type)
2600 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002601 return 0;
2602 }
2603 else
2604 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002605 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002606 list->Append(final_value);
2607 return 1;
2608 }
2609 }
2610 }
2611 }
2612 else
2613 {
2614 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2615 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2616 ret_val,
2617 list,
2618 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2619 final_value_type ? final_value_type : &dummy_final_value_type,
2620 options,
2621 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2622 }
2623 // in any non-covered case, just do the obviously right thing
2624 list->Append(ret_val);
2625 return 1;
2626}
2627
Greg Claytonafacd142011-09-02 01:15:17 +00002628ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002629ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2630 const char** first_unparsed,
2631 ExpressionPathScanEndReason* reason_to_stop,
2632 ExpressionPathEndResultType* final_result,
2633 const GetValueForExpressionPathOptions& options,
2634 ExpressionPathAftermath* what_next)
2635{
2636 ValueObjectSP root = GetSP();
2637
2638 if (!root.get())
2639 return ValueObjectSP();
2640
2641 *first_unparsed = expression_cstr;
2642
2643 while (true)
2644 {
2645
2646 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2647
Greg Clayton57ee3062013-07-11 22:46:58 +00002648 ClangASTType root_clang_type = root->GetClangType();
2649 ClangASTType pointee_clang_type;
2650 Flags pointee_clang_type_info;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002651
Greg Clayton57ee3062013-07-11 22:46:58 +00002652 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002653 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00002654 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002655
2656 if (!expression_cstr || *expression_cstr == '\0')
2657 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002658 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002659 return root;
2660 }
2661
2662 switch (*expression_cstr)
2663 {
2664 case '-':
2665 {
2666 if (options.m_check_dot_vs_arrow_syntax &&
Greg Clayton57ee3062013-07-11 22:46:58 +00002667 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 +00002668 {
2669 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002670 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2671 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002672 return ValueObjectSP();
2673 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002674 if (root_clang_type_info.Test(ClangASTType::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2675 root_clang_type_info.Test(ClangASTType::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002676 options.m_no_fragile_ivar)
2677 {
2678 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002679 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2680 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002681 return ValueObjectSP();
2682 }
2683 if (expression_cstr[1] != '>')
2684 {
2685 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002686 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2687 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002688 return ValueObjectSP();
2689 }
2690 expression_cstr++; // skip the -
2691 }
2692 case '.': // or fallthrough from ->
2693 {
2694 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Greg Clayton57ee3062013-07-11 22:46:58 +00002695 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 +00002696 {
2697 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002698 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2699 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002700 return ValueObjectSP();
2701 }
2702 expression_cstr++; // skip .
2703 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2704 ConstString child_name;
2705 if (!next_separator) // if no other separator just expand this last layer
2706 {
2707 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002708 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2709
2710 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002711 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002712 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002713 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2714 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002715 return child_valobj_sp;
2716 }
2717 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2718 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002719 if (root->IsSynthetic())
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002720 {
2721 *first_unparsed = expression_cstr;
2722 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2723 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2724 return ValueObjectSP();
2725 }
2726
2727 child_valobj_sp = root->GetSyntheticValue();
Enrico Granata86cc9822012-03-19 22:58:49 +00002728 if (child_valobj_sp.get())
2729 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002730 }
2731
2732 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2733 // so we hit the "else" branch, and return an error
2734 if(child_valobj_sp.get()) // if it worked, just return
2735 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002736 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002737 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2738 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002739 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002740 }
2741 else
2742 {
2743 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002744 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2745 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002746 return ValueObjectSP();
2747 }
2748 }
2749 else // other layers do expand
2750 {
2751 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002752 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2753 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002754 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002755 root = child_valobj_sp;
2756 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002757 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002758 continue;
2759 }
2760 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2761 {
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002762 if (root->IsSynthetic())
2763 {
2764 *first_unparsed = expression_cstr;
2765 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2766 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2767 return ValueObjectSP();
2768 }
2769
Enrico Granata86cc9822012-03-19 22:58:49 +00002770 child_valobj_sp = root->GetSyntheticValue(true);
2771 if (child_valobj_sp)
2772 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002773 }
2774
2775 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2776 // so we hit the "else" branch, and return an error
2777 if(child_valobj_sp.get()) // if it worked, move on
2778 {
2779 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002780 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002781 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002782 continue;
2783 }
2784 else
2785 {
2786 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002787 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2788 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002789 return ValueObjectSP();
2790 }
2791 }
2792 break;
2793 }
2794 case '[':
2795 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002796 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 +00002797 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002798 if (!root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002799 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002800 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2801 {
2802 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002803 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2804 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002805 return ValueObjectSP();
2806 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002807 }
2808 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2809 {
2810 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002811 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2812 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002813 return ValueObjectSP();
2814 }
2815 }
2816 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2817 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002818 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002819 {
2820 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002821 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2822 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002823 return ValueObjectSP();
2824 }
2825 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2826 {
2827 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002828 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2829 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002830 return root;
2831 }
2832 }
2833 const char *separator_position = ::strchr(expression_cstr+1,'-');
2834 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2835 if (!close_bracket_position) // if there is no ], this is a syntax error
2836 {
2837 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002838 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2839 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002840 return ValueObjectSP();
2841 }
2842 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2843 {
2844 char *end = NULL;
2845 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2846 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2847 {
2848 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002849 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2850 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002851 return ValueObjectSP();
2852 }
2853 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2854 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002855 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002856 {
2857 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002858 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2859 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002860 return root;
2861 }
2862 else
2863 {
2864 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002865 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2866 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002867 return ValueObjectSP();
2868 }
2869 }
2870 // from here on we do have a valid index
Greg Clayton57ee3062013-07-11 22:46:58 +00002871 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002872 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002873 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2874 if (!child_valobj_sp)
2875 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002876 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002877 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2878 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002879 if (child_valobj_sp)
2880 {
2881 root = child_valobj_sp;
2882 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002883 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002884 continue;
2885 }
2886 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002887 {
2888 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002889 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2890 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002891 return ValueObjectSP();
2892 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002893 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002894 else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002895 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002896 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 +00002897 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002898 {
2899 Error error;
2900 root = root->Dereference(error);
2901 if (error.Fail() || !root.get())
2902 {
2903 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002904 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2905 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002906 return ValueObjectSP();
2907 }
2908 else
2909 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002910 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002911 continue;
2912 }
2913 }
2914 else
2915 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002916 if (root->GetClangType().GetMinimumLanguage() == eLanguageTypeObjC
2917 && pointee_clang_type_info.AllClear(ClangASTType::eTypeIsPointer)
Greg Clayton84db9102012-03-26 23:03:23 +00002918 && root->HasSyntheticValue()
2919 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002920 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002921 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002922 }
2923 else
2924 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002925 if (!root.get())
2926 {
2927 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002928 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2929 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002930 return ValueObjectSP();
2931 }
2932 else
2933 {
2934 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002935 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002936 continue;
2937 }
2938 }
2939 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002940 else if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002941 {
2942 root = root->GetSyntheticBitFieldChild(index, index, true);
2943 if (!root.get())
2944 {
2945 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002946 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2947 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002948 return ValueObjectSP();
2949 }
2950 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2951 {
2952 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002953 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2954 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002955 return root;
2956 }
2957 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002958 else if (root_clang_type_info.Test(ClangASTType::eTypeIsVector))
Enrico Granata08a1bb82013-06-19 00:00:45 +00002959 {
2960 root = root->GetChildAtIndex(index, true);
2961 if (!root.get())
2962 {
2963 *first_unparsed = expression_cstr;
2964 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2965 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2966 return ValueObjectSP();
2967 }
2968 else
2969 {
2970 *first_unparsed = end+1; // skip ]
2971 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2972 continue;
2973 }
2974 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002975 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002976 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002977 if (root->HasSyntheticValue())
2978 root = root->GetSyntheticValue();
2979 else if (!root->IsSynthetic())
2980 {
2981 *first_unparsed = expression_cstr;
2982 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2983 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2984 return ValueObjectSP();
2985 }
2986 // if we are here, then root itself is a synthetic VO.. should be good to go
2987
Enrico Granata27b625e2011-08-09 01:04:56 +00002988 if (!root.get())
2989 {
2990 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002991 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2992 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2993 return ValueObjectSP();
2994 }
2995 root = root->GetChildAtIndex(index, true);
2996 if (!root.get())
2997 {
2998 *first_unparsed = expression_cstr;
2999 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3000 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003001 return ValueObjectSP();
3002 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00003003 else
3004 {
3005 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003006 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00003007 continue;
3008 }
Enrico Granata27b625e2011-08-09 01:04:56 +00003009 }
3010 else
3011 {
3012 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003013 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3014 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003015 return ValueObjectSP();
3016 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003017 }
3018 else // we have a low and a high index
3019 {
3020 char *end = NULL;
3021 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3022 if (!end || end != separator_position) // if something weird is in our way return an error
3023 {
3024 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003025 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3026 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003027 return ValueObjectSP();
3028 }
3029 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3030 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3031 {
3032 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003033 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3034 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003035 return ValueObjectSP();
3036 }
3037 if (index_lower > index_higher) // swap indices if required
3038 {
3039 unsigned long temp = index_lower;
3040 index_lower = index_higher;
3041 index_higher = temp;
3042 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003043 if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003044 {
3045 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3046 if (!root.get())
3047 {
3048 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003049 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3050 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003051 return ValueObjectSP();
3052 }
3053 else
3054 {
3055 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003056 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3057 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003058 return root;
3059 }
3060 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003061 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 +00003062 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Greg Clayton57ee3062013-07-11 22:46:58 +00003063 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003064 {
3065 Error error;
3066 root = root->Dereference(error);
3067 if (error.Fail() || !root.get())
3068 {
3069 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003070 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3071 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003072 return ValueObjectSP();
3073 }
3074 else
3075 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003076 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003077 continue;
3078 }
3079 }
3080 else
3081 {
3082 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003083 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3084 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003085 return root;
3086 }
3087 }
3088 break;
3089 }
3090 default: // some non-separator is in the way
3091 {
3092 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003093 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3094 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003095 return ValueObjectSP();
3096 break;
3097 }
3098 }
3099 }
3100}
3101
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003102int
3103ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3104 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00003105 ValueObjectSP root,
3106 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003107 ExpressionPathScanEndReason* reason_to_stop,
3108 ExpressionPathEndResultType* final_result,
3109 const GetValueForExpressionPathOptions& options,
3110 ExpressionPathAftermath* what_next)
3111{
3112 if (!root.get())
3113 return 0;
3114
3115 *first_unparsed = expression_cstr;
3116
3117 while (true)
3118 {
3119
3120 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3121
Greg Clayton57ee3062013-07-11 22:46:58 +00003122 ClangASTType root_clang_type = root->GetClangType();
3123 ClangASTType pointee_clang_type;
3124 Flags pointee_clang_type_info;
3125 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003126 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00003127 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003128
3129 if (!expression_cstr || *expression_cstr == '\0')
3130 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003131 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003132 list->Append(root);
3133 return 1;
3134 }
3135
3136 switch (*expression_cstr)
3137 {
3138 case '[':
3139 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003140 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 +00003141 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003142 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 +00003143 {
3144 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003145 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3146 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003147 return 0;
3148 }
3149 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3150 {
3151 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003152 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3153 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003154 return 0;
3155 }
3156 }
3157 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3158 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003159 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003160 {
3161 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003162 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3163 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003164 return 0;
3165 }
3166 else // expand this into list
3167 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003168 const size_t max_index = root->GetNumChildren() - 1;
3169 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003170 {
3171 ValueObjectSP child =
3172 root->GetChildAtIndex(index, true);
3173 list->Append(child);
3174 }
3175 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003176 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3177 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003178 return max_index; // tell me number of items I added to the VOList
3179 }
3180 }
3181 const char *separator_position = ::strchr(expression_cstr+1,'-');
3182 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3183 if (!close_bracket_position) // if there is no ], this is a syntax error
3184 {
3185 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003186 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3187 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003188 return 0;
3189 }
3190 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3191 {
3192 char *end = NULL;
3193 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3194 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3195 {
3196 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003197 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3198 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003199 return 0;
3200 }
3201 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3202 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003203 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003204 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003205 const size_t max_index = root->GetNumChildren() - 1;
3206 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003207 {
3208 ValueObjectSP child =
3209 root->GetChildAtIndex(index, true);
3210 list->Append(child);
3211 }
3212 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003213 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3214 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003215 return max_index; // tell me number of items I added to the VOList
3216 }
3217 else
3218 {
3219 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003220 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3221 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003222 return 0;
3223 }
3224 }
3225 // from here on we do have a valid index
Greg Clayton57ee3062013-07-11 22:46:58 +00003226 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003227 {
3228 root = root->GetChildAtIndex(index, true);
3229 if (!root.get())
3230 {
3231 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003232 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3233 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003234 return 0;
3235 }
3236 else
3237 {
3238 list->Append(root);
3239 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003240 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3241 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003242 return 1;
3243 }
3244 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003245 else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003246 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003247 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 +00003248 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003249 {
3250 Error error;
3251 root = root->Dereference(error);
3252 if (error.Fail() || !root.get())
3253 {
3254 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003255 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3256 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003257 return 0;
3258 }
3259 else
3260 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003261 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003262 continue;
3263 }
3264 }
3265 else
3266 {
3267 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3268 if (!root.get())
3269 {
3270 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003271 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3272 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003273 return 0;
3274 }
3275 else
3276 {
3277 list->Append(root);
3278 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003279 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3280 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003281 return 1;
3282 }
3283 }
3284 }
3285 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3286 {
3287 root = root->GetSyntheticBitFieldChild(index, index, true);
3288 if (!root.get())
3289 {
3290 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003291 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3292 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003293 return 0;
3294 }
3295 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3296 {
3297 list->Append(root);
3298 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003299 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3300 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003301 return 1;
3302 }
3303 }
3304 }
3305 else // we have a low and a high index
3306 {
3307 char *end = NULL;
3308 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3309 if (!end || end != separator_position) // if something weird is in our way return an error
3310 {
3311 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003312 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3313 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003314 return 0;
3315 }
3316 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3317 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3318 {
3319 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003320 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3321 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003322 return 0;
3323 }
3324 if (index_lower > index_higher) // swap indices if required
3325 {
3326 unsigned long temp = index_lower;
3327 index_lower = index_higher;
3328 index_higher = temp;
3329 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003330 if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // expansion only works for scalars
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003331 {
3332 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3333 if (!root.get())
3334 {
3335 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003336 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3337 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003338 return 0;
3339 }
3340 else
3341 {
3342 list->Append(root);
3343 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003344 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3345 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003346 return 1;
3347 }
3348 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003349 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 +00003350 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Greg Clayton57ee3062013-07-11 22:46:58 +00003351 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003352 {
3353 Error error;
3354 root = root->Dereference(error);
3355 if (error.Fail() || !root.get())
3356 {
3357 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003358 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3359 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003360 return 0;
3361 }
3362 else
3363 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003364 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003365 continue;
3366 }
3367 }
3368 else
3369 {
Johnny Chen44805302011-07-19 19:48:13 +00003370 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003371 index <= index_higher; index++)
3372 {
3373 ValueObjectSP child =
3374 root->GetChildAtIndex(index, true);
3375 list->Append(child);
3376 }
3377 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003378 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3379 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003380 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3381 }
3382 }
3383 break;
3384 }
3385 default: // some non-[ separator, or something entirely wrong, is in the way
3386 {
3387 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003388 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3389 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003390 return 0;
3391 break;
3392 }
3393 }
3394 }
3395}
3396
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003397void
3398ValueObject::LogValueObject (Log *log)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003399{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003400 if (log)
3401 return LogValueObject (log, DumpValueObjectOptions::DefaultOptions());
Greg Clayton1d3afba2010-10-05 00:00:42 +00003402}
3403
Enrico Granata0c489f52012-03-01 04:24:26 +00003404void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003405ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003406{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003407 if (log)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003408 {
3409 StreamString s;
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003410 Dump (s, options);
Greg Claytonf830dbb2012-03-22 18:15:37 +00003411 if (s.GetSize())
3412 log->PutCString(s.GetData());
3413 }
3414}
3415
3416void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003417ValueObject::Dump (Stream &s)
Enrico Granata0c489f52012-03-01 04:24:26 +00003418{
3419
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003420 ValueObjectPrinter printer(this,&s,DumpValueObjectOptions::DefaultOptions());
3421 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003422}
3423
3424void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003425ValueObject::Dump (Stream &s,
3426 const DumpValueObjectOptions& options)
Enrico Granata0c489f52012-03-01 04:24:26 +00003427{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003428 ValueObjectPrinter printer(this,&s,options);
3429 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003430}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003431
3432ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003433ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003434{
3435 ValueObjectSP valobj_sp;
3436
Enrico Granatac3e320a2011-08-02 17:27:39 +00003437 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003438 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003439 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003440
3441 DataExtractor data;
3442 data.SetByteOrder (m_data.GetByteOrder());
3443 data.SetAddressByteSize(m_data.GetAddressByteSize());
3444
Enrico Granata9f1e2042012-04-24 22:15:37 +00003445 if (IsBitfield())
3446 {
3447 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
Greg Clayton57ee3062013-07-11 22:46:58 +00003448 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Enrico Granata9f1e2042012-04-24 22:15:37 +00003449 }
3450 else
Greg Clayton57ee3062013-07-11 22:46:58 +00003451 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003452
3453 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003454 GetClangType(),
3455 name,
3456 data,
3457 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003458 }
Jim Ingham6035b672011-03-31 00:19:25 +00003459
3460 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003461 {
Greg Claytoneeb15652013-12-10 23:16:40 +00003462 ExecutionContext exe_ctx (GetExecutionContextRef());
3463 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003464 }
3465 return valobj_sp;
3466}
3467
Greg Claytonafacd142011-09-02 01:15:17 +00003468ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003469ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003470{
Jim Ingham58b59f92011-04-22 23:53:53 +00003471 if (m_deref_valobj)
3472 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003473
Greg Clayton54979cd2010-12-15 05:08:08 +00003474 const bool is_pointer_type = IsPointerType();
3475 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003476 {
3477 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003478 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003479
3480 std::string child_name_str;
3481 uint32_t child_byte_size = 0;
3482 int32_t child_byte_offset = 0;
3483 uint32_t child_bitfield_bit_size = 0;
3484 uint32_t child_bitfield_bit_offset = 0;
3485 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003486 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003487 const bool transparent_pointers = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00003488 ClangASTType clang_type = GetClangType();
3489 ClangASTType child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003490
Greg Claytoncc4d0142012-02-17 07:49:44 +00003491 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003492
Greg Clayton57ee3062013-07-11 22:46:58 +00003493 child_clang_type = clang_type.GetChildClangTypeAtIndex (&exe_ctx,
3494 GetName().GetCString(),
3495 0,
3496 transparent_pointers,
3497 omit_empty_base_classes,
3498 ignore_array_bounds,
3499 child_name_str,
3500 child_byte_size,
3501 child_byte_offset,
3502 child_bitfield_bit_size,
3503 child_bitfield_bit_offset,
3504 child_is_base_class,
3505 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003506 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003507 {
3508 ConstString child_name;
3509 if (!child_name_str.empty())
3510 child_name.SetCString (child_name_str.c_str());
3511
Jim Ingham58b59f92011-04-22 23:53:53 +00003512 m_deref_valobj = new ValueObjectChild (*this,
Jim Ingham58b59f92011-04-22 23:53:53 +00003513 child_clang_type,
3514 child_name,
3515 child_byte_size,
3516 child_byte_offset,
3517 child_bitfield_bit_size,
3518 child_bitfield_bit_offset,
3519 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003520 child_is_deref_of_parent,
3521 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003522 }
3523 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003524
Jim Ingham58b59f92011-04-22 23:53:53 +00003525 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003526 {
3527 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003528 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003529 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003530 else
3531 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003532 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003533 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003534
3535 if (is_pointer_type)
3536 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3537 else
3538 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003539 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003540 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003541}
3542
Greg Claytonafacd142011-09-02 01:15:17 +00003543ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003544ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003545{
Jim Ingham78a685a2011-04-16 00:01:13 +00003546 if (m_addr_of_valobj_sp)
3547 return m_addr_of_valobj_sp;
3548
Greg Claytone0d378b2011-03-24 21:19:54 +00003549 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003550 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003551 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003552 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003553 if (addr != LLDB_INVALID_ADDRESS)
3554 {
3555 switch (address_type)
3556 {
3557 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003558 {
3559 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003560 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003561 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3562 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003563 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003564
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003565 case eAddressTypeFile:
3566 case eAddressTypeLoad:
3567 case eAddressTypeHost:
3568 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003569 ClangASTType clang_type = GetClangType();
3570 if (clang_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003571 {
3572 std::string name (1, '&');
3573 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003574 ExecutionContext exe_ctx (GetExecutionContextRef());
3575 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00003576 clang_type.GetPointerType(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003577 ConstString (name.c_str()),
3578 addr,
3579 eAddressTypeInvalid,
3580 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003581 }
3582 }
3583 break;
3584 }
3585 }
Sean Callananed185ab2013-04-19 19:47:32 +00003586 else
3587 {
3588 StreamString expr_path_strm;
3589 GetExpressionPath(expr_path_strm, true);
3590 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3591 }
3592
Jim Ingham78a685a2011-04-16 00:01:13 +00003593 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003594}
3595
Greg Clayton9a142cf2012-02-03 05:34:10 +00003596ValueObjectSP
3597ValueObject::Cast (const ClangASTType &clang_ast_type)
3598{
Greg Clayton81e871e2012-02-04 02:27:34 +00003599 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003600}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003601
Greg Claytonafacd142011-09-02 01:15:17 +00003602ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003603ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3604{
Greg Claytonafacd142011-09-02 01:15:17 +00003605 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003606 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003607 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003608
3609 if (ptr_value != LLDB_INVALID_ADDRESS)
3610 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003611 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003612 ExecutionContext exe_ctx (GetExecutionContextRef());
3613 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003614 name,
3615 ptr_addr,
3616 clang_ast_type);
3617 }
3618 return valobj_sp;
3619}
3620
Greg Claytonafacd142011-09-02 01:15:17 +00003621ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003622ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3623{
Greg Claytonafacd142011-09-02 01:15:17 +00003624 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003625 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003626 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003627
3628 if (ptr_value != LLDB_INVALID_ADDRESS)
3629 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003630 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003631 ExecutionContext exe_ctx (GetExecutionContextRef());
3632 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003633 name,
3634 ptr_addr,
3635 type_sp);
3636 }
3637 return valobj_sp;
3638}
3639
Jim Ingham6035b672011-03-31 00:19:25 +00003640ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003641 m_mod_id(),
3642 m_exe_ctx_ref(),
3643 m_needs_update (true),
3644 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003645{
3646}
3647
3648ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003649 m_mod_id(),
3650 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003651 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003652 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003653{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003654 ExecutionContext exe_ctx(exe_scope);
3655 TargetSP target_sp (exe_ctx.GetTargetSP());
3656 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003657 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003658 m_exe_ctx_ref.SetTargetSP (target_sp);
3659 ProcessSP process_sp (exe_ctx.GetProcessSP());
3660 if (!process_sp)
3661 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003662
Greg Claytoncc4d0142012-02-17 07:49:44 +00003663 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003664 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003665 m_mod_id = process_sp->GetModID();
3666 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003667
Greg Claytoncc4d0142012-02-17 07:49:44 +00003668 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003669
Greg Claytoncc4d0142012-02-17 07:49:44 +00003670 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003671 {
3672 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003673 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003674 }
Jim Ingham6035b672011-03-31 00:19:25 +00003675
Greg Claytoncc4d0142012-02-17 07:49:44 +00003676 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003677 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003678 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003679
Jason Molendab57e4a12013-11-04 09:33:30 +00003680 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003681 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003682 {
3683 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003684 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003685 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003686 if (frame_sp)
3687 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003688 }
3689 }
3690 }
Jim Ingham6035b672011-03-31 00:19:25 +00003691}
3692
3693ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003694 m_mod_id(),
3695 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3696 m_needs_update (true),
3697 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003698{
3699}
3700
3701ValueObject::EvaluationPoint::~EvaluationPoint ()
3702{
3703}
3704
Jim Ingham6035b672011-03-31 00:19:25 +00003705// This function checks the EvaluationPoint against the current process state. If the current
3706// state matches the evaluation point, or the evaluation point is already invalid, then we return
3707// false, meaning "no change". If the current state is different, we update our state, and return
3708// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3709// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003710// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003711
3712bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003713ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003714{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003715
3716 // Start with the target, if it is NULL, then we're obviously not going to get any further:
Greg Clayton44d93782014-01-27 23:43:24 +00003717 const bool thread_and_frame_only_if_stopped = true;
3718 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
Jim Ingham73ca05a2011-12-17 01:35:57 +00003719
Greg Claytoncc4d0142012-02-17 07:49:44 +00003720 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003721 return false;
3722
Jim Ingham6035b672011-03-31 00:19:25 +00003723 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003724 Process *process = exe_ctx.GetProcessPtr();
3725 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003726 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003727
Jim Ingham6035b672011-03-31 00:19:25 +00003728 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003729 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003730
Jim Ingham78a685a2011-04-16 00:01:13 +00003731 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3732 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003733 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003734 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003735
Greg Clayton23f59502012-07-17 03:23:13 +00003736 bool changed = false;
3737 const bool was_valid = m_mod_id.IsValid();
3738 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003739 {
3740 if (m_mod_id == current_mod_id)
3741 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003742 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003743 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003744 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003745 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003746 else
3747 {
3748 m_mod_id = current_mod_id;
3749 m_needs_update = true;
3750 changed = true;
3751 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003752 }
Jim Ingham6035b672011-03-31 00:19:25 +00003753
Jim Ingham73ca05a2011-12-17 01:35:57 +00003754 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3755 // That way we'll be sure to return a valid exe_scope.
3756 // 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 +00003757
Greg Claytoncc4d0142012-02-17 07:49:44 +00003758 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003759 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003760 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3761 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003762 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003763 if (m_exe_ctx_ref.HasFrameRef())
3764 {
Jason Molendab57e4a12013-11-04 09:33:30 +00003765 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003766 if (!frame_sp)
3767 {
3768 // We used to have a frame, but now it is gone
3769 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003770 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00003771 }
3772 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003773 }
Jim Ingham6035b672011-03-31 00:19:25 +00003774 else
3775 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003776 // We used to have a thread, but now it is gone
3777 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003778 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00003779 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003780
Jim Ingham6035b672011-03-31 00:19:25 +00003781 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003782 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003783}
3784
Jim Ingham61be0902011-05-02 18:13:59 +00003785void
3786ValueObject::EvaluationPoint::SetUpdated ()
3787{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003788 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3789 if (process_sp)
3790 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003791 m_first_update = false;
3792 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003793}
3794
3795
Enrico Granataf2bbf712011-07-15 02:26:42 +00003796
3797void
Enrico Granata86cc9822012-03-19 22:58:49 +00003798ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00003799{
Enrico Granata86cc9822012-03-19 22:58:49 +00003800 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
3801 m_value_str.clear();
3802
3803 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
3804 m_location_str.clear();
3805
3806 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
3807 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003808 m_summary_str.clear();
3809 }
3810
3811 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
3812 m_object_desc_str.clear();
3813
3814 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
3815 {
3816 if (m_synthetic_value)
3817 m_synthetic_value = NULL;
3818 }
Johnny Chen44805302011-07-19 19:48:13 +00003819}
Enrico Granata9128ee22011-09-06 19:20:51 +00003820
3821SymbolContextScope *
3822ValueObject::GetSymbolContextScope()
3823{
3824 if (m_parent)
3825 {
3826 if (!m_parent->IsPointerOrReferenceType())
3827 return m_parent->GetSymbolContextScope();
3828 }
3829 return NULL;
3830}
Enrico Granatab2698cd2012-09-13 18:27:09 +00003831
3832lldb::ValueObjectSP
3833ValueObject::CreateValueObjectFromExpression (const char* name,
3834 const char* expression,
3835 const ExecutionContext& exe_ctx)
3836{
3837 lldb::ValueObjectSP retval_sp;
3838 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
3839 if (!target_sp)
3840 return retval_sp;
3841 if (!expression || !*expression)
3842 return retval_sp;
3843 target_sp->EvaluateExpression (expression,
3844 exe_ctx.GetFrameSP().get(),
3845 retval_sp);
3846 if (retval_sp && name && *name)
3847 retval_sp->SetName(ConstString(name));
3848 return retval_sp;
3849}
3850
3851lldb::ValueObjectSP
3852ValueObject::CreateValueObjectFromAddress (const char* name,
3853 uint64_t address,
3854 const ExecutionContext& exe_ctx,
3855 ClangASTType type)
3856{
Greg Clayton57ee3062013-07-11 22:46:58 +00003857 if (type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00003858 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003859 ClangASTType pointer_type(type.GetPointerType());
3860 if (pointer_type)
3861 {
3862 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
3863 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3864 pointer_type,
3865 ConstString(name),
3866 buffer,
3867 lldb::endian::InlHostByteOrder(),
3868 exe_ctx.GetAddressByteSize()));
3869 if (ptr_result_valobj_sp)
3870 {
3871 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
3872 Error err;
3873 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
3874 if (ptr_result_valobj_sp && name && *name)
3875 ptr_result_valobj_sp->SetName(ConstString(name));
3876 }
3877 return ptr_result_valobj_sp;
3878 }
Enrico Granatab2698cd2012-09-13 18:27:09 +00003879 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003880 return lldb::ValueObjectSP();
Enrico Granatab2698cd2012-09-13 18:27:09 +00003881}
3882
3883lldb::ValueObjectSP
3884ValueObject::CreateValueObjectFromData (const char* name,
3885 DataExtractor& data,
3886 const ExecutionContext& exe_ctx,
3887 ClangASTType type)
3888{
3889 lldb::ValueObjectSP new_value_sp;
3890 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00003891 type,
Enrico Granatab2698cd2012-09-13 18:27:09 +00003892 ConstString(name),
3893 data,
3894 LLDB_INVALID_ADDRESS);
3895 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
3896 if (new_value_sp && name && *name)
3897 new_value_sp->SetName(ConstString(name));
3898 return new_value_sp;
3899}
Enrico Granata4873e522013-04-11 22:48:58 +00003900
3901ModuleSP
3902ValueObject::GetModule ()
3903{
3904 ValueObject* root(GetRoot());
3905 if (root != this)
3906 return root->GetModule();
3907 return lldb::ModuleSP();
3908}
3909
3910ValueObject*
3911ValueObject::GetRoot ()
3912{
3913 if (m_root)
3914 return m_root;
3915 ValueObject* parent = m_parent;
3916 if (!parent)
3917 return (m_root = this);
3918 while (parent->m_parent)
3919 {
3920 if (parent->m_root)
3921 return (m_root = parent->m_root);
3922 parent = parent->m_parent;
3923 }
3924 return (m_root = parent);
3925}
3926
3927AddressType
3928ValueObject::GetAddressTypeOfChildren()
3929{
3930 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
3931 {
3932 ValueObject* root(GetRoot());
3933 if (root != this)
3934 return root->GetAddressTypeOfChildren();
3935 }
3936 return m_address_type_of_ptr_or_ref_children;
3937}
3938
3939lldb::DynamicValueType
3940ValueObject::GetDynamicValueType ()
3941{
3942 ValueObject* with_dv_info = this;
3943 while (with_dv_info)
3944 {
3945 if (with_dv_info->HasDynamicValueTypeInfo())
3946 return with_dv_info->GetDynamicValueTypeImpl();
3947 with_dv_info = with_dv_info->m_parent;
3948 }
3949 return lldb::eNoDynamicValues;
3950}
Enrico Granata39d51412013-05-31 17:43:40 +00003951
Enrico Granata4873e522013-04-11 22:48:58 +00003952lldb::Format
3953ValueObject::GetFormat () const
3954{
3955 const ValueObject* with_fmt_info = this;
3956 while (with_fmt_info)
3957 {
3958 if (with_fmt_info->m_format != lldb::eFormatDefault)
3959 return with_fmt_info->m_format;
3960 with_fmt_info = with_fmt_info->m_parent;
3961 }
3962 return m_format;
3963}