blob: 90d30d2593d7e363b9b762bed2f560b82b2a2c70 [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",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000240 GetName().GetCString(), static_cast<void*>(this),
241 m_last_format_mgr_revision,
242 DataVisualization::GetCurrentRevision());
243
Enrico Granata9128ee22011-09-06 19:20:51 +0000244 bool any_change = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000245
Enrico Granata5548cb52013-01-28 23:47:25 +0000246 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()))
Enrico Granata4becb372011-06-29 22:27:15 +0000247 {
Enrico Granata852cc952013-10-08 19:03:22 +0000248 SetValueFormat(DataVisualization::GetFormat (*this, eNoDynamicValues));
Enrico Granata5548cb52013-01-28 23:47:25 +0000249 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000250#ifndef LLDB_DISABLE_PYTHON
Enrico Granata5548cb52013-01-28 23:47:25 +0000251 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000252#endif
Enrico Granata1490c6f2011-07-19 02:34:21 +0000253
Enrico Granata85933ed2011-08-18 16:38:26 +0000254 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000255
Enrico Granata855cd902011-09-06 22:59:55 +0000256 any_change = true;
Enrico Granata4becb372011-06-29 22:27:15 +0000257 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000258
Enrico Granata9128ee22011-09-06 19:20:51 +0000259 return any_change;
Enrico Granata4becb372011-06-29 22:27:15 +0000260}
261
Jim Ingham16e0c682011-08-12 23:34:31 +0000262void
263ValueObject::SetNeedsUpdate ()
264{
265 m_update_point.SetNeedsUpdate();
266 // We have to clear the value string here so ConstResult children will notice if their values are
267 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000268 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000269}
270
Enrico Granata13ac0e22012-10-17 19:03:34 +0000271void
Enrico Granatae3e91512012-10-22 18:18:36 +0000272ValueObject::ClearDynamicTypeInformation ()
Enrico Granata13ac0e22012-10-17 19:03:34 +0000273{
Enrico Granata38c54632013-10-30 00:04:29 +0000274 m_children_count_valid = false;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000275 m_did_calculate_complete_objc_class_type = false;
Enrico Granatae3e91512012-10-22 18:18:36 +0000276 m_last_format_mgr_revision = 0;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000277 m_override_type = ClangASTType();
Enrico Granatae3e91512012-10-22 18:18:36 +0000278 SetValueFormat(lldb::TypeFormatImplSP());
279 SetSummaryFormat(lldb::TypeSummaryImplSP());
280 SetSyntheticChildren(lldb::SyntheticChildrenSP());
Enrico Granata13ac0e22012-10-17 19:03:34 +0000281}
282
Sean Callanan72772842012-02-22 23:57:45 +0000283ClangASTType
284ValueObject::MaybeCalculateCompleteType ()
285{
Greg Clayton57ee3062013-07-11 22:46:58 +0000286 ClangASTType clang_type(GetClangTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000287
Sean Callanan72772842012-02-22 23:57:45 +0000288 if (m_did_calculate_complete_objc_class_type)
289 {
290 if (m_override_type.IsValid())
291 return m_override_type;
292 else
Greg Clayton57ee3062013-07-11 22:46:58 +0000293 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000294 }
295
Greg Clayton57ee3062013-07-11 22:46:58 +0000296 ClangASTType class_type;
297 bool is_pointer_type = false;
Sean Callanan72772842012-02-22 23:57:45 +0000298
Greg Clayton57ee3062013-07-11 22:46:58 +0000299 if (clang_type.IsObjCObjectPointerType(&class_type))
Sean Callanan72772842012-02-22 23:57:45 +0000300 {
301 is_pointer_type = true;
302 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000303 else if (clang_type.IsObjCObjectOrInterfaceType())
Sean Callanan72772842012-02-22 23:57:45 +0000304 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000305 class_type = clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000306 }
307 else
308 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000309 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000310 }
311
312 m_did_calculate_complete_objc_class_type = true;
313
Greg Clayton57ee3062013-07-11 22:46:58 +0000314 if (class_type)
Sean Callanan72772842012-02-22 23:57:45 +0000315 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000316 ConstString class_name (class_type.GetConstTypeName());
Sean Callanan72772842012-02-22 23:57:45 +0000317
Greg Clayton57ee3062013-07-11 22:46:58 +0000318 if (class_name)
319 {
320 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
321
322 if (process_sp)
323 {
324 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
325
326 if (objc_language_runtime)
327 {
328 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name);
329
330 if (complete_objc_class_type_sp)
331 {
332 ClangASTType complete_class(complete_objc_class_type_sp->GetClangFullType());
333
334 if (complete_class.GetCompleteType())
335 {
336 if (is_pointer_type)
337 {
338 m_override_type = complete_class.GetPointerType();
339 }
340 else
341 {
342 m_override_type = complete_class;
343 }
344
345 if (m_override_type.IsValid())
346 return m_override_type;
347 }
348 }
349 }
350 }
351 }
Sean Callanan72772842012-02-22 23:57:45 +0000352 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000353 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000354}
355
Greg Clayton57ee3062013-07-11 22:46:58 +0000356ClangASTType
Sean Callanan72772842012-02-22 23:57:45 +0000357ValueObject::GetClangType ()
358{
Greg Clayton57ee3062013-07-11 22:46:58 +0000359 return MaybeCalculateCompleteType();
Sean Callanan72772842012-02-22 23:57:45 +0000360}
361
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000362TypeImpl
363ValueObject::GetTypeImpl ()
364{
365 return TypeImpl(GetClangType());
366}
367
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000368DataExtractor &
369ValueObject::GetDataExtractor ()
370{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000371 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000372 return m_data;
373}
374
375const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000376ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000377{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000378 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000379 return m_error;
380}
381
382const ConstString &
383ValueObject::GetName() const
384{
385 return m_name;
386}
387
388const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000389ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000390{
Enrico Granata82fabf82013-04-30 20:45:04 +0000391 return GetLocationAsCStringImpl(m_value,
392 m_data);
393}
394
395const char *
396ValueObject::GetLocationAsCStringImpl (const Value& value,
397 const DataExtractor& data)
398{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000399 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000400 {
401 if (m_location_str.empty())
402 {
403 StreamString sstr;
Enrico Granata82fabf82013-04-30 20:45:04 +0000404
405 Value::ValueType value_type = value.GetValueType();
406
407 switch (value_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000408 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000409 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +0000410 case Value::eValueTypeVector:
Enrico Granata82fabf82013-04-30 20:45:04 +0000411 if (value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000412 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000413 RegisterInfo *reg_info = value.GetRegisterInfo();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000414 if (reg_info)
415 {
416 if (reg_info->name)
417 m_location_str = reg_info->name;
418 else if (reg_info->alt_name)
419 m_location_str = reg_info->alt_name;
Enrico Granata82fabf82013-04-30 20:45:04 +0000420 if (m_location_str.empty())
421 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000422 }
423 }
Enrico Granata82fabf82013-04-30 20:45:04 +0000424 if (m_location_str.empty())
425 m_location_str = (value_type == Value::eValueTypeVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000426 break;
427
428 case Value::eValueTypeLoadAddress:
429 case Value::eValueTypeFileAddress:
430 case Value::eValueTypeHostAddress:
431 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000432 uint32_t addr_nibble_size = data.GetAddressByteSize() * 2;
433 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000434 m_location_str.swap(sstr.GetString());
435 }
436 break;
437 }
438 }
439 }
440 return m_location_str.c_str();
441}
442
443Value &
444ValueObject::GetValue()
445{
446 return m_value;
447}
448
449const Value &
450ValueObject::GetValue() const
451{
452 return m_value;
453}
454
455bool
Jim Ingham6035b672011-03-31 00:19:25 +0000456ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000457{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000458 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
459 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000460 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000461 Value tmp_value(m_value);
Greg Clayton57ee3062013-07-11 22:46:58 +0000462 scalar = tmp_value.ResolveValue(&exe_ctx);
Greg Claytondcad5022011-12-29 01:26:56 +0000463 if (scalar.IsValid())
464 {
465 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
466 if (bitfield_bit_size)
467 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
468 return true;
469 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000470 }
Greg Claytondcad5022011-12-29 01:26:56 +0000471 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000472}
473
474bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000475ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000476{
Greg Clayton288bdf92010-09-02 02:59:18 +0000477 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000478}
479
480
481void
482ValueObject::SetValueIsValid (bool b)
483{
Greg Clayton288bdf92010-09-02 02:59:18 +0000484 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000485}
486
487bool
Jim Ingham6035b672011-03-31 00:19:25 +0000488ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000489{
Jim Ingham6035b672011-03-31 00:19:25 +0000490 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000491 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000492}
493
494void
495ValueObject::SetValueDidChange (bool value_changed)
496{
Greg Clayton288bdf92010-09-02 02:59:18 +0000497 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000498}
499
500ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000501ValueObject::GetChildAtIndex (size_t idx, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000502{
503 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000504 // We may need to update our value if we are dynamic
505 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000506 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000507 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000508 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000509 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000510 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000511 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000512 // No we haven't created the child at this index, so lets have our
513 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000514 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000515 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000516
Enrico Granata9d60f602012-03-09 03:09:58 +0000517 ValueObject* child = m_children.GetChildAtIndex(idx);
518 if (child != NULL)
519 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000520 }
521 return child_sp;
522}
523
Enrico Granata3309d882013-01-12 01:00:22 +0000524ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000525ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
526 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000527{
528 if (idxs.size() == 0)
529 return GetSP();
530 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000531 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000532 {
533 root = root->GetChildAtIndex(idx, true);
534 if (!root)
535 {
536 if (index_of_error)
537 *index_of_error = idx;
538 return root;
539 }
540 }
541 return root;
542}
543
544ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000545ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
546 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000547{
548 if (idxs.size() == 0)
549 return GetSP();
550 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000551 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000552 {
553 root = root->GetChildAtIndex(idx.first, idx.second);
554 if (!root)
555 {
556 if (index_of_error)
557 *index_of_error = idx.first;
558 return root;
559 }
560 }
561 return root;
562}
563
564lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000565ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
566 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000567{
568 if (idxs.size() == 0)
569 return GetSP();
570 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000571 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000572 {
573 root = root->GetChildAtIndex(idx, true);
574 if (!root)
575 {
576 if (index_of_error)
577 *index_of_error = idx;
578 return root;
579 }
580 }
581 return root;
582}
583
584lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000585ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
586 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000587{
588 if (idxs.size() == 0)
589 return GetSP();
590 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000591 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000592 {
593 root = root->GetChildAtIndex(idx.first, idx.second);
594 if (!root)
595 {
596 if (index_of_error)
597 *index_of_error = idx.first;
598 return root;
599 }
600 }
601 return root;
602}
603
Enrico Granatae2e220a2013-09-12 00:48:47 +0000604lldb::ValueObjectSP
605ValueObject::GetChildAtNamePath (const std::initializer_list<ConstString> &names,
606 ConstString* name_of_error)
607{
608 if (names.size() == 0)
609 return GetSP();
610 ValueObjectSP root(GetSP());
611 for (ConstString name : names)
612 {
613 root = root->GetChildMemberWithName(name, true);
614 if (!root)
615 {
616 if (name_of_error)
617 *name_of_error = name;
618 return root;
619 }
620 }
621 return root;
622}
623
624lldb::ValueObjectSP
625ValueObject::GetChildAtNamePath (const std::vector<ConstString> &names,
626 ConstString* name_of_error)
627{
628 if (names.size() == 0)
629 return GetSP();
630 ValueObjectSP root(GetSP());
631 for (ConstString name : names)
632 {
633 root = root->GetChildMemberWithName(name, true);
634 if (!root)
635 {
636 if (name_of_error)
637 *name_of_error = name;
638 return root;
639 }
640 }
641 return root;
642}
643
644lldb::ValueObjectSP
645ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names,
646 ConstString* name_of_error)
647{
648 if (names.size() == 0)
649 return GetSP();
650 ValueObjectSP root(GetSP());
651 for (std::pair<ConstString, bool> name : names)
652 {
653 root = root->GetChildMemberWithName(name.first, name.second);
654 if (!root)
655 {
656 if (name_of_error)
657 *name_of_error = name.first;
658 return root;
659 }
660 }
661 return root;
662}
663
664lldb::ValueObjectSP
665ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names,
666 ConstString* name_of_error)
667{
668 if (names.size() == 0)
669 return GetSP();
670 ValueObjectSP root(GetSP());
671 for (std::pair<ConstString, bool> name : names)
672 {
673 root = root->GetChildMemberWithName(name.first, name.second);
674 if (!root)
675 {
676 if (name_of_error)
677 *name_of_error = name.first;
678 return root;
679 }
680 }
681 return root;
682}
683
Greg Claytonc7bece562013-01-25 18:06:21 +0000684size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000685ValueObject::GetIndexOfChildWithName (const ConstString &name)
686{
687 bool omit_empty_base_classes = true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000688 return GetClangType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000689}
690
691ValueObjectSP
692ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
693{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000694 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000695 // classes (which really aren't part of the expression path), so we
696 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000697 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000698
Greg Claytondea8cb42011-06-29 22:09:02 +0000699 // We may need to update our value if we are dynamic
700 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000701 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000702
703 std::vector<uint32_t> child_indexes;
Greg Claytondea8cb42011-06-29 22:09:02 +0000704 bool omit_empty_base_classes = true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000705 const size_t num_child_indexes = GetClangType().GetIndexOfChildMemberWithName (name.GetCString(),
706 omit_empty_base_classes,
707 child_indexes);
Greg Claytondea8cb42011-06-29 22:09:02 +0000708 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000709 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000710 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
711 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
712
713 child_sp = GetChildAtIndex(*pos, can_create);
714 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000715 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000716 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000717 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000718 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
719 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000720 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000721 else
722 {
723 child_sp.reset();
724 }
725
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000726 }
727 }
728 return child_sp;
729}
730
731
Greg Claytonc7bece562013-01-25 18:06:21 +0000732size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000733ValueObject::GetNumChildren ()
734{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000735 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000736 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000737 {
738 SetNumChildren (CalculateNumChildren());
739 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000740 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000741}
Greg Clayton4a792072012-10-23 01:50:10 +0000742
743bool
744ValueObject::MightHaveChildren()
745{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000746 bool has_children = false;
Greg Clayton2452ab72013-02-08 22:02:02 +0000747 const uint32_t type_info = GetTypeInfo();
748 if (type_info)
Greg Clayton4a792072012-10-23 01:50:10 +0000749 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000750 if (type_info & (ClangASTType::eTypeHasChildren |
751 ClangASTType::eTypeIsPointer |
752 ClangASTType::eTypeIsReference))
Greg Clayton4a792072012-10-23 01:50:10 +0000753 has_children = true;
754 }
755 else
756 {
757 has_children = GetNumChildren () > 0;
758 }
759 return has_children;
760}
761
762// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000763void
Greg Claytonc7bece562013-01-25 18:06:21 +0000764ValueObject::SetNumChildren (size_t num_children)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000765{
Greg Clayton288bdf92010-09-02 02:59:18 +0000766 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000767 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000768}
769
770void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000771ValueObject::SetName (const ConstString &name)
772{
773 m_name = name;
774}
775
Jim Ingham58b59f92011-04-22 23:53:53 +0000776ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000777ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000778{
Jim Ingham2eec4872011-05-07 00:10:58 +0000779 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000780
Greg Claytondea8cb42011-06-29 22:09:02 +0000781 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000782 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000783 std::string child_name_str;
784 uint32_t child_byte_size = 0;
785 int32_t child_byte_offset = 0;
786 uint32_t child_bitfield_bit_size = 0;
787 uint32_t child_bitfield_bit_offset = 0;
788 bool child_is_base_class = false;
789 bool child_is_deref_of_parent = false;
790
791 const bool transparent_pointers = synthetic_array_member == false;
Greg Clayton57ee3062013-07-11 22:46:58 +0000792 ClangASTType child_clang_type;
Greg Claytondea8cb42011-06-29 22:09:02 +0000793
Greg Claytoncc4d0142012-02-17 07:49:44 +0000794 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000795
Greg Clayton57ee3062013-07-11 22:46:58 +0000796 child_clang_type = GetClangType().GetChildClangTypeAtIndex (&exe_ctx,
797 GetName().GetCString(),
798 idx,
799 transparent_pointers,
800 omit_empty_base_classes,
801 ignore_array_bounds,
802 child_name_str,
803 child_byte_size,
804 child_byte_offset,
805 child_bitfield_bit_size,
806 child_bitfield_bit_offset,
807 child_is_base_class,
808 child_is_deref_of_parent);
Greg Clayton4ef877f2012-12-06 02:33:54 +0000809 if (child_clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000810 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000811 if (synthetic_index)
812 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000813
Greg Claytondea8cb42011-06-29 22:09:02 +0000814 ConstString child_name;
815 if (!child_name_str.empty())
816 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000817
Greg Claytondea8cb42011-06-29 22:09:02 +0000818 valobj = new ValueObjectChild (*this,
Greg Claytondea8cb42011-06-29 22:09:02 +0000819 child_clang_type,
820 child_name,
821 child_byte_size,
822 child_byte_offset,
823 child_bitfield_bit_size,
824 child_bitfield_bit_offset,
825 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000826 child_is_deref_of_parent,
827 eAddressTypeInvalid);
828 //if (valobj)
829 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
830 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000831
Jim Ingham58b59f92011-04-22 23:53:53 +0000832 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000833}
834
Enrico Granata0c489f52012-03-01 04:24:26 +0000835bool
836ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
837 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000838{
Enrico Granata0c489f52012-03-01 04:24:26 +0000839 destination.clear();
840
841 // ideally we would like to bail out if passing NULL, but if we do so
842 // we end up not providing the summary for function pointers anymore
843 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
844 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000845
846 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000847
848 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
849 // information that we might care to see in a crash log. might be useful in very specific situations though.
850 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
851 GetTypeName().GetCString(),
852 GetName().GetCString(),
853 summary_ptr->GetDescription().c_str());*/
854
Enrico Granata0c489f52012-03-01 04:24:26 +0000855 if (UpdateValueIfNeeded (false))
856 {
857 if (summary_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000858 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000859 if (HasSyntheticValue())
860 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
861 summary_ptr->FormatObject(this, destination);
Enrico Granata0c489f52012-03-01 04:24:26 +0000862 }
863 else
864 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000865 ClangASTType clang_type = GetClangType();
Enrico Granata0c489f52012-03-01 04:24:26 +0000866
867 // Do some default printout for function pointers
868 if (clang_type)
Enrico Granata4becb372011-06-29 22:27:15 +0000869 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000870 if (clang_type.IsFunctionPointerType ())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000871 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000872 StreamString sstr;
Enrico Granata0c489f52012-03-01 04:24:26 +0000873 AddressType func_ptr_address_type = eAddressTypeInvalid;
874 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
875 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000876 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000877 switch (func_ptr_address_type)
Jim Ingham6035b672011-03-31 00:19:25 +0000878 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000879 case eAddressTypeInvalid:
880 case eAddressTypeFile:
881 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000882
Greg Claytoncc4d0142012-02-17 07:49:44 +0000883 case eAddressTypeLoad:
Enrico Granata0c489f52012-03-01 04:24:26 +0000884 {
885 ExecutionContext exe_ctx (GetExecutionContextRef());
886
887 Address so_addr;
888 Target *target = exe_ctx.GetTargetPtr();
889 if (target && target->GetSectionLoadList().IsEmpty() == false)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000890 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000891 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000892 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000893 so_addr.Dump (&sstr,
894 exe_ctx.GetBestExecutionContextScope(),
895 Address::DumpStyleResolvedDescription,
896 Address::DumpStyleSectionNameOffset);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000897 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000898 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000899 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000900 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000901
Greg Claytoncc4d0142012-02-17 07:49:44 +0000902 case eAddressTypeHost:
903 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +0000904 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000905 }
906 if (sstr.GetSize() > 0)
907 {
908 destination.assign (1, '(');
909 destination.append (sstr.GetData(), sstr.GetSize());
910 destination.append (1, ')');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000911 }
912 }
913 }
914 }
915 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000916 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000917 return !destination.empty();
918}
919
920const char *
921ValueObject::GetSummaryAsCString ()
922{
923 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
924 {
925 GetSummaryAsCString(GetSummaryFormat().get(),
926 m_summary_str);
927 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000928 if (m_summary_str.empty())
929 return NULL;
930 return m_summary_str.c_str();
931}
932
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000933bool
934ValueObject::IsCStringContainer(bool check_pointer)
935{
Greg Clayton57ee3062013-07-11 22:46:58 +0000936 ClangASTType pointee_or_element_clang_type;
937 const Flags type_flags (GetTypeInfo (&pointee_or_element_clang_type));
938 bool is_char_arr_ptr (type_flags.AnySet (ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer) &&
939 pointee_or_element_clang_type.IsCharType ());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000940 if (!is_char_arr_ptr)
941 return false;
942 if (!check_pointer)
943 return true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000944 if (type_flags.Test(ClangASTType::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000945 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000946 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000947 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000948 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000949 return (cstr_address != LLDB_INVALID_ADDRESS);
950}
951
Enrico Granata9128ee22011-09-06 19:20:51 +0000952size_t
953ValueObject::GetPointeeData (DataExtractor& data,
954 uint32_t item_idx,
955 uint32_t item_count)
956{
Greg Clayton57ee3062013-07-11 22:46:58 +0000957 ClangASTType pointee_or_element_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +0000958 const uint32_t type_info = GetTypeInfo (&pointee_or_element_clang_type);
Greg Clayton57ee3062013-07-11 22:46:58 +0000959 const bool is_pointer_type = type_info & ClangASTType::eTypeIsPointer;
960 const bool is_array_type = type_info & ClangASTType::eTypeIsArray;
Greg Clayton2452ab72013-02-08 22:02:02 +0000961 if (!(is_pointer_type || is_array_type))
Enrico Granata9128ee22011-09-06 19:20:51 +0000962 return 0;
963
964 if (item_count == 0)
965 return 0;
966
Greg Clayton57ee3062013-07-11 22:46:58 +0000967 const uint64_t item_type_size = pointee_or_element_clang_type.GetByteSize();
Enrico Granata9128ee22011-09-06 19:20:51 +0000968 const uint64_t bytes = item_count * item_type_size;
Enrico Granata9128ee22011-09-06 19:20:51 +0000969 const uint64_t offset = item_idx * item_type_size;
970
971 if (item_idx == 0 && item_count == 1) // simply a deref
972 {
Greg Clayton2452ab72013-02-08 22:02:02 +0000973 if (is_pointer_type)
Enrico Granata9128ee22011-09-06 19:20:51 +0000974 {
975 Error error;
976 ValueObjectSP pointee_sp = Dereference(error);
977 if (error.Fail() || pointee_sp.get() == NULL)
978 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +0000979 return pointee_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +0000980 }
981 else
982 {
983 ValueObjectSP child_sp = GetChildAtIndex(0, true);
984 if (child_sp.get() == NULL)
985 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +0000986 Error error;
987 return child_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +0000988 }
989 return true;
990 }
991 else /* (items > 1) */
992 {
993 Error error;
994 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
995 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
996
997 AddressType addr_type;
Greg Clayton2452ab72013-02-08 22:02:02 +0000998 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +0000999
Enrico Granata9128ee22011-09-06 19:20:51 +00001000 switch (addr_type)
1001 {
1002 case eAddressTypeFile:
1003 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001004 ModuleSP module_sp (GetModule());
1005 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001006 {
Enrico Granata9c2efe32012-08-07 01:49:34 +00001007 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +00001008 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001009 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001010 ExecutionContext exe_ctx (GetExecutionContextRef());
1011 Target* target = exe_ctx.GetTargetPtr();
1012 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +00001013 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001014 heap_buf_ptr->SetByteSize(bytes);
1015 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
1016 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +00001017 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001018 data.SetData(data_sp);
1019 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +00001020 }
1021 }
1022 }
1023 }
1024 break;
1025 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +00001026 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001027 ExecutionContext exe_ctx (GetExecutionContextRef());
1028 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +00001029 if (process)
1030 {
1031 heap_buf_ptr->SetByteSize(bytes);
1032 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
Enrico Granata5e1480c2013-10-30 17:52:44 +00001033 if (error.Success() || bytes_read > 0)
Enrico Granata9128ee22011-09-06 19:20:51 +00001034 {
1035 data.SetData(data_sp);
1036 return bytes_read;
1037 }
1038 }
1039 }
1040 break;
1041 case eAddressTypeHost:
1042 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001043 const uint64_t max_bytes = GetClangType().GetByteSize();
Greg Clayton2452ab72013-02-08 22:02:02 +00001044 if (max_bytes > offset)
1045 {
1046 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
1047 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
1048 data.SetData(data_sp);
1049 return bytes_read;
1050 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001051 }
1052 break;
1053 case eAddressTypeInvalid:
Enrico Granata9128ee22011-09-06 19:20:51 +00001054 break;
1055 }
1056 }
1057 return 0;
1058}
1059
Greg Claytonfaac1112013-03-14 18:31:44 +00001060uint64_t
Sean Callanan866e91c2014-02-28 22:27:53 +00001061ValueObject::GetData (DataExtractor& data, Error &error)
Enrico Granata9128ee22011-09-06 19:20:51 +00001062{
1063 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001064 ExecutionContext exe_ctx (GetExecutionContextRef());
Sean Callanan866e91c2014-02-28 22:27:53 +00001065 error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001066 if (error.Fail())
Sean Callananed185ab2013-04-19 19:47:32 +00001067 {
1068 if (m_data.GetByteSize())
1069 {
1070 data = m_data;
1071 return data.GetByteSize();
1072 }
1073 else
1074 {
1075 return 0;
1076 }
1077 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001078 data.SetAddressByteSize(m_data.GetAddressByteSize());
1079 data.SetByteOrder(m_data.GetByteOrder());
1080 return data.GetByteSize();
1081}
1082
Sean Callanan389823e2013-04-13 01:21:23 +00001083bool
1084ValueObject::SetData (DataExtractor &data, Error &error)
1085{
1086 error.Clear();
1087 // Make sure our value is up to date first so that our location and location
1088 // type is valid.
1089 if (!UpdateValueIfNeeded(false))
1090 {
1091 error.SetErrorString("unable to read value");
1092 return false;
1093 }
1094
1095 uint64_t count = 0;
Greg Clayton57ee3062013-07-11 22:46:58 +00001096 const Encoding encoding = GetClangType().GetEncoding(count);
Sean Callanan389823e2013-04-13 01:21:23 +00001097
1098 const size_t byte_size = GetByteSize();
1099
1100 Value::ValueType value_type = m_value.GetValueType();
1101
1102 switch (value_type)
1103 {
1104 case Value::eValueTypeScalar:
1105 {
1106 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1107
1108 if (!set_error.Success())
1109 {
1110 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1111 return false;
1112 }
1113 }
1114 break;
1115 case Value::eValueTypeLoadAddress:
1116 {
1117 // If it is a load address, then the scalar value is the storage location
1118 // of the data, and we have to shove this value down to that load location.
1119 ExecutionContext exe_ctx (GetExecutionContextRef());
1120 Process *process = exe_ctx.GetProcessPtr();
1121 if (process)
1122 {
1123 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1124 size_t bytes_written = process->WriteMemory(target_addr,
1125 data.GetDataStart(),
1126 byte_size,
1127 error);
1128 if (!error.Success())
1129 return false;
1130 if (bytes_written != byte_size)
1131 {
1132 error.SetErrorString("unable to write value to memory");
1133 return false;
1134 }
1135 }
1136 }
1137 break;
1138 case Value::eValueTypeHostAddress:
1139 {
1140 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1141 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1142 m_data.SetData(buffer_sp, 0);
1143 data.CopyByteOrderedData (0,
1144 byte_size,
1145 const_cast<uint8_t *>(m_data.GetDataStart()),
1146 byte_size,
1147 m_data.GetByteOrder());
1148 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1149 }
1150 break;
1151 case Value::eValueTypeFileAddress:
1152 case Value::eValueTypeVector:
1153 break;
1154 }
1155
1156 // If we have reached this point, then we have successfully changed the value.
1157 SetNeedsUpdate();
1158 return true;
1159}
1160
Enrico Granata9128ee22011-09-06 19:20:51 +00001161// will compute strlen(str), but without consuming more than
1162// maxlen bytes out of str (this serves the purpose of reading
1163// chunks of a string without having to worry about
1164// missing NULL terminators in the chunk)
1165// of course, if strlen(str) > maxlen, the function will return
1166// maxlen_value (which should be != maxlen, because that allows you
1167// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1168static uint32_t
1169strlen_or_inf (const char* str,
1170 uint32_t maxlen,
1171 uint32_t maxlen_value)
1172{
1173 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +00001174 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +00001175 {
Greg Clayton8dd5c172011-10-05 22:19:51 +00001176 while(*str)
1177 {
1178 len++;str++;
Greg Clayton2452ab72013-02-08 22:02:02 +00001179 if (len >= maxlen)
Greg Clayton8dd5c172011-10-05 22:19:51 +00001180 return maxlen_value;
1181 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001182 }
1183 return len;
1184}
1185
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001186size_t
Greg Claytoncc4d0142012-02-17 07:49:44 +00001187ValueObject::ReadPointedString (Stream& s,
1188 Error& error,
1189 uint32_t max_length,
1190 bool honor_array,
1191 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001192{
Greg Claytoncc4d0142012-02-17 07:49:44 +00001193 ExecutionContext exe_ctx (GetExecutionContextRef());
1194 Target* target = exe_ctx.GetTargetPtr();
1195
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001196 if (!target)
1197 {
1198 s << "<no target to read from>";
1199 error.SetErrorString("no target to read from");
1200 return 0;
1201 }
1202
1203 if (max_length == 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001204 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001205
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001206 size_t bytes_read = 0;
1207 size_t total_bytes_read = 0;
1208
Greg Clayton57ee3062013-07-11 22:46:58 +00001209 ClangASTType clang_type = GetClangType();
1210 ClangASTType elem_or_pointee_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001211 const Flags type_flags (GetTypeInfo (&elem_or_pointee_clang_type));
Greg Clayton57ee3062013-07-11 22:46:58 +00001212 if (type_flags.AnySet (ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer) &&
1213 elem_or_pointee_clang_type.IsCharType ())
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001214 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001215 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1216 AddressType cstr_address_type = eAddressTypeInvalid;
1217
1218 size_t cstr_len = 0;
1219 bool capped_data = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00001220 if (type_flags.Test (ClangASTType::eTypeIsArray))
Greg Claytoncc4d0142012-02-17 07:49:44 +00001221 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001222 // We have an array
Greg Clayton57ee3062013-07-11 22:46:58 +00001223 uint64_t array_size = 0;
1224 if (clang_type.IsArrayType(NULL, &array_size, NULL))
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001225 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001226 cstr_len = array_size;
1227 if (cstr_len > max_length)
1228 {
1229 capped_data = true;
1230 cstr_len = max_length;
1231 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001232 }
1233 cstr_address = GetAddressOf (true, &cstr_address_type);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001234 }
1235 else
1236 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001237 // We have a pointer
1238 cstr_address = GetPointerValue (&cstr_address_type);
1239 }
1240
1241 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1242 {
1243 s << "<invalid address>";
1244 error.SetErrorString("invalid address");
1245 return 0;
1246 }
1247
1248 Address cstr_so_addr (cstr_address);
1249 DataExtractor data;
1250 if (cstr_len > 0 && honor_array)
1251 {
1252 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1253 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1254 GetPointeeData(data, 0, cstr_len);
1255
1256 if ((bytes_read = data.GetByteSize()) > 0)
1257 {
1258 total_bytes_read = bytes_read;
1259 s << '"';
1260 data.Dump (&s,
1261 0, // Start offset in "data"
1262 item_format,
1263 1, // Size of item (1 byte for a char!)
1264 bytes_read, // How many bytes to print?
1265 UINT32_MAX, // num per line
1266 LLDB_INVALID_ADDRESS,// base address
1267 0, // bitfield bit size
1268 0); // bitfield bit offset
1269 if (capped_data)
1270 s << "...";
1271 s << '"';
1272 }
1273 }
1274 else
1275 {
1276 cstr_len = max_length;
1277 const size_t k_max_buf_size = 64;
1278
1279 size_t offset = 0;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001280
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001281 int cstr_len_displayed = -1;
1282 bool capped_cstr = false;
1283 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1284 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1285 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001286 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001287 total_bytes_read += bytes_read;
1288 const char *cstr = data.PeekCStr(0);
1289 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1290 if (len > k_max_buf_size)
1291 len = k_max_buf_size;
1292 if (cstr && cstr_len_displayed < 0)
1293 s << '"';
1294
1295 if (cstr_len_displayed < 0)
1296 cstr_len_displayed = len;
1297
1298 if (len == 0)
1299 break;
1300 cstr_len_displayed += len;
1301 if (len > bytes_read)
1302 len = bytes_read;
1303 if (len > cstr_len)
1304 len = cstr_len;
1305
1306 data.Dump (&s,
1307 0, // Start offset in "data"
1308 item_format,
1309 1, // Size of item (1 byte for a char!)
1310 len, // How many bytes to print?
1311 UINT32_MAX, // num per line
1312 LLDB_INVALID_ADDRESS,// base address
1313 0, // bitfield bit size
1314 0); // bitfield bit offset
1315
1316 if (len < k_max_buf_size)
1317 break;
1318
1319 if (len >= cstr_len)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001320 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001321 capped_cstr = true;
1322 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001323 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001324
1325 cstr_len -= len;
1326 offset += len;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001327 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001328
1329 if (cstr_len_displayed >= 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001330 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001331 s << '"';
1332 if (capped_cstr)
1333 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001334 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001335 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001336 }
1337 else
1338 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001339 error.SetErrorString("not a string object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001340 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001341 }
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001342 return total_bytes_read;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001343}
1344
Jim Ingham53c47f12010-09-10 23:12:17 +00001345const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001346ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001347{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001348
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001349 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001350 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001351
1352 if (!m_object_desc_str.empty())
1353 return m_object_desc_str.c_str();
1354
Greg Claytoncc4d0142012-02-17 07:49:44 +00001355 ExecutionContext exe_ctx (GetExecutionContextRef());
1356 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001357 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001358 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001359
Jim Ingham53c47f12010-09-10 23:12:17 +00001360 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001361
Greg Claytonafacd142011-09-02 01:15:17 +00001362 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001363 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1364
Jim Inghama2cf2632010-12-23 02:29:54 +00001365 if (runtime == NULL)
1366 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001367 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Greg Clayton57ee3062013-07-11 22:46:58 +00001368 ClangASTType clang_type = GetClangType();
1369 if (clang_type)
Jim Inghama2cf2632010-12-23 02:29:54 +00001370 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001371 bool is_signed;
Greg Clayton57ee3062013-07-11 22:46:58 +00001372 if (clang_type.IsIntegerType (is_signed) || clang_type.IsPointerType ())
Jim Inghamb7603bb2011-03-18 00:05:18 +00001373 {
Greg Claytonafacd142011-09-02 01:15:17 +00001374 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001375 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001376 }
1377 }
1378
Jim Ingham8d543de2011-03-31 23:01:21 +00001379 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001380 {
1381 m_object_desc_str.append (s.GetData());
1382 }
Sean Callanan672ad942010-10-23 00:18:49 +00001383
1384 if (m_object_desc_str.empty())
1385 return NULL;
1386 else
1387 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001388}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001389
Enrico Granata0c489f52012-03-01 04:24:26 +00001390bool
Enrico Granata4939b982013-12-22 09:24:22 +00001391ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format,
1392 std::string& destination)
1393{
1394 if (UpdateValueIfNeeded(false))
1395 return format.FormatObject(this,destination);
1396 else
1397 return false;
1398}
1399
1400bool
Enrico Granata0c489f52012-03-01 04:24:26 +00001401ValueObject::GetValueAsCString (lldb::Format format,
1402 std::string& destination)
1403{
Enrico Granata30f287f2013-12-28 08:44:02 +00001404 return GetValueAsCString(TypeFormatImpl_Format(format),destination);
Enrico Granata0c489f52012-03-01 04:24:26 +00001405}
1406
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001407const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001408ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001409{
Enrico Granatab294fd22013-05-31 19:18:19 +00001410 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001411 {
Enrico Granata4939b982013-12-22 09:24:22 +00001412 lldb::TypeFormatImplSP format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001413 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001414 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001415 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001416 if (m_type_format_sp)
Enrico Granata4939b982013-12-22 09:24:22 +00001417 format_sp = m_type_format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001418 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001419 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001420 if (m_is_bitfield_for_scalar)
1421 my_format = eFormatUnsigned;
1422 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001423 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001424 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001425 {
1426 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1427 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001428 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001429 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001430 else
1431 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001432 my_format = GetClangType().GetFormat();
Enrico Granata0c489f52012-03-01 04:24:26 +00001433 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001434 }
1435 }
1436 }
Enrico Granatab294fd22013-05-31 19:18:19 +00001437 if (my_format != m_last_format || m_value_str.empty())
Enrico Granata297e69f2012-03-06 23:21:16 +00001438 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001439 m_last_format = my_format;
Enrico Granata4939b982013-12-22 09:24:22 +00001440 if (!format_sp)
Enrico Granata30f287f2013-12-28 08:44:02 +00001441 format_sp.reset(new TypeFormatImpl_Format(my_format));
Enrico Granata4939b982013-12-22 09:24:22 +00001442 if (GetValueAsCString(*format_sp.get(), m_value_str))
Enrico Granata297e69f2012-03-06 23:21:16 +00001443 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001444 if (!m_value_did_change && m_old_value_valid)
1445 {
1446 // The value was gotten successfully, so we consider the
1447 // value as changed if the value string differs
1448 SetValueDidChange (m_old_value_str != m_value_str);
1449 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001450 }
1451 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001452 }
1453 if (m_value_str.empty())
1454 return NULL;
1455 return m_value_str.c_str();
1456}
1457
Enrico Granatac3e320a2011-08-02 17:27:39 +00001458// if > 8bytes, 0 is returned. this method should mostly be used
1459// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001460uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001461ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001462{
1463 // If our byte size is zero this is an aggregate type that has children
Greg Clayton57ee3062013-07-11 22:46:58 +00001464 if (!GetClangType().IsAggregateType())
Enrico Granatac3e320a2011-08-02 17:27:39 +00001465 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001466 Scalar scalar;
1467 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001468 {
1469 if (success)
1470 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001471 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001472 }
1473 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001474 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001475
1476 if (success)
1477 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001478 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001479}
1480
Enrico Granatad7373f62013-10-31 18:57:50 +00001481int64_t
1482ValueObject::GetValueAsSigned (int64_t fail_value, bool *success)
1483{
1484 // If our byte size is zero this is an aggregate type that has children
1485 if (!GetClangType().IsAggregateType())
1486 {
1487 Scalar scalar;
1488 if (ResolveValue (scalar))
1489 {
1490 if (success)
1491 *success = true;
1492 return scalar.SLongLong(fail_value);
1493 }
1494 // fallthrough, otherwise...
1495 }
1496
1497 if (success)
1498 *success = false;
1499 return fail_value;
1500}
1501
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001502// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1503// this call up to date by returning true for your new special cases. We will eventually move
1504// to checking this call result before trying to display special cases
1505bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001506ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1507 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001508{
Greg Clayton57ee3062013-07-11 22:46:58 +00001509 Flags flags(GetTypeInfo());
1510 if (flags.AnySet(ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001511 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001512 {
1513 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001514 (custom_format == eFormatCString ||
1515 custom_format == eFormatCharArray ||
1516 custom_format == eFormatChar ||
1517 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001518 return true;
1519
Greg Clayton57ee3062013-07-11 22:46:58 +00001520 if (flags.Test(ClangASTType::eTypeIsArray))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001521 {
Greg Claytonafacd142011-09-02 01:15:17 +00001522 if ((custom_format == eFormatBytes) ||
1523 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001524 return true;
1525
Greg Claytonafacd142011-09-02 01:15:17 +00001526 if ((custom_format == eFormatVectorOfChar) ||
1527 (custom_format == eFormatVectorOfFloat32) ||
1528 (custom_format == eFormatVectorOfFloat64) ||
1529 (custom_format == eFormatVectorOfSInt16) ||
1530 (custom_format == eFormatVectorOfSInt32) ||
1531 (custom_format == eFormatVectorOfSInt64) ||
1532 (custom_format == eFormatVectorOfSInt8) ||
1533 (custom_format == eFormatVectorOfUInt128) ||
1534 (custom_format == eFormatVectorOfUInt16) ||
1535 (custom_format == eFormatVectorOfUInt32) ||
1536 (custom_format == eFormatVectorOfUInt64) ||
1537 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001538 return true;
1539 }
1540 }
1541 return false;
1542}
1543
Enrico Granata9fc19442011-07-06 02:13:41 +00001544bool
1545ValueObject::DumpPrintableRepresentation(Stream& s,
1546 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001547 Format custom_format,
Enrico Granata0dba9b32014-01-08 01:36:59 +00001548 PrintableRepresentationSpecialCases special,
1549 bool do_dump_error)
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
Enrico Granata465f4bc2014-02-15 01:24:44 +00001687 if (custom_format != eFormatInvalid)
Enrico Granata86cc9822012-03-19 22:58:49 +00001688 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:
Deepak Panickal99fbc072014-03-03 15:39:47 +00001709 strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren());
Greg Claytonc7bece562013-01-25 18:06:21 +00001710 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())
Enrico Granata0dba9b32014-01-08 01:36:59 +00001748 {
1749 if (do_dump_error)
1750 s.Printf("<%s>", m_error.AsCString());
1751 else
1752 return false;
1753 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001754 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1755 s.PutCString("<no summary available>");
1756 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1757 s.PutCString("<no value available>");
1758 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1759 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1760 else
1761 s.PutCString("<no printable representation>");
1762 }
1763
1764 // we should only return false here if we could not do *anything*
1765 // even if we have an error message as output, that's a success
1766 // from our callers' perspective, so return true
1767 var_success = true;
Enrico Granata465f4bc2014-02-15 01:24:44 +00001768
1769 if (custom_format != eFormatInvalid)
1770 SetFormat(eFormatDefault);
Enrico Granata86cc9822012-03-19 22:58:49 +00001771 }
1772
Enrico Granataf4efecd2011-07-12 22:56:10 +00001773 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001774}
1775
Greg Clayton737b9322010-09-13 03:32:57 +00001776addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001777ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001778{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001779 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001780 return LLDB_INVALID_ADDRESS;
1781
Greg Clayton73b472d2010-10-27 03:32:59 +00001782 switch (m_value.GetValueType())
1783 {
1784 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001785 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001786 if (scalar_is_load_address)
1787 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001788 if(address_type)
1789 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001790 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1791 }
1792 break;
1793
1794 case Value::eValueTypeLoadAddress:
1795 case Value::eValueTypeFileAddress:
1796 case Value::eValueTypeHostAddress:
1797 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001798 if(address_type)
1799 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001800 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1801 }
1802 break;
1803 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001804 if (address_type)
1805 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001806 return LLDB_INVALID_ADDRESS;
1807}
1808
1809addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001810ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001811{
Greg Claytonafacd142011-09-02 01:15:17 +00001812 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001813 if(address_type)
1814 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001815
Enrico Granatac3e320a2011-08-02 17:27:39 +00001816 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001817 return address;
1818
Greg Clayton73b472d2010-10-27 03:32:59 +00001819 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001820 {
1821 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001822 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001823 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001824 break;
1825
Enrico Granata9128ee22011-09-06 19:20:51 +00001826 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001827 case Value::eValueTypeLoadAddress:
1828 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001829 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001830 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001831 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001832 }
1833 break;
1834 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001835
Enrico Granata9128ee22011-09-06 19:20:51 +00001836 if (address_type)
1837 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001838
Greg Clayton737b9322010-09-13 03:32:57 +00001839 return address;
1840}
1841
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001842bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001843ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001844{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001845 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001846 // Make sure our value is up to date first so that our location and location
1847 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001848 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001849 {
1850 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001851 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001852 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001853
Greg Claytonfaac1112013-03-14 18:31:44 +00001854 uint64_t count = 0;
Greg Clayton57ee3062013-07-11 22:46:58 +00001855 const Encoding encoding = GetClangType().GetEncoding (count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001856
Greg Claytonb1320972010-07-14 00:18:15 +00001857 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001858
Jim Ingham16e0c682011-08-12 23:34:31 +00001859 Value::ValueType value_type = m_value.GetValueType();
1860
1861 if (value_type == Value::eValueTypeScalar)
1862 {
1863 // If the value is already a scalar, then let the scalar change itself:
1864 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1865 }
1866 else if (byte_size <= Scalar::GetMaxByteSize())
1867 {
1868 // If the value fits in a scalar, then make a new scalar and again let the
1869 // scalar code do the conversion, then figure out where to put the new value.
1870 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001871 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1872 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001873 {
Jim Ingham4b536182011-08-09 02:12:22 +00001874 switch (value_type)
1875 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001876 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001877 {
1878 // If it is a load address, then the scalar value is the storage location
1879 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001880 ExecutionContext exe_ctx (GetExecutionContextRef());
1881 Process *process = exe_ctx.GetProcessPtr();
1882 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001883 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001884 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001885 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1886 new_scalar,
1887 byte_size,
1888 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001889 if (!error.Success())
1890 return false;
1891 if (bytes_written != byte_size)
1892 {
1893 error.SetErrorString("unable to write value to memory");
1894 return false;
1895 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001896 }
1897 }
Jim Ingham4b536182011-08-09 02:12:22 +00001898 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001899 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001900 {
1901 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1902 DataExtractor new_data;
1903 new_data.SetByteOrder (m_data.GetByteOrder());
1904
1905 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1906 m_data.SetData(buffer_sp, 0);
1907 bool success = new_scalar.GetData(new_data);
1908 if (success)
1909 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001910 new_data.CopyByteOrderedData (0,
1911 byte_size,
1912 const_cast<uint8_t *>(m_data.GetDataStart()),
1913 byte_size,
1914 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001915 }
1916 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1917
1918 }
Jim Ingham4b536182011-08-09 02:12:22 +00001919 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001920 case Value::eValueTypeFileAddress:
1921 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001922 case Value::eValueTypeVector:
1923 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001924 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001925 }
1926 else
1927 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001928 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001929 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001930 }
1931 else
1932 {
1933 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001934 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001935 return false;
1936 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001937
1938 // If we have reached this point, then we have successfully changed the value.
1939 SetNeedsUpdate();
1940 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001941}
1942
Greg Clayton81e871e2012-02-04 02:27:34 +00001943bool
1944ValueObject::GetDeclaration (Declaration &decl)
1945{
1946 decl.Clear();
1947 return false;
1948}
1949
Greg Clayton84db9102012-03-26 23:03:23 +00001950ConstString
1951ValueObject::GetTypeName()
1952{
Greg Clayton57ee3062013-07-11 22:46:58 +00001953 return GetClangType().GetConstTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00001954}
1955
1956ConstString
1957ValueObject::GetQualifiedTypeName()
1958{
Greg Clayton57ee3062013-07-11 22:46:58 +00001959 return GetClangType().GetConstQualifiedTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00001960}
1961
1962
Greg Claytonafacd142011-09-02 01:15:17 +00001963LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001964ValueObject::GetObjectRuntimeLanguage ()
1965{
Greg Clayton57ee3062013-07-11 22:46:58 +00001966 return GetClangType().GetMinimumLanguage ();
Jim Ingham5a369122010-09-28 01:25:32 +00001967}
1968
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001969void
Jim Ingham58b59f92011-04-22 23:53:53 +00001970ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001971{
Jim Ingham58b59f92011-04-22 23:53:53 +00001972 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001973}
1974
1975ValueObjectSP
1976ValueObject::GetSyntheticChild (const ConstString &key) const
1977{
1978 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001979 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001980 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001981 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001982 return synthetic_child_sp;
1983}
1984
Greg Clayton2452ab72013-02-08 22:02:02 +00001985uint32_t
Greg Clayton57ee3062013-07-11 22:46:58 +00001986ValueObject::GetTypeInfo (ClangASTType *pointee_or_element_clang_type)
Greg Clayton2452ab72013-02-08 22:02:02 +00001987{
Greg Clayton57ee3062013-07-11 22:46:58 +00001988 return GetClangType().GetTypeInfo (pointee_or_element_clang_type);
Greg Clayton2452ab72013-02-08 22:02:02 +00001989}
1990
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001991bool
1992ValueObject::IsPointerType ()
1993{
Greg Clayton57ee3062013-07-11 22:46:58 +00001994 return GetClangType().IsPointerType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001995}
1996
Jim Inghamb7603bb2011-03-18 00:05:18 +00001997bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001998ValueObject::IsArrayType ()
1999{
Greg Clayton57ee3062013-07-11 22:46:58 +00002000 return GetClangType().IsArrayType (NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00002001}
2002
2003bool
Enrico Granata9fc19442011-07-06 02:13:41 +00002004ValueObject::IsScalarType ()
2005{
Greg Clayton57ee3062013-07-11 22:46:58 +00002006 return GetClangType().IsScalarType ();
Enrico Granata9fc19442011-07-06 02:13:41 +00002007}
2008
2009bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00002010ValueObject::IsIntegerType (bool &is_signed)
2011{
Greg Clayton57ee3062013-07-11 22:46:58 +00002012 return GetClangType().IsIntegerType (is_signed);
Jim Inghamb7603bb2011-03-18 00:05:18 +00002013}
Greg Clayton73b472d2010-10-27 03:32:59 +00002014
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002015bool
2016ValueObject::IsPointerOrReferenceType ()
2017{
Greg Clayton57ee3062013-07-11 22:46:58 +00002018 return GetClangType().IsPointerOrReferenceType ();
Greg Clayton007d5be2011-05-30 00:49:24 +00002019}
2020
2021bool
Greg Claytondea8cb42011-06-29 22:09:02 +00002022ValueObject::IsPossibleDynamicType ()
2023{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002024 ExecutionContext exe_ctx (GetExecutionContextRef());
2025 Process *process = exe_ctx.GetProcessPtr();
2026 if (process)
2027 return process->IsPossibleDynamicValue(*this);
2028 else
Greg Clayton57ee3062013-07-11 22:46:58 +00002029 return GetClangType().IsPossibleDynamicType (NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00002030}
2031
Enrico Granata9e7b3882012-12-13 23:50:33 +00002032bool
2033ValueObject::IsObjCNil ()
2034{
Greg Clayton57ee3062013-07-11 22:46:58 +00002035 const uint32_t mask = ClangASTType::eTypeIsObjC | ClangASTType::eTypeIsPointer;
2036 bool isObjCpointer = (((GetClangType().GetTypeInfo(NULL)) & mask) == mask);
Enrico Granata7277d202013-03-15 23:33:15 +00002037 if (!isObjCpointer)
2038 return false;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002039 bool canReadValue = true;
2040 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
Enrico Granata7277d202013-03-15 23:33:15 +00002041 return canReadValue && isZero;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002042}
2043
Greg Claytonafacd142011-09-02 01:15:17 +00002044ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002045ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002046{
Greg Clayton2452ab72013-02-08 22:02:02 +00002047 const uint32_t type_info = GetTypeInfo ();
Greg Clayton57ee3062013-07-11 22:46:58 +00002048 if (type_info & ClangASTType::eTypeIsArray)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002049 return GetSyntheticArrayMemberFromArray(index, can_create);
2050
Greg Clayton57ee3062013-07-11 22:46:58 +00002051 if (type_info & ClangASTType::eTypeIsPointer)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002052 return GetSyntheticArrayMemberFromPointer(index, can_create);
2053
2054 return ValueObjectSP();
2055
2056}
2057
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002058ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002059ValueObject::GetSyntheticArrayMemberFromPointer (size_t index, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002060{
2061 ValueObjectSP synthetic_child_sp;
2062 if (IsPointerType ())
2063 {
2064 char index_str[64];
Deepak Panickal99fbc072014-03-03 15:39:47 +00002065 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002066 ConstString index_const_str(index_str);
2067 // Check if we have already created a synthetic array member in this
2068 // valid object. If we have we will re-use it.
2069 synthetic_child_sp = GetSyntheticChild (index_const_str);
2070 if (!synthetic_child_sp)
2071 {
Jim Ingham58b59f92011-04-22 23:53:53 +00002072 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002073 // We haven't made a synthetic array member for INDEX yet, so
2074 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00002075 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002076
2077 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00002078 if (synthetic_child)
2079 {
2080 AddSyntheticChild(index_const_str, synthetic_child);
2081 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002082 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00002083 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00002084 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002085 }
2086 }
2087 return synthetic_child_sp;
2088}
Jim Ingham22777012010-09-23 02:01:19 +00002089
Greg Claytondaf515f2011-07-09 20:12:33 +00002090// This allows you to create an array member using and index
2091// that doesn't not fall in the normal bounds of the array.
2092// Many times structure can be defined as:
2093// struct Collection
2094// {
2095// uint32_t item_count;
2096// Item item_array[0];
2097// };
2098// The size of the "item_array" is 1, but many times in practice
2099// there are more items in "item_array".
2100
2101ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002102ValueObject::GetSyntheticArrayMemberFromArray (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00002103{
2104 ValueObjectSP synthetic_child_sp;
2105 if (IsArrayType ())
2106 {
2107 char index_str[64];
Deepak Panickal99fbc072014-03-03 15:39:47 +00002108 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
Greg Claytondaf515f2011-07-09 20:12:33 +00002109 ConstString index_const_str(index_str);
2110 // Check if we have already created a synthetic array member in this
2111 // valid object. If we have we will re-use it.
2112 synthetic_child_sp = GetSyntheticChild (index_const_str);
2113 if (!synthetic_child_sp)
2114 {
2115 ValueObject *synthetic_child;
2116 // We haven't made a synthetic array member for INDEX yet, so
2117 // lets make one and cache it for any future reference.
2118 synthetic_child = CreateChildAtIndex(0, true, index);
2119
2120 // Cache the value if we got one back...
2121 if (synthetic_child)
2122 {
2123 AddSyntheticChild(index_const_str, synthetic_child);
2124 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002125 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00002126 synthetic_child_sp->m_is_array_item_for_pointer = true;
2127 }
2128 }
2129 }
2130 return synthetic_child_sp;
2131}
2132
Enrico Granata9fc19442011-07-06 02:13:41 +00002133ValueObjectSP
2134ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2135{
2136 ValueObjectSP synthetic_child_sp;
2137 if (IsScalarType ())
2138 {
2139 char index_str[64];
2140 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2141 ConstString index_const_str(index_str);
2142 // Check if we have already created a synthetic array member in this
2143 // valid object. If we have we will re-use it.
2144 synthetic_child_sp = GetSyntheticChild (index_const_str);
2145 if (!synthetic_child_sp)
2146 {
Enrico Granata9fc19442011-07-06 02:13:41 +00002147 // We haven't made a synthetic array member for INDEX yet, so
2148 // lets make one and cache it for any future reference.
Greg Clayton57ee3062013-07-11 22:46:58 +00002149 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
2150 GetClangType(),
2151 index_const_str,
2152 GetByteSize(),
2153 0,
2154 to-from+1,
2155 from,
2156 false,
2157 false,
2158 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002159
2160 // Cache the value if we got one back...
2161 if (synthetic_child)
2162 {
2163 AddSyntheticChild(index_const_str, synthetic_child);
2164 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002165 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002166 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2167 }
2168 }
2169 }
2170 return synthetic_child_sp;
2171}
2172
Greg Claytonafacd142011-09-02 01:15:17 +00002173ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00002174ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
2175{
2176
2177 ValueObjectSP synthetic_child_sp;
2178
2179 char name_str[64];
2180 snprintf(name_str, sizeof(name_str), "@%i", offset);
2181 ConstString name_const_str(name_str);
2182
2183 // Check if we have already created a synthetic array member in this
2184 // valid object. If we have we will re-use it.
2185 synthetic_child_sp = GetSyntheticChild (name_const_str);
2186
2187 if (synthetic_child_sp.get())
2188 return synthetic_child_sp;
2189
2190 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002191 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002192
2193 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
Greg Clayton57ee3062013-07-11 22:46:58 +00002194 type,
Enrico Granata6f3533f2011-07-29 19:53:35 +00002195 name_const_str,
Greg Clayton57ee3062013-07-11 22:46:58 +00002196 type.GetByteSize(),
Enrico Granata6f3533f2011-07-29 19:53:35 +00002197 offset,
2198 0,
2199 0,
2200 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002201 false,
2202 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002203 if (synthetic_child)
2204 {
2205 AddSyntheticChild(name_const_str, synthetic_child);
2206 synthetic_child_sp = synthetic_child->GetSP();
2207 synthetic_child_sp->SetName(name_const_str);
2208 synthetic_child_sp->m_is_child_at_offset = true;
2209 }
2210 return synthetic_child_sp;
2211}
2212
Enrico Granatad55546b2011-07-22 00:16:08 +00002213// your expression path needs to have a leading . or ->
2214// (unless it somehow "looks like" an array, in which case it has
2215// a leading [ symbol). while the [ is meaningful and should be shown
2216// to the user, . and -> are just parser design, but by no means
2217// added information for the user.. strip them off
2218static const char*
2219SkipLeadingExpressionPathSeparators(const char* expression)
2220{
2221 if (!expression || !expression[0])
2222 return expression;
2223 if (expression[0] == '.')
2224 return expression+1;
2225 if (expression[0] == '-' && expression[1] == '>')
2226 return expression+2;
2227 return expression;
2228}
2229
Greg Claytonafacd142011-09-02 01:15:17 +00002230ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002231ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2232{
2233 ValueObjectSP synthetic_child_sp;
2234 ConstString name_const_string(expression);
2235 // Check if we have already created a synthetic array member in this
2236 // valid object. If we have we will re-use it.
2237 synthetic_child_sp = GetSyntheticChild (name_const_string);
2238 if (!synthetic_child_sp)
2239 {
2240 // We haven't made a synthetic array member for expression yet, so
2241 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002242 synthetic_child_sp = GetValueForExpressionPath(expression,
2243 NULL, NULL, NULL,
2244 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
Enrico Granatad55546b2011-07-22 00:16:08 +00002245
2246 // Cache the value if we got one back...
2247 if (synthetic_child_sp.get())
2248 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002249 // 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 +00002250 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002251 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002252 }
2253 }
2254 return synthetic_child_sp;
2255}
2256
2257void
Enrico Granata86cc9822012-03-19 22:58:49 +00002258ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002259{
Enrico Granata86cc9822012-03-19 22:58:49 +00002260 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002261 return;
2262
Enrico Granatac5bc4122012-03-27 02:35:13 +00002263 TargetSP target_sp(GetTargetSP());
Enrico Granata5d5f60c2013-09-24 22:58:37 +00002264 if (target_sp && target_sp->GetEnableSyntheticValue() == false)
Enrico Granatac5bc4122012-03-27 02:35:13 +00002265 {
2266 m_synthetic_value = NULL;
2267 return;
2268 }
2269
Enrico Granatae3e91512012-10-22 18:18:36 +00002270 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2271
Enrico Granata5548cb52013-01-28 23:47:25 +00002272 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002273 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002274
Enrico Granata0c489f52012-03-01 04:24:26 +00002275 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002276 return;
2277
Enrico Granatae3e91512012-10-22 18:18:36 +00002278 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2279 return;
2280
Enrico Granata86cc9822012-03-19 22:58:49 +00002281 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002282}
2283
Jim Ingham78a685a2011-04-16 00:01:13 +00002284void
Greg Claytonafacd142011-09-02 01:15:17 +00002285ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002286{
Greg Claytonafacd142011-09-02 01:15:17 +00002287 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002288 return;
2289
Jim Ingham58b59f92011-04-22 23:53:53 +00002290 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002291 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002292 ExecutionContext exe_ctx (GetExecutionContextRef());
2293 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002294 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002295 {
2296 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002297 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002298 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002299 }
2300}
2301
Jim Ingham58b59f92011-04-22 23:53:53 +00002302ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002303ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002304{
Greg Claytonafacd142011-09-02 01:15:17 +00002305 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002306 return ValueObjectSP();
2307
2308 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002309 {
Jim Ingham2837b762011-05-04 03:43:18 +00002310 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002311 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002312 if (m_dynamic_value)
2313 return m_dynamic_value->GetSP();
2314 else
2315 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002316}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002317
Jim Ingham60dbabb2011-12-08 19:44:08 +00002318ValueObjectSP
2319ValueObject::GetStaticValue()
2320{
2321 return GetSP();
2322}
2323
Enrico Granata886147f2012-05-08 18:47:08 +00002324lldb::ValueObjectSP
2325ValueObject::GetNonSyntheticValue ()
2326{
2327 return GetSP();
2328}
2329
Enrico Granatad55546b2011-07-22 00:16:08 +00002330ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002331ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002332{
Enrico Granata86cc9822012-03-19 22:58:49 +00002333 if (use_synthetic == false)
2334 return ValueObjectSP();
2335
Enrico Granatad55546b2011-07-22 00:16:08 +00002336 CalculateSyntheticValue(use_synthetic);
2337
2338 if (m_synthetic_value)
2339 return m_synthetic_value->GetSP();
2340 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002341 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002342}
2343
Greg Claytone221f822011-01-21 01:59:00 +00002344bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002345ValueObject::HasSyntheticValue()
2346{
Enrico Granata5548cb52013-01-28 23:47:25 +00002347 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002348
Enrico Granata0c489f52012-03-01 04:24:26 +00002349 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002350 return false;
2351
Enrico Granata86cc9822012-03-19 22:58:49 +00002352 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002353
2354 if (m_synthetic_value)
2355 return true;
2356 else
2357 return false;
2358}
2359
2360bool
Greg Claytone221f822011-01-21 01:59:00 +00002361ValueObject::GetBaseClassPath (Stream &s)
2362{
2363 if (IsBaseClass())
2364 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002365 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Clayton57ee3062013-07-11 22:46:58 +00002366 ClangASTType clang_type = GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002367 std::string cxx_class_name;
Greg Clayton57ee3062013-07-11 22:46:58 +00002368 bool this_had_base_class = clang_type.GetCXXClassName (cxx_class_name);
Greg Claytone221f822011-01-21 01:59:00 +00002369 if (this_had_base_class)
2370 {
2371 if (parent_had_base_class)
2372 s.PutCString("::");
2373 s.PutCString(cxx_class_name.c_str());
2374 }
2375 return parent_had_base_class || this_had_base_class;
2376 }
2377 return false;
2378}
2379
2380
2381ValueObject *
2382ValueObject::GetNonBaseClassParent()
2383{
Jim Ingham78a685a2011-04-16 00:01:13 +00002384 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002385 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002386 if (GetParent()->IsBaseClass())
2387 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002388 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002389 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002390 }
2391 return NULL;
2392}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002393
2394void
Enrico Granata4becb372011-06-29 22:27:15 +00002395ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002396{
Greg Claytone221f822011-01-21 01:59:00 +00002397 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002398
Enrico Granata86cc9822012-03-19 22:58:49 +00002399 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002400 {
Enrico Granata4becb372011-06-29 22:27:15 +00002401 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2402 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2403 // the eHonorPointers mode is meant to produce strings in this latter format
2404 s.PutCString("*(");
2405 }
Greg Claytone221f822011-01-21 01:59:00 +00002406
Enrico Granata4becb372011-06-29 22:27:15 +00002407 ValueObject* parent = GetParent();
2408
2409 if (parent)
2410 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002411
2412 // if we are a deref_of_parent just because we are synthetic array
2413 // members made up to allow ptr[%d] syntax to work in variable
2414 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002415 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002416 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002417
Greg Claytone221f822011-01-21 01:59:00 +00002418 if (!IsBaseClass())
2419 {
2420 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002421 {
Greg Claytone221f822011-01-21 01:59:00 +00002422 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2423 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002424 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002425 ClangASTType non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002426 if (non_base_class_parent_clang_type)
2427 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002428 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002429 {
2430 s.PutCString("->");
2431 }
Enrico Granata4becb372011-06-29 22:27:15 +00002432 else
2433 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002434 const uint32_t non_base_class_parent_type_info = non_base_class_parent_clang_type.GetTypeInfo();
2435
2436 if (non_base_class_parent_type_info & ClangASTType::eTypeIsPointer)
Enrico Granata4becb372011-06-29 22:27:15 +00002437 {
2438 s.PutCString("->");
2439 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002440 else if ((non_base_class_parent_type_info & ClangASTType::eTypeHasChildren) &&
2441 !(non_base_class_parent_type_info & ClangASTType::eTypeIsArray))
Enrico Granata4becb372011-06-29 22:27:15 +00002442 {
2443 s.PutChar('.');
2444 }
Greg Claytone221f822011-01-21 01:59:00 +00002445 }
2446 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002447 }
Greg Claytone221f822011-01-21 01:59:00 +00002448
2449 const char *name = GetName().GetCString();
2450 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002451 {
Greg Claytone221f822011-01-21 01:59:00 +00002452 if (qualify_cxx_base_classes)
2453 {
2454 if (GetBaseClassPath (s))
2455 s.PutCString("::");
2456 }
2457 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002458 }
2459 }
2460 }
2461
Enrico Granata86cc9822012-03-19 22:58:49 +00002462 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002463 {
Greg Claytone221f822011-01-21 01:59:00 +00002464 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002465 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002466}
2467
Greg Claytonafacd142011-09-02 01:15:17 +00002468ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002469ValueObject::GetValueForExpressionPath(const char* expression,
2470 const char** first_unparsed,
2471 ExpressionPathScanEndReason* reason_to_stop,
2472 ExpressionPathEndResultType* final_value_type,
2473 const GetValueForExpressionPathOptions& options,
2474 ExpressionPathAftermath* final_task_on_target)
2475{
2476
2477 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002478 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2479 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002480 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002481
2482 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2483 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2484 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2485 final_value_type ? final_value_type : &dummy_final_value_type,
2486 options,
2487 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2488
Enrico Granata86cc9822012-03-19 22:58:49 +00002489 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002490 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002491
Enrico Granata86cc9822012-03-19 22:58:49 +00002492 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 +00002493 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002494 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002495 {
2496 Error error;
2497 ValueObjectSP final_value = ret_val->Dereference(error);
2498 if (error.Fail() || !final_value.get())
2499 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002500 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002501 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002502 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002503 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002504 return ValueObjectSP();
2505 }
2506 else
2507 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002508 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002509 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002510 return final_value;
2511 }
2512 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002513 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002514 {
2515 Error error;
2516 ValueObjectSP final_value = ret_val->AddressOf(error);
2517 if (error.Fail() || !final_value.get())
2518 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002519 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002520 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002521 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002522 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002523 return ValueObjectSP();
2524 }
2525 else
2526 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002527 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002528 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002529 return final_value;
2530 }
2531 }
2532 }
2533 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2534}
2535
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002536int
2537ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002538 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002539 const char** first_unparsed,
2540 ExpressionPathScanEndReason* reason_to_stop,
2541 ExpressionPathEndResultType* final_value_type,
2542 const GetValueForExpressionPathOptions& options,
2543 ExpressionPathAftermath* final_task_on_target)
2544{
2545 const char* dummy_first_unparsed;
2546 ExpressionPathScanEndReason dummy_reason_to_stop;
2547 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002548 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002549
2550 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2551 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2552 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2553 final_value_type ? final_value_type : &dummy_final_value_type,
2554 options,
2555 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2556
2557 if (!ret_val.get()) // if there are errors, I add nothing to the list
2558 return 0;
2559
Enrico Granata86ea8d82012-03-29 01:34:34 +00002560 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002561 {
2562 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002563 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002564 {
2565 list->Append(ret_val);
2566 return 1;
2567 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002568 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 +00002569 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002570 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002571 {
2572 Error error;
2573 ValueObjectSP final_value = ret_val->Dereference(error);
2574 if (error.Fail() || !final_value.get())
2575 {
Greg Clayton23f59502012-07-17 03:23:13 +00002576 if (reason_to_stop)
2577 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2578 if (final_value_type)
2579 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002580 return 0;
2581 }
2582 else
2583 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002584 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002585 list->Append(final_value);
2586 return 1;
2587 }
2588 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002589 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002590 {
2591 Error error;
2592 ValueObjectSP final_value = ret_val->AddressOf(error);
2593 if (error.Fail() || !final_value.get())
2594 {
Greg Clayton23f59502012-07-17 03:23:13 +00002595 if (reason_to_stop)
2596 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2597 if (final_value_type)
2598 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002599 return 0;
2600 }
2601 else
2602 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002603 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002604 list->Append(final_value);
2605 return 1;
2606 }
2607 }
2608 }
2609 }
2610 else
2611 {
2612 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2613 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2614 ret_val,
2615 list,
2616 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2617 final_value_type ? final_value_type : &dummy_final_value_type,
2618 options,
2619 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2620 }
2621 // in any non-covered case, just do the obviously right thing
2622 list->Append(ret_val);
2623 return 1;
2624}
2625
Greg Claytonafacd142011-09-02 01:15:17 +00002626ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002627ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2628 const char** first_unparsed,
2629 ExpressionPathScanEndReason* reason_to_stop,
2630 ExpressionPathEndResultType* final_result,
2631 const GetValueForExpressionPathOptions& options,
2632 ExpressionPathAftermath* what_next)
2633{
2634 ValueObjectSP root = GetSP();
2635
2636 if (!root.get())
2637 return ValueObjectSP();
2638
2639 *first_unparsed = expression_cstr;
2640
2641 while (true)
2642 {
2643
2644 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2645
Greg Clayton57ee3062013-07-11 22:46:58 +00002646 ClangASTType root_clang_type = root->GetClangType();
2647 ClangASTType pointee_clang_type;
2648 Flags pointee_clang_type_info;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002649
Greg Clayton57ee3062013-07-11 22:46:58 +00002650 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002651 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00002652 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002653
2654 if (!expression_cstr || *expression_cstr == '\0')
2655 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002656 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002657 return root;
2658 }
2659
2660 switch (*expression_cstr)
2661 {
2662 case '-':
2663 {
2664 if (options.m_check_dot_vs_arrow_syntax &&
Greg Clayton57ee3062013-07-11 22:46:58 +00002665 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 +00002666 {
2667 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002668 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2669 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002670 return ValueObjectSP();
2671 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002672 if (root_clang_type_info.Test(ClangASTType::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2673 root_clang_type_info.Test(ClangASTType::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002674 options.m_no_fragile_ivar)
2675 {
2676 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002677 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2678 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002679 return ValueObjectSP();
2680 }
2681 if (expression_cstr[1] != '>')
2682 {
2683 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002684 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2685 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002686 return ValueObjectSP();
2687 }
2688 expression_cstr++; // skip the -
2689 }
2690 case '.': // or fallthrough from ->
2691 {
2692 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Greg Clayton57ee3062013-07-11 22:46:58 +00002693 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 +00002694 {
2695 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002696 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2697 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002698 return ValueObjectSP();
2699 }
2700 expression_cstr++; // skip .
2701 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2702 ConstString child_name;
2703 if (!next_separator) // if no other separator just expand this last layer
2704 {
2705 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002706 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2707
2708 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002709 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002710 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002711 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2712 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002713 return child_valobj_sp;
2714 }
2715 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2716 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002717 if (root->IsSynthetic())
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002718 {
2719 *first_unparsed = expression_cstr;
2720 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2721 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2722 return ValueObjectSP();
2723 }
2724
2725 child_valobj_sp = root->GetSyntheticValue();
Enrico Granata86cc9822012-03-19 22:58:49 +00002726 if (child_valobj_sp.get())
2727 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002728 }
2729
2730 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2731 // so we hit the "else" branch, and return an error
2732 if(child_valobj_sp.get()) // if it worked, just return
2733 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002734 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002735 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2736 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002737 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002738 }
2739 else
2740 {
2741 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002742 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2743 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002744 return ValueObjectSP();
2745 }
2746 }
2747 else // other layers do expand
2748 {
2749 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002750 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2751 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002752 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002753 root = child_valobj_sp;
2754 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002755 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002756 continue;
2757 }
2758 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2759 {
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002760 if (root->IsSynthetic())
2761 {
2762 *first_unparsed = expression_cstr;
2763 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2764 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2765 return ValueObjectSP();
2766 }
2767
Enrico Granata86cc9822012-03-19 22:58:49 +00002768 child_valobj_sp = root->GetSyntheticValue(true);
2769 if (child_valobj_sp)
2770 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002771 }
2772
2773 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2774 // so we hit the "else" branch, and return an error
2775 if(child_valobj_sp.get()) // if it worked, move on
2776 {
2777 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002778 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002779 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002780 continue;
2781 }
2782 else
2783 {
2784 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002785 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2786 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002787 return ValueObjectSP();
2788 }
2789 }
2790 break;
2791 }
2792 case '[':
2793 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002794 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 +00002795 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002796 if (!root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002797 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002798 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2799 {
2800 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002801 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2802 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002803 return ValueObjectSP();
2804 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002805 }
2806 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2807 {
2808 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002809 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2810 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002811 return ValueObjectSP();
2812 }
2813 }
2814 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2815 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002816 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002817 {
2818 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002819 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2820 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002821 return ValueObjectSP();
2822 }
2823 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2824 {
2825 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002826 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2827 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002828 return root;
2829 }
2830 }
2831 const char *separator_position = ::strchr(expression_cstr+1,'-');
2832 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2833 if (!close_bracket_position) // if there is no ], this is a syntax error
2834 {
2835 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002836 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2837 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002838 return ValueObjectSP();
2839 }
2840 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2841 {
2842 char *end = NULL;
2843 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2844 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2845 {
2846 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002847 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2848 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002849 return ValueObjectSP();
2850 }
2851 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2852 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002853 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002854 {
2855 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002856 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2857 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002858 return root;
2859 }
2860 else
2861 {
2862 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002863 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2864 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002865 return ValueObjectSP();
2866 }
2867 }
2868 // from here on we do have a valid index
Greg Clayton57ee3062013-07-11 22:46:58 +00002869 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002870 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002871 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2872 if (!child_valobj_sp)
2873 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002874 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002875 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2876 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002877 if (child_valobj_sp)
2878 {
2879 root = child_valobj_sp;
2880 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002881 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002882 continue;
2883 }
2884 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002885 {
2886 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002887 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2888 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002889 return ValueObjectSP();
2890 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002891 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002892 else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002893 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002894 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 +00002895 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002896 {
2897 Error error;
2898 root = root->Dereference(error);
2899 if (error.Fail() || !root.get())
2900 {
2901 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002902 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2903 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002904 return ValueObjectSP();
2905 }
2906 else
2907 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002908 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002909 continue;
2910 }
2911 }
2912 else
2913 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002914 if (root->GetClangType().GetMinimumLanguage() == eLanguageTypeObjC
2915 && pointee_clang_type_info.AllClear(ClangASTType::eTypeIsPointer)
Greg Clayton84db9102012-03-26 23:03:23 +00002916 && root->HasSyntheticValue()
2917 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002918 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002919 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002920 }
2921 else
2922 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002923 if (!root.get())
2924 {
2925 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002926 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2927 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002928 return ValueObjectSP();
2929 }
2930 else
2931 {
2932 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002933 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002934 continue;
2935 }
2936 }
2937 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002938 else if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002939 {
2940 root = root->GetSyntheticBitFieldChild(index, index, true);
2941 if (!root.get())
2942 {
2943 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002944 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2945 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002946 return ValueObjectSP();
2947 }
2948 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2949 {
2950 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002951 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2952 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002953 return root;
2954 }
2955 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002956 else if (root_clang_type_info.Test(ClangASTType::eTypeIsVector))
Enrico Granata08a1bb82013-06-19 00:00:45 +00002957 {
2958 root = root->GetChildAtIndex(index, true);
2959 if (!root.get())
2960 {
2961 *first_unparsed = expression_cstr;
2962 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2963 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2964 return ValueObjectSP();
2965 }
2966 else
2967 {
2968 *first_unparsed = end+1; // skip ]
2969 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2970 continue;
2971 }
2972 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002973 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002974 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002975 if (root->HasSyntheticValue())
2976 root = root->GetSyntheticValue();
2977 else if (!root->IsSynthetic())
2978 {
2979 *first_unparsed = expression_cstr;
2980 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2981 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2982 return ValueObjectSP();
2983 }
2984 // if we are here, then root itself is a synthetic VO.. should be good to go
2985
Enrico Granata27b625e2011-08-09 01:04:56 +00002986 if (!root.get())
2987 {
2988 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002989 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2990 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2991 return ValueObjectSP();
2992 }
2993 root = root->GetChildAtIndex(index, true);
2994 if (!root.get())
2995 {
2996 *first_unparsed = expression_cstr;
2997 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2998 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002999 return ValueObjectSP();
3000 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00003001 else
3002 {
3003 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003004 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00003005 continue;
3006 }
Enrico Granata27b625e2011-08-09 01:04:56 +00003007 }
3008 else
3009 {
3010 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003011 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3012 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003013 return ValueObjectSP();
3014 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003015 }
3016 else // we have a low and a high index
3017 {
3018 char *end = NULL;
3019 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3020 if (!end || end != separator_position) // if something weird is in our way return an error
3021 {
3022 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003023 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3024 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003025 return ValueObjectSP();
3026 }
3027 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3028 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3029 {
3030 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003031 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3032 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003033 return ValueObjectSP();
3034 }
3035 if (index_lower > index_higher) // swap indices if required
3036 {
3037 unsigned long temp = index_lower;
3038 index_lower = index_higher;
3039 index_higher = temp;
3040 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003041 if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003042 {
3043 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3044 if (!root.get())
3045 {
3046 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003047 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3048 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003049 return ValueObjectSP();
3050 }
3051 else
3052 {
3053 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003054 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3055 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003056 return root;
3057 }
3058 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003059 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 +00003060 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Greg Clayton57ee3062013-07-11 22:46:58 +00003061 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003062 {
3063 Error error;
3064 root = root->Dereference(error);
3065 if (error.Fail() || !root.get())
3066 {
3067 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003068 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3069 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003070 return ValueObjectSP();
3071 }
3072 else
3073 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003074 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003075 continue;
3076 }
3077 }
3078 else
3079 {
3080 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003081 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3082 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003083 return root;
3084 }
3085 }
3086 break;
3087 }
3088 default: // some non-separator is in the way
3089 {
3090 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003091 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3092 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003093 return ValueObjectSP();
3094 break;
3095 }
3096 }
3097 }
3098}
3099
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003100int
3101ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3102 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00003103 ValueObjectSP root,
3104 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003105 ExpressionPathScanEndReason* reason_to_stop,
3106 ExpressionPathEndResultType* final_result,
3107 const GetValueForExpressionPathOptions& options,
3108 ExpressionPathAftermath* what_next)
3109{
3110 if (!root.get())
3111 return 0;
3112
3113 *first_unparsed = expression_cstr;
3114
3115 while (true)
3116 {
3117
3118 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3119
Greg Clayton57ee3062013-07-11 22:46:58 +00003120 ClangASTType root_clang_type = root->GetClangType();
3121 ClangASTType pointee_clang_type;
3122 Flags pointee_clang_type_info;
3123 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003124 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00003125 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003126
3127 if (!expression_cstr || *expression_cstr == '\0')
3128 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003129 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003130 list->Append(root);
3131 return 1;
3132 }
3133
3134 switch (*expression_cstr)
3135 {
3136 case '[':
3137 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003138 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 +00003139 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003140 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 +00003141 {
3142 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003143 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3144 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003145 return 0;
3146 }
3147 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3148 {
3149 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003150 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3151 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003152 return 0;
3153 }
3154 }
3155 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3156 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003157 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003158 {
3159 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003160 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3161 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003162 return 0;
3163 }
3164 else // expand this into list
3165 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003166 const size_t max_index = root->GetNumChildren() - 1;
3167 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003168 {
3169 ValueObjectSP child =
3170 root->GetChildAtIndex(index, true);
3171 list->Append(child);
3172 }
3173 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003174 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3175 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003176 return max_index; // tell me number of items I added to the VOList
3177 }
3178 }
3179 const char *separator_position = ::strchr(expression_cstr+1,'-');
3180 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3181 if (!close_bracket_position) // if there is no ], this is a syntax error
3182 {
3183 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003184 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3185 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003186 return 0;
3187 }
3188 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3189 {
3190 char *end = NULL;
3191 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3192 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3193 {
3194 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003195 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3196 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003197 return 0;
3198 }
3199 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3200 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003201 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003202 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003203 const size_t max_index = root->GetNumChildren() - 1;
3204 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003205 {
3206 ValueObjectSP child =
3207 root->GetChildAtIndex(index, true);
3208 list->Append(child);
3209 }
3210 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003211 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3212 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003213 return max_index; // tell me number of items I added to the VOList
3214 }
3215 else
3216 {
3217 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003218 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3219 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003220 return 0;
3221 }
3222 }
3223 // from here on we do have a valid index
Greg Clayton57ee3062013-07-11 22:46:58 +00003224 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003225 {
3226 root = root->GetChildAtIndex(index, true);
3227 if (!root.get())
3228 {
3229 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003230 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3231 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003232 return 0;
3233 }
3234 else
3235 {
3236 list->Append(root);
3237 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003238 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3239 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003240 return 1;
3241 }
3242 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003243 else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003244 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003245 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 +00003246 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003247 {
3248 Error error;
3249 root = root->Dereference(error);
3250 if (error.Fail() || !root.get())
3251 {
3252 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003253 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3254 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003255 return 0;
3256 }
3257 else
3258 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003259 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003260 continue;
3261 }
3262 }
3263 else
3264 {
3265 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3266 if (!root.get())
3267 {
3268 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003269 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3270 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003271 return 0;
3272 }
3273 else
3274 {
3275 list->Append(root);
3276 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003277 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3278 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003279 return 1;
3280 }
3281 }
3282 }
3283 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3284 {
3285 root = root->GetSyntheticBitFieldChild(index, index, true);
3286 if (!root.get())
3287 {
3288 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003289 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3290 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003291 return 0;
3292 }
3293 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3294 {
3295 list->Append(root);
3296 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003297 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3298 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003299 return 1;
3300 }
3301 }
3302 }
3303 else // we have a low and a high index
3304 {
3305 char *end = NULL;
3306 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3307 if (!end || end != separator_position) // if something weird is in our way return an error
3308 {
3309 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003310 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3311 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003312 return 0;
3313 }
3314 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3315 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3316 {
3317 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003318 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3319 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003320 return 0;
3321 }
3322 if (index_lower > index_higher) // swap indices if required
3323 {
3324 unsigned long temp = index_lower;
3325 index_lower = index_higher;
3326 index_higher = temp;
3327 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003328 if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // expansion only works for scalars
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003329 {
3330 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3331 if (!root.get())
3332 {
3333 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003334 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3335 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003336 return 0;
3337 }
3338 else
3339 {
3340 list->Append(root);
3341 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003342 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3343 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003344 return 1;
3345 }
3346 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003347 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 +00003348 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Greg Clayton57ee3062013-07-11 22:46:58 +00003349 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003350 {
3351 Error error;
3352 root = root->Dereference(error);
3353 if (error.Fail() || !root.get())
3354 {
3355 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003356 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3357 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003358 return 0;
3359 }
3360 else
3361 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003362 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003363 continue;
3364 }
3365 }
3366 else
3367 {
Johnny Chen44805302011-07-19 19:48:13 +00003368 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003369 index <= index_higher; index++)
3370 {
3371 ValueObjectSP child =
3372 root->GetChildAtIndex(index, true);
3373 list->Append(child);
3374 }
3375 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003376 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3377 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003378 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3379 }
3380 }
3381 break;
3382 }
3383 default: // some non-[ separator, or something entirely wrong, is in the way
3384 {
3385 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003386 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3387 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003388 return 0;
3389 break;
3390 }
3391 }
3392 }
3393}
3394
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003395void
3396ValueObject::LogValueObject (Log *log)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003397{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003398 if (log)
3399 return LogValueObject (log, DumpValueObjectOptions::DefaultOptions());
Greg Clayton1d3afba2010-10-05 00:00:42 +00003400}
3401
Enrico Granata0c489f52012-03-01 04:24:26 +00003402void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003403ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003404{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003405 if (log)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003406 {
3407 StreamString s;
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003408 Dump (s, options);
Greg Claytonf830dbb2012-03-22 18:15:37 +00003409 if (s.GetSize())
3410 log->PutCString(s.GetData());
3411 }
3412}
3413
3414void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003415ValueObject::Dump (Stream &s)
Enrico Granata0c489f52012-03-01 04:24:26 +00003416{
3417
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003418 ValueObjectPrinter printer(this,&s,DumpValueObjectOptions::DefaultOptions());
3419 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003420}
3421
3422void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003423ValueObject::Dump (Stream &s,
3424 const DumpValueObjectOptions& options)
Enrico Granata0c489f52012-03-01 04:24:26 +00003425{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003426 ValueObjectPrinter printer(this,&s,options);
3427 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003428}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003429
3430ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003431ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003432{
3433 ValueObjectSP valobj_sp;
3434
Enrico Granatac3e320a2011-08-02 17:27:39 +00003435 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003436 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003437 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003438
3439 DataExtractor data;
3440 data.SetByteOrder (m_data.GetByteOrder());
3441 data.SetAddressByteSize(m_data.GetAddressByteSize());
3442
Enrico Granata9f1e2042012-04-24 22:15:37 +00003443 if (IsBitfield())
3444 {
3445 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
Greg Clayton57ee3062013-07-11 22:46:58 +00003446 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Enrico Granata9f1e2042012-04-24 22:15:37 +00003447 }
3448 else
Greg Clayton57ee3062013-07-11 22:46:58 +00003449 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003450
3451 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003452 GetClangType(),
3453 name,
3454 data,
3455 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003456 }
Jim Ingham6035b672011-03-31 00:19:25 +00003457
3458 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003459 {
Greg Claytoneeb15652013-12-10 23:16:40 +00003460 ExecutionContext exe_ctx (GetExecutionContextRef());
3461 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003462 }
3463 return valobj_sp;
3464}
3465
Greg Claytonafacd142011-09-02 01:15:17 +00003466ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003467ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003468{
Jim Ingham58b59f92011-04-22 23:53:53 +00003469 if (m_deref_valobj)
3470 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003471
Greg Clayton54979cd2010-12-15 05:08:08 +00003472 const bool is_pointer_type = IsPointerType();
3473 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003474 {
3475 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003476 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003477
3478 std::string child_name_str;
3479 uint32_t child_byte_size = 0;
3480 int32_t child_byte_offset = 0;
3481 uint32_t child_bitfield_bit_size = 0;
3482 uint32_t child_bitfield_bit_offset = 0;
3483 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003484 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003485 const bool transparent_pointers = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00003486 ClangASTType clang_type = GetClangType();
3487 ClangASTType child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003488
Greg Claytoncc4d0142012-02-17 07:49:44 +00003489 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003490
Greg Clayton57ee3062013-07-11 22:46:58 +00003491 child_clang_type = clang_type.GetChildClangTypeAtIndex (&exe_ctx,
3492 GetName().GetCString(),
3493 0,
3494 transparent_pointers,
3495 omit_empty_base_classes,
3496 ignore_array_bounds,
3497 child_name_str,
3498 child_byte_size,
3499 child_byte_offset,
3500 child_bitfield_bit_size,
3501 child_bitfield_bit_offset,
3502 child_is_base_class,
3503 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003504 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003505 {
3506 ConstString child_name;
3507 if (!child_name_str.empty())
3508 child_name.SetCString (child_name_str.c_str());
3509
Jim Ingham58b59f92011-04-22 23:53:53 +00003510 m_deref_valobj = new ValueObjectChild (*this,
Jim Ingham58b59f92011-04-22 23:53:53 +00003511 child_clang_type,
3512 child_name,
3513 child_byte_size,
3514 child_byte_offset,
3515 child_bitfield_bit_size,
3516 child_bitfield_bit_offset,
3517 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003518 child_is_deref_of_parent,
3519 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003520 }
3521 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003522
Jim Ingham58b59f92011-04-22 23:53:53 +00003523 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003524 {
3525 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003526 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003527 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003528 else
3529 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003530 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003531 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003532
3533 if (is_pointer_type)
3534 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3535 else
3536 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003537 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003538 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003539}
3540
Greg Claytonafacd142011-09-02 01:15:17 +00003541ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003542ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003543{
Jim Ingham78a685a2011-04-16 00:01:13 +00003544 if (m_addr_of_valobj_sp)
3545 return m_addr_of_valobj_sp;
3546
Greg Claytone0d378b2011-03-24 21:19:54 +00003547 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003548 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003549 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003550 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003551 if (addr != LLDB_INVALID_ADDRESS)
3552 {
3553 switch (address_type)
3554 {
3555 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003556 {
3557 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003558 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003559 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3560 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003561 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003562
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003563 case eAddressTypeFile:
3564 case eAddressTypeLoad:
3565 case eAddressTypeHost:
3566 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003567 ClangASTType clang_type = GetClangType();
3568 if (clang_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003569 {
3570 std::string name (1, '&');
3571 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003572 ExecutionContext exe_ctx (GetExecutionContextRef());
3573 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00003574 clang_type.GetPointerType(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003575 ConstString (name.c_str()),
3576 addr,
3577 eAddressTypeInvalid,
3578 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003579 }
3580 }
3581 break;
3582 }
3583 }
Sean Callananed185ab2013-04-19 19:47:32 +00003584 else
3585 {
3586 StreamString expr_path_strm;
3587 GetExpressionPath(expr_path_strm, true);
3588 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3589 }
3590
Jim Ingham78a685a2011-04-16 00:01:13 +00003591 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003592}
3593
Greg Clayton9a142cf2012-02-03 05:34:10 +00003594ValueObjectSP
3595ValueObject::Cast (const ClangASTType &clang_ast_type)
3596{
Greg Clayton81e871e2012-02-04 02:27:34 +00003597 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003598}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003599
Greg Claytonafacd142011-09-02 01:15:17 +00003600ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003601ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3602{
Greg Claytonafacd142011-09-02 01:15:17 +00003603 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003604 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003605 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003606
3607 if (ptr_value != LLDB_INVALID_ADDRESS)
3608 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003609 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003610 ExecutionContext exe_ctx (GetExecutionContextRef());
3611 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003612 name,
3613 ptr_addr,
3614 clang_ast_type);
3615 }
3616 return valobj_sp;
3617}
3618
Greg Claytonafacd142011-09-02 01:15:17 +00003619ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003620ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3621{
Greg Claytonafacd142011-09-02 01:15:17 +00003622 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003623 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003624 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003625
3626 if (ptr_value != LLDB_INVALID_ADDRESS)
3627 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003628 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003629 ExecutionContext exe_ctx (GetExecutionContextRef());
3630 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003631 name,
3632 ptr_addr,
3633 type_sp);
3634 }
3635 return valobj_sp;
3636}
3637
Jim Ingham6035b672011-03-31 00:19:25 +00003638ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003639 m_mod_id(),
3640 m_exe_ctx_ref(),
3641 m_needs_update (true),
3642 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003643{
3644}
3645
3646ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003647 m_mod_id(),
3648 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003649 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003650 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003651{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003652 ExecutionContext exe_ctx(exe_scope);
3653 TargetSP target_sp (exe_ctx.GetTargetSP());
3654 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003655 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003656 m_exe_ctx_ref.SetTargetSP (target_sp);
3657 ProcessSP process_sp (exe_ctx.GetProcessSP());
3658 if (!process_sp)
3659 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003660
Greg Claytoncc4d0142012-02-17 07:49:44 +00003661 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003662 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003663 m_mod_id = process_sp->GetModID();
3664 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003665
Greg Claytoncc4d0142012-02-17 07:49:44 +00003666 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003667
Greg Claytoncc4d0142012-02-17 07:49:44 +00003668 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003669 {
3670 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003671 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003672 }
Jim Ingham6035b672011-03-31 00:19:25 +00003673
Greg Claytoncc4d0142012-02-17 07:49:44 +00003674 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003675 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003676 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003677
Jason Molendab57e4a12013-11-04 09:33:30 +00003678 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003679 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003680 {
3681 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003682 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003683 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003684 if (frame_sp)
3685 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003686 }
3687 }
3688 }
Jim Ingham6035b672011-03-31 00:19:25 +00003689}
3690
3691ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003692 m_mod_id(),
3693 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3694 m_needs_update (true),
3695 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003696{
3697}
3698
3699ValueObject::EvaluationPoint::~EvaluationPoint ()
3700{
3701}
3702
Jim Ingham6035b672011-03-31 00:19:25 +00003703// This function checks the EvaluationPoint against the current process state. If the current
3704// state matches the evaluation point, or the evaluation point is already invalid, then we return
3705// false, meaning "no change". If the current state is different, we update our state, and return
3706// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3707// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003708// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003709
3710bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003711ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003712{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003713
3714 // Start with the target, if it is NULL, then we're obviously not going to get any further:
Greg Clayton44d93782014-01-27 23:43:24 +00003715 const bool thread_and_frame_only_if_stopped = true;
3716 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
Jim Ingham73ca05a2011-12-17 01:35:57 +00003717
Greg Claytoncc4d0142012-02-17 07:49:44 +00003718 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003719 return false;
3720
Jim Ingham6035b672011-03-31 00:19:25 +00003721 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003722 Process *process = exe_ctx.GetProcessPtr();
3723 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003724 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003725
Jim Ingham6035b672011-03-31 00:19:25 +00003726 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003727 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003728
Jim Ingham78a685a2011-04-16 00:01:13 +00003729 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3730 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003731 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003732 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003733
Greg Clayton23f59502012-07-17 03:23:13 +00003734 bool changed = false;
3735 const bool was_valid = m_mod_id.IsValid();
3736 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003737 {
3738 if (m_mod_id == current_mod_id)
3739 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003740 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003741 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003742 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003743 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003744 else
3745 {
3746 m_mod_id = current_mod_id;
3747 m_needs_update = true;
3748 changed = true;
3749 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003750 }
Jim Ingham6035b672011-03-31 00:19:25 +00003751
Jim Ingham73ca05a2011-12-17 01:35:57 +00003752 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3753 // That way we'll be sure to return a valid exe_scope.
3754 // 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 +00003755
Greg Claytoncc4d0142012-02-17 07:49:44 +00003756 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003757 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003758 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3759 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003760 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003761 if (m_exe_ctx_ref.HasFrameRef())
3762 {
Jason Molendab57e4a12013-11-04 09:33:30 +00003763 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003764 if (!frame_sp)
3765 {
3766 // We used to have a frame, but now it is gone
3767 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003768 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00003769 }
3770 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003771 }
Jim Ingham6035b672011-03-31 00:19:25 +00003772 else
3773 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003774 // We used to have a thread, but now it is gone
3775 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003776 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00003777 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003778
Jim Ingham6035b672011-03-31 00:19:25 +00003779 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003780 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003781}
3782
Jim Ingham61be0902011-05-02 18:13:59 +00003783void
3784ValueObject::EvaluationPoint::SetUpdated ()
3785{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003786 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3787 if (process_sp)
3788 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003789 m_first_update = false;
3790 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003791}
3792
3793
Enrico Granataf2bbf712011-07-15 02:26:42 +00003794
3795void
Enrico Granata86cc9822012-03-19 22:58:49 +00003796ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00003797{
Enrico Granata86cc9822012-03-19 22:58:49 +00003798 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
3799 m_value_str.clear();
3800
3801 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
3802 m_location_str.clear();
3803
3804 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
3805 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003806 m_summary_str.clear();
3807 }
3808
3809 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
3810 m_object_desc_str.clear();
3811
3812 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
3813 {
3814 if (m_synthetic_value)
3815 m_synthetic_value = NULL;
3816 }
Johnny Chen44805302011-07-19 19:48:13 +00003817}
Enrico Granata9128ee22011-09-06 19:20:51 +00003818
3819SymbolContextScope *
3820ValueObject::GetSymbolContextScope()
3821{
3822 if (m_parent)
3823 {
3824 if (!m_parent->IsPointerOrReferenceType())
3825 return m_parent->GetSymbolContextScope();
3826 }
3827 return NULL;
3828}
Enrico Granatab2698cd2012-09-13 18:27:09 +00003829
3830lldb::ValueObjectSP
3831ValueObject::CreateValueObjectFromExpression (const char* name,
3832 const char* expression,
3833 const ExecutionContext& exe_ctx)
3834{
3835 lldb::ValueObjectSP retval_sp;
3836 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
3837 if (!target_sp)
3838 return retval_sp;
3839 if (!expression || !*expression)
3840 return retval_sp;
3841 target_sp->EvaluateExpression (expression,
3842 exe_ctx.GetFrameSP().get(),
3843 retval_sp);
3844 if (retval_sp && name && *name)
3845 retval_sp->SetName(ConstString(name));
3846 return retval_sp;
3847}
3848
3849lldb::ValueObjectSP
3850ValueObject::CreateValueObjectFromAddress (const char* name,
3851 uint64_t address,
3852 const ExecutionContext& exe_ctx,
3853 ClangASTType type)
3854{
Greg Clayton57ee3062013-07-11 22:46:58 +00003855 if (type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00003856 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003857 ClangASTType pointer_type(type.GetPointerType());
3858 if (pointer_type)
3859 {
3860 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
3861 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3862 pointer_type,
3863 ConstString(name),
3864 buffer,
3865 lldb::endian::InlHostByteOrder(),
3866 exe_ctx.GetAddressByteSize()));
3867 if (ptr_result_valobj_sp)
3868 {
3869 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
3870 Error err;
3871 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
3872 if (ptr_result_valobj_sp && name && *name)
3873 ptr_result_valobj_sp->SetName(ConstString(name));
3874 }
3875 return ptr_result_valobj_sp;
3876 }
Enrico Granatab2698cd2012-09-13 18:27:09 +00003877 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003878 return lldb::ValueObjectSP();
Enrico Granatab2698cd2012-09-13 18:27:09 +00003879}
3880
3881lldb::ValueObjectSP
3882ValueObject::CreateValueObjectFromData (const char* name,
Enrico Granata7ca1c762014-03-31 23:02:25 +00003883 const DataExtractor& data,
Enrico Granatab2698cd2012-09-13 18:27:09 +00003884 const ExecutionContext& exe_ctx,
3885 ClangASTType type)
3886{
3887 lldb::ValueObjectSP new_value_sp;
3888 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00003889 type,
Enrico Granatab2698cd2012-09-13 18:27:09 +00003890 ConstString(name),
3891 data,
3892 LLDB_INVALID_ADDRESS);
3893 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
3894 if (new_value_sp && name && *name)
3895 new_value_sp->SetName(ConstString(name));
3896 return new_value_sp;
3897}
Enrico Granata4873e522013-04-11 22:48:58 +00003898
3899ModuleSP
3900ValueObject::GetModule ()
3901{
3902 ValueObject* root(GetRoot());
3903 if (root != this)
3904 return root->GetModule();
3905 return lldb::ModuleSP();
3906}
3907
3908ValueObject*
3909ValueObject::GetRoot ()
3910{
3911 if (m_root)
3912 return m_root;
3913 ValueObject* parent = m_parent;
3914 if (!parent)
3915 return (m_root = this);
3916 while (parent->m_parent)
3917 {
3918 if (parent->m_root)
3919 return (m_root = parent->m_root);
3920 parent = parent->m_parent;
3921 }
3922 return (m_root = parent);
3923}
3924
3925AddressType
3926ValueObject::GetAddressTypeOfChildren()
3927{
3928 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
3929 {
3930 ValueObject* root(GetRoot());
3931 if (root != this)
3932 return root->GetAddressTypeOfChildren();
3933 }
3934 return m_address_type_of_ptr_or_ref_children;
3935}
3936
3937lldb::DynamicValueType
3938ValueObject::GetDynamicValueType ()
3939{
3940 ValueObject* with_dv_info = this;
3941 while (with_dv_info)
3942 {
3943 if (with_dv_info->HasDynamicValueTypeInfo())
3944 return with_dv_info->GetDynamicValueTypeImpl();
3945 with_dv_info = with_dv_info->m_parent;
3946 }
3947 return lldb::eNoDynamicValues;
3948}
Enrico Granata39d51412013-05-31 17:43:40 +00003949
Enrico Granata4873e522013-04-11 22:48:58 +00003950lldb::Format
3951ValueObject::GetFormat () const
3952{
3953 const ValueObject* with_fmt_info = this;
3954 while (with_fmt_info)
3955 {
3956 if (with_fmt_info->m_format != lldb::eFormatDefault)
3957 return with_fmt_info->m_format;
3958 with_fmt_info = with_fmt_info->m_parent;
3959 }
3960 return m_format;
3961}