blob: fc29f6dcc9906d8b9eb10ec2fbe877d1548222a0 [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;
981 return pointee_sp->GetDataExtractor().Copy(data);
982 }
983 else
984 {
985 ValueObjectSP child_sp = GetChildAtIndex(0, true);
986 if (child_sp.get() == NULL)
987 return 0;
988 return child_sp->GetDataExtractor().Copy(data);
989 }
990 return true;
991 }
992 else /* (items > 1) */
993 {
994 Error error;
995 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
996 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
997
998 AddressType addr_type;
Greg Clayton2452ab72013-02-08 22:02:02 +0000999 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001000
Enrico Granata9128ee22011-09-06 19:20:51 +00001001 switch (addr_type)
1002 {
1003 case eAddressTypeFile:
1004 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001005 ModuleSP module_sp (GetModule());
1006 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001007 {
Enrico Granata9c2efe32012-08-07 01:49:34 +00001008 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +00001009 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001010 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001011 ExecutionContext exe_ctx (GetExecutionContextRef());
1012 Target* target = exe_ctx.GetTargetPtr();
1013 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +00001014 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001015 heap_buf_ptr->SetByteSize(bytes);
1016 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
1017 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +00001018 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001019 data.SetData(data_sp);
1020 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +00001021 }
1022 }
1023 }
1024 }
1025 break;
1026 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +00001027 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001028 ExecutionContext exe_ctx (GetExecutionContextRef());
1029 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +00001030 if (process)
1031 {
1032 heap_buf_ptr->SetByteSize(bytes);
1033 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
Enrico Granata5e1480c2013-10-30 17:52:44 +00001034 if (error.Success() || bytes_read > 0)
Enrico Granata9128ee22011-09-06 19:20:51 +00001035 {
1036 data.SetData(data_sp);
1037 return bytes_read;
1038 }
1039 }
1040 }
1041 break;
1042 case eAddressTypeHost:
1043 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001044 const uint64_t max_bytes = GetClangType().GetByteSize();
Greg Clayton2452ab72013-02-08 22:02:02 +00001045 if (max_bytes > offset)
1046 {
1047 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
1048 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
1049 data.SetData(data_sp);
1050 return bytes_read;
1051 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001052 }
1053 break;
1054 case eAddressTypeInvalid:
Enrico Granata9128ee22011-09-06 19:20:51 +00001055 break;
1056 }
1057 }
1058 return 0;
1059}
1060
Greg Claytonfaac1112013-03-14 18:31:44 +00001061uint64_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001062ValueObject::GetData (DataExtractor& data)
1063{
1064 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001065 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Clayton57ee3062013-07-11 22:46:58 +00001066 Error error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001067 if (error.Fail())
Sean Callananed185ab2013-04-19 19:47:32 +00001068 {
1069 if (m_data.GetByteSize())
1070 {
1071 data = m_data;
1072 return data.GetByteSize();
1073 }
1074 else
1075 {
1076 return 0;
1077 }
1078 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001079 data.SetAddressByteSize(m_data.GetAddressByteSize());
1080 data.SetByteOrder(m_data.GetByteOrder());
1081 return data.GetByteSize();
1082}
1083
Sean Callanan389823e2013-04-13 01:21:23 +00001084bool
1085ValueObject::SetData (DataExtractor &data, Error &error)
1086{
1087 error.Clear();
1088 // Make sure our value is up to date first so that our location and location
1089 // type is valid.
1090 if (!UpdateValueIfNeeded(false))
1091 {
1092 error.SetErrorString("unable to read value");
1093 return false;
1094 }
1095
1096 uint64_t count = 0;
Greg Clayton57ee3062013-07-11 22:46:58 +00001097 const Encoding encoding = GetClangType().GetEncoding(count);
Sean Callanan389823e2013-04-13 01:21:23 +00001098
1099 const size_t byte_size = GetByteSize();
1100
1101 Value::ValueType value_type = m_value.GetValueType();
1102
1103 switch (value_type)
1104 {
1105 case Value::eValueTypeScalar:
1106 {
1107 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1108
1109 if (!set_error.Success())
1110 {
1111 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1112 return false;
1113 }
1114 }
1115 break;
1116 case Value::eValueTypeLoadAddress:
1117 {
1118 // If it is a load address, then the scalar value is the storage location
1119 // of the data, and we have to shove this value down to that load location.
1120 ExecutionContext exe_ctx (GetExecutionContextRef());
1121 Process *process = exe_ctx.GetProcessPtr();
1122 if (process)
1123 {
1124 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1125 size_t bytes_written = process->WriteMemory(target_addr,
1126 data.GetDataStart(),
1127 byte_size,
1128 error);
1129 if (!error.Success())
1130 return false;
1131 if (bytes_written != byte_size)
1132 {
1133 error.SetErrorString("unable to write value to memory");
1134 return false;
1135 }
1136 }
1137 }
1138 break;
1139 case Value::eValueTypeHostAddress:
1140 {
1141 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1142 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1143 m_data.SetData(buffer_sp, 0);
1144 data.CopyByteOrderedData (0,
1145 byte_size,
1146 const_cast<uint8_t *>(m_data.GetDataStart()),
1147 byte_size,
1148 m_data.GetByteOrder());
1149 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1150 }
1151 break;
1152 case Value::eValueTypeFileAddress:
1153 case Value::eValueTypeVector:
1154 break;
1155 }
1156
1157 // If we have reached this point, then we have successfully changed the value.
1158 SetNeedsUpdate();
1159 return true;
1160}
1161
Enrico Granata9128ee22011-09-06 19:20:51 +00001162// will compute strlen(str), but without consuming more than
1163// maxlen bytes out of str (this serves the purpose of reading
1164// chunks of a string without having to worry about
1165// missing NULL terminators in the chunk)
1166// of course, if strlen(str) > maxlen, the function will return
1167// maxlen_value (which should be != maxlen, because that allows you
1168// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1169static uint32_t
1170strlen_or_inf (const char* str,
1171 uint32_t maxlen,
1172 uint32_t maxlen_value)
1173{
1174 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +00001175 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +00001176 {
Greg Clayton8dd5c172011-10-05 22:19:51 +00001177 while(*str)
1178 {
1179 len++;str++;
Greg Clayton2452ab72013-02-08 22:02:02 +00001180 if (len >= maxlen)
Greg Clayton8dd5c172011-10-05 22:19:51 +00001181 return maxlen_value;
1182 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001183 }
1184 return len;
1185}
1186
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001187size_t
Greg Claytoncc4d0142012-02-17 07:49:44 +00001188ValueObject::ReadPointedString (Stream& s,
1189 Error& error,
1190 uint32_t max_length,
1191 bool honor_array,
1192 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001193{
Greg Claytoncc4d0142012-02-17 07:49:44 +00001194 ExecutionContext exe_ctx (GetExecutionContextRef());
1195 Target* target = exe_ctx.GetTargetPtr();
1196
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001197 if (!target)
1198 {
1199 s << "<no target to read from>";
1200 error.SetErrorString("no target to read from");
1201 return 0;
1202 }
1203
1204 if (max_length == 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001205 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001206
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001207 size_t bytes_read = 0;
1208 size_t total_bytes_read = 0;
1209
Greg Clayton57ee3062013-07-11 22:46:58 +00001210 ClangASTType clang_type = GetClangType();
1211 ClangASTType elem_or_pointee_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001212 const Flags type_flags (GetTypeInfo (&elem_or_pointee_clang_type));
Greg Clayton57ee3062013-07-11 22:46:58 +00001213 if (type_flags.AnySet (ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer) &&
1214 elem_or_pointee_clang_type.IsCharType ())
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001215 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001216 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1217 AddressType cstr_address_type = eAddressTypeInvalid;
1218
1219 size_t cstr_len = 0;
1220 bool capped_data = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00001221 if (type_flags.Test (ClangASTType::eTypeIsArray))
Greg Claytoncc4d0142012-02-17 07:49:44 +00001222 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001223 // We have an array
Greg Clayton57ee3062013-07-11 22:46:58 +00001224 uint64_t array_size = 0;
1225 if (clang_type.IsArrayType(NULL, &array_size, NULL))
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001226 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001227 cstr_len = array_size;
1228 if (cstr_len > max_length)
1229 {
1230 capped_data = true;
1231 cstr_len = max_length;
1232 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001233 }
1234 cstr_address = GetAddressOf (true, &cstr_address_type);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001235 }
1236 else
1237 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001238 // We have a pointer
1239 cstr_address = GetPointerValue (&cstr_address_type);
1240 }
1241
1242 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1243 {
1244 s << "<invalid address>";
1245 error.SetErrorString("invalid address");
1246 return 0;
1247 }
1248
1249 Address cstr_so_addr (cstr_address);
1250 DataExtractor data;
1251 if (cstr_len > 0 && honor_array)
1252 {
1253 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1254 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1255 GetPointeeData(data, 0, cstr_len);
1256
1257 if ((bytes_read = data.GetByteSize()) > 0)
1258 {
1259 total_bytes_read = bytes_read;
1260 s << '"';
1261 data.Dump (&s,
1262 0, // Start offset in "data"
1263 item_format,
1264 1, // Size of item (1 byte for a char!)
1265 bytes_read, // How many bytes to print?
1266 UINT32_MAX, // num per line
1267 LLDB_INVALID_ADDRESS,// base address
1268 0, // bitfield bit size
1269 0); // bitfield bit offset
1270 if (capped_data)
1271 s << "...";
1272 s << '"';
1273 }
1274 }
1275 else
1276 {
1277 cstr_len = max_length;
1278 const size_t k_max_buf_size = 64;
1279
1280 size_t offset = 0;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001281
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001282 int cstr_len_displayed = -1;
1283 bool capped_cstr = false;
1284 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1285 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1286 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001287 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001288 total_bytes_read += bytes_read;
1289 const char *cstr = data.PeekCStr(0);
1290 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1291 if (len > k_max_buf_size)
1292 len = k_max_buf_size;
1293 if (cstr && cstr_len_displayed < 0)
1294 s << '"';
1295
1296 if (cstr_len_displayed < 0)
1297 cstr_len_displayed = len;
1298
1299 if (len == 0)
1300 break;
1301 cstr_len_displayed += len;
1302 if (len > bytes_read)
1303 len = bytes_read;
1304 if (len > cstr_len)
1305 len = cstr_len;
1306
1307 data.Dump (&s,
1308 0, // Start offset in "data"
1309 item_format,
1310 1, // Size of item (1 byte for a char!)
1311 len, // How many bytes to print?
1312 UINT32_MAX, // num per line
1313 LLDB_INVALID_ADDRESS,// base address
1314 0, // bitfield bit size
1315 0); // bitfield bit offset
1316
1317 if (len < k_max_buf_size)
1318 break;
1319
1320 if (len >= cstr_len)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001321 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001322 capped_cstr = true;
1323 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001324 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001325
1326 cstr_len -= len;
1327 offset += len;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001328 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001329
1330 if (cstr_len_displayed >= 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001331 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001332 s << '"';
1333 if (capped_cstr)
1334 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001335 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001336 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001337 }
1338 else
1339 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001340 error.SetErrorString("not a string object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001341 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001342 }
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001343 return total_bytes_read;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001344}
1345
Jim Ingham53c47f12010-09-10 23:12:17 +00001346const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001347ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001348{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001349
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001350 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001351 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001352
1353 if (!m_object_desc_str.empty())
1354 return m_object_desc_str.c_str();
1355
Greg Claytoncc4d0142012-02-17 07:49:44 +00001356 ExecutionContext exe_ctx (GetExecutionContextRef());
1357 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001358 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001359 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001360
Jim Ingham53c47f12010-09-10 23:12:17 +00001361 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001362
Greg Claytonafacd142011-09-02 01:15:17 +00001363 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001364 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1365
Jim Inghama2cf2632010-12-23 02:29:54 +00001366 if (runtime == NULL)
1367 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001368 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Greg Clayton57ee3062013-07-11 22:46:58 +00001369 ClangASTType clang_type = GetClangType();
1370 if (clang_type)
Jim Inghama2cf2632010-12-23 02:29:54 +00001371 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001372 bool is_signed;
Greg Clayton57ee3062013-07-11 22:46:58 +00001373 if (clang_type.IsIntegerType (is_signed) || clang_type.IsPointerType ())
Jim Inghamb7603bb2011-03-18 00:05:18 +00001374 {
Greg Claytonafacd142011-09-02 01:15:17 +00001375 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001376 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001377 }
1378 }
1379
Jim Ingham8d543de2011-03-31 23:01:21 +00001380 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001381 {
1382 m_object_desc_str.append (s.GetData());
1383 }
Sean Callanan672ad942010-10-23 00:18:49 +00001384
1385 if (m_object_desc_str.empty())
1386 return NULL;
1387 else
1388 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001389}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001390
Enrico Granata0c489f52012-03-01 04:24:26 +00001391bool
Enrico Granata4939b982013-12-22 09:24:22 +00001392ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format,
1393 std::string& destination)
1394{
1395 if (UpdateValueIfNeeded(false))
1396 return format.FormatObject(this,destination);
1397 else
1398 return false;
1399}
1400
1401bool
Enrico Granata0c489f52012-03-01 04:24:26 +00001402ValueObject::GetValueAsCString (lldb::Format format,
1403 std::string& destination)
1404{
Enrico Granata4939b982013-12-22 09:24:22 +00001405 return GetValueAsCString(TypeFormatImpl(format),destination);
Enrico Granata0c489f52012-03-01 04:24:26 +00001406}
1407
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001408const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001409ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001410{
Enrico Granatab294fd22013-05-31 19:18:19 +00001411 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001412 {
Enrico Granata4939b982013-12-22 09:24:22 +00001413 lldb::TypeFormatImplSP format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001414 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001415 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001416 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001417 if (m_type_format_sp)
Enrico Granata4939b982013-12-22 09:24:22 +00001418 format_sp = m_type_format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001419 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001420 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001421 if (m_is_bitfield_for_scalar)
1422 my_format = eFormatUnsigned;
1423 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001424 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001425 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001426 {
1427 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1428 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001429 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001430 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001431 else
1432 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001433 my_format = GetClangType().GetFormat();
Enrico Granata0c489f52012-03-01 04:24:26 +00001434 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001435 }
1436 }
1437 }
Enrico Granatab294fd22013-05-31 19:18:19 +00001438 if (my_format != m_last_format || m_value_str.empty())
Enrico Granata297e69f2012-03-06 23:21:16 +00001439 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001440 m_last_format = my_format;
Enrico Granata4939b982013-12-22 09:24:22 +00001441 if (!format_sp)
1442 format_sp.reset(new TypeFormatImpl(my_format));
1443 if (GetValueAsCString(*format_sp.get(), m_value_str))
Enrico Granata297e69f2012-03-06 23:21:16 +00001444 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001445 if (!m_value_did_change && m_old_value_valid)
1446 {
1447 // The value was gotten successfully, so we consider the
1448 // value as changed if the value string differs
1449 SetValueDidChange (m_old_value_str != m_value_str);
1450 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001451 }
1452 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001453 }
1454 if (m_value_str.empty())
1455 return NULL;
1456 return m_value_str.c_str();
1457}
1458
Enrico Granatac3e320a2011-08-02 17:27:39 +00001459// if > 8bytes, 0 is returned. this method should mostly be used
1460// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001461uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001462ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001463{
1464 // If our byte size is zero this is an aggregate type that has children
Greg Clayton57ee3062013-07-11 22:46:58 +00001465 if (!GetClangType().IsAggregateType())
Enrico Granatac3e320a2011-08-02 17:27:39 +00001466 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001467 Scalar scalar;
1468 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001469 {
1470 if (success)
1471 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001472 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001473 }
1474 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001475 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001476
1477 if (success)
1478 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001479 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001480}
1481
Enrico Granatad7373f62013-10-31 18:57:50 +00001482int64_t
1483ValueObject::GetValueAsSigned (int64_t fail_value, bool *success)
1484{
1485 // If our byte size is zero this is an aggregate type that has children
1486 if (!GetClangType().IsAggregateType())
1487 {
1488 Scalar scalar;
1489 if (ResolveValue (scalar))
1490 {
1491 if (success)
1492 *success = true;
1493 return scalar.SLongLong(fail_value);
1494 }
1495 // fallthrough, otherwise...
1496 }
1497
1498 if (success)
1499 *success = false;
1500 return fail_value;
1501}
1502
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001503// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1504// this call up to date by returning true for your new special cases. We will eventually move
1505// to checking this call result before trying to display special cases
1506bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001507ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1508 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001509{
Greg Clayton57ee3062013-07-11 22:46:58 +00001510 Flags flags(GetTypeInfo());
1511 if (flags.AnySet(ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001512 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001513 {
1514 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001515 (custom_format == eFormatCString ||
1516 custom_format == eFormatCharArray ||
1517 custom_format == eFormatChar ||
1518 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001519 return true;
1520
Greg Clayton57ee3062013-07-11 22:46:58 +00001521 if (flags.Test(ClangASTType::eTypeIsArray))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001522 {
Greg Claytonafacd142011-09-02 01:15:17 +00001523 if ((custom_format == eFormatBytes) ||
1524 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001525 return true;
1526
Greg Claytonafacd142011-09-02 01:15:17 +00001527 if ((custom_format == eFormatVectorOfChar) ||
1528 (custom_format == eFormatVectorOfFloat32) ||
1529 (custom_format == eFormatVectorOfFloat64) ||
1530 (custom_format == eFormatVectorOfSInt16) ||
1531 (custom_format == eFormatVectorOfSInt32) ||
1532 (custom_format == eFormatVectorOfSInt64) ||
1533 (custom_format == eFormatVectorOfSInt8) ||
1534 (custom_format == eFormatVectorOfUInt128) ||
1535 (custom_format == eFormatVectorOfUInt16) ||
1536 (custom_format == eFormatVectorOfUInt32) ||
1537 (custom_format == eFormatVectorOfUInt64) ||
1538 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001539 return true;
1540 }
1541 }
1542 return false;
1543}
1544
Enrico Granata9fc19442011-07-06 02:13:41 +00001545bool
1546ValueObject::DumpPrintableRepresentation(Stream& s,
1547 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001548 Format custom_format,
Enrico Granata86cc9822012-03-19 22:58:49 +00001549 PrintableRepresentationSpecialCases special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001550{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001551
Greg Clayton57ee3062013-07-11 22:46:58 +00001552 Flags flags(GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001553
Enrico Granata86cc9822012-03-19 22:58:49 +00001554 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1555 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1556
1557 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001558 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001559 if (flags.AnySet(ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001560 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001561 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001562 // when being asked to get a printable display an array or pointer type directly,
1563 // try to "do the right thing"
1564
1565 if (IsCStringContainer(true) &&
1566 (custom_format == eFormatCString ||
1567 custom_format == eFormatCharArray ||
1568 custom_format == eFormatChar ||
1569 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001570 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001571 Error error;
1572 ReadPointedString(s,
1573 error,
1574 0,
1575 (custom_format == eFormatVectorOfChar) ||
1576 (custom_format == eFormatCharArray));
1577 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001578 }
1579
Enrico Granata86cc9822012-03-19 22:58:49 +00001580 if (custom_format == eFormatEnum)
1581 return false;
1582
1583 // this only works for arrays, because I have no way to know when
1584 // the pointed memory ends, and no special \0 end of data marker
Greg Clayton57ee3062013-07-11 22:46:58 +00001585 if (flags.Test(ClangASTType::eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001586 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001587 if ((custom_format == eFormatBytes) ||
1588 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001589 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001590 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001591
1592 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001593 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001594 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001595
1596 if (low)
1597 s << ',';
1598
1599 ValueObjectSP child = GetChildAtIndex(low,true);
1600 if (!child.get())
1601 {
1602 s << "<invalid child>";
1603 continue;
1604 }
1605 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1606 }
1607
1608 s << ']';
1609
1610 return true;
1611 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001612
Enrico Granata86cc9822012-03-19 22:58:49 +00001613 if ((custom_format == eFormatVectorOfChar) ||
1614 (custom_format == eFormatVectorOfFloat32) ||
1615 (custom_format == eFormatVectorOfFloat64) ||
1616 (custom_format == eFormatVectorOfSInt16) ||
1617 (custom_format == eFormatVectorOfSInt32) ||
1618 (custom_format == eFormatVectorOfSInt64) ||
1619 (custom_format == eFormatVectorOfSInt8) ||
1620 (custom_format == eFormatVectorOfUInt128) ||
1621 (custom_format == eFormatVectorOfUInt16) ||
1622 (custom_format == eFormatVectorOfUInt32) ||
1623 (custom_format == eFormatVectorOfUInt64) ||
1624 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1625 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001626 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001627
1628 Format format = FormatManager::GetSingleItemFormat(custom_format);
1629
1630 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001631 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001632 {
1633
1634 if (low)
1635 s << ',';
1636
1637 ValueObjectSP child = GetChildAtIndex(low,true);
1638 if (!child.get())
1639 {
1640 s << "<invalid child>";
1641 continue;
1642 }
1643 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1644 }
1645
1646 s << ']';
1647
1648 return true;
1649 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001650 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001651
1652 if ((custom_format == eFormatBoolean) ||
1653 (custom_format == eFormatBinary) ||
1654 (custom_format == eFormatChar) ||
1655 (custom_format == eFormatCharPrintable) ||
1656 (custom_format == eFormatComplexFloat) ||
1657 (custom_format == eFormatDecimal) ||
1658 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001659 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001660 (custom_format == eFormatFloat) ||
1661 (custom_format == eFormatOctal) ||
1662 (custom_format == eFormatOSType) ||
1663 (custom_format == eFormatUnicode16) ||
1664 (custom_format == eFormatUnicode32) ||
1665 (custom_format == eFormatUnsigned) ||
1666 (custom_format == eFormatPointer) ||
1667 (custom_format == eFormatComplexInteger) ||
1668 (custom_format == eFormatComplex) ||
1669 (custom_format == eFormatDefault)) // use the [] operator
1670 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001671 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001672 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001673
1674 if (only_special)
1675 return false;
1676
Enrico Granata86cc9822012-03-19 22:58:49 +00001677 bool var_success = false;
1678
1679 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001680 const char *cstr = NULL;
Enrico Granata2c75f112013-06-21 00:04:51 +00001681
1682 // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1683 // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1684 // area for cases where our desired output is not backed by some other longer-term storage
Greg Claytonc7bece562013-01-25 18:06:21 +00001685 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001686
1687 if (custom_format != eFormatInvalid)
1688 SetFormat(custom_format);
1689
1690 switch(val_obj_display)
1691 {
1692 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001693 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001694 break;
1695
1696 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001697 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001698 break;
1699
1700 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001701 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001702 break;
1703
1704 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001705 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001706 break;
1707
1708 case eValueObjectRepresentationStyleChildrenCount:
Greg Claytonc7bece562013-01-25 18:06:21 +00001709 strm.Printf("%zu", GetNumChildren());
1710 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001711 break;
1712
1713 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001714 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001715 break;
Enrico Granata2c75f112013-06-21 00:04:51 +00001716
1717 case eValueObjectRepresentationStyleName:
1718 cstr = GetName().AsCString();
1719 break;
1720
1721 case eValueObjectRepresentationStyleExpressionPath:
1722 GetExpressionPath(strm, false);
1723 cstr = strm.GetString().c_str();
1724 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001725 }
1726
Greg Claytonc7bece562013-01-25 18:06:21 +00001727 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001728 {
1729 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001730 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001731 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1732 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001733 if (GetClangType().IsAggregateType())
Enrico Granata86cc9822012-03-19 22:58:49 +00001734 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001735 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1736 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001737 }
1738 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001739 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001740 }
1741 }
1742
Greg Claytonc7bece562013-01-25 18:06:21 +00001743 if (cstr)
1744 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001745 else
1746 {
1747 if (m_error.Fail())
1748 s.Printf("<%s>", m_error.AsCString());
1749 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1750 s.PutCString("<no summary available>");
1751 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1752 s.PutCString("<no value available>");
1753 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1754 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1755 else
1756 s.PutCString("<no printable representation>");
1757 }
1758
1759 // we should only return false here if we could not do *anything*
1760 // even if we have an error message as output, that's a success
1761 // from our callers' perspective, so return true
1762 var_success = true;
1763
1764 if (custom_format != eFormatInvalid)
1765 SetFormat(eFormatDefault);
1766 }
1767
Enrico Granataf4efecd2011-07-12 22:56:10 +00001768 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001769}
1770
Greg Clayton737b9322010-09-13 03:32:57 +00001771addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001772ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001773{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001774 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001775 return LLDB_INVALID_ADDRESS;
1776
Greg Clayton73b472d2010-10-27 03:32:59 +00001777 switch (m_value.GetValueType())
1778 {
1779 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001780 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001781 if (scalar_is_load_address)
1782 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001783 if(address_type)
1784 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001785 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1786 }
1787 break;
1788
1789 case Value::eValueTypeLoadAddress:
1790 case Value::eValueTypeFileAddress:
1791 case Value::eValueTypeHostAddress:
1792 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001793 if(address_type)
1794 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001795 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1796 }
1797 break;
1798 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001799 if (address_type)
1800 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001801 return LLDB_INVALID_ADDRESS;
1802}
1803
1804addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001805ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001806{
Greg Claytonafacd142011-09-02 01:15:17 +00001807 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001808 if(address_type)
1809 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001810
Enrico Granatac3e320a2011-08-02 17:27:39 +00001811 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001812 return address;
1813
Greg Clayton73b472d2010-10-27 03:32:59 +00001814 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001815 {
1816 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001817 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001818 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001819 break;
1820
Enrico Granata9128ee22011-09-06 19:20:51 +00001821 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001822 case Value::eValueTypeLoadAddress:
1823 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001824 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001825 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001826 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001827 }
1828 break;
1829 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001830
Enrico Granata9128ee22011-09-06 19:20:51 +00001831 if (address_type)
1832 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001833
Greg Clayton737b9322010-09-13 03:32:57 +00001834 return address;
1835}
1836
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001837bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001838ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001839{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001840 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001841 // Make sure our value is up to date first so that our location and location
1842 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001843 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001844 {
1845 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001846 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001847 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001848
Greg Claytonfaac1112013-03-14 18:31:44 +00001849 uint64_t count = 0;
Greg Clayton57ee3062013-07-11 22:46:58 +00001850 const Encoding encoding = GetClangType().GetEncoding (count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001851
Greg Claytonb1320972010-07-14 00:18:15 +00001852 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001853
Jim Ingham16e0c682011-08-12 23:34:31 +00001854 Value::ValueType value_type = m_value.GetValueType();
1855
1856 if (value_type == Value::eValueTypeScalar)
1857 {
1858 // If the value is already a scalar, then let the scalar change itself:
1859 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1860 }
1861 else if (byte_size <= Scalar::GetMaxByteSize())
1862 {
1863 // If the value fits in a scalar, then make a new scalar and again let the
1864 // scalar code do the conversion, then figure out where to put the new value.
1865 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001866 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1867 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001868 {
Jim Ingham4b536182011-08-09 02:12:22 +00001869 switch (value_type)
1870 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001871 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001872 {
1873 // If it is a load address, then the scalar value is the storage location
1874 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001875 ExecutionContext exe_ctx (GetExecutionContextRef());
1876 Process *process = exe_ctx.GetProcessPtr();
1877 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001878 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001879 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001880 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1881 new_scalar,
1882 byte_size,
1883 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001884 if (!error.Success())
1885 return false;
1886 if (bytes_written != byte_size)
1887 {
1888 error.SetErrorString("unable to write value to memory");
1889 return false;
1890 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001891 }
1892 }
Jim Ingham4b536182011-08-09 02:12:22 +00001893 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001894 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001895 {
1896 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1897 DataExtractor new_data;
1898 new_data.SetByteOrder (m_data.GetByteOrder());
1899
1900 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1901 m_data.SetData(buffer_sp, 0);
1902 bool success = new_scalar.GetData(new_data);
1903 if (success)
1904 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001905 new_data.CopyByteOrderedData (0,
1906 byte_size,
1907 const_cast<uint8_t *>(m_data.GetDataStart()),
1908 byte_size,
1909 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001910 }
1911 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1912
1913 }
Jim Ingham4b536182011-08-09 02:12:22 +00001914 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001915 case Value::eValueTypeFileAddress:
1916 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001917 case Value::eValueTypeVector:
1918 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001919 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001920 }
1921 else
1922 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001923 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001924 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001925 }
1926 else
1927 {
1928 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001929 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001930 return false;
1931 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001932
1933 // If we have reached this point, then we have successfully changed the value.
1934 SetNeedsUpdate();
1935 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001936}
1937
Greg Clayton81e871e2012-02-04 02:27:34 +00001938bool
1939ValueObject::GetDeclaration (Declaration &decl)
1940{
1941 decl.Clear();
1942 return false;
1943}
1944
Greg Clayton84db9102012-03-26 23:03:23 +00001945ConstString
1946ValueObject::GetTypeName()
1947{
Greg Clayton57ee3062013-07-11 22:46:58 +00001948 return GetClangType().GetConstTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00001949}
1950
1951ConstString
1952ValueObject::GetQualifiedTypeName()
1953{
Greg Clayton57ee3062013-07-11 22:46:58 +00001954 return GetClangType().GetConstQualifiedTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00001955}
1956
1957
Greg Claytonafacd142011-09-02 01:15:17 +00001958LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001959ValueObject::GetObjectRuntimeLanguage ()
1960{
Greg Clayton57ee3062013-07-11 22:46:58 +00001961 return GetClangType().GetMinimumLanguage ();
Jim Ingham5a369122010-09-28 01:25:32 +00001962}
1963
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001964void
Jim Ingham58b59f92011-04-22 23:53:53 +00001965ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001966{
Jim Ingham58b59f92011-04-22 23:53:53 +00001967 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001968}
1969
1970ValueObjectSP
1971ValueObject::GetSyntheticChild (const ConstString &key) const
1972{
1973 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001974 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001975 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001976 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001977 return synthetic_child_sp;
1978}
1979
Greg Clayton2452ab72013-02-08 22:02:02 +00001980uint32_t
Greg Clayton57ee3062013-07-11 22:46:58 +00001981ValueObject::GetTypeInfo (ClangASTType *pointee_or_element_clang_type)
Greg Clayton2452ab72013-02-08 22:02:02 +00001982{
Greg Clayton57ee3062013-07-11 22:46:58 +00001983 return GetClangType().GetTypeInfo (pointee_or_element_clang_type);
Greg Clayton2452ab72013-02-08 22:02:02 +00001984}
1985
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001986bool
1987ValueObject::IsPointerType ()
1988{
Greg Clayton57ee3062013-07-11 22:46:58 +00001989 return GetClangType().IsPointerType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001990}
1991
Jim Inghamb7603bb2011-03-18 00:05:18 +00001992bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001993ValueObject::IsArrayType ()
1994{
Greg Clayton57ee3062013-07-11 22:46:58 +00001995 return GetClangType().IsArrayType (NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00001996}
1997
1998bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001999ValueObject::IsScalarType ()
2000{
Greg Clayton57ee3062013-07-11 22:46:58 +00002001 return GetClangType().IsScalarType ();
Enrico Granata9fc19442011-07-06 02:13:41 +00002002}
2003
2004bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00002005ValueObject::IsIntegerType (bool &is_signed)
2006{
Greg Clayton57ee3062013-07-11 22:46:58 +00002007 return GetClangType().IsIntegerType (is_signed);
Jim Inghamb7603bb2011-03-18 00:05:18 +00002008}
Greg Clayton73b472d2010-10-27 03:32:59 +00002009
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002010bool
2011ValueObject::IsPointerOrReferenceType ()
2012{
Greg Clayton57ee3062013-07-11 22:46:58 +00002013 return GetClangType().IsPointerOrReferenceType ();
Greg Clayton007d5be2011-05-30 00:49:24 +00002014}
2015
2016bool
Greg Claytondea8cb42011-06-29 22:09:02 +00002017ValueObject::IsPossibleDynamicType ()
2018{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002019 ExecutionContext exe_ctx (GetExecutionContextRef());
2020 Process *process = exe_ctx.GetProcessPtr();
2021 if (process)
2022 return process->IsPossibleDynamicValue(*this);
2023 else
Greg Clayton57ee3062013-07-11 22:46:58 +00002024 return GetClangType().IsPossibleDynamicType (NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00002025}
2026
Enrico Granata9e7b3882012-12-13 23:50:33 +00002027bool
2028ValueObject::IsObjCNil ()
2029{
Greg Clayton57ee3062013-07-11 22:46:58 +00002030 const uint32_t mask = ClangASTType::eTypeIsObjC | ClangASTType::eTypeIsPointer;
2031 bool isObjCpointer = (((GetClangType().GetTypeInfo(NULL)) & mask) == mask);
Enrico Granata7277d202013-03-15 23:33:15 +00002032 if (!isObjCpointer)
2033 return false;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002034 bool canReadValue = true;
2035 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
Enrico Granata7277d202013-03-15 23:33:15 +00002036 return canReadValue && isZero;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002037}
2038
Greg Claytonafacd142011-09-02 01:15:17 +00002039ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002040ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002041{
Greg Clayton2452ab72013-02-08 22:02:02 +00002042 const uint32_t type_info = GetTypeInfo ();
Greg Clayton57ee3062013-07-11 22:46:58 +00002043 if (type_info & ClangASTType::eTypeIsArray)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002044 return GetSyntheticArrayMemberFromArray(index, can_create);
2045
Greg Clayton57ee3062013-07-11 22:46:58 +00002046 if (type_info & ClangASTType::eTypeIsPointer)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002047 return GetSyntheticArrayMemberFromPointer(index, can_create);
2048
2049 return ValueObjectSP();
2050
2051}
2052
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002053ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002054ValueObject::GetSyntheticArrayMemberFromPointer (size_t index, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002055{
2056 ValueObjectSP synthetic_child_sp;
2057 if (IsPointerType ())
2058 {
2059 char index_str[64];
Greg Claytonc7bece562013-01-25 18:06:21 +00002060 snprintf(index_str, sizeof(index_str), "[%zu]", index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002061 ConstString index_const_str(index_str);
2062 // Check if we have already created a synthetic array member in this
2063 // valid object. If we have we will re-use it.
2064 synthetic_child_sp = GetSyntheticChild (index_const_str);
2065 if (!synthetic_child_sp)
2066 {
Jim Ingham58b59f92011-04-22 23:53:53 +00002067 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002068 // We haven't made a synthetic array member for INDEX yet, so
2069 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00002070 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002071
2072 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00002073 if (synthetic_child)
2074 {
2075 AddSyntheticChild(index_const_str, synthetic_child);
2076 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002077 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00002078 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00002079 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002080 }
2081 }
2082 return synthetic_child_sp;
2083}
Jim Ingham22777012010-09-23 02:01:19 +00002084
Greg Claytondaf515f2011-07-09 20:12:33 +00002085// This allows you to create an array member using and index
2086// that doesn't not fall in the normal bounds of the array.
2087// Many times structure can be defined as:
2088// struct Collection
2089// {
2090// uint32_t item_count;
2091// Item item_array[0];
2092// };
2093// The size of the "item_array" is 1, but many times in practice
2094// there are more items in "item_array".
2095
2096ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002097ValueObject::GetSyntheticArrayMemberFromArray (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00002098{
2099 ValueObjectSP synthetic_child_sp;
2100 if (IsArrayType ())
2101 {
2102 char index_str[64];
Greg Claytonc7bece562013-01-25 18:06:21 +00002103 snprintf(index_str, sizeof(index_str), "[%zu]", index);
Greg Claytondaf515f2011-07-09 20:12:33 +00002104 ConstString index_const_str(index_str);
2105 // Check if we have already created a synthetic array member in this
2106 // valid object. If we have we will re-use it.
2107 synthetic_child_sp = GetSyntheticChild (index_const_str);
2108 if (!synthetic_child_sp)
2109 {
2110 ValueObject *synthetic_child;
2111 // We haven't made a synthetic array member for INDEX yet, so
2112 // lets make one and cache it for any future reference.
2113 synthetic_child = CreateChildAtIndex(0, true, index);
2114
2115 // Cache the value if we got one back...
2116 if (synthetic_child)
2117 {
2118 AddSyntheticChild(index_const_str, synthetic_child);
2119 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002120 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00002121 synthetic_child_sp->m_is_array_item_for_pointer = true;
2122 }
2123 }
2124 }
2125 return synthetic_child_sp;
2126}
2127
Enrico Granata9fc19442011-07-06 02:13:41 +00002128ValueObjectSP
2129ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2130{
2131 ValueObjectSP synthetic_child_sp;
2132 if (IsScalarType ())
2133 {
2134 char index_str[64];
2135 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2136 ConstString index_const_str(index_str);
2137 // Check if we have already created a synthetic array member in this
2138 // valid object. If we have we will re-use it.
2139 synthetic_child_sp = GetSyntheticChild (index_const_str);
2140 if (!synthetic_child_sp)
2141 {
Enrico Granata9fc19442011-07-06 02:13:41 +00002142 // We haven't made a synthetic array member for INDEX yet, so
2143 // lets make one and cache it for any future reference.
Greg Clayton57ee3062013-07-11 22:46:58 +00002144 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
2145 GetClangType(),
2146 index_const_str,
2147 GetByteSize(),
2148 0,
2149 to-from+1,
2150 from,
2151 false,
2152 false,
2153 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002154
2155 // Cache the value if we got one back...
2156 if (synthetic_child)
2157 {
2158 AddSyntheticChild(index_const_str, synthetic_child);
2159 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002160 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002161 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2162 }
2163 }
2164 }
2165 return synthetic_child_sp;
2166}
2167
Greg Claytonafacd142011-09-02 01:15:17 +00002168ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00002169ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
2170{
2171
2172 ValueObjectSP synthetic_child_sp;
2173
2174 char name_str[64];
2175 snprintf(name_str, sizeof(name_str), "@%i", offset);
2176 ConstString name_const_str(name_str);
2177
2178 // Check if we have already created a synthetic array member in this
2179 // valid object. If we have we will re-use it.
2180 synthetic_child_sp = GetSyntheticChild (name_const_str);
2181
2182 if (synthetic_child_sp.get())
2183 return synthetic_child_sp;
2184
2185 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002186 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002187
2188 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
Greg Clayton57ee3062013-07-11 22:46:58 +00002189 type,
Enrico Granata6f3533f2011-07-29 19:53:35 +00002190 name_const_str,
Greg Clayton57ee3062013-07-11 22:46:58 +00002191 type.GetByteSize(),
Enrico Granata6f3533f2011-07-29 19:53:35 +00002192 offset,
2193 0,
2194 0,
2195 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002196 false,
2197 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002198 if (synthetic_child)
2199 {
2200 AddSyntheticChild(name_const_str, synthetic_child);
2201 synthetic_child_sp = synthetic_child->GetSP();
2202 synthetic_child_sp->SetName(name_const_str);
2203 synthetic_child_sp->m_is_child_at_offset = true;
2204 }
2205 return synthetic_child_sp;
2206}
2207
Enrico Granatad55546b2011-07-22 00:16:08 +00002208// your expression path needs to have a leading . or ->
2209// (unless it somehow "looks like" an array, in which case it has
2210// a leading [ symbol). while the [ is meaningful and should be shown
2211// to the user, . and -> are just parser design, but by no means
2212// added information for the user.. strip them off
2213static const char*
2214SkipLeadingExpressionPathSeparators(const char* expression)
2215{
2216 if (!expression || !expression[0])
2217 return expression;
2218 if (expression[0] == '.')
2219 return expression+1;
2220 if (expression[0] == '-' && expression[1] == '>')
2221 return expression+2;
2222 return expression;
2223}
2224
Greg Claytonafacd142011-09-02 01:15:17 +00002225ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002226ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2227{
2228 ValueObjectSP synthetic_child_sp;
2229 ConstString name_const_string(expression);
2230 // Check if we have already created a synthetic array member in this
2231 // valid object. If we have we will re-use it.
2232 synthetic_child_sp = GetSyntheticChild (name_const_string);
2233 if (!synthetic_child_sp)
2234 {
2235 // We haven't made a synthetic array member for expression yet, so
2236 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002237 synthetic_child_sp = GetValueForExpressionPath(expression,
2238 NULL, NULL, NULL,
2239 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
Enrico Granatad55546b2011-07-22 00:16:08 +00002240
2241 // Cache the value if we got one back...
2242 if (synthetic_child_sp.get())
2243 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002244 // 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 +00002245 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002246 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002247 }
2248 }
2249 return synthetic_child_sp;
2250}
2251
2252void
Enrico Granata86cc9822012-03-19 22:58:49 +00002253ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002254{
Enrico Granata86cc9822012-03-19 22:58:49 +00002255 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002256 return;
2257
Enrico Granatac5bc4122012-03-27 02:35:13 +00002258 TargetSP target_sp(GetTargetSP());
Enrico Granata5d5f60c2013-09-24 22:58:37 +00002259 if (target_sp && target_sp->GetEnableSyntheticValue() == false)
Enrico Granatac5bc4122012-03-27 02:35:13 +00002260 {
2261 m_synthetic_value = NULL;
2262 return;
2263 }
2264
Enrico Granatae3e91512012-10-22 18:18:36 +00002265 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2266
Enrico Granata5548cb52013-01-28 23:47:25 +00002267 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002268 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002269
Enrico Granata0c489f52012-03-01 04:24:26 +00002270 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002271 return;
2272
Enrico Granatae3e91512012-10-22 18:18:36 +00002273 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2274 return;
2275
Enrico Granata86cc9822012-03-19 22:58:49 +00002276 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002277}
2278
Jim Ingham78a685a2011-04-16 00:01:13 +00002279void
Greg Claytonafacd142011-09-02 01:15:17 +00002280ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002281{
Greg Claytonafacd142011-09-02 01:15:17 +00002282 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002283 return;
2284
Jim Ingham58b59f92011-04-22 23:53:53 +00002285 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002286 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002287 ExecutionContext exe_ctx (GetExecutionContextRef());
2288 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002289 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002290 {
2291 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002292 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002293 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002294 }
2295}
2296
Jim Ingham58b59f92011-04-22 23:53:53 +00002297ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002298ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002299{
Greg Claytonafacd142011-09-02 01:15:17 +00002300 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002301 return ValueObjectSP();
2302
2303 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002304 {
Jim Ingham2837b762011-05-04 03:43:18 +00002305 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002306 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002307 if (m_dynamic_value)
2308 return m_dynamic_value->GetSP();
2309 else
2310 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002311}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002312
Jim Ingham60dbabb2011-12-08 19:44:08 +00002313ValueObjectSP
2314ValueObject::GetStaticValue()
2315{
2316 return GetSP();
2317}
2318
Enrico Granata886147f2012-05-08 18:47:08 +00002319lldb::ValueObjectSP
2320ValueObject::GetNonSyntheticValue ()
2321{
2322 return GetSP();
2323}
2324
Enrico Granatad55546b2011-07-22 00:16:08 +00002325ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002326ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002327{
Enrico Granata86cc9822012-03-19 22:58:49 +00002328 if (use_synthetic == false)
2329 return ValueObjectSP();
2330
Enrico Granatad55546b2011-07-22 00:16:08 +00002331 CalculateSyntheticValue(use_synthetic);
2332
2333 if (m_synthetic_value)
2334 return m_synthetic_value->GetSP();
2335 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002336 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002337}
2338
Greg Claytone221f822011-01-21 01:59:00 +00002339bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002340ValueObject::HasSyntheticValue()
2341{
Enrico Granata5548cb52013-01-28 23:47:25 +00002342 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002343
Enrico Granata0c489f52012-03-01 04:24:26 +00002344 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002345 return false;
2346
Enrico Granata86cc9822012-03-19 22:58:49 +00002347 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002348
2349 if (m_synthetic_value)
2350 return true;
2351 else
2352 return false;
2353}
2354
2355bool
Greg Claytone221f822011-01-21 01:59:00 +00002356ValueObject::GetBaseClassPath (Stream &s)
2357{
2358 if (IsBaseClass())
2359 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002360 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Clayton57ee3062013-07-11 22:46:58 +00002361 ClangASTType clang_type = GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002362 std::string cxx_class_name;
Greg Clayton57ee3062013-07-11 22:46:58 +00002363 bool this_had_base_class = clang_type.GetCXXClassName (cxx_class_name);
Greg Claytone221f822011-01-21 01:59:00 +00002364 if (this_had_base_class)
2365 {
2366 if (parent_had_base_class)
2367 s.PutCString("::");
2368 s.PutCString(cxx_class_name.c_str());
2369 }
2370 return parent_had_base_class || this_had_base_class;
2371 }
2372 return false;
2373}
2374
2375
2376ValueObject *
2377ValueObject::GetNonBaseClassParent()
2378{
Jim Ingham78a685a2011-04-16 00:01:13 +00002379 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002380 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002381 if (GetParent()->IsBaseClass())
2382 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002383 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002384 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002385 }
2386 return NULL;
2387}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002388
2389void
Enrico Granata4becb372011-06-29 22:27:15 +00002390ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002391{
Greg Claytone221f822011-01-21 01:59:00 +00002392 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002393
Enrico Granata86cc9822012-03-19 22:58:49 +00002394 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002395 {
Enrico Granata4becb372011-06-29 22:27:15 +00002396 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2397 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2398 // the eHonorPointers mode is meant to produce strings in this latter format
2399 s.PutCString("*(");
2400 }
Greg Claytone221f822011-01-21 01:59:00 +00002401
Enrico Granata4becb372011-06-29 22:27:15 +00002402 ValueObject* parent = GetParent();
2403
2404 if (parent)
2405 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002406
2407 // if we are a deref_of_parent just because we are synthetic array
2408 // members made up to allow ptr[%d] syntax to work in variable
2409 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002410 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002411 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002412
Greg Claytone221f822011-01-21 01:59:00 +00002413 if (!IsBaseClass())
2414 {
2415 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002416 {
Greg Claytone221f822011-01-21 01:59:00 +00002417 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2418 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002419 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002420 ClangASTType non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002421 if (non_base_class_parent_clang_type)
2422 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002423 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002424 {
2425 s.PutCString("->");
2426 }
Enrico Granata4becb372011-06-29 22:27:15 +00002427 else
2428 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002429 const uint32_t non_base_class_parent_type_info = non_base_class_parent_clang_type.GetTypeInfo();
2430
2431 if (non_base_class_parent_type_info & ClangASTType::eTypeIsPointer)
Enrico Granata4becb372011-06-29 22:27:15 +00002432 {
2433 s.PutCString("->");
2434 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002435 else if ((non_base_class_parent_type_info & ClangASTType::eTypeHasChildren) &&
2436 !(non_base_class_parent_type_info & ClangASTType::eTypeIsArray))
Enrico Granata4becb372011-06-29 22:27:15 +00002437 {
2438 s.PutChar('.');
2439 }
Greg Claytone221f822011-01-21 01:59:00 +00002440 }
2441 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002442 }
Greg Claytone221f822011-01-21 01:59:00 +00002443
2444 const char *name = GetName().GetCString();
2445 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002446 {
Greg Claytone221f822011-01-21 01:59:00 +00002447 if (qualify_cxx_base_classes)
2448 {
2449 if (GetBaseClassPath (s))
2450 s.PutCString("::");
2451 }
2452 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002453 }
2454 }
2455 }
2456
Enrico Granata86cc9822012-03-19 22:58:49 +00002457 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002458 {
Greg Claytone221f822011-01-21 01:59:00 +00002459 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002460 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002461}
2462
Greg Claytonafacd142011-09-02 01:15:17 +00002463ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002464ValueObject::GetValueForExpressionPath(const char* expression,
2465 const char** first_unparsed,
2466 ExpressionPathScanEndReason* reason_to_stop,
2467 ExpressionPathEndResultType* final_value_type,
2468 const GetValueForExpressionPathOptions& options,
2469 ExpressionPathAftermath* final_task_on_target)
2470{
2471
2472 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002473 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2474 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002475 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002476
2477 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2478 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2479 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2480 final_value_type ? final_value_type : &dummy_final_value_type,
2481 options,
2482 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2483
Enrico Granata86cc9822012-03-19 22:58:49 +00002484 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002485 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002486
Enrico Granata86cc9822012-03-19 22:58:49 +00002487 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 +00002488 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002489 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002490 {
2491 Error error;
2492 ValueObjectSP final_value = ret_val->Dereference(error);
2493 if (error.Fail() || !final_value.get())
2494 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002495 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002496 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002497 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002498 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002499 return ValueObjectSP();
2500 }
2501 else
2502 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002503 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002504 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002505 return final_value;
2506 }
2507 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002508 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002509 {
2510 Error error;
2511 ValueObjectSP final_value = ret_val->AddressOf(error);
2512 if (error.Fail() || !final_value.get())
2513 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002514 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002515 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002516 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002517 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002518 return ValueObjectSP();
2519 }
2520 else
2521 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002522 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002523 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002524 return final_value;
2525 }
2526 }
2527 }
2528 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2529}
2530
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002531int
2532ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002533 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002534 const char** first_unparsed,
2535 ExpressionPathScanEndReason* reason_to_stop,
2536 ExpressionPathEndResultType* final_value_type,
2537 const GetValueForExpressionPathOptions& options,
2538 ExpressionPathAftermath* final_task_on_target)
2539{
2540 const char* dummy_first_unparsed;
2541 ExpressionPathScanEndReason dummy_reason_to_stop;
2542 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002543 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002544
2545 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2546 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2547 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2548 final_value_type ? final_value_type : &dummy_final_value_type,
2549 options,
2550 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2551
2552 if (!ret_val.get()) // if there are errors, I add nothing to the list
2553 return 0;
2554
Enrico Granata86ea8d82012-03-29 01:34:34 +00002555 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002556 {
2557 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002558 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002559 {
2560 list->Append(ret_val);
2561 return 1;
2562 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002563 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 +00002564 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002565 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002566 {
2567 Error error;
2568 ValueObjectSP final_value = ret_val->Dereference(error);
2569 if (error.Fail() || !final_value.get())
2570 {
Greg Clayton23f59502012-07-17 03:23:13 +00002571 if (reason_to_stop)
2572 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2573 if (final_value_type)
2574 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002575 return 0;
2576 }
2577 else
2578 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002579 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002580 list->Append(final_value);
2581 return 1;
2582 }
2583 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002584 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002585 {
2586 Error error;
2587 ValueObjectSP final_value = ret_val->AddressOf(error);
2588 if (error.Fail() || !final_value.get())
2589 {
Greg Clayton23f59502012-07-17 03:23:13 +00002590 if (reason_to_stop)
2591 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2592 if (final_value_type)
2593 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002594 return 0;
2595 }
2596 else
2597 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002598 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002599 list->Append(final_value);
2600 return 1;
2601 }
2602 }
2603 }
2604 }
2605 else
2606 {
2607 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2608 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2609 ret_val,
2610 list,
2611 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2612 final_value_type ? final_value_type : &dummy_final_value_type,
2613 options,
2614 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2615 }
2616 // in any non-covered case, just do the obviously right thing
2617 list->Append(ret_val);
2618 return 1;
2619}
2620
Greg Claytonafacd142011-09-02 01:15:17 +00002621ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002622ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2623 const char** first_unparsed,
2624 ExpressionPathScanEndReason* reason_to_stop,
2625 ExpressionPathEndResultType* final_result,
2626 const GetValueForExpressionPathOptions& options,
2627 ExpressionPathAftermath* what_next)
2628{
2629 ValueObjectSP root = GetSP();
2630
2631 if (!root.get())
2632 return ValueObjectSP();
2633
2634 *first_unparsed = expression_cstr;
2635
2636 while (true)
2637 {
2638
2639 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2640
Greg Clayton57ee3062013-07-11 22:46:58 +00002641 ClangASTType root_clang_type = root->GetClangType();
2642 ClangASTType pointee_clang_type;
2643 Flags pointee_clang_type_info;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002644
Greg Clayton57ee3062013-07-11 22:46:58 +00002645 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002646 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00002647 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002648
2649 if (!expression_cstr || *expression_cstr == '\0')
2650 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002651 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002652 return root;
2653 }
2654
2655 switch (*expression_cstr)
2656 {
2657 case '-':
2658 {
2659 if (options.m_check_dot_vs_arrow_syntax &&
Greg Clayton57ee3062013-07-11 22:46:58 +00002660 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 +00002661 {
2662 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002663 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2664 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002665 return ValueObjectSP();
2666 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002667 if (root_clang_type_info.Test(ClangASTType::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2668 root_clang_type_info.Test(ClangASTType::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002669 options.m_no_fragile_ivar)
2670 {
2671 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002672 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2673 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002674 return ValueObjectSP();
2675 }
2676 if (expression_cstr[1] != '>')
2677 {
2678 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002679 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2680 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002681 return ValueObjectSP();
2682 }
2683 expression_cstr++; // skip the -
2684 }
2685 case '.': // or fallthrough from ->
2686 {
2687 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Greg Clayton57ee3062013-07-11 22:46:58 +00002688 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 +00002689 {
2690 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002691 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2692 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002693 return ValueObjectSP();
2694 }
2695 expression_cstr++; // skip .
2696 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2697 ConstString child_name;
2698 if (!next_separator) // if no other separator just expand this last layer
2699 {
2700 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002701 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2702
2703 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002704 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002705 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002706 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2707 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002708 return child_valobj_sp;
2709 }
2710 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2711 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002712 if (root->IsSynthetic())
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002713 {
2714 *first_unparsed = expression_cstr;
2715 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2716 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2717 return ValueObjectSP();
2718 }
2719
2720 child_valobj_sp = root->GetSyntheticValue();
Enrico Granata86cc9822012-03-19 22:58:49 +00002721 if (child_valobj_sp.get())
2722 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002723 }
2724
2725 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2726 // so we hit the "else" branch, and return an error
2727 if(child_valobj_sp.get()) // if it worked, just return
2728 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002729 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002730 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2731 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002732 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002733 }
2734 else
2735 {
2736 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002737 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2738 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002739 return ValueObjectSP();
2740 }
2741 }
2742 else // other layers do expand
2743 {
2744 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002745 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2746 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002747 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002748 root = child_valobj_sp;
2749 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002750 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002751 continue;
2752 }
2753 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2754 {
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002755 if (root->IsSynthetic())
2756 {
2757 *first_unparsed = expression_cstr;
2758 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2759 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2760 return ValueObjectSP();
2761 }
2762
Enrico Granata86cc9822012-03-19 22:58:49 +00002763 child_valobj_sp = root->GetSyntheticValue(true);
2764 if (child_valobj_sp)
2765 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002766 }
2767
2768 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2769 // so we hit the "else" branch, and return an error
2770 if(child_valobj_sp.get()) // if it worked, move on
2771 {
2772 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002773 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002774 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002775 continue;
2776 }
2777 else
2778 {
2779 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002780 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2781 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002782 return ValueObjectSP();
2783 }
2784 }
2785 break;
2786 }
2787 case '[':
2788 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002789 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 +00002790 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002791 if (!root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002792 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002793 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2794 {
2795 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002796 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2797 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002798 return ValueObjectSP();
2799 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002800 }
2801 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2802 {
2803 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002804 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2805 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002806 return ValueObjectSP();
2807 }
2808 }
2809 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2810 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002811 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002812 {
2813 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002814 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2815 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002816 return ValueObjectSP();
2817 }
2818 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2819 {
2820 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002821 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2822 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002823 return root;
2824 }
2825 }
2826 const char *separator_position = ::strchr(expression_cstr+1,'-');
2827 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2828 if (!close_bracket_position) // if there is no ], this is a syntax error
2829 {
2830 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002831 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2832 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002833 return ValueObjectSP();
2834 }
2835 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2836 {
2837 char *end = NULL;
2838 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2839 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2840 {
2841 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002842 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2843 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002844 return ValueObjectSP();
2845 }
2846 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2847 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002848 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002849 {
2850 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002851 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2852 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002853 return root;
2854 }
2855 else
2856 {
2857 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002858 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2859 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002860 return ValueObjectSP();
2861 }
2862 }
2863 // from here on we do have a valid index
Greg Clayton57ee3062013-07-11 22:46:58 +00002864 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002865 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002866 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2867 if (!child_valobj_sp)
2868 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002869 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002870 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2871 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002872 if (child_valobj_sp)
2873 {
2874 root = child_valobj_sp;
2875 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002876 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002877 continue;
2878 }
2879 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002880 {
2881 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002882 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2883 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002884 return ValueObjectSP();
2885 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002886 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002887 else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002888 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002889 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 +00002890 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002891 {
2892 Error error;
2893 root = root->Dereference(error);
2894 if (error.Fail() || !root.get())
2895 {
2896 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002897 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2898 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002899 return ValueObjectSP();
2900 }
2901 else
2902 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002903 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002904 continue;
2905 }
2906 }
2907 else
2908 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002909 if (root->GetClangType().GetMinimumLanguage() == eLanguageTypeObjC
2910 && pointee_clang_type_info.AllClear(ClangASTType::eTypeIsPointer)
Greg Clayton84db9102012-03-26 23:03:23 +00002911 && root->HasSyntheticValue()
2912 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002913 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002914 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002915 }
2916 else
2917 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002918 if (!root.get())
2919 {
2920 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002921 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2922 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002923 return ValueObjectSP();
2924 }
2925 else
2926 {
2927 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002928 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002929 continue;
2930 }
2931 }
2932 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002933 else if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002934 {
2935 root = root->GetSyntheticBitFieldChild(index, index, true);
2936 if (!root.get())
2937 {
2938 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002939 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2940 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002941 return ValueObjectSP();
2942 }
2943 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2944 {
2945 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002946 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2947 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002948 return root;
2949 }
2950 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002951 else if (root_clang_type_info.Test(ClangASTType::eTypeIsVector))
Enrico Granata08a1bb82013-06-19 00:00:45 +00002952 {
2953 root = root->GetChildAtIndex(index, true);
2954 if (!root.get())
2955 {
2956 *first_unparsed = expression_cstr;
2957 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2958 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2959 return ValueObjectSP();
2960 }
2961 else
2962 {
2963 *first_unparsed = end+1; // skip ]
2964 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2965 continue;
2966 }
2967 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002968 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002969 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002970 if (root->HasSyntheticValue())
2971 root = root->GetSyntheticValue();
2972 else if (!root->IsSynthetic())
2973 {
2974 *first_unparsed = expression_cstr;
2975 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2976 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2977 return ValueObjectSP();
2978 }
2979 // if we are here, then root itself is a synthetic VO.. should be good to go
2980
Enrico Granata27b625e2011-08-09 01:04:56 +00002981 if (!root.get())
2982 {
2983 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002984 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2985 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2986 return ValueObjectSP();
2987 }
2988 root = root->GetChildAtIndex(index, true);
2989 if (!root.get())
2990 {
2991 *first_unparsed = expression_cstr;
2992 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2993 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002994 return ValueObjectSP();
2995 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002996 else
2997 {
2998 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002999 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00003000 continue;
3001 }
Enrico Granata27b625e2011-08-09 01:04:56 +00003002 }
3003 else
3004 {
3005 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003006 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3007 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003008 return ValueObjectSP();
3009 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003010 }
3011 else // we have a low and a high index
3012 {
3013 char *end = NULL;
3014 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3015 if (!end || end != separator_position) // if something weird is in our way return an error
3016 {
3017 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003018 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3019 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003020 return ValueObjectSP();
3021 }
3022 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3023 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3024 {
3025 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003026 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3027 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003028 return ValueObjectSP();
3029 }
3030 if (index_lower > index_higher) // swap indices if required
3031 {
3032 unsigned long temp = index_lower;
3033 index_lower = index_higher;
3034 index_higher = temp;
3035 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003036 if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003037 {
3038 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3039 if (!root.get())
3040 {
3041 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003042 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3043 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003044 return ValueObjectSP();
3045 }
3046 else
3047 {
3048 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003049 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3050 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003051 return root;
3052 }
3053 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003054 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 +00003055 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Greg Clayton57ee3062013-07-11 22:46:58 +00003056 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003057 {
3058 Error error;
3059 root = root->Dereference(error);
3060 if (error.Fail() || !root.get())
3061 {
3062 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003063 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3064 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003065 return ValueObjectSP();
3066 }
3067 else
3068 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003069 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003070 continue;
3071 }
3072 }
3073 else
3074 {
3075 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003076 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3077 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003078 return root;
3079 }
3080 }
3081 break;
3082 }
3083 default: // some non-separator is in the way
3084 {
3085 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003086 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3087 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003088 return ValueObjectSP();
3089 break;
3090 }
3091 }
3092 }
3093}
3094
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003095int
3096ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3097 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00003098 ValueObjectSP root,
3099 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003100 ExpressionPathScanEndReason* reason_to_stop,
3101 ExpressionPathEndResultType* final_result,
3102 const GetValueForExpressionPathOptions& options,
3103 ExpressionPathAftermath* what_next)
3104{
3105 if (!root.get())
3106 return 0;
3107
3108 *first_unparsed = expression_cstr;
3109
3110 while (true)
3111 {
3112
3113 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3114
Greg Clayton57ee3062013-07-11 22:46:58 +00003115 ClangASTType root_clang_type = root->GetClangType();
3116 ClangASTType pointee_clang_type;
3117 Flags pointee_clang_type_info;
3118 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003119 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00003120 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003121
3122 if (!expression_cstr || *expression_cstr == '\0')
3123 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003124 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003125 list->Append(root);
3126 return 1;
3127 }
3128
3129 switch (*expression_cstr)
3130 {
3131 case '[':
3132 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003133 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 +00003134 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003135 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 +00003136 {
3137 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003138 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3139 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003140 return 0;
3141 }
3142 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3143 {
3144 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003145 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3146 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003147 return 0;
3148 }
3149 }
3150 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3151 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003152 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003153 {
3154 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003155 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3156 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003157 return 0;
3158 }
3159 else // expand this into list
3160 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003161 const size_t max_index = root->GetNumChildren() - 1;
3162 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003163 {
3164 ValueObjectSP child =
3165 root->GetChildAtIndex(index, true);
3166 list->Append(child);
3167 }
3168 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003169 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3170 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003171 return max_index; // tell me number of items I added to the VOList
3172 }
3173 }
3174 const char *separator_position = ::strchr(expression_cstr+1,'-');
3175 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3176 if (!close_bracket_position) // if there is no ], this is a syntax error
3177 {
3178 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003179 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3180 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003181 return 0;
3182 }
3183 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3184 {
3185 char *end = NULL;
3186 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3187 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3188 {
3189 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003190 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3191 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003192 return 0;
3193 }
3194 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3195 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003196 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003197 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003198 const size_t max_index = root->GetNumChildren() - 1;
3199 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003200 {
3201 ValueObjectSP child =
3202 root->GetChildAtIndex(index, true);
3203 list->Append(child);
3204 }
3205 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003206 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3207 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003208 return max_index; // tell me number of items I added to the VOList
3209 }
3210 else
3211 {
3212 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003213 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3214 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003215 return 0;
3216 }
3217 }
3218 // from here on we do have a valid index
Greg Clayton57ee3062013-07-11 22:46:58 +00003219 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003220 {
3221 root = root->GetChildAtIndex(index, true);
3222 if (!root.get())
3223 {
3224 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003225 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3226 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003227 return 0;
3228 }
3229 else
3230 {
3231 list->Append(root);
3232 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003233 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3234 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003235 return 1;
3236 }
3237 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003238 else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003239 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003240 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 +00003241 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003242 {
3243 Error error;
3244 root = root->Dereference(error);
3245 if (error.Fail() || !root.get())
3246 {
3247 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003248 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3249 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003250 return 0;
3251 }
3252 else
3253 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003254 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003255 continue;
3256 }
3257 }
3258 else
3259 {
3260 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3261 if (!root.get())
3262 {
3263 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003264 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3265 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003266 return 0;
3267 }
3268 else
3269 {
3270 list->Append(root);
3271 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003272 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3273 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003274 return 1;
3275 }
3276 }
3277 }
3278 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3279 {
3280 root = root->GetSyntheticBitFieldChild(index, index, true);
3281 if (!root.get())
3282 {
3283 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003284 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3285 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003286 return 0;
3287 }
3288 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3289 {
3290 list->Append(root);
3291 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003292 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3293 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003294 return 1;
3295 }
3296 }
3297 }
3298 else // we have a low and a high index
3299 {
3300 char *end = NULL;
3301 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3302 if (!end || end != separator_position) // if something weird is in our way return an error
3303 {
3304 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003305 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3306 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003307 return 0;
3308 }
3309 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3310 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3311 {
3312 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003313 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3314 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003315 return 0;
3316 }
3317 if (index_lower > index_higher) // swap indices if required
3318 {
3319 unsigned long temp = index_lower;
3320 index_lower = index_higher;
3321 index_higher = temp;
3322 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003323 if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // expansion only works for scalars
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003324 {
3325 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3326 if (!root.get())
3327 {
3328 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003329 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3330 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003331 return 0;
3332 }
3333 else
3334 {
3335 list->Append(root);
3336 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003337 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3338 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003339 return 1;
3340 }
3341 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003342 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 +00003343 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Greg Clayton57ee3062013-07-11 22:46:58 +00003344 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003345 {
3346 Error error;
3347 root = root->Dereference(error);
3348 if (error.Fail() || !root.get())
3349 {
3350 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003351 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3352 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003353 return 0;
3354 }
3355 else
3356 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003357 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003358 continue;
3359 }
3360 }
3361 else
3362 {
Johnny Chen44805302011-07-19 19:48:13 +00003363 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003364 index <= index_higher; index++)
3365 {
3366 ValueObjectSP child =
3367 root->GetChildAtIndex(index, true);
3368 list->Append(child);
3369 }
3370 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003371 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3372 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003373 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3374 }
3375 }
3376 break;
3377 }
3378 default: // some non-[ separator, or something entirely wrong, is in the way
3379 {
3380 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003381 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3382 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003383 return 0;
3384 break;
3385 }
3386 }
3387 }
3388}
3389
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003390void
3391ValueObject::LogValueObject (Log *log)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003392{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003393 if (log)
3394 return LogValueObject (log, DumpValueObjectOptions::DefaultOptions());
Greg Clayton1d3afba2010-10-05 00:00:42 +00003395}
3396
Enrico Granata0c489f52012-03-01 04:24:26 +00003397void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003398ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003399{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003400 if (log)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003401 {
3402 StreamString s;
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003403 Dump (s, options);
Greg Claytonf830dbb2012-03-22 18:15:37 +00003404 if (s.GetSize())
3405 log->PutCString(s.GetData());
3406 }
3407}
3408
3409void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003410ValueObject::Dump (Stream &s)
Enrico Granata0c489f52012-03-01 04:24:26 +00003411{
3412
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003413 ValueObjectPrinter printer(this,&s,DumpValueObjectOptions::DefaultOptions());
3414 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003415}
3416
3417void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003418ValueObject::Dump (Stream &s,
3419 const DumpValueObjectOptions& options)
Enrico Granata0c489f52012-03-01 04:24:26 +00003420{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003421 ValueObjectPrinter printer(this,&s,options);
3422 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003423}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003424
3425ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003426ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003427{
3428 ValueObjectSP valobj_sp;
3429
Enrico Granatac3e320a2011-08-02 17:27:39 +00003430 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003431 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003432 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003433
3434 DataExtractor data;
3435 data.SetByteOrder (m_data.GetByteOrder());
3436 data.SetAddressByteSize(m_data.GetAddressByteSize());
3437
Enrico Granata9f1e2042012-04-24 22:15:37 +00003438 if (IsBitfield())
3439 {
3440 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
Greg Clayton57ee3062013-07-11 22:46:58 +00003441 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Enrico Granata9f1e2042012-04-24 22:15:37 +00003442 }
3443 else
Greg Clayton57ee3062013-07-11 22:46:58 +00003444 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003445
3446 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003447 GetClangType(),
3448 name,
3449 data,
3450 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003451 }
Jim Ingham6035b672011-03-31 00:19:25 +00003452
3453 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003454 {
Greg Claytoneeb15652013-12-10 23:16:40 +00003455 ExecutionContext exe_ctx (GetExecutionContextRef());
3456 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003457 }
3458 return valobj_sp;
3459}
3460
Greg Claytonafacd142011-09-02 01:15:17 +00003461ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003462ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003463{
Jim Ingham58b59f92011-04-22 23:53:53 +00003464 if (m_deref_valobj)
3465 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003466
Greg Clayton54979cd2010-12-15 05:08:08 +00003467 const bool is_pointer_type = IsPointerType();
3468 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003469 {
3470 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003471 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003472
3473 std::string child_name_str;
3474 uint32_t child_byte_size = 0;
3475 int32_t child_byte_offset = 0;
3476 uint32_t child_bitfield_bit_size = 0;
3477 uint32_t child_bitfield_bit_offset = 0;
3478 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003479 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003480 const bool transparent_pointers = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00003481 ClangASTType clang_type = GetClangType();
3482 ClangASTType child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003483
Greg Claytoncc4d0142012-02-17 07:49:44 +00003484 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003485
Greg Clayton57ee3062013-07-11 22:46:58 +00003486 child_clang_type = clang_type.GetChildClangTypeAtIndex (&exe_ctx,
3487 GetName().GetCString(),
3488 0,
3489 transparent_pointers,
3490 omit_empty_base_classes,
3491 ignore_array_bounds,
3492 child_name_str,
3493 child_byte_size,
3494 child_byte_offset,
3495 child_bitfield_bit_size,
3496 child_bitfield_bit_offset,
3497 child_is_base_class,
3498 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003499 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003500 {
3501 ConstString child_name;
3502 if (!child_name_str.empty())
3503 child_name.SetCString (child_name_str.c_str());
3504
Jim Ingham58b59f92011-04-22 23:53:53 +00003505 m_deref_valobj = new ValueObjectChild (*this,
Jim Ingham58b59f92011-04-22 23:53:53 +00003506 child_clang_type,
3507 child_name,
3508 child_byte_size,
3509 child_byte_offset,
3510 child_bitfield_bit_size,
3511 child_bitfield_bit_offset,
3512 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003513 child_is_deref_of_parent,
3514 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003515 }
3516 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003517
Jim Ingham58b59f92011-04-22 23:53:53 +00003518 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003519 {
3520 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003521 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003522 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003523 else
3524 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003525 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003526 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003527
3528 if (is_pointer_type)
3529 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3530 else
3531 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003532 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003533 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003534}
3535
Greg Claytonafacd142011-09-02 01:15:17 +00003536ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003537ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003538{
Jim Ingham78a685a2011-04-16 00:01:13 +00003539 if (m_addr_of_valobj_sp)
3540 return m_addr_of_valobj_sp;
3541
Greg Claytone0d378b2011-03-24 21:19:54 +00003542 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003543 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003544 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003545 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003546 if (addr != LLDB_INVALID_ADDRESS)
3547 {
3548 switch (address_type)
3549 {
3550 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003551 {
3552 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003553 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003554 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3555 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003556 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003557
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003558 case eAddressTypeFile:
3559 case eAddressTypeLoad:
3560 case eAddressTypeHost:
3561 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003562 ClangASTType clang_type = GetClangType();
3563 if (clang_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003564 {
3565 std::string name (1, '&');
3566 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003567 ExecutionContext exe_ctx (GetExecutionContextRef());
3568 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00003569 clang_type.GetPointerType(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003570 ConstString (name.c_str()),
3571 addr,
3572 eAddressTypeInvalid,
3573 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003574 }
3575 }
3576 break;
3577 }
3578 }
Sean Callananed185ab2013-04-19 19:47:32 +00003579 else
3580 {
3581 StreamString expr_path_strm;
3582 GetExpressionPath(expr_path_strm, true);
3583 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3584 }
3585
Jim Ingham78a685a2011-04-16 00:01:13 +00003586 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003587}
3588
Greg Clayton9a142cf2012-02-03 05:34:10 +00003589ValueObjectSP
3590ValueObject::Cast (const ClangASTType &clang_ast_type)
3591{
Greg Clayton81e871e2012-02-04 02:27:34 +00003592 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003593}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003594
Greg Claytonafacd142011-09-02 01:15:17 +00003595ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003596ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3597{
Greg Claytonafacd142011-09-02 01:15:17 +00003598 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003599 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003600 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003601
3602 if (ptr_value != LLDB_INVALID_ADDRESS)
3603 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003604 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003605 ExecutionContext exe_ctx (GetExecutionContextRef());
3606 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003607 name,
3608 ptr_addr,
3609 clang_ast_type);
3610 }
3611 return valobj_sp;
3612}
3613
Greg Claytonafacd142011-09-02 01:15:17 +00003614ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003615ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3616{
Greg Claytonafacd142011-09-02 01:15:17 +00003617 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003618 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003619 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003620
3621 if (ptr_value != LLDB_INVALID_ADDRESS)
3622 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003623 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003624 ExecutionContext exe_ctx (GetExecutionContextRef());
3625 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003626 name,
3627 ptr_addr,
3628 type_sp);
3629 }
3630 return valobj_sp;
3631}
3632
Jim Ingham6035b672011-03-31 00:19:25 +00003633ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003634 m_mod_id(),
3635 m_exe_ctx_ref(),
3636 m_needs_update (true),
3637 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003638{
3639}
3640
3641ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003642 m_mod_id(),
3643 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003644 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003645 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003646{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003647 ExecutionContext exe_ctx(exe_scope);
3648 TargetSP target_sp (exe_ctx.GetTargetSP());
3649 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003650 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003651 m_exe_ctx_ref.SetTargetSP (target_sp);
3652 ProcessSP process_sp (exe_ctx.GetProcessSP());
3653 if (!process_sp)
3654 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003655
Greg Claytoncc4d0142012-02-17 07:49:44 +00003656 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003657 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003658 m_mod_id = process_sp->GetModID();
3659 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003660
Greg Claytoncc4d0142012-02-17 07:49:44 +00003661 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003662
Greg Claytoncc4d0142012-02-17 07:49:44 +00003663 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003664 {
3665 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003666 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003667 }
Jim Ingham6035b672011-03-31 00:19:25 +00003668
Greg Claytoncc4d0142012-02-17 07:49:44 +00003669 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003670 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003671 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003672
Jason Molendab57e4a12013-11-04 09:33:30 +00003673 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003674 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003675 {
3676 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003677 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003678 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003679 if (frame_sp)
3680 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003681 }
3682 }
3683 }
Jim Ingham6035b672011-03-31 00:19:25 +00003684}
3685
3686ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003687 m_mod_id(),
3688 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3689 m_needs_update (true),
3690 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003691{
3692}
3693
3694ValueObject::EvaluationPoint::~EvaluationPoint ()
3695{
3696}
3697
Jim Ingham6035b672011-03-31 00:19:25 +00003698// This function checks the EvaluationPoint against the current process state. If the current
3699// state matches the evaluation point, or the evaluation point is already invalid, then we return
3700// false, meaning "no change". If the current state is different, we update our state, and return
3701// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3702// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003703// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003704
3705bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003706ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003707{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003708
3709 // Start with the target, if it is NULL, then we're obviously not going to get any further:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003710 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00003711
Greg Claytoncc4d0142012-02-17 07:49:44 +00003712 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003713 return false;
3714
Jim Ingham6035b672011-03-31 00:19:25 +00003715 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003716 Process *process = exe_ctx.GetProcessPtr();
3717 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003718 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003719
Jim Ingham6035b672011-03-31 00:19:25 +00003720 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003721 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003722
Jim Ingham78a685a2011-04-16 00:01:13 +00003723 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3724 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003725 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003726 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003727
Greg Clayton23f59502012-07-17 03:23:13 +00003728 bool changed = false;
3729 const bool was_valid = m_mod_id.IsValid();
3730 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003731 {
3732 if (m_mod_id == current_mod_id)
3733 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003734 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003735 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003736 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003737 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003738 else
3739 {
3740 m_mod_id = current_mod_id;
3741 m_needs_update = true;
3742 changed = true;
3743 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003744 }
Jim Ingham6035b672011-03-31 00:19:25 +00003745
Jim Ingham73ca05a2011-12-17 01:35:57 +00003746 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3747 // That way we'll be sure to return a valid exe_scope.
3748 // 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 +00003749
Greg Claytoncc4d0142012-02-17 07:49:44 +00003750 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003751 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003752 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3753 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003754 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003755 if (m_exe_ctx_ref.HasFrameRef())
3756 {
Jason Molendab57e4a12013-11-04 09:33:30 +00003757 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003758 if (!frame_sp)
3759 {
3760 // We used to have a frame, but now it is gone
3761 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003762 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00003763 }
3764 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003765 }
Jim Ingham6035b672011-03-31 00:19:25 +00003766 else
3767 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003768 // We used to have a thread, but now it is gone
3769 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003770 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00003771 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003772
Jim Ingham6035b672011-03-31 00:19:25 +00003773 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003774 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003775}
3776
Jim Ingham61be0902011-05-02 18:13:59 +00003777void
3778ValueObject::EvaluationPoint::SetUpdated ()
3779{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003780 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3781 if (process_sp)
3782 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003783 m_first_update = false;
3784 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003785}
3786
3787
Enrico Granataf2bbf712011-07-15 02:26:42 +00003788
3789void
Enrico Granata86cc9822012-03-19 22:58:49 +00003790ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00003791{
Enrico Granata86cc9822012-03-19 22:58:49 +00003792 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
3793 m_value_str.clear();
3794
3795 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
3796 m_location_str.clear();
3797
3798 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
3799 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003800 m_summary_str.clear();
3801 }
3802
3803 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
3804 m_object_desc_str.clear();
3805
3806 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
3807 {
3808 if (m_synthetic_value)
3809 m_synthetic_value = NULL;
3810 }
Johnny Chen44805302011-07-19 19:48:13 +00003811}
Enrico Granata9128ee22011-09-06 19:20:51 +00003812
3813SymbolContextScope *
3814ValueObject::GetSymbolContextScope()
3815{
3816 if (m_parent)
3817 {
3818 if (!m_parent->IsPointerOrReferenceType())
3819 return m_parent->GetSymbolContextScope();
3820 }
3821 return NULL;
3822}
Enrico Granatab2698cd2012-09-13 18:27:09 +00003823
3824lldb::ValueObjectSP
3825ValueObject::CreateValueObjectFromExpression (const char* name,
3826 const char* expression,
3827 const ExecutionContext& exe_ctx)
3828{
3829 lldb::ValueObjectSP retval_sp;
3830 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
3831 if (!target_sp)
3832 return retval_sp;
3833 if (!expression || !*expression)
3834 return retval_sp;
3835 target_sp->EvaluateExpression (expression,
3836 exe_ctx.GetFrameSP().get(),
3837 retval_sp);
3838 if (retval_sp && name && *name)
3839 retval_sp->SetName(ConstString(name));
3840 return retval_sp;
3841}
3842
3843lldb::ValueObjectSP
3844ValueObject::CreateValueObjectFromAddress (const char* name,
3845 uint64_t address,
3846 const ExecutionContext& exe_ctx,
3847 ClangASTType type)
3848{
Greg Clayton57ee3062013-07-11 22:46:58 +00003849 if (type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00003850 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003851 ClangASTType pointer_type(type.GetPointerType());
3852 if (pointer_type)
3853 {
3854 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
3855 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3856 pointer_type,
3857 ConstString(name),
3858 buffer,
3859 lldb::endian::InlHostByteOrder(),
3860 exe_ctx.GetAddressByteSize()));
3861 if (ptr_result_valobj_sp)
3862 {
3863 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
3864 Error err;
3865 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
3866 if (ptr_result_valobj_sp && name && *name)
3867 ptr_result_valobj_sp->SetName(ConstString(name));
3868 }
3869 return ptr_result_valobj_sp;
3870 }
Enrico Granatab2698cd2012-09-13 18:27:09 +00003871 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003872 return lldb::ValueObjectSP();
Enrico Granatab2698cd2012-09-13 18:27:09 +00003873}
3874
3875lldb::ValueObjectSP
3876ValueObject::CreateValueObjectFromData (const char* name,
3877 DataExtractor& data,
3878 const ExecutionContext& exe_ctx,
3879 ClangASTType type)
3880{
3881 lldb::ValueObjectSP new_value_sp;
3882 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00003883 type,
Enrico Granatab2698cd2012-09-13 18:27:09 +00003884 ConstString(name),
3885 data,
3886 LLDB_INVALID_ADDRESS);
3887 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
3888 if (new_value_sp && name && *name)
3889 new_value_sp->SetName(ConstString(name));
3890 return new_value_sp;
3891}
Enrico Granata4873e522013-04-11 22:48:58 +00003892
3893ModuleSP
3894ValueObject::GetModule ()
3895{
3896 ValueObject* root(GetRoot());
3897 if (root != this)
3898 return root->GetModule();
3899 return lldb::ModuleSP();
3900}
3901
3902ValueObject*
3903ValueObject::GetRoot ()
3904{
3905 if (m_root)
3906 return m_root;
3907 ValueObject* parent = m_parent;
3908 if (!parent)
3909 return (m_root = this);
3910 while (parent->m_parent)
3911 {
3912 if (parent->m_root)
3913 return (m_root = parent->m_root);
3914 parent = parent->m_parent;
3915 }
3916 return (m_root = parent);
3917}
3918
3919AddressType
3920ValueObject::GetAddressTypeOfChildren()
3921{
3922 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
3923 {
3924 ValueObject* root(GetRoot());
3925 if (root != this)
3926 return root->GetAddressTypeOfChildren();
3927 }
3928 return m_address_type_of_ptr_or_ref_children;
3929}
3930
3931lldb::DynamicValueType
3932ValueObject::GetDynamicValueType ()
3933{
3934 ValueObject* with_dv_info = this;
3935 while (with_dv_info)
3936 {
3937 if (with_dv_info->HasDynamicValueTypeInfo())
3938 return with_dv_info->GetDynamicValueTypeImpl();
3939 with_dv_info = with_dv_info->m_parent;
3940 }
3941 return lldb::eNoDynamicValues;
3942}
Enrico Granata39d51412013-05-31 17:43:40 +00003943
Enrico Granata4873e522013-04-11 22:48:58 +00003944lldb::Format
3945ValueObject::GetFormat () const
3946{
3947 const ValueObject* with_fmt_info = this;
3948 while (with_fmt_info)
3949 {
3950 if (with_fmt_info->m_format != lldb::eFormatDefault)
3951 return with_fmt_info->m_format;
3952 with_fmt_info = with_fmt_info->m_parent;
3953 }
3954 return m_format;
3955}