blob: 50b917f1566dbc45c9b31d58369658509bd9c7e1 [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 Granataa0db6ed2014-04-09 21:06:11 +0000248 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
249 any_change = true;
250
Enrico Granata852cc952013-10-08 19:03:22 +0000251 SetValueFormat(DataVisualization::GetFormat (*this, eNoDynamicValues));
Enrico Granata5548cb52013-01-28 23:47:25 +0000252 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000253#ifndef LLDB_DISABLE_PYTHON
Enrico Granata5548cb52013-01-28 23:47:25 +0000254 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000255#endif
Enrico Granata4becb372011-06-29 22:27:15 +0000256 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000257
Enrico Granata9128ee22011-09-06 19:20:51 +0000258 return any_change;
Enrico Granata4becb372011-06-29 22:27:15 +0000259}
260
Jim Ingham16e0c682011-08-12 23:34:31 +0000261void
262ValueObject::SetNeedsUpdate ()
263{
264 m_update_point.SetNeedsUpdate();
265 // We have to clear the value string here so ConstResult children will notice if their values are
266 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000267 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000268}
269
Enrico Granata13ac0e22012-10-17 19:03:34 +0000270void
Enrico Granatae3e91512012-10-22 18:18:36 +0000271ValueObject::ClearDynamicTypeInformation ()
Enrico Granata13ac0e22012-10-17 19:03:34 +0000272{
Enrico Granata38c54632013-10-30 00:04:29 +0000273 m_children_count_valid = false;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000274 m_did_calculate_complete_objc_class_type = false;
Enrico Granatae3e91512012-10-22 18:18:36 +0000275 m_last_format_mgr_revision = 0;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000276 m_override_type = ClangASTType();
Enrico Granatae3e91512012-10-22 18:18:36 +0000277 SetValueFormat(lldb::TypeFormatImplSP());
278 SetSummaryFormat(lldb::TypeSummaryImplSP());
279 SetSyntheticChildren(lldb::SyntheticChildrenSP());
Enrico Granata13ac0e22012-10-17 19:03:34 +0000280}
281
Sean Callanan72772842012-02-22 23:57:45 +0000282ClangASTType
283ValueObject::MaybeCalculateCompleteType ()
284{
Greg Clayton57ee3062013-07-11 22:46:58 +0000285 ClangASTType clang_type(GetClangTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000286
Sean Callanan72772842012-02-22 23:57:45 +0000287 if (m_did_calculate_complete_objc_class_type)
288 {
289 if (m_override_type.IsValid())
290 return m_override_type;
291 else
Greg Clayton57ee3062013-07-11 22:46:58 +0000292 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000293 }
294
Greg Clayton57ee3062013-07-11 22:46:58 +0000295 ClangASTType class_type;
296 bool is_pointer_type = false;
Sean Callanan72772842012-02-22 23:57:45 +0000297
Greg Clayton57ee3062013-07-11 22:46:58 +0000298 if (clang_type.IsObjCObjectPointerType(&class_type))
Sean Callanan72772842012-02-22 23:57:45 +0000299 {
300 is_pointer_type = true;
301 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000302 else if (clang_type.IsObjCObjectOrInterfaceType())
Sean Callanan72772842012-02-22 23:57:45 +0000303 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000304 class_type = clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000305 }
306 else
307 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000308 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000309 }
310
311 m_did_calculate_complete_objc_class_type = true;
312
Greg Clayton57ee3062013-07-11 22:46:58 +0000313 if (class_type)
Sean Callanan72772842012-02-22 23:57:45 +0000314 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000315 ConstString class_name (class_type.GetConstTypeName());
Sean Callanan72772842012-02-22 23:57:45 +0000316
Greg Clayton57ee3062013-07-11 22:46:58 +0000317 if (class_name)
318 {
319 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
320
321 if (process_sp)
322 {
323 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
324
325 if (objc_language_runtime)
326 {
327 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name);
328
329 if (complete_objc_class_type_sp)
330 {
331 ClangASTType complete_class(complete_objc_class_type_sp->GetClangFullType());
332
333 if (complete_class.GetCompleteType())
334 {
335 if (is_pointer_type)
336 {
337 m_override_type = complete_class.GetPointerType();
338 }
339 else
340 {
341 m_override_type = complete_class;
342 }
343
344 if (m_override_type.IsValid())
345 return m_override_type;
346 }
347 }
348 }
349 }
350 }
Sean Callanan72772842012-02-22 23:57:45 +0000351 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000352 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000353}
354
Greg Clayton57ee3062013-07-11 22:46:58 +0000355ClangASTType
Sean Callanan72772842012-02-22 23:57:45 +0000356ValueObject::GetClangType ()
357{
Greg Clayton57ee3062013-07-11 22:46:58 +0000358 return MaybeCalculateCompleteType();
Sean Callanan72772842012-02-22 23:57:45 +0000359}
360
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000361TypeImpl
362ValueObject::GetTypeImpl ()
363{
364 return TypeImpl(GetClangType());
365}
366
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000367DataExtractor &
368ValueObject::GetDataExtractor ()
369{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000370 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000371 return m_data;
372}
373
374const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000375ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000376{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000377 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000378 return m_error;
379}
380
381const ConstString &
382ValueObject::GetName() const
383{
384 return m_name;
385}
386
387const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000388ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000389{
Enrico Granata82fabf82013-04-30 20:45:04 +0000390 return GetLocationAsCStringImpl(m_value,
391 m_data);
392}
393
394const char *
395ValueObject::GetLocationAsCStringImpl (const Value& value,
396 const DataExtractor& data)
397{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000398 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000399 {
400 if (m_location_str.empty())
401 {
402 StreamString sstr;
Enrico Granata82fabf82013-04-30 20:45:04 +0000403
404 Value::ValueType value_type = value.GetValueType();
405
406 switch (value_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000407 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000408 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +0000409 case Value::eValueTypeVector:
Enrico Granata82fabf82013-04-30 20:45:04 +0000410 if (value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000411 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000412 RegisterInfo *reg_info = value.GetRegisterInfo();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000413 if (reg_info)
414 {
415 if (reg_info->name)
416 m_location_str = reg_info->name;
417 else if (reg_info->alt_name)
418 m_location_str = reg_info->alt_name;
Enrico Granata82fabf82013-04-30 20:45:04 +0000419 if (m_location_str.empty())
420 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000421 }
422 }
Enrico Granata82fabf82013-04-30 20:45:04 +0000423 if (m_location_str.empty())
424 m_location_str = (value_type == Value::eValueTypeVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000425 break;
426
427 case Value::eValueTypeLoadAddress:
428 case Value::eValueTypeFileAddress:
429 case Value::eValueTypeHostAddress:
430 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000431 uint32_t addr_nibble_size = data.GetAddressByteSize() * 2;
432 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000433 m_location_str.swap(sstr.GetString());
434 }
435 break;
436 }
437 }
438 }
439 return m_location_str.c_str();
440}
441
442Value &
443ValueObject::GetValue()
444{
445 return m_value;
446}
447
448const Value &
449ValueObject::GetValue() const
450{
451 return m_value;
452}
453
454bool
Jim Ingham6035b672011-03-31 00:19:25 +0000455ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000456{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000457 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
458 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000459 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000460 Value tmp_value(m_value);
Greg Clayton57ee3062013-07-11 22:46:58 +0000461 scalar = tmp_value.ResolveValue(&exe_ctx);
Greg Claytondcad5022011-12-29 01:26:56 +0000462 if (scalar.IsValid())
463 {
464 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
465 if (bitfield_bit_size)
466 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
467 return true;
468 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000469 }
Greg Claytondcad5022011-12-29 01:26:56 +0000470 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000471}
472
473bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000474ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000475{
Greg Clayton288bdf92010-09-02 02:59:18 +0000476 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000477}
478
479
480void
481ValueObject::SetValueIsValid (bool b)
482{
Greg Clayton288bdf92010-09-02 02:59:18 +0000483 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000484}
485
486bool
Jim Ingham6035b672011-03-31 00:19:25 +0000487ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000488{
Jim Ingham6035b672011-03-31 00:19:25 +0000489 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000490 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000491}
492
493void
494ValueObject::SetValueDidChange (bool value_changed)
495{
Greg Clayton288bdf92010-09-02 02:59:18 +0000496 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000497}
498
499ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000500ValueObject::GetChildAtIndex (size_t idx, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000501{
502 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000503 // We may need to update our value if we are dynamic
504 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000505 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000506 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000507 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000508 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000509 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000510 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000511 // No we haven't created the child at this index, so lets have our
512 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000513 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000514 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000515
Enrico Granata9d60f602012-03-09 03:09:58 +0000516 ValueObject* child = m_children.GetChildAtIndex(idx);
517 if (child != NULL)
518 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000519 }
520 return child_sp;
521}
522
Enrico Granata3309d882013-01-12 01:00:22 +0000523ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000524ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
525 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000526{
527 if (idxs.size() == 0)
528 return GetSP();
529 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000530 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000531 {
532 root = root->GetChildAtIndex(idx, true);
533 if (!root)
534 {
535 if (index_of_error)
536 *index_of_error = idx;
537 return root;
538 }
539 }
540 return root;
541}
542
543ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000544ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
545 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000546{
547 if (idxs.size() == 0)
548 return GetSP();
549 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000550 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000551 {
552 root = root->GetChildAtIndex(idx.first, idx.second);
553 if (!root)
554 {
555 if (index_of_error)
556 *index_of_error = idx.first;
557 return root;
558 }
559 }
560 return root;
561}
562
563lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000564ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
565 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000566{
567 if (idxs.size() == 0)
568 return GetSP();
569 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000570 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000571 {
572 root = root->GetChildAtIndex(idx, true);
573 if (!root)
574 {
575 if (index_of_error)
576 *index_of_error = idx;
577 return root;
578 }
579 }
580 return root;
581}
582
583lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000584ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
585 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000586{
587 if (idxs.size() == 0)
588 return GetSP();
589 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000590 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000591 {
592 root = root->GetChildAtIndex(idx.first, idx.second);
593 if (!root)
594 {
595 if (index_of_error)
596 *index_of_error = idx.first;
597 return root;
598 }
599 }
600 return root;
601}
602
Enrico Granatae2e220a2013-09-12 00:48:47 +0000603lldb::ValueObjectSP
604ValueObject::GetChildAtNamePath (const std::initializer_list<ConstString> &names,
605 ConstString* name_of_error)
606{
607 if (names.size() == 0)
608 return GetSP();
609 ValueObjectSP root(GetSP());
610 for (ConstString name : names)
611 {
612 root = root->GetChildMemberWithName(name, true);
613 if (!root)
614 {
615 if (name_of_error)
616 *name_of_error = name;
617 return root;
618 }
619 }
620 return root;
621}
622
623lldb::ValueObjectSP
624ValueObject::GetChildAtNamePath (const std::vector<ConstString> &names,
625 ConstString* name_of_error)
626{
627 if (names.size() == 0)
628 return GetSP();
629 ValueObjectSP root(GetSP());
630 for (ConstString name : names)
631 {
632 root = root->GetChildMemberWithName(name, true);
633 if (!root)
634 {
635 if (name_of_error)
636 *name_of_error = name;
637 return root;
638 }
639 }
640 return root;
641}
642
643lldb::ValueObjectSP
644ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names,
645 ConstString* name_of_error)
646{
647 if (names.size() == 0)
648 return GetSP();
649 ValueObjectSP root(GetSP());
650 for (std::pair<ConstString, bool> name : names)
651 {
652 root = root->GetChildMemberWithName(name.first, name.second);
653 if (!root)
654 {
655 if (name_of_error)
656 *name_of_error = name.first;
657 return root;
658 }
659 }
660 return root;
661}
662
663lldb::ValueObjectSP
664ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names,
665 ConstString* name_of_error)
666{
667 if (names.size() == 0)
668 return GetSP();
669 ValueObjectSP root(GetSP());
670 for (std::pair<ConstString, bool> name : names)
671 {
672 root = root->GetChildMemberWithName(name.first, name.second);
673 if (!root)
674 {
675 if (name_of_error)
676 *name_of_error = name.first;
677 return root;
678 }
679 }
680 return root;
681}
682
Greg Claytonc7bece562013-01-25 18:06:21 +0000683size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000684ValueObject::GetIndexOfChildWithName (const ConstString &name)
685{
686 bool omit_empty_base_classes = true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000687 return GetClangType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000688}
689
690ValueObjectSP
691ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
692{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000693 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000694 // classes (which really aren't part of the expression path), so we
695 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000696 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000697
Greg Claytondea8cb42011-06-29 22:09:02 +0000698 // We may need to update our value if we are dynamic
699 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000700 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000701
702 std::vector<uint32_t> child_indexes;
Greg Claytondea8cb42011-06-29 22:09:02 +0000703 bool omit_empty_base_classes = true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000704 const size_t num_child_indexes = GetClangType().GetIndexOfChildMemberWithName (name.GetCString(),
705 omit_empty_base_classes,
706 child_indexes);
Greg Claytondea8cb42011-06-29 22:09:02 +0000707 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000708 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000709 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
710 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
711
712 child_sp = GetChildAtIndex(*pos, can_create);
713 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000714 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000715 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000716 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000717 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
718 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000719 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000720 else
721 {
722 child_sp.reset();
723 }
724
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000725 }
726 }
727 return child_sp;
728}
729
730
Greg Claytonc7bece562013-01-25 18:06:21 +0000731size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000732ValueObject::GetNumChildren ()
733{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000734 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000735 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000736 {
737 SetNumChildren (CalculateNumChildren());
738 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000739 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000740}
Greg Clayton4a792072012-10-23 01:50:10 +0000741
742bool
743ValueObject::MightHaveChildren()
744{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000745 bool has_children = false;
Greg Clayton2452ab72013-02-08 22:02:02 +0000746 const uint32_t type_info = GetTypeInfo();
747 if (type_info)
Greg Clayton4a792072012-10-23 01:50:10 +0000748 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000749 if (type_info & (ClangASTType::eTypeHasChildren |
750 ClangASTType::eTypeIsPointer |
751 ClangASTType::eTypeIsReference))
Greg Clayton4a792072012-10-23 01:50:10 +0000752 has_children = true;
753 }
754 else
755 {
756 has_children = GetNumChildren () > 0;
757 }
758 return has_children;
759}
760
761// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000762void
Greg Claytonc7bece562013-01-25 18:06:21 +0000763ValueObject::SetNumChildren (size_t num_children)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000764{
Greg Clayton288bdf92010-09-02 02:59:18 +0000765 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000766 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000767}
768
769void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000770ValueObject::SetName (const ConstString &name)
771{
772 m_name = name;
773}
774
Jim Ingham58b59f92011-04-22 23:53:53 +0000775ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000776ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000777{
Jim Ingham2eec4872011-05-07 00:10:58 +0000778 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000779
Greg Claytondea8cb42011-06-29 22:09:02 +0000780 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000781 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000782 std::string child_name_str;
783 uint32_t child_byte_size = 0;
784 int32_t child_byte_offset = 0;
785 uint32_t child_bitfield_bit_size = 0;
786 uint32_t child_bitfield_bit_offset = 0;
787 bool child_is_base_class = false;
788 bool child_is_deref_of_parent = false;
789
790 const bool transparent_pointers = synthetic_array_member == false;
Greg Clayton57ee3062013-07-11 22:46:58 +0000791 ClangASTType child_clang_type;
Greg Claytondea8cb42011-06-29 22:09:02 +0000792
Greg Claytoncc4d0142012-02-17 07:49:44 +0000793 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000794
Greg Clayton57ee3062013-07-11 22:46:58 +0000795 child_clang_type = GetClangType().GetChildClangTypeAtIndex (&exe_ctx,
Greg Clayton57ee3062013-07-11 22:46:58 +0000796 idx,
797 transparent_pointers,
798 omit_empty_base_classes,
799 ignore_array_bounds,
800 child_name_str,
801 child_byte_size,
802 child_byte_offset,
803 child_bitfield_bit_size,
804 child_bitfield_bit_offset,
805 child_is_base_class,
Greg Clayton759e7442014-07-19 00:12:57 +0000806 child_is_deref_of_parent,
807 this);
Greg Clayton4ef877f2012-12-06 02:33:54 +0000808 if (child_clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000809 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000810 if (synthetic_index)
811 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000812
Greg Claytondea8cb42011-06-29 22:09:02 +0000813 ConstString child_name;
814 if (!child_name_str.empty())
815 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000816
Greg Claytondea8cb42011-06-29 22:09:02 +0000817 valobj = new ValueObjectChild (*this,
Greg Claytondea8cb42011-06-29 22:09:02 +0000818 child_clang_type,
819 child_name,
820 child_byte_size,
821 child_byte_offset,
822 child_bitfield_bit_size,
823 child_bitfield_bit_offset,
824 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000825 child_is_deref_of_parent,
826 eAddressTypeInvalid);
827 //if (valobj)
828 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
829 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000830
Jim Ingham58b59f92011-04-22 23:53:53 +0000831 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000832}
833
Enrico Granata0c489f52012-03-01 04:24:26 +0000834bool
835ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
836 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000837{
Enrico Granata0c489f52012-03-01 04:24:26 +0000838 destination.clear();
839
840 // ideally we would like to bail out if passing NULL, but if we do so
841 // we end up not providing the summary for function pointers anymore
842 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
843 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000844
845 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000846
847 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
848 // information that we might care to see in a crash log. might be useful in very specific situations though.
849 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
850 GetTypeName().GetCString(),
851 GetName().GetCString(),
852 summary_ptr->GetDescription().c_str());*/
853
Enrico Granata0c489f52012-03-01 04:24:26 +0000854 if (UpdateValueIfNeeded (false))
855 {
856 if (summary_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000857 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000858 if (HasSyntheticValue())
859 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
860 summary_ptr->FormatObject(this, destination);
Enrico Granata0c489f52012-03-01 04:24:26 +0000861 }
862 else
863 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000864 ClangASTType clang_type = GetClangType();
Enrico Granata0c489f52012-03-01 04:24:26 +0000865
866 // Do some default printout for function pointers
867 if (clang_type)
Enrico Granata4becb372011-06-29 22:27:15 +0000868 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000869 if (clang_type.IsFunctionPointerType ())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000870 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000871 StreamString sstr;
Enrico Granata0c489f52012-03-01 04:24:26 +0000872 AddressType func_ptr_address_type = eAddressTypeInvalid;
873 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
874 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000875 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000876 switch (func_ptr_address_type)
Jim Ingham6035b672011-03-31 00:19:25 +0000877 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000878 case eAddressTypeInvalid:
879 case eAddressTypeFile:
880 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000881
Greg Claytoncc4d0142012-02-17 07:49:44 +0000882 case eAddressTypeLoad:
Enrico Granata0c489f52012-03-01 04:24:26 +0000883 {
884 ExecutionContext exe_ctx (GetExecutionContextRef());
885
886 Address so_addr;
887 Target *target = exe_ctx.GetTargetPtr();
888 if (target && target->GetSectionLoadList().IsEmpty() == false)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000889 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000890 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000891 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000892 so_addr.Dump (&sstr,
893 exe_ctx.GetBestExecutionContextScope(),
894 Address::DumpStyleResolvedDescription,
895 Address::DumpStyleSectionNameOffset);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000896 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000897 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000898 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000899 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000900
Greg Claytoncc4d0142012-02-17 07:49:44 +0000901 case eAddressTypeHost:
902 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +0000903 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000904 }
905 if (sstr.GetSize() > 0)
906 {
907 destination.assign (1, '(');
908 destination.append (sstr.GetData(), sstr.GetSize());
909 destination.append (1, ')');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000910 }
911 }
912 }
913 }
914 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000915 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000916 return !destination.empty();
917}
918
919const char *
920ValueObject::GetSummaryAsCString ()
921{
922 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
923 {
924 GetSummaryAsCString(GetSummaryFormat().get(),
925 m_summary_str);
926 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000927 if (m_summary_str.empty())
928 return NULL;
929 return m_summary_str.c_str();
930}
931
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000932bool
933ValueObject::IsCStringContainer(bool check_pointer)
934{
Greg Clayton57ee3062013-07-11 22:46:58 +0000935 ClangASTType pointee_or_element_clang_type;
936 const Flags type_flags (GetTypeInfo (&pointee_or_element_clang_type));
937 bool is_char_arr_ptr (type_flags.AnySet (ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer) &&
938 pointee_or_element_clang_type.IsCharType ());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000939 if (!is_char_arr_ptr)
940 return false;
941 if (!check_pointer)
942 return true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000943 if (type_flags.Test(ClangASTType::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000944 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000945 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000946 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000947 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000948 return (cstr_address != LLDB_INVALID_ADDRESS);
949}
950
Enrico Granata9128ee22011-09-06 19:20:51 +0000951size_t
952ValueObject::GetPointeeData (DataExtractor& data,
953 uint32_t item_idx,
954 uint32_t item_count)
955{
Greg Clayton57ee3062013-07-11 22:46:58 +0000956 ClangASTType pointee_or_element_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +0000957 const uint32_t type_info = GetTypeInfo (&pointee_or_element_clang_type);
Greg Clayton57ee3062013-07-11 22:46:58 +0000958 const bool is_pointer_type = type_info & ClangASTType::eTypeIsPointer;
959 const bool is_array_type = type_info & ClangASTType::eTypeIsArray;
Greg Clayton2452ab72013-02-08 22:02:02 +0000960 if (!(is_pointer_type || is_array_type))
Enrico Granata9128ee22011-09-06 19:20:51 +0000961 return 0;
962
963 if (item_count == 0)
964 return 0;
965
Greg Clayton57ee3062013-07-11 22:46:58 +0000966 const uint64_t item_type_size = pointee_or_element_clang_type.GetByteSize();
Enrico Granata9128ee22011-09-06 19:20:51 +0000967 const uint64_t bytes = item_count * item_type_size;
Enrico Granata9128ee22011-09-06 19:20:51 +0000968 const uint64_t offset = item_idx * item_type_size;
969
970 if (item_idx == 0 && item_count == 1) // simply a deref
971 {
Greg Clayton2452ab72013-02-08 22:02:02 +0000972 if (is_pointer_type)
Enrico Granata9128ee22011-09-06 19:20:51 +0000973 {
974 Error error;
975 ValueObjectSP pointee_sp = Dereference(error);
976 if (error.Fail() || pointee_sp.get() == NULL)
977 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +0000978 return pointee_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +0000979 }
980 else
981 {
982 ValueObjectSP child_sp = GetChildAtIndex(0, true);
983 if (child_sp.get() == NULL)
984 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +0000985 Error error;
986 return child_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +0000987 }
988 return true;
989 }
990 else /* (items > 1) */
991 {
992 Error error;
993 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
994 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
995
996 AddressType addr_type;
Greg Clayton2452ab72013-02-08 22:02:02 +0000997 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +0000998
Enrico Granata9128ee22011-09-06 19:20:51 +0000999 switch (addr_type)
1000 {
1001 case eAddressTypeFile:
1002 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001003 ModuleSP module_sp (GetModule());
1004 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001005 {
Enrico Granata9c2efe32012-08-07 01:49:34 +00001006 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +00001007 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001008 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001009 ExecutionContext exe_ctx (GetExecutionContextRef());
1010 Target* target = exe_ctx.GetTargetPtr();
1011 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +00001012 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001013 heap_buf_ptr->SetByteSize(bytes);
1014 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
1015 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +00001016 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001017 data.SetData(data_sp);
1018 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +00001019 }
1020 }
1021 }
1022 }
1023 break;
1024 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +00001025 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001026 ExecutionContext exe_ctx (GetExecutionContextRef());
1027 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +00001028 if (process)
1029 {
1030 heap_buf_ptr->SetByteSize(bytes);
1031 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
Enrico Granata5e1480c2013-10-30 17:52:44 +00001032 if (error.Success() || bytes_read > 0)
Enrico Granata9128ee22011-09-06 19:20:51 +00001033 {
1034 data.SetData(data_sp);
1035 return bytes_read;
1036 }
1037 }
1038 }
1039 break;
1040 case eAddressTypeHost:
1041 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001042 const uint64_t max_bytes = GetClangType().GetByteSize();
Greg Clayton2452ab72013-02-08 22:02:02 +00001043 if (max_bytes > offset)
1044 {
1045 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
1046 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
1047 data.SetData(data_sp);
1048 return bytes_read;
1049 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001050 }
1051 break;
1052 case eAddressTypeInvalid:
Enrico Granata9128ee22011-09-06 19:20:51 +00001053 break;
1054 }
1055 }
1056 return 0;
1057}
1058
Greg Claytonfaac1112013-03-14 18:31:44 +00001059uint64_t
Sean Callanan866e91c2014-02-28 22:27:53 +00001060ValueObject::GetData (DataExtractor& data, Error &error)
Enrico Granata9128ee22011-09-06 19:20:51 +00001061{
1062 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001063 ExecutionContext exe_ctx (GetExecutionContextRef());
Sean Callanan866e91c2014-02-28 22:27:53 +00001064 error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001065 if (error.Fail())
Sean Callananed185ab2013-04-19 19:47:32 +00001066 {
1067 if (m_data.GetByteSize())
1068 {
1069 data = m_data;
1070 return data.GetByteSize();
1071 }
1072 else
1073 {
1074 return 0;
1075 }
1076 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001077 data.SetAddressByteSize(m_data.GetAddressByteSize());
1078 data.SetByteOrder(m_data.GetByteOrder());
1079 return data.GetByteSize();
1080}
1081
Sean Callanan389823e2013-04-13 01:21:23 +00001082bool
1083ValueObject::SetData (DataExtractor &data, Error &error)
1084{
1085 error.Clear();
1086 // Make sure our value is up to date first so that our location and location
1087 // type is valid.
1088 if (!UpdateValueIfNeeded(false))
1089 {
1090 error.SetErrorString("unable to read value");
1091 return false;
1092 }
1093
1094 uint64_t count = 0;
Greg Clayton57ee3062013-07-11 22:46:58 +00001095 const Encoding encoding = GetClangType().GetEncoding(count);
Sean Callanan389823e2013-04-13 01:21:23 +00001096
1097 const size_t byte_size = GetByteSize();
1098
1099 Value::ValueType value_type = m_value.GetValueType();
1100
1101 switch (value_type)
1102 {
1103 case Value::eValueTypeScalar:
1104 {
1105 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1106
1107 if (!set_error.Success())
1108 {
1109 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1110 return false;
1111 }
1112 }
1113 break;
1114 case Value::eValueTypeLoadAddress:
1115 {
1116 // If it is a load address, then the scalar value is the storage location
1117 // of the data, and we have to shove this value down to that load location.
1118 ExecutionContext exe_ctx (GetExecutionContextRef());
1119 Process *process = exe_ctx.GetProcessPtr();
1120 if (process)
1121 {
1122 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1123 size_t bytes_written = process->WriteMemory(target_addr,
1124 data.GetDataStart(),
1125 byte_size,
1126 error);
1127 if (!error.Success())
1128 return false;
1129 if (bytes_written != byte_size)
1130 {
1131 error.SetErrorString("unable to write value to memory");
1132 return false;
1133 }
1134 }
1135 }
1136 break;
1137 case Value::eValueTypeHostAddress:
1138 {
1139 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1140 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1141 m_data.SetData(buffer_sp, 0);
1142 data.CopyByteOrderedData (0,
1143 byte_size,
1144 const_cast<uint8_t *>(m_data.GetDataStart()),
1145 byte_size,
1146 m_data.GetByteOrder());
1147 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1148 }
1149 break;
1150 case Value::eValueTypeFileAddress:
1151 case Value::eValueTypeVector:
1152 break;
1153 }
1154
1155 // If we have reached this point, then we have successfully changed the value.
1156 SetNeedsUpdate();
1157 return true;
1158}
1159
Enrico Granata9128ee22011-09-06 19:20:51 +00001160// will compute strlen(str), but without consuming more than
1161// maxlen bytes out of str (this serves the purpose of reading
1162// chunks of a string without having to worry about
1163// missing NULL terminators in the chunk)
1164// of course, if strlen(str) > maxlen, the function will return
1165// maxlen_value (which should be != maxlen, because that allows you
1166// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1167static uint32_t
1168strlen_or_inf (const char* str,
1169 uint32_t maxlen,
1170 uint32_t maxlen_value)
1171{
1172 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +00001173 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +00001174 {
Greg Clayton8dd5c172011-10-05 22:19:51 +00001175 while(*str)
1176 {
1177 len++;str++;
Greg Clayton2452ab72013-02-08 22:02:02 +00001178 if (len >= maxlen)
Greg Clayton8dd5c172011-10-05 22:19:51 +00001179 return maxlen_value;
1180 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001181 }
1182 return len;
1183}
1184
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001185size_t
Greg Claytoncc4d0142012-02-17 07:49:44 +00001186ValueObject::ReadPointedString (Stream& s,
1187 Error& error,
1188 uint32_t max_length,
1189 bool honor_array,
1190 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001191{
Greg Claytoncc4d0142012-02-17 07:49:44 +00001192 ExecutionContext exe_ctx (GetExecutionContextRef());
1193 Target* target = exe_ctx.GetTargetPtr();
1194
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001195 if (!target)
1196 {
1197 s << "<no target to read from>";
1198 error.SetErrorString("no target to read from");
1199 return 0;
1200 }
1201
1202 if (max_length == 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001203 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001204
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001205 size_t bytes_read = 0;
1206 size_t total_bytes_read = 0;
1207
Greg Clayton57ee3062013-07-11 22:46:58 +00001208 ClangASTType clang_type = GetClangType();
1209 ClangASTType elem_or_pointee_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001210 const Flags type_flags (GetTypeInfo (&elem_or_pointee_clang_type));
Greg Clayton57ee3062013-07-11 22:46:58 +00001211 if (type_flags.AnySet (ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer) &&
1212 elem_or_pointee_clang_type.IsCharType ())
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001213 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001214 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1215 AddressType cstr_address_type = eAddressTypeInvalid;
1216
1217 size_t cstr_len = 0;
1218 bool capped_data = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00001219 if (type_flags.Test (ClangASTType::eTypeIsArray))
Greg Claytoncc4d0142012-02-17 07:49:44 +00001220 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001221 // We have an array
Greg Clayton57ee3062013-07-11 22:46:58 +00001222 uint64_t array_size = 0;
1223 if (clang_type.IsArrayType(NULL, &array_size, NULL))
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001224 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001225 cstr_len = array_size;
1226 if (cstr_len > max_length)
1227 {
1228 capped_data = true;
1229 cstr_len = max_length;
1230 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001231 }
1232 cstr_address = GetAddressOf (true, &cstr_address_type);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001233 }
1234 else
1235 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001236 // We have a pointer
1237 cstr_address = GetPointerValue (&cstr_address_type);
1238 }
1239
1240 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1241 {
1242 s << "<invalid address>";
1243 error.SetErrorString("invalid address");
1244 return 0;
1245 }
1246
1247 Address cstr_so_addr (cstr_address);
1248 DataExtractor data;
1249 if (cstr_len > 0 && honor_array)
1250 {
1251 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1252 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1253 GetPointeeData(data, 0, cstr_len);
1254
1255 if ((bytes_read = data.GetByteSize()) > 0)
1256 {
1257 total_bytes_read = bytes_read;
1258 s << '"';
1259 data.Dump (&s,
1260 0, // Start offset in "data"
1261 item_format,
1262 1, // Size of item (1 byte for a char!)
1263 bytes_read, // How many bytes to print?
1264 UINT32_MAX, // num per line
1265 LLDB_INVALID_ADDRESS,// base address
1266 0, // bitfield bit size
1267 0); // bitfield bit offset
1268 if (capped_data)
1269 s << "...";
1270 s << '"';
1271 }
1272 }
1273 else
1274 {
1275 cstr_len = max_length;
1276 const size_t k_max_buf_size = 64;
1277
1278 size_t offset = 0;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001279
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001280 int cstr_len_displayed = -1;
1281 bool capped_cstr = false;
1282 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1283 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1284 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001285 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001286 total_bytes_read += bytes_read;
1287 const char *cstr = data.PeekCStr(0);
1288 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1289 if (len > k_max_buf_size)
1290 len = k_max_buf_size;
1291 if (cstr && cstr_len_displayed < 0)
1292 s << '"';
1293
1294 if (cstr_len_displayed < 0)
1295 cstr_len_displayed = len;
1296
1297 if (len == 0)
1298 break;
1299 cstr_len_displayed += len;
1300 if (len > bytes_read)
1301 len = bytes_read;
1302 if (len > cstr_len)
1303 len = cstr_len;
1304
1305 data.Dump (&s,
1306 0, // Start offset in "data"
1307 item_format,
1308 1, // Size of item (1 byte for a char!)
1309 len, // How many bytes to print?
1310 UINT32_MAX, // num per line
1311 LLDB_INVALID_ADDRESS,// base address
1312 0, // bitfield bit size
1313 0); // bitfield bit offset
1314
1315 if (len < k_max_buf_size)
1316 break;
1317
1318 if (len >= cstr_len)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001319 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001320 capped_cstr = true;
1321 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001322 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001323
1324 cstr_len -= len;
1325 offset += len;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001326 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001327
1328 if (cstr_len_displayed >= 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001329 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001330 s << '"';
1331 if (capped_cstr)
1332 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001333 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001334 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001335 }
1336 else
1337 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001338 error.SetErrorString("not a string object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001339 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001340 }
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001341 return total_bytes_read;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001342}
1343
Jim Ingham53c47f12010-09-10 23:12:17 +00001344const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001345ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001346{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001347
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001348 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001349 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001350
1351 if (!m_object_desc_str.empty())
1352 return m_object_desc_str.c_str();
1353
Greg Claytoncc4d0142012-02-17 07:49:44 +00001354 ExecutionContext exe_ctx (GetExecutionContextRef());
1355 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001356 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001357 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001358
Jim Ingham53c47f12010-09-10 23:12:17 +00001359 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001360
Greg Claytonafacd142011-09-02 01:15:17 +00001361 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001362 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1363
Jim Inghama2cf2632010-12-23 02:29:54 +00001364 if (runtime == NULL)
1365 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001366 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Greg Clayton57ee3062013-07-11 22:46:58 +00001367 ClangASTType clang_type = GetClangType();
1368 if (clang_type)
Jim Inghama2cf2632010-12-23 02:29:54 +00001369 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001370 bool is_signed;
Greg Clayton57ee3062013-07-11 22:46:58 +00001371 if (clang_type.IsIntegerType (is_signed) || clang_type.IsPointerType ())
Jim Inghamb7603bb2011-03-18 00:05:18 +00001372 {
Greg Claytonafacd142011-09-02 01:15:17 +00001373 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001374 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001375 }
1376 }
1377
Jim Ingham8d543de2011-03-31 23:01:21 +00001378 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001379 {
1380 m_object_desc_str.append (s.GetData());
1381 }
Sean Callanan672ad942010-10-23 00:18:49 +00001382
1383 if (m_object_desc_str.empty())
1384 return NULL;
1385 else
1386 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001387}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001388
Enrico Granata0c489f52012-03-01 04:24:26 +00001389bool
Enrico Granata4939b982013-12-22 09:24:22 +00001390ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format,
1391 std::string& destination)
1392{
1393 if (UpdateValueIfNeeded(false))
1394 return format.FormatObject(this,destination);
1395 else
1396 return false;
1397}
1398
1399bool
Enrico Granata0c489f52012-03-01 04:24:26 +00001400ValueObject::GetValueAsCString (lldb::Format format,
1401 std::string& destination)
1402{
Enrico Granata30f287f2013-12-28 08:44:02 +00001403 return GetValueAsCString(TypeFormatImpl_Format(format),destination);
Enrico Granata0c489f52012-03-01 04:24:26 +00001404}
1405
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001406const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001407ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001408{
Enrico Granatab294fd22013-05-31 19:18:19 +00001409 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001410 {
Enrico Granata4939b982013-12-22 09:24:22 +00001411 lldb::TypeFormatImplSP format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001412 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001413 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001414 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001415 if (m_type_format_sp)
Enrico Granata4939b982013-12-22 09:24:22 +00001416 format_sp = m_type_format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001417 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001418 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001419 if (m_is_bitfield_for_scalar)
1420 my_format = eFormatUnsigned;
1421 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001422 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001423 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001424 {
1425 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1426 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001427 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001428 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001429 else
1430 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001431 my_format = GetClangType().GetFormat();
Enrico Granata0c489f52012-03-01 04:24:26 +00001432 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001433 }
1434 }
1435 }
Enrico Granatab294fd22013-05-31 19:18:19 +00001436 if (my_format != m_last_format || m_value_str.empty())
Enrico Granata297e69f2012-03-06 23:21:16 +00001437 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001438 m_last_format = my_format;
Enrico Granata4939b982013-12-22 09:24:22 +00001439 if (!format_sp)
Enrico Granata30f287f2013-12-28 08:44:02 +00001440 format_sp.reset(new TypeFormatImpl_Format(my_format));
Enrico Granata4939b982013-12-22 09:24:22 +00001441 if (GetValueAsCString(*format_sp.get(), m_value_str))
Enrico Granata297e69f2012-03-06 23:21:16 +00001442 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001443 if (!m_value_did_change && m_old_value_valid)
1444 {
1445 // The value was gotten successfully, so we consider the
1446 // value as changed if the value string differs
1447 SetValueDidChange (m_old_value_str != m_value_str);
1448 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001449 }
1450 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001451 }
1452 if (m_value_str.empty())
1453 return NULL;
1454 return m_value_str.c_str();
1455}
1456
Enrico Granatac3e320a2011-08-02 17:27:39 +00001457// if > 8bytes, 0 is returned. this method should mostly be used
1458// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001459uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001460ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001461{
1462 // If our byte size is zero this is an aggregate type that has children
Greg Clayton57ee3062013-07-11 22:46:58 +00001463 if (!GetClangType().IsAggregateType())
Enrico Granatac3e320a2011-08-02 17:27:39 +00001464 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001465 Scalar scalar;
1466 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001467 {
1468 if (success)
1469 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001470 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001471 }
1472 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001473 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001474
1475 if (success)
1476 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001477 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001478}
1479
Enrico Granatad7373f62013-10-31 18:57:50 +00001480int64_t
1481ValueObject::GetValueAsSigned (int64_t fail_value, bool *success)
1482{
1483 // If our byte size is zero this is an aggregate type that has children
1484 if (!GetClangType().IsAggregateType())
1485 {
1486 Scalar scalar;
1487 if (ResolveValue (scalar))
1488 {
1489 if (success)
1490 *success = true;
1491 return scalar.SLongLong(fail_value);
1492 }
1493 // fallthrough, otherwise...
1494 }
1495
1496 if (success)
1497 *success = false;
1498 return fail_value;
1499}
1500
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001501// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1502// this call up to date by returning true for your new special cases. We will eventually move
1503// to checking this call result before trying to display special cases
1504bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001505ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1506 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001507{
Greg Clayton57ee3062013-07-11 22:46:58 +00001508 Flags flags(GetTypeInfo());
1509 if (flags.AnySet(ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001510 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001511 {
1512 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001513 (custom_format == eFormatCString ||
1514 custom_format == eFormatCharArray ||
1515 custom_format == eFormatChar ||
1516 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001517 return true;
1518
Greg Clayton57ee3062013-07-11 22:46:58 +00001519 if (flags.Test(ClangASTType::eTypeIsArray))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001520 {
Greg Claytonafacd142011-09-02 01:15:17 +00001521 if ((custom_format == eFormatBytes) ||
1522 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001523 return true;
1524
Greg Claytonafacd142011-09-02 01:15:17 +00001525 if ((custom_format == eFormatVectorOfChar) ||
1526 (custom_format == eFormatVectorOfFloat32) ||
1527 (custom_format == eFormatVectorOfFloat64) ||
1528 (custom_format == eFormatVectorOfSInt16) ||
1529 (custom_format == eFormatVectorOfSInt32) ||
1530 (custom_format == eFormatVectorOfSInt64) ||
1531 (custom_format == eFormatVectorOfSInt8) ||
1532 (custom_format == eFormatVectorOfUInt128) ||
1533 (custom_format == eFormatVectorOfUInt16) ||
1534 (custom_format == eFormatVectorOfUInt32) ||
1535 (custom_format == eFormatVectorOfUInt64) ||
1536 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001537 return true;
1538 }
1539 }
1540 return false;
1541}
1542
Enrico Granata9fc19442011-07-06 02:13:41 +00001543bool
1544ValueObject::DumpPrintableRepresentation(Stream& s,
1545 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001546 Format custom_format,
Enrico Granata0dba9b32014-01-08 01:36:59 +00001547 PrintableRepresentationSpecialCases special,
1548 bool do_dump_error)
Enrico Granata9fc19442011-07-06 02:13:41 +00001549{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001550
Greg Clayton57ee3062013-07-11 22:46:58 +00001551 Flags flags(GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001552
Enrico Granata86cc9822012-03-19 22:58:49 +00001553 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1554 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1555
1556 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001557 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001558 if (flags.AnySet(ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001559 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001560 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001561 // when being asked to get a printable display an array or pointer type directly,
1562 // try to "do the right thing"
1563
1564 if (IsCStringContainer(true) &&
1565 (custom_format == eFormatCString ||
1566 custom_format == eFormatCharArray ||
1567 custom_format == eFormatChar ||
1568 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001569 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001570 Error error;
1571 ReadPointedString(s,
1572 error,
1573 0,
1574 (custom_format == eFormatVectorOfChar) ||
1575 (custom_format == eFormatCharArray));
1576 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001577 }
1578
Enrico Granata86cc9822012-03-19 22:58:49 +00001579 if (custom_format == eFormatEnum)
1580 return false;
1581
1582 // this only works for arrays, because I have no way to know when
1583 // the pointed memory ends, and no special \0 end of data marker
Greg Clayton57ee3062013-07-11 22:46:58 +00001584 if (flags.Test(ClangASTType::eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001585 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001586 if ((custom_format == eFormatBytes) ||
1587 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001588 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001589 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001590
1591 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001592 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001593 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001594
1595 if (low)
1596 s << ',';
1597
1598 ValueObjectSP child = GetChildAtIndex(low,true);
1599 if (!child.get())
1600 {
1601 s << "<invalid child>";
1602 continue;
1603 }
1604 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1605 }
1606
1607 s << ']';
1608
1609 return true;
1610 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001611
Enrico Granata86cc9822012-03-19 22:58:49 +00001612 if ((custom_format == eFormatVectorOfChar) ||
1613 (custom_format == eFormatVectorOfFloat32) ||
1614 (custom_format == eFormatVectorOfFloat64) ||
1615 (custom_format == eFormatVectorOfSInt16) ||
1616 (custom_format == eFormatVectorOfSInt32) ||
1617 (custom_format == eFormatVectorOfSInt64) ||
1618 (custom_format == eFormatVectorOfSInt8) ||
1619 (custom_format == eFormatVectorOfUInt128) ||
1620 (custom_format == eFormatVectorOfUInt16) ||
1621 (custom_format == eFormatVectorOfUInt32) ||
1622 (custom_format == eFormatVectorOfUInt64) ||
1623 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1624 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001625 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001626
1627 Format format = FormatManager::GetSingleItemFormat(custom_format);
1628
1629 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001630 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001631 {
1632
1633 if (low)
1634 s << ',';
1635
1636 ValueObjectSP child = GetChildAtIndex(low,true);
1637 if (!child.get())
1638 {
1639 s << "<invalid child>";
1640 continue;
1641 }
1642 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1643 }
1644
1645 s << ']';
1646
1647 return true;
1648 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001649 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001650
1651 if ((custom_format == eFormatBoolean) ||
1652 (custom_format == eFormatBinary) ||
1653 (custom_format == eFormatChar) ||
1654 (custom_format == eFormatCharPrintable) ||
1655 (custom_format == eFormatComplexFloat) ||
1656 (custom_format == eFormatDecimal) ||
1657 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001658 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001659 (custom_format == eFormatFloat) ||
1660 (custom_format == eFormatOctal) ||
1661 (custom_format == eFormatOSType) ||
1662 (custom_format == eFormatUnicode16) ||
1663 (custom_format == eFormatUnicode32) ||
1664 (custom_format == eFormatUnsigned) ||
1665 (custom_format == eFormatPointer) ||
1666 (custom_format == eFormatComplexInteger) ||
1667 (custom_format == eFormatComplex) ||
1668 (custom_format == eFormatDefault)) // use the [] operator
1669 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001670 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001671 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001672
1673 if (only_special)
1674 return false;
1675
Enrico Granata86cc9822012-03-19 22:58:49 +00001676 bool var_success = false;
1677
1678 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001679 const char *cstr = NULL;
Enrico Granata2c75f112013-06-21 00:04:51 +00001680
1681 // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1682 // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1683 // area for cases where our desired output is not backed by some other longer-term storage
Greg Claytonc7bece562013-01-25 18:06:21 +00001684 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001685
Enrico Granata465f4bc2014-02-15 01:24:44 +00001686 if (custom_format != eFormatInvalid)
Enrico Granata86cc9822012-03-19 22:58:49 +00001687 SetFormat(custom_format);
1688
1689 switch(val_obj_display)
1690 {
1691 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001692 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001693 break;
1694
1695 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001696 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001697 break;
1698
1699 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001700 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001701 break;
1702
1703 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001704 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001705 break;
1706
1707 case eValueObjectRepresentationStyleChildrenCount:
Deepak Panickal99fbc072014-03-03 15:39:47 +00001708 strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren());
Greg Claytonc7bece562013-01-25 18:06:21 +00001709 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001710 break;
1711
1712 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001713 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001714 break;
Enrico Granata2c75f112013-06-21 00:04:51 +00001715
1716 case eValueObjectRepresentationStyleName:
1717 cstr = GetName().AsCString();
1718 break;
1719
1720 case eValueObjectRepresentationStyleExpressionPath:
1721 GetExpressionPath(strm, false);
1722 cstr = strm.GetString().c_str();
1723 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001724 }
1725
Greg Claytonc7bece562013-01-25 18:06:21 +00001726 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001727 {
1728 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001729 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001730 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1731 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001732 if (GetClangType().IsAggregateType())
Enrico Granata86cc9822012-03-19 22:58:49 +00001733 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001734 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1735 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001736 }
1737 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001738 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001739 }
1740 }
1741
Greg Claytonc7bece562013-01-25 18:06:21 +00001742 if (cstr)
1743 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001744 else
1745 {
1746 if (m_error.Fail())
Enrico Granata0dba9b32014-01-08 01:36:59 +00001747 {
1748 if (do_dump_error)
1749 s.Printf("<%s>", m_error.AsCString());
1750 else
1751 return false;
1752 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001753 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1754 s.PutCString("<no summary available>");
1755 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1756 s.PutCString("<no value available>");
1757 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1758 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1759 else
1760 s.PutCString("<no printable representation>");
1761 }
1762
1763 // we should only return false here if we could not do *anything*
1764 // even if we have an error message as output, that's a success
1765 // from our callers' perspective, so return true
1766 var_success = true;
Enrico Granata465f4bc2014-02-15 01:24:44 +00001767
1768 if (custom_format != eFormatInvalid)
1769 SetFormat(eFormatDefault);
Enrico Granata86cc9822012-03-19 22:58:49 +00001770 }
1771
Enrico Granataf4efecd2011-07-12 22:56:10 +00001772 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001773}
1774
Greg Clayton737b9322010-09-13 03:32:57 +00001775addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001776ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001777{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001778 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001779 return LLDB_INVALID_ADDRESS;
1780
Greg Clayton73b472d2010-10-27 03:32:59 +00001781 switch (m_value.GetValueType())
1782 {
1783 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001784 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001785 if (scalar_is_load_address)
1786 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001787 if(address_type)
1788 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001789 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1790 }
1791 break;
1792
1793 case Value::eValueTypeLoadAddress:
1794 case Value::eValueTypeFileAddress:
1795 case Value::eValueTypeHostAddress:
1796 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001797 if(address_type)
1798 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001799 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1800 }
1801 break;
1802 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001803 if (address_type)
1804 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001805 return LLDB_INVALID_ADDRESS;
1806}
1807
1808addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001809ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001810{
Greg Claytonafacd142011-09-02 01:15:17 +00001811 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001812 if(address_type)
1813 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001814
Enrico Granatac3e320a2011-08-02 17:27:39 +00001815 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001816 return address;
1817
Greg Clayton73b472d2010-10-27 03:32:59 +00001818 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001819 {
1820 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001821 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001822 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001823 break;
1824
Enrico Granata9128ee22011-09-06 19:20:51 +00001825 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001826 case Value::eValueTypeLoadAddress:
1827 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001828 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001829 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001830 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001831 }
1832 break;
1833 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001834
Enrico Granata9128ee22011-09-06 19:20:51 +00001835 if (address_type)
1836 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001837
Greg Clayton737b9322010-09-13 03:32:57 +00001838 return address;
1839}
1840
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001841bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001842ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001843{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001844 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001845 // Make sure our value is up to date first so that our location and location
1846 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001847 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001848 {
1849 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001850 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001851 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001852
Greg Claytonfaac1112013-03-14 18:31:44 +00001853 uint64_t count = 0;
Greg Clayton57ee3062013-07-11 22:46:58 +00001854 const Encoding encoding = GetClangType().GetEncoding (count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001855
Greg Claytonb1320972010-07-14 00:18:15 +00001856 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001857
Jim Ingham16e0c682011-08-12 23:34:31 +00001858 Value::ValueType value_type = m_value.GetValueType();
1859
1860 if (value_type == Value::eValueTypeScalar)
1861 {
1862 // If the value is already a scalar, then let the scalar change itself:
1863 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1864 }
1865 else if (byte_size <= Scalar::GetMaxByteSize())
1866 {
1867 // If the value fits in a scalar, then make a new scalar and again let the
1868 // scalar code do the conversion, then figure out where to put the new value.
1869 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001870 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1871 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001872 {
Jim Ingham4b536182011-08-09 02:12:22 +00001873 switch (value_type)
1874 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001875 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001876 {
1877 // If it is a load address, then the scalar value is the storage location
1878 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001879 ExecutionContext exe_ctx (GetExecutionContextRef());
1880 Process *process = exe_ctx.GetProcessPtr();
1881 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001882 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001883 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001884 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1885 new_scalar,
1886 byte_size,
1887 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001888 if (!error.Success())
1889 return false;
1890 if (bytes_written != byte_size)
1891 {
1892 error.SetErrorString("unable to write value to memory");
1893 return false;
1894 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001895 }
1896 }
Jim Ingham4b536182011-08-09 02:12:22 +00001897 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001898 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001899 {
1900 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1901 DataExtractor new_data;
1902 new_data.SetByteOrder (m_data.GetByteOrder());
1903
1904 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1905 m_data.SetData(buffer_sp, 0);
1906 bool success = new_scalar.GetData(new_data);
1907 if (success)
1908 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001909 new_data.CopyByteOrderedData (0,
1910 byte_size,
1911 const_cast<uint8_t *>(m_data.GetDataStart()),
1912 byte_size,
1913 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001914 }
1915 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1916
1917 }
Jim Ingham4b536182011-08-09 02:12:22 +00001918 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001919 case Value::eValueTypeFileAddress:
1920 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001921 case Value::eValueTypeVector:
1922 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001923 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001924 }
1925 else
1926 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001927 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001928 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001929 }
1930 else
1931 {
1932 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001933 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001934 return false;
1935 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001936
1937 // If we have reached this point, then we have successfully changed the value.
1938 SetNeedsUpdate();
1939 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001940}
1941
Greg Clayton81e871e2012-02-04 02:27:34 +00001942bool
1943ValueObject::GetDeclaration (Declaration &decl)
1944{
1945 decl.Clear();
1946 return false;
1947}
1948
Greg Clayton84db9102012-03-26 23:03:23 +00001949ConstString
1950ValueObject::GetTypeName()
1951{
Greg Clayton57ee3062013-07-11 22:46:58 +00001952 return GetClangType().GetConstTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00001953}
1954
1955ConstString
Enrico Granatae8daa2f2014-05-17 19:14:17 +00001956ValueObject::GetDisplayTypeName()
1957{
1958 return GetTypeName();
1959}
1960
1961ConstString
Greg Clayton84db9102012-03-26 23:03:23 +00001962ValueObject::GetQualifiedTypeName()
1963{
Greg Clayton57ee3062013-07-11 22:46:58 +00001964 return GetClangType().GetConstQualifiedTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00001965}
1966
1967
Greg Claytonafacd142011-09-02 01:15:17 +00001968LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001969ValueObject::GetObjectRuntimeLanguage ()
1970{
Greg Clayton57ee3062013-07-11 22:46:58 +00001971 return GetClangType().GetMinimumLanguage ();
Jim Ingham5a369122010-09-28 01:25:32 +00001972}
1973
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001974void
Jim Ingham58b59f92011-04-22 23:53:53 +00001975ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001976{
Jim Ingham58b59f92011-04-22 23:53:53 +00001977 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001978}
1979
1980ValueObjectSP
1981ValueObject::GetSyntheticChild (const ConstString &key) const
1982{
1983 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001984 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001985 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001986 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001987 return synthetic_child_sp;
1988}
1989
Greg Clayton2452ab72013-02-08 22:02:02 +00001990uint32_t
Greg Clayton57ee3062013-07-11 22:46:58 +00001991ValueObject::GetTypeInfo (ClangASTType *pointee_or_element_clang_type)
Greg Clayton2452ab72013-02-08 22:02:02 +00001992{
Greg Clayton57ee3062013-07-11 22:46:58 +00001993 return GetClangType().GetTypeInfo (pointee_or_element_clang_type);
Greg Clayton2452ab72013-02-08 22:02:02 +00001994}
1995
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001996bool
1997ValueObject::IsPointerType ()
1998{
Greg Clayton57ee3062013-07-11 22:46:58 +00001999 return GetClangType().IsPointerType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002000}
2001
Jim Inghamb7603bb2011-03-18 00:05:18 +00002002bool
Greg Claytondaf515f2011-07-09 20:12:33 +00002003ValueObject::IsArrayType ()
2004{
Greg Clayton57ee3062013-07-11 22:46:58 +00002005 return GetClangType().IsArrayType (NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00002006}
2007
2008bool
Enrico Granata9fc19442011-07-06 02:13:41 +00002009ValueObject::IsScalarType ()
2010{
Greg Clayton57ee3062013-07-11 22:46:58 +00002011 return GetClangType().IsScalarType ();
Enrico Granata9fc19442011-07-06 02:13:41 +00002012}
2013
2014bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00002015ValueObject::IsIntegerType (bool &is_signed)
2016{
Greg Clayton57ee3062013-07-11 22:46:58 +00002017 return GetClangType().IsIntegerType (is_signed);
Jim Inghamb7603bb2011-03-18 00:05:18 +00002018}
Greg Clayton73b472d2010-10-27 03:32:59 +00002019
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002020bool
2021ValueObject::IsPointerOrReferenceType ()
2022{
Greg Clayton57ee3062013-07-11 22:46:58 +00002023 return GetClangType().IsPointerOrReferenceType ();
Greg Clayton007d5be2011-05-30 00:49:24 +00002024}
2025
2026bool
Greg Claytondea8cb42011-06-29 22:09:02 +00002027ValueObject::IsPossibleDynamicType ()
2028{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002029 ExecutionContext exe_ctx (GetExecutionContextRef());
2030 Process *process = exe_ctx.GetProcessPtr();
2031 if (process)
2032 return process->IsPossibleDynamicValue(*this);
2033 else
Greg Clayton57ee3062013-07-11 22:46:58 +00002034 return GetClangType().IsPossibleDynamicType (NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00002035}
2036
Enrico Granata9e7b3882012-12-13 23:50:33 +00002037bool
2038ValueObject::IsObjCNil ()
2039{
Greg Clayton57ee3062013-07-11 22:46:58 +00002040 const uint32_t mask = ClangASTType::eTypeIsObjC | ClangASTType::eTypeIsPointer;
2041 bool isObjCpointer = (((GetClangType().GetTypeInfo(NULL)) & mask) == mask);
Enrico Granata7277d202013-03-15 23:33:15 +00002042 if (!isObjCpointer)
2043 return false;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002044 bool canReadValue = true;
2045 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
Enrico Granata7277d202013-03-15 23:33:15 +00002046 return canReadValue && isZero;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002047}
2048
Greg Claytonafacd142011-09-02 01:15:17 +00002049ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002050ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002051{
Greg Clayton2452ab72013-02-08 22:02:02 +00002052 const uint32_t type_info = GetTypeInfo ();
Greg Clayton57ee3062013-07-11 22:46:58 +00002053 if (type_info & ClangASTType::eTypeIsArray)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002054 return GetSyntheticArrayMemberFromArray(index, can_create);
2055
Greg Clayton57ee3062013-07-11 22:46:58 +00002056 if (type_info & ClangASTType::eTypeIsPointer)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002057 return GetSyntheticArrayMemberFromPointer(index, can_create);
2058
2059 return ValueObjectSP();
2060
2061}
2062
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002063ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002064ValueObject::GetSyntheticArrayMemberFromPointer (size_t index, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002065{
2066 ValueObjectSP synthetic_child_sp;
2067 if (IsPointerType ())
2068 {
2069 char index_str[64];
Deepak Panickal99fbc072014-03-03 15:39:47 +00002070 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002071 ConstString index_const_str(index_str);
2072 // Check if we have already created a synthetic array member in this
2073 // valid object. If we have we will re-use it.
2074 synthetic_child_sp = GetSyntheticChild (index_const_str);
2075 if (!synthetic_child_sp)
2076 {
Jim Ingham58b59f92011-04-22 23:53:53 +00002077 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002078 // We haven't made a synthetic array member for INDEX yet, so
2079 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00002080 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002081
2082 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00002083 if (synthetic_child)
2084 {
2085 AddSyntheticChild(index_const_str, synthetic_child);
2086 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002087 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00002088 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00002089 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002090 }
2091 }
2092 return synthetic_child_sp;
2093}
Jim Ingham22777012010-09-23 02:01:19 +00002094
Greg Claytondaf515f2011-07-09 20:12:33 +00002095// This allows you to create an array member using and index
2096// that doesn't not fall in the normal bounds of the array.
2097// Many times structure can be defined as:
2098// struct Collection
2099// {
2100// uint32_t item_count;
2101// Item item_array[0];
2102// };
2103// The size of the "item_array" is 1, but many times in practice
2104// there are more items in "item_array".
2105
2106ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002107ValueObject::GetSyntheticArrayMemberFromArray (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00002108{
2109 ValueObjectSP synthetic_child_sp;
2110 if (IsArrayType ())
2111 {
2112 char index_str[64];
Deepak Panickal99fbc072014-03-03 15:39:47 +00002113 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
Greg Claytondaf515f2011-07-09 20:12:33 +00002114 ConstString index_const_str(index_str);
2115 // Check if we have already created a synthetic array member in this
2116 // valid object. If we have we will re-use it.
2117 synthetic_child_sp = GetSyntheticChild (index_const_str);
2118 if (!synthetic_child_sp)
2119 {
2120 ValueObject *synthetic_child;
2121 // We haven't made a synthetic array member for INDEX yet, so
2122 // lets make one and cache it for any future reference.
2123 synthetic_child = CreateChildAtIndex(0, true, index);
2124
2125 // Cache the value if we got one back...
2126 if (synthetic_child)
2127 {
2128 AddSyntheticChild(index_const_str, synthetic_child);
2129 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002130 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00002131 synthetic_child_sp->m_is_array_item_for_pointer = true;
2132 }
2133 }
2134 }
2135 return synthetic_child_sp;
2136}
2137
Enrico Granata9fc19442011-07-06 02:13:41 +00002138ValueObjectSP
2139ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2140{
2141 ValueObjectSP synthetic_child_sp;
2142 if (IsScalarType ())
2143 {
2144 char index_str[64];
2145 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2146 ConstString index_const_str(index_str);
2147 // Check if we have already created a synthetic array member in this
2148 // valid object. If we have we will re-use it.
2149 synthetic_child_sp = GetSyntheticChild (index_const_str);
2150 if (!synthetic_child_sp)
2151 {
Enrico Granata9fc19442011-07-06 02:13:41 +00002152 // We haven't made a synthetic array member for INDEX yet, so
2153 // lets make one and cache it for any future reference.
Greg Clayton57ee3062013-07-11 22:46:58 +00002154 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
2155 GetClangType(),
2156 index_const_str,
2157 GetByteSize(),
2158 0,
2159 to-from+1,
2160 from,
2161 false,
2162 false,
2163 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002164
2165 // Cache the value if we got one back...
2166 if (synthetic_child)
2167 {
2168 AddSyntheticChild(index_const_str, synthetic_child);
2169 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002170 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002171 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2172 }
2173 }
2174 }
2175 return synthetic_child_sp;
2176}
2177
Greg Claytonafacd142011-09-02 01:15:17 +00002178ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00002179ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
2180{
2181
2182 ValueObjectSP synthetic_child_sp;
2183
2184 char name_str[64];
2185 snprintf(name_str, sizeof(name_str), "@%i", offset);
2186 ConstString name_const_str(name_str);
2187
2188 // Check if we have already created a synthetic array member in this
2189 // valid object. If we have we will re-use it.
2190 synthetic_child_sp = GetSyntheticChild (name_const_str);
2191
2192 if (synthetic_child_sp.get())
2193 return synthetic_child_sp;
2194
2195 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002196 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002197
2198 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
Greg Clayton57ee3062013-07-11 22:46:58 +00002199 type,
Enrico Granata6f3533f2011-07-29 19:53:35 +00002200 name_const_str,
Greg Clayton57ee3062013-07-11 22:46:58 +00002201 type.GetByteSize(),
Enrico Granata6f3533f2011-07-29 19:53:35 +00002202 offset,
2203 0,
2204 0,
2205 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002206 false,
2207 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002208 if (synthetic_child)
2209 {
2210 AddSyntheticChild(name_const_str, synthetic_child);
2211 synthetic_child_sp = synthetic_child->GetSP();
2212 synthetic_child_sp->SetName(name_const_str);
2213 synthetic_child_sp->m_is_child_at_offset = true;
2214 }
2215 return synthetic_child_sp;
2216}
2217
Enrico Granatad55546b2011-07-22 00:16:08 +00002218// your expression path needs to have a leading . or ->
2219// (unless it somehow "looks like" an array, in which case it has
2220// a leading [ symbol). while the [ is meaningful and should be shown
2221// to the user, . and -> are just parser design, but by no means
2222// added information for the user.. strip them off
2223static const char*
2224SkipLeadingExpressionPathSeparators(const char* expression)
2225{
2226 if (!expression || !expression[0])
2227 return expression;
2228 if (expression[0] == '.')
2229 return expression+1;
2230 if (expression[0] == '-' && expression[1] == '>')
2231 return expression+2;
2232 return expression;
2233}
2234
Greg Claytonafacd142011-09-02 01:15:17 +00002235ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002236ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2237{
2238 ValueObjectSP synthetic_child_sp;
2239 ConstString name_const_string(expression);
2240 // Check if we have already created a synthetic array member in this
2241 // valid object. If we have we will re-use it.
2242 synthetic_child_sp = GetSyntheticChild (name_const_string);
2243 if (!synthetic_child_sp)
2244 {
2245 // We haven't made a synthetic array member for expression yet, so
2246 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002247 synthetic_child_sp = GetValueForExpressionPath(expression,
2248 NULL, NULL, NULL,
2249 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
Enrico Granatad55546b2011-07-22 00:16:08 +00002250
2251 // Cache the value if we got one back...
2252 if (synthetic_child_sp.get())
2253 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002254 // 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 +00002255 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002256 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002257 }
2258 }
2259 return synthetic_child_sp;
2260}
2261
2262void
Enrico Granata86cc9822012-03-19 22:58:49 +00002263ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002264{
Enrico Granata86cc9822012-03-19 22:58:49 +00002265 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002266 return;
2267
Enrico Granatac5bc4122012-03-27 02:35:13 +00002268 TargetSP target_sp(GetTargetSP());
Enrico Granata5d5f60c2013-09-24 22:58:37 +00002269 if (target_sp && target_sp->GetEnableSyntheticValue() == false)
Enrico Granatac5bc4122012-03-27 02:35:13 +00002270 {
2271 m_synthetic_value = NULL;
2272 return;
2273 }
2274
Enrico Granatae3e91512012-10-22 18:18:36 +00002275 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2276
Enrico Granata5548cb52013-01-28 23:47:25 +00002277 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002278 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002279
Enrico Granata0c489f52012-03-01 04:24:26 +00002280 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002281 return;
2282
Enrico Granatae3e91512012-10-22 18:18:36 +00002283 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2284 return;
2285
Enrico Granata86cc9822012-03-19 22:58:49 +00002286 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002287}
2288
Jim Ingham78a685a2011-04-16 00:01:13 +00002289void
Greg Claytonafacd142011-09-02 01:15:17 +00002290ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002291{
Greg Claytonafacd142011-09-02 01:15:17 +00002292 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002293 return;
2294
Jim Ingham58b59f92011-04-22 23:53:53 +00002295 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002296 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002297 ExecutionContext exe_ctx (GetExecutionContextRef());
2298 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002299 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002300 {
2301 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002302 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002303 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002304 }
2305}
2306
Jim Ingham58b59f92011-04-22 23:53:53 +00002307ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002308ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002309{
Greg Claytonafacd142011-09-02 01:15:17 +00002310 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002311 return ValueObjectSP();
2312
2313 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002314 {
Jim Ingham2837b762011-05-04 03:43:18 +00002315 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002316 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002317 if (m_dynamic_value)
2318 return m_dynamic_value->GetSP();
2319 else
2320 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002321}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002322
Jim Ingham60dbabb2011-12-08 19:44:08 +00002323ValueObjectSP
2324ValueObject::GetStaticValue()
2325{
2326 return GetSP();
2327}
2328
Enrico Granata886147f2012-05-08 18:47:08 +00002329lldb::ValueObjectSP
2330ValueObject::GetNonSyntheticValue ()
2331{
2332 return GetSP();
2333}
2334
Enrico Granatad55546b2011-07-22 00:16:08 +00002335ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002336ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002337{
Enrico Granata86cc9822012-03-19 22:58:49 +00002338 if (use_synthetic == false)
2339 return ValueObjectSP();
2340
Enrico Granatad55546b2011-07-22 00:16:08 +00002341 CalculateSyntheticValue(use_synthetic);
2342
2343 if (m_synthetic_value)
2344 return m_synthetic_value->GetSP();
2345 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002346 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002347}
2348
Greg Claytone221f822011-01-21 01:59:00 +00002349bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002350ValueObject::HasSyntheticValue()
2351{
Enrico Granata5548cb52013-01-28 23:47:25 +00002352 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002353
Enrico Granata0c489f52012-03-01 04:24:26 +00002354 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002355 return false;
2356
Enrico Granata86cc9822012-03-19 22:58:49 +00002357 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002358
2359 if (m_synthetic_value)
2360 return true;
2361 else
2362 return false;
2363}
2364
2365bool
Greg Claytone221f822011-01-21 01:59:00 +00002366ValueObject::GetBaseClassPath (Stream &s)
2367{
2368 if (IsBaseClass())
2369 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002370 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Clayton57ee3062013-07-11 22:46:58 +00002371 ClangASTType clang_type = GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002372 std::string cxx_class_name;
Greg Clayton57ee3062013-07-11 22:46:58 +00002373 bool this_had_base_class = clang_type.GetCXXClassName (cxx_class_name);
Greg Claytone221f822011-01-21 01:59:00 +00002374 if (this_had_base_class)
2375 {
2376 if (parent_had_base_class)
2377 s.PutCString("::");
2378 s.PutCString(cxx_class_name.c_str());
2379 }
2380 return parent_had_base_class || this_had_base_class;
2381 }
2382 return false;
2383}
2384
2385
2386ValueObject *
2387ValueObject::GetNonBaseClassParent()
2388{
Jim Ingham78a685a2011-04-16 00:01:13 +00002389 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002390 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002391 if (GetParent()->IsBaseClass())
2392 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002393 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002394 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002395 }
2396 return NULL;
2397}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002398
2399void
Enrico Granata4becb372011-06-29 22:27:15 +00002400ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002401{
Greg Claytone221f822011-01-21 01:59:00 +00002402 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002403
Enrico Granata86cc9822012-03-19 22:58:49 +00002404 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002405 {
Enrico Granata4becb372011-06-29 22:27:15 +00002406 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2407 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2408 // the eHonorPointers mode is meant to produce strings in this latter format
2409 s.PutCString("*(");
2410 }
Greg Claytone221f822011-01-21 01:59:00 +00002411
Enrico Granata4becb372011-06-29 22:27:15 +00002412 ValueObject* parent = GetParent();
2413
2414 if (parent)
2415 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002416
2417 // if we are a deref_of_parent just because we are synthetic array
2418 // members made up to allow ptr[%d] syntax to work in variable
2419 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002420 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002421 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002422
Greg Claytone221f822011-01-21 01:59:00 +00002423 if (!IsBaseClass())
2424 {
2425 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002426 {
Greg Claytone221f822011-01-21 01:59:00 +00002427 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2428 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002429 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002430 ClangASTType non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002431 if (non_base_class_parent_clang_type)
2432 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002433 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002434 {
2435 s.PutCString("->");
2436 }
Enrico Granata4becb372011-06-29 22:27:15 +00002437 else
2438 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002439 const uint32_t non_base_class_parent_type_info = non_base_class_parent_clang_type.GetTypeInfo();
2440
2441 if (non_base_class_parent_type_info & ClangASTType::eTypeIsPointer)
Enrico Granata4becb372011-06-29 22:27:15 +00002442 {
2443 s.PutCString("->");
2444 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002445 else if ((non_base_class_parent_type_info & ClangASTType::eTypeHasChildren) &&
2446 !(non_base_class_parent_type_info & ClangASTType::eTypeIsArray))
Enrico Granata4becb372011-06-29 22:27:15 +00002447 {
2448 s.PutChar('.');
2449 }
Greg Claytone221f822011-01-21 01:59:00 +00002450 }
2451 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002452 }
Greg Claytone221f822011-01-21 01:59:00 +00002453
2454 const char *name = GetName().GetCString();
2455 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002456 {
Greg Claytone221f822011-01-21 01:59:00 +00002457 if (qualify_cxx_base_classes)
2458 {
2459 if (GetBaseClassPath (s))
2460 s.PutCString("::");
2461 }
2462 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002463 }
2464 }
2465 }
2466
Enrico Granata86cc9822012-03-19 22:58:49 +00002467 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002468 {
Greg Claytone221f822011-01-21 01:59:00 +00002469 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002470 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002471}
2472
Greg Claytonafacd142011-09-02 01:15:17 +00002473ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002474ValueObject::GetValueForExpressionPath(const char* expression,
2475 const char** first_unparsed,
2476 ExpressionPathScanEndReason* reason_to_stop,
2477 ExpressionPathEndResultType* final_value_type,
2478 const GetValueForExpressionPathOptions& options,
2479 ExpressionPathAftermath* final_task_on_target)
2480{
2481
2482 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002483 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2484 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002485 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002486
2487 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2488 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2489 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2490 final_value_type ? final_value_type : &dummy_final_value_type,
2491 options,
2492 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2493
Enrico Granata86cc9822012-03-19 22:58:49 +00002494 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002495 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002496
Enrico Granata86cc9822012-03-19 22:58:49 +00002497 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 +00002498 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002499 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002500 {
2501 Error error;
2502 ValueObjectSP final_value = ret_val->Dereference(error);
2503 if (error.Fail() || !final_value.get())
2504 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002505 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002506 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002507 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002508 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002509 return ValueObjectSP();
2510 }
2511 else
2512 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002513 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002514 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002515 return final_value;
2516 }
2517 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002518 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002519 {
2520 Error error;
2521 ValueObjectSP final_value = ret_val->AddressOf(error);
2522 if (error.Fail() || !final_value.get())
2523 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002524 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002525 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002526 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002527 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002528 return ValueObjectSP();
2529 }
2530 else
2531 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002532 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002533 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002534 return final_value;
2535 }
2536 }
2537 }
2538 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2539}
2540
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002541int
2542ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002543 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002544 const char** first_unparsed,
2545 ExpressionPathScanEndReason* reason_to_stop,
2546 ExpressionPathEndResultType* final_value_type,
2547 const GetValueForExpressionPathOptions& options,
2548 ExpressionPathAftermath* final_task_on_target)
2549{
2550 const char* dummy_first_unparsed;
2551 ExpressionPathScanEndReason dummy_reason_to_stop;
2552 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002553 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002554
2555 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2556 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2557 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2558 final_value_type ? final_value_type : &dummy_final_value_type,
2559 options,
2560 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2561
2562 if (!ret_val.get()) // if there are errors, I add nothing to the list
2563 return 0;
2564
Enrico Granata86ea8d82012-03-29 01:34:34 +00002565 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002566 {
2567 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002568 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002569 {
2570 list->Append(ret_val);
2571 return 1;
2572 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002573 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 +00002574 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002575 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002576 {
2577 Error error;
2578 ValueObjectSP final_value = ret_val->Dereference(error);
2579 if (error.Fail() || !final_value.get())
2580 {
Greg Clayton23f59502012-07-17 03:23:13 +00002581 if (reason_to_stop)
2582 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2583 if (final_value_type)
2584 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002585 return 0;
2586 }
2587 else
2588 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002589 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002590 list->Append(final_value);
2591 return 1;
2592 }
2593 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002594 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002595 {
2596 Error error;
2597 ValueObjectSP final_value = ret_val->AddressOf(error);
2598 if (error.Fail() || !final_value.get())
2599 {
Greg Clayton23f59502012-07-17 03:23:13 +00002600 if (reason_to_stop)
2601 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2602 if (final_value_type)
2603 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002604 return 0;
2605 }
2606 else
2607 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002608 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002609 list->Append(final_value);
2610 return 1;
2611 }
2612 }
2613 }
2614 }
2615 else
2616 {
2617 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2618 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2619 ret_val,
2620 list,
2621 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2622 final_value_type ? final_value_type : &dummy_final_value_type,
2623 options,
2624 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2625 }
2626 // in any non-covered case, just do the obviously right thing
2627 list->Append(ret_val);
2628 return 1;
2629}
2630
Greg Claytonafacd142011-09-02 01:15:17 +00002631ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002632ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2633 const char** first_unparsed,
2634 ExpressionPathScanEndReason* reason_to_stop,
2635 ExpressionPathEndResultType* final_result,
2636 const GetValueForExpressionPathOptions& options,
2637 ExpressionPathAftermath* what_next)
2638{
2639 ValueObjectSP root = GetSP();
2640
2641 if (!root.get())
2642 return ValueObjectSP();
2643
2644 *first_unparsed = expression_cstr;
2645
2646 while (true)
2647 {
2648
2649 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2650
Greg Clayton57ee3062013-07-11 22:46:58 +00002651 ClangASTType root_clang_type = root->GetClangType();
2652 ClangASTType pointee_clang_type;
2653 Flags pointee_clang_type_info;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002654
Greg Clayton57ee3062013-07-11 22:46:58 +00002655 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002656 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00002657 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002658
2659 if (!expression_cstr || *expression_cstr == '\0')
2660 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002661 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002662 return root;
2663 }
2664
2665 switch (*expression_cstr)
2666 {
2667 case '-':
2668 {
2669 if (options.m_check_dot_vs_arrow_syntax &&
Greg Clayton57ee3062013-07-11 22:46:58 +00002670 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 +00002671 {
2672 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002673 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2674 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002675 return ValueObjectSP();
2676 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002677 if (root_clang_type_info.Test(ClangASTType::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2678 root_clang_type_info.Test(ClangASTType::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002679 options.m_no_fragile_ivar)
2680 {
2681 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002682 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2683 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002684 return ValueObjectSP();
2685 }
2686 if (expression_cstr[1] != '>')
2687 {
2688 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002689 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2690 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002691 return ValueObjectSP();
2692 }
2693 expression_cstr++; // skip the -
2694 }
2695 case '.': // or fallthrough from ->
2696 {
2697 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Greg Clayton57ee3062013-07-11 22:46:58 +00002698 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 +00002699 {
2700 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002701 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2702 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002703 return ValueObjectSP();
2704 }
2705 expression_cstr++; // skip .
2706 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2707 ConstString child_name;
2708 if (!next_separator) // if no other separator just expand this last layer
2709 {
2710 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002711 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2712
2713 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002714 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002715 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002716 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2717 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002718 return child_valobj_sp;
2719 }
2720 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2721 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002722 if (root->IsSynthetic())
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002723 {
2724 *first_unparsed = expression_cstr;
2725 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2726 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2727 return ValueObjectSP();
2728 }
2729
2730 child_valobj_sp = root->GetSyntheticValue();
Enrico Granata86cc9822012-03-19 22:58:49 +00002731 if (child_valobj_sp.get())
2732 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002733 }
2734
2735 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2736 // so we hit the "else" branch, and return an error
2737 if(child_valobj_sp.get()) // if it worked, just return
2738 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002739 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002740 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2741 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002742 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002743 }
2744 else
2745 {
2746 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002747 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2748 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002749 return ValueObjectSP();
2750 }
2751 }
2752 else // other layers do expand
2753 {
2754 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002755 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2756 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002757 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002758 root = child_valobj_sp;
2759 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002760 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002761 continue;
2762 }
2763 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2764 {
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002765 if (root->IsSynthetic())
2766 {
2767 *first_unparsed = expression_cstr;
2768 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2769 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2770 return ValueObjectSP();
2771 }
2772
Enrico Granata86cc9822012-03-19 22:58:49 +00002773 child_valobj_sp = root->GetSyntheticValue(true);
2774 if (child_valobj_sp)
2775 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002776 }
2777
2778 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2779 // so we hit the "else" branch, and return an error
2780 if(child_valobj_sp.get()) // if it worked, move on
2781 {
2782 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002783 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002784 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002785 continue;
2786 }
2787 else
2788 {
2789 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002790 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2791 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002792 return ValueObjectSP();
2793 }
2794 }
2795 break;
2796 }
2797 case '[':
2798 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002799 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 +00002800 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002801 if (!root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002802 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002803 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2804 {
2805 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002806 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2807 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002808 return ValueObjectSP();
2809 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002810 }
2811 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2812 {
2813 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002814 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2815 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002816 return ValueObjectSP();
2817 }
2818 }
2819 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2820 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002821 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002822 {
2823 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002824 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2825 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002826 return ValueObjectSP();
2827 }
2828 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2829 {
2830 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002831 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2832 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002833 return root;
2834 }
2835 }
2836 const char *separator_position = ::strchr(expression_cstr+1,'-');
2837 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2838 if (!close_bracket_position) // if there is no ], this is a syntax error
2839 {
2840 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002841 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2842 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002843 return ValueObjectSP();
2844 }
2845 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2846 {
2847 char *end = NULL;
2848 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2849 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2850 {
2851 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002852 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2853 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002854 return ValueObjectSP();
2855 }
2856 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2857 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002858 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002859 {
2860 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002861 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2862 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002863 return root;
2864 }
2865 else
2866 {
2867 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002868 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2869 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002870 return ValueObjectSP();
2871 }
2872 }
2873 // from here on we do have a valid index
Greg Clayton57ee3062013-07-11 22:46:58 +00002874 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002875 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002876 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2877 if (!child_valobj_sp)
2878 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002879 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002880 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2881 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002882 if (child_valobj_sp)
2883 {
2884 root = child_valobj_sp;
2885 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002886 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002887 continue;
2888 }
2889 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002890 {
2891 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002892 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2893 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002894 return ValueObjectSP();
2895 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002896 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002897 else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002898 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002899 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 +00002900 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002901 {
2902 Error error;
2903 root = root->Dereference(error);
2904 if (error.Fail() || !root.get())
2905 {
2906 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002907 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2908 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002909 return ValueObjectSP();
2910 }
2911 else
2912 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002913 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002914 continue;
2915 }
2916 }
2917 else
2918 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002919 if (root->GetClangType().GetMinimumLanguage() == eLanguageTypeObjC
2920 && pointee_clang_type_info.AllClear(ClangASTType::eTypeIsPointer)
Greg Clayton84db9102012-03-26 23:03:23 +00002921 && root->HasSyntheticValue()
2922 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002923 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002924 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002925 }
2926 else
2927 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002928 if (!root.get())
2929 {
2930 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002931 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2932 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002933 return ValueObjectSP();
2934 }
2935 else
2936 {
2937 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002938 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002939 continue;
2940 }
2941 }
2942 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002943 else if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002944 {
2945 root = root->GetSyntheticBitFieldChild(index, index, true);
2946 if (!root.get())
2947 {
2948 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002949 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2950 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002951 return ValueObjectSP();
2952 }
2953 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2954 {
2955 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002956 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2957 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002958 return root;
2959 }
2960 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002961 else if (root_clang_type_info.Test(ClangASTType::eTypeIsVector))
Enrico Granata08a1bb82013-06-19 00:00:45 +00002962 {
2963 root = root->GetChildAtIndex(index, true);
2964 if (!root.get())
2965 {
2966 *first_unparsed = expression_cstr;
2967 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2968 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2969 return ValueObjectSP();
2970 }
2971 else
2972 {
2973 *first_unparsed = end+1; // skip ]
2974 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2975 continue;
2976 }
2977 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002978 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002979 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002980 if (root->HasSyntheticValue())
2981 root = root->GetSyntheticValue();
2982 else if (!root->IsSynthetic())
2983 {
2984 *first_unparsed = expression_cstr;
2985 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2986 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2987 return ValueObjectSP();
2988 }
2989 // if we are here, then root itself is a synthetic VO.. should be good to go
2990
Enrico Granata27b625e2011-08-09 01:04:56 +00002991 if (!root.get())
2992 {
2993 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002994 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2995 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2996 return ValueObjectSP();
2997 }
2998 root = root->GetChildAtIndex(index, true);
2999 if (!root.get())
3000 {
3001 *first_unparsed = expression_cstr;
3002 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3003 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003004 return ValueObjectSP();
3005 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00003006 else
3007 {
3008 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003009 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00003010 continue;
3011 }
Enrico Granata27b625e2011-08-09 01:04:56 +00003012 }
3013 else
3014 {
3015 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003016 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3017 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003018 return ValueObjectSP();
3019 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003020 }
3021 else // we have a low and a high index
3022 {
3023 char *end = NULL;
3024 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3025 if (!end || end != separator_position) // if something weird is in our way return an error
3026 {
3027 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003028 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3029 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003030 return ValueObjectSP();
3031 }
3032 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3033 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3034 {
3035 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003036 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3037 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003038 return ValueObjectSP();
3039 }
3040 if (index_lower > index_higher) // swap indices if required
3041 {
3042 unsigned long temp = index_lower;
3043 index_lower = index_higher;
3044 index_higher = temp;
3045 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003046 if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003047 {
3048 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3049 if (!root.get())
3050 {
3051 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003052 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3053 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003054 return ValueObjectSP();
3055 }
3056 else
3057 {
3058 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003059 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3060 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003061 return root;
3062 }
3063 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003064 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 +00003065 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Greg Clayton57ee3062013-07-11 22:46:58 +00003066 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003067 {
3068 Error error;
3069 root = root->Dereference(error);
3070 if (error.Fail() || !root.get())
3071 {
3072 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003073 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3074 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003075 return ValueObjectSP();
3076 }
3077 else
3078 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003079 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003080 continue;
3081 }
3082 }
3083 else
3084 {
3085 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003086 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3087 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003088 return root;
3089 }
3090 }
3091 break;
3092 }
3093 default: // some non-separator is in the way
3094 {
3095 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003096 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3097 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003098 return ValueObjectSP();
3099 break;
3100 }
3101 }
3102 }
3103}
3104
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003105int
3106ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3107 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00003108 ValueObjectSP root,
3109 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003110 ExpressionPathScanEndReason* reason_to_stop,
3111 ExpressionPathEndResultType* final_result,
3112 const GetValueForExpressionPathOptions& options,
3113 ExpressionPathAftermath* what_next)
3114{
3115 if (!root.get())
3116 return 0;
3117
3118 *first_unparsed = expression_cstr;
3119
3120 while (true)
3121 {
3122
3123 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3124
Greg Clayton57ee3062013-07-11 22:46:58 +00003125 ClangASTType root_clang_type = root->GetClangType();
3126 ClangASTType pointee_clang_type;
3127 Flags pointee_clang_type_info;
3128 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003129 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00003130 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003131
3132 if (!expression_cstr || *expression_cstr == '\0')
3133 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003134 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003135 list->Append(root);
3136 return 1;
3137 }
3138
3139 switch (*expression_cstr)
3140 {
3141 case '[':
3142 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003143 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 +00003144 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003145 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 +00003146 {
3147 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003148 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3149 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003150 return 0;
3151 }
3152 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3153 {
3154 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003155 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3156 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003157 return 0;
3158 }
3159 }
3160 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3161 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003162 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003163 {
3164 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003165 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3166 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003167 return 0;
3168 }
3169 else // expand this into list
3170 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003171 const size_t max_index = root->GetNumChildren() - 1;
3172 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003173 {
3174 ValueObjectSP child =
3175 root->GetChildAtIndex(index, true);
3176 list->Append(child);
3177 }
3178 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003179 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3180 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003181 return max_index; // tell me number of items I added to the VOList
3182 }
3183 }
3184 const char *separator_position = ::strchr(expression_cstr+1,'-');
3185 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3186 if (!close_bracket_position) // if there is no ], this is a syntax error
3187 {
3188 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003189 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3190 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003191 return 0;
3192 }
3193 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3194 {
3195 char *end = NULL;
3196 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3197 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3198 {
3199 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003200 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3201 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003202 return 0;
3203 }
3204 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3205 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003206 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003207 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003208 const size_t max_index = root->GetNumChildren() - 1;
3209 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003210 {
3211 ValueObjectSP child =
3212 root->GetChildAtIndex(index, true);
3213 list->Append(child);
3214 }
3215 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003216 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3217 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003218 return max_index; // tell me number of items I added to the VOList
3219 }
3220 else
3221 {
3222 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003223 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3224 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003225 return 0;
3226 }
3227 }
3228 // from here on we do have a valid index
Greg Clayton57ee3062013-07-11 22:46:58 +00003229 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003230 {
3231 root = root->GetChildAtIndex(index, true);
3232 if (!root.get())
3233 {
3234 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003235 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3236 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003237 return 0;
3238 }
3239 else
3240 {
3241 list->Append(root);
3242 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003243 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3244 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003245 return 1;
3246 }
3247 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003248 else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003249 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003250 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 +00003251 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003252 {
3253 Error error;
3254 root = root->Dereference(error);
3255 if (error.Fail() || !root.get())
3256 {
3257 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003258 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3259 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003260 return 0;
3261 }
3262 else
3263 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003264 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003265 continue;
3266 }
3267 }
3268 else
3269 {
3270 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3271 if (!root.get())
3272 {
3273 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003274 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3275 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003276 return 0;
3277 }
3278 else
3279 {
3280 list->Append(root);
3281 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003282 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3283 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003284 return 1;
3285 }
3286 }
3287 }
3288 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3289 {
3290 root = root->GetSyntheticBitFieldChild(index, index, true);
3291 if (!root.get())
3292 {
3293 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003294 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3295 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003296 return 0;
3297 }
3298 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3299 {
3300 list->Append(root);
3301 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003302 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3303 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003304 return 1;
3305 }
3306 }
3307 }
3308 else // we have a low and a high index
3309 {
3310 char *end = NULL;
3311 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3312 if (!end || end != separator_position) // if something weird is in our way return an error
3313 {
3314 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003315 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3316 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003317 return 0;
3318 }
3319 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3320 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3321 {
3322 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003323 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3324 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003325 return 0;
3326 }
3327 if (index_lower > index_higher) // swap indices if required
3328 {
3329 unsigned long temp = index_lower;
3330 index_lower = index_higher;
3331 index_higher = temp;
3332 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003333 if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // expansion only works for scalars
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003334 {
3335 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3336 if (!root.get())
3337 {
3338 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003339 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3340 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003341 return 0;
3342 }
3343 else
3344 {
3345 list->Append(root);
3346 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003347 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3348 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003349 return 1;
3350 }
3351 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003352 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 +00003353 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Greg Clayton57ee3062013-07-11 22:46:58 +00003354 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003355 {
3356 Error error;
3357 root = root->Dereference(error);
3358 if (error.Fail() || !root.get())
3359 {
3360 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003361 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3362 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003363 return 0;
3364 }
3365 else
3366 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003367 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003368 continue;
3369 }
3370 }
3371 else
3372 {
Johnny Chen44805302011-07-19 19:48:13 +00003373 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003374 index <= index_higher; index++)
3375 {
3376 ValueObjectSP child =
3377 root->GetChildAtIndex(index, true);
3378 list->Append(child);
3379 }
3380 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003381 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3382 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003383 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3384 }
3385 }
3386 break;
3387 }
3388 default: // some non-[ separator, or something entirely wrong, is in the way
3389 {
3390 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003391 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3392 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003393 return 0;
3394 break;
3395 }
3396 }
3397 }
3398}
3399
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003400void
3401ValueObject::LogValueObject (Log *log)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003402{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003403 if (log)
3404 return LogValueObject (log, DumpValueObjectOptions::DefaultOptions());
Greg Clayton1d3afba2010-10-05 00:00:42 +00003405}
3406
Enrico Granata0c489f52012-03-01 04:24:26 +00003407void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003408ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003409{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003410 if (log)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003411 {
3412 StreamString s;
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003413 Dump (s, options);
Greg Claytonf830dbb2012-03-22 18:15:37 +00003414 if (s.GetSize())
3415 log->PutCString(s.GetData());
3416 }
3417}
3418
3419void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003420ValueObject::Dump (Stream &s)
Enrico Granata0c489f52012-03-01 04:24:26 +00003421{
3422
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003423 ValueObjectPrinter printer(this,&s,DumpValueObjectOptions::DefaultOptions());
3424 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003425}
3426
3427void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003428ValueObject::Dump (Stream &s,
3429 const DumpValueObjectOptions& options)
Enrico Granata0c489f52012-03-01 04:24:26 +00003430{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003431 ValueObjectPrinter printer(this,&s,options);
3432 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003433}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003434
3435ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003436ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003437{
3438 ValueObjectSP valobj_sp;
3439
Enrico Granatac3e320a2011-08-02 17:27:39 +00003440 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003441 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003442 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003443
3444 DataExtractor data;
3445 data.SetByteOrder (m_data.GetByteOrder());
3446 data.SetAddressByteSize(m_data.GetAddressByteSize());
3447
Enrico Granata9f1e2042012-04-24 22:15:37 +00003448 if (IsBitfield())
3449 {
3450 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
Greg Clayton57ee3062013-07-11 22:46:58 +00003451 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Enrico Granata9f1e2042012-04-24 22:15:37 +00003452 }
3453 else
Greg Clayton57ee3062013-07-11 22:46:58 +00003454 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003455
3456 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003457 GetClangType(),
3458 name,
3459 data,
3460 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003461 }
Jim Ingham6035b672011-03-31 00:19:25 +00003462
3463 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003464 {
Greg Claytoneeb15652013-12-10 23:16:40 +00003465 ExecutionContext exe_ctx (GetExecutionContextRef());
3466 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003467 }
3468 return valobj_sp;
3469}
3470
Greg Clayton759e7442014-07-19 00:12:57 +00003471lldb::addr_t
3472ValueObject::GetCPPVTableAddress (AddressType &address_type)
3473{
3474 ClangASTType pointee_type;
3475 ClangASTType this_type(GetClangType());
3476 uint32_t type_info = this_type.GetTypeInfo(&pointee_type);
3477 if (type_info)
3478 {
3479 bool ptr_or_ref = false;
3480 if (type_info & (ClangASTType::eTypeIsPointer | ClangASTType::eTypeIsReference))
3481 {
3482 ptr_or_ref = true;
3483 type_info = pointee_type.GetTypeInfo();
3484 }
3485
3486 const uint32_t cpp_class = ClangASTType::eTypeIsClass | ClangASTType::eTypeIsCPlusPlus;
3487 if ((type_info & cpp_class) == cpp_class)
3488 {
3489 if (ptr_or_ref)
3490 {
3491 address_type = GetAddressTypeOfChildren();
3492 return GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
3493 }
3494 else
3495 return GetAddressOf (false, &address_type);
3496 }
3497 }
3498
3499 address_type = eAddressTypeInvalid;
3500 return LLDB_INVALID_ADDRESS;
3501}
3502
Greg Claytonafacd142011-09-02 01:15:17 +00003503ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003504ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003505{
Jim Ingham58b59f92011-04-22 23:53:53 +00003506 if (m_deref_valobj)
3507 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003508
Greg Clayton54979cd2010-12-15 05:08:08 +00003509 const bool is_pointer_type = IsPointerType();
3510 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003511 {
3512 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003513 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003514
3515 std::string child_name_str;
3516 uint32_t child_byte_size = 0;
3517 int32_t child_byte_offset = 0;
3518 uint32_t child_bitfield_bit_size = 0;
3519 uint32_t child_bitfield_bit_offset = 0;
3520 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003521 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003522 const bool transparent_pointers = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00003523 ClangASTType clang_type = GetClangType();
3524 ClangASTType child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003525
Greg Claytoncc4d0142012-02-17 07:49:44 +00003526 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003527
Greg Clayton57ee3062013-07-11 22:46:58 +00003528 child_clang_type = clang_type.GetChildClangTypeAtIndex (&exe_ctx,
Greg Clayton57ee3062013-07-11 22:46:58 +00003529 0,
3530 transparent_pointers,
3531 omit_empty_base_classes,
3532 ignore_array_bounds,
3533 child_name_str,
3534 child_byte_size,
3535 child_byte_offset,
3536 child_bitfield_bit_size,
3537 child_bitfield_bit_offset,
3538 child_is_base_class,
Greg Clayton759e7442014-07-19 00:12:57 +00003539 child_is_deref_of_parent,
3540 this);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003541 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003542 {
3543 ConstString child_name;
3544 if (!child_name_str.empty())
3545 child_name.SetCString (child_name_str.c_str());
3546
Jim Ingham58b59f92011-04-22 23:53:53 +00003547 m_deref_valobj = new ValueObjectChild (*this,
Jim Ingham58b59f92011-04-22 23:53:53 +00003548 child_clang_type,
3549 child_name,
3550 child_byte_size,
3551 child_byte_offset,
3552 child_bitfield_bit_size,
3553 child_bitfield_bit_offset,
3554 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003555 child_is_deref_of_parent,
3556 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003557 }
3558 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003559
Jim Ingham58b59f92011-04-22 23:53:53 +00003560 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003561 {
3562 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003563 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003564 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003565 else
3566 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003567 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003568 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003569
3570 if (is_pointer_type)
3571 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3572 else
3573 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003574 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003575 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003576}
3577
Greg Claytonafacd142011-09-02 01:15:17 +00003578ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003579ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003580{
Jim Ingham78a685a2011-04-16 00:01:13 +00003581 if (m_addr_of_valobj_sp)
3582 return m_addr_of_valobj_sp;
3583
Greg Claytone0d378b2011-03-24 21:19:54 +00003584 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003585 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003586 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003587 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003588 if (addr != LLDB_INVALID_ADDRESS)
3589 {
3590 switch (address_type)
3591 {
3592 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003593 {
3594 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003595 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003596 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3597 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003598 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003599
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003600 case eAddressTypeFile:
3601 case eAddressTypeLoad:
3602 case eAddressTypeHost:
3603 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003604 ClangASTType clang_type = GetClangType();
3605 if (clang_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003606 {
3607 std::string name (1, '&');
3608 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003609 ExecutionContext exe_ctx (GetExecutionContextRef());
3610 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00003611 clang_type.GetPointerType(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003612 ConstString (name.c_str()),
3613 addr,
3614 eAddressTypeInvalid,
3615 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003616 }
3617 }
3618 break;
3619 }
3620 }
Sean Callananed185ab2013-04-19 19:47:32 +00003621 else
3622 {
3623 StreamString expr_path_strm;
3624 GetExpressionPath(expr_path_strm, true);
3625 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3626 }
3627
Jim Ingham78a685a2011-04-16 00:01:13 +00003628 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003629}
3630
Greg Clayton9a142cf2012-02-03 05:34:10 +00003631ValueObjectSP
3632ValueObject::Cast (const ClangASTType &clang_ast_type)
3633{
Greg Clayton81e871e2012-02-04 02:27:34 +00003634 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003635}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003636
Greg Claytonafacd142011-09-02 01:15:17 +00003637ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003638ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3639{
Greg Claytonafacd142011-09-02 01:15:17 +00003640 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003641 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003642 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003643
3644 if (ptr_value != LLDB_INVALID_ADDRESS)
3645 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003646 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003647 ExecutionContext exe_ctx (GetExecutionContextRef());
3648 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003649 name,
3650 ptr_addr,
3651 clang_ast_type);
3652 }
3653 return valobj_sp;
3654}
3655
Greg Claytonafacd142011-09-02 01:15:17 +00003656ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003657ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3658{
Greg Claytonafacd142011-09-02 01:15:17 +00003659 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003660 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003661 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003662
3663 if (ptr_value != LLDB_INVALID_ADDRESS)
3664 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003665 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003666 ExecutionContext exe_ctx (GetExecutionContextRef());
3667 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003668 name,
3669 ptr_addr,
3670 type_sp);
3671 }
3672 return valobj_sp;
3673}
3674
Jim Ingham6035b672011-03-31 00:19:25 +00003675ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003676 m_mod_id(),
3677 m_exe_ctx_ref(),
3678 m_needs_update (true),
3679 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003680{
3681}
3682
3683ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003684 m_mod_id(),
3685 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003686 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003687 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003688{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003689 ExecutionContext exe_ctx(exe_scope);
3690 TargetSP target_sp (exe_ctx.GetTargetSP());
3691 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003692 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003693 m_exe_ctx_ref.SetTargetSP (target_sp);
3694 ProcessSP process_sp (exe_ctx.GetProcessSP());
3695 if (!process_sp)
3696 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003697
Greg Claytoncc4d0142012-02-17 07:49:44 +00003698 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003699 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003700 m_mod_id = process_sp->GetModID();
3701 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003702
Greg Claytoncc4d0142012-02-17 07:49:44 +00003703 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003704
Greg Claytoncc4d0142012-02-17 07:49:44 +00003705 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003706 {
3707 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003708 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003709 }
Jim Ingham6035b672011-03-31 00:19:25 +00003710
Greg Claytoncc4d0142012-02-17 07:49:44 +00003711 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003712 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003713 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003714
Jason Molendab57e4a12013-11-04 09:33:30 +00003715 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003716 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003717 {
3718 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003719 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003720 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003721 if (frame_sp)
3722 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003723 }
3724 }
3725 }
Jim Ingham6035b672011-03-31 00:19:25 +00003726}
3727
3728ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003729 m_mod_id(),
3730 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3731 m_needs_update (true),
3732 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003733{
3734}
3735
3736ValueObject::EvaluationPoint::~EvaluationPoint ()
3737{
3738}
3739
Jim Ingham6035b672011-03-31 00:19:25 +00003740// This function checks the EvaluationPoint against the current process state. If the current
3741// state matches the evaluation point, or the evaluation point is already invalid, then we return
3742// false, meaning "no change". If the current state is different, we update our state, and return
3743// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3744// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003745// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003746
3747bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003748ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003749{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003750
3751 // 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 +00003752 const bool thread_and_frame_only_if_stopped = true;
3753 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
Jim Ingham73ca05a2011-12-17 01:35:57 +00003754
Greg Claytoncc4d0142012-02-17 07:49:44 +00003755 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003756 return false;
3757
Jim Ingham6035b672011-03-31 00:19:25 +00003758 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003759 Process *process = exe_ctx.GetProcessPtr();
3760 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003761 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003762
Jim Ingham6035b672011-03-31 00:19:25 +00003763 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003764 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003765
Jim Ingham78a685a2011-04-16 00:01:13 +00003766 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3767 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003768 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003769 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003770
Greg Clayton23f59502012-07-17 03:23:13 +00003771 bool changed = false;
3772 const bool was_valid = m_mod_id.IsValid();
3773 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003774 {
3775 if (m_mod_id == current_mod_id)
3776 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003777 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003778 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003779 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003780 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003781 else
3782 {
3783 m_mod_id = current_mod_id;
3784 m_needs_update = true;
3785 changed = true;
3786 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003787 }
Jim Ingham6035b672011-03-31 00:19:25 +00003788
Jim Ingham73ca05a2011-12-17 01:35:57 +00003789 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3790 // That way we'll be sure to return a valid exe_scope.
3791 // 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 +00003792
Greg Claytoncc4d0142012-02-17 07:49:44 +00003793 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003794 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003795 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3796 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003797 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003798 if (m_exe_ctx_ref.HasFrameRef())
3799 {
Jason Molendab57e4a12013-11-04 09:33:30 +00003800 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003801 if (!frame_sp)
3802 {
3803 // We used to have a frame, but now it is gone
3804 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003805 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00003806 }
3807 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003808 }
Jim Ingham6035b672011-03-31 00:19:25 +00003809 else
3810 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003811 // We used to have a thread, but now it is gone
3812 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003813 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00003814 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003815
Jim Ingham6035b672011-03-31 00:19:25 +00003816 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003817 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003818}
3819
Jim Ingham61be0902011-05-02 18:13:59 +00003820void
3821ValueObject::EvaluationPoint::SetUpdated ()
3822{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003823 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3824 if (process_sp)
3825 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003826 m_first_update = false;
3827 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003828}
3829
3830
Enrico Granataf2bbf712011-07-15 02:26:42 +00003831
3832void
Enrico Granata86cc9822012-03-19 22:58:49 +00003833ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00003834{
Enrico Granata86cc9822012-03-19 22:58:49 +00003835 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
3836 m_value_str.clear();
3837
3838 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
3839 m_location_str.clear();
3840
3841 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
3842 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003843 m_summary_str.clear();
3844 }
3845
3846 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
3847 m_object_desc_str.clear();
3848
3849 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
3850 {
3851 if (m_synthetic_value)
3852 m_synthetic_value = NULL;
3853 }
Johnny Chen44805302011-07-19 19:48:13 +00003854}
Enrico Granata9128ee22011-09-06 19:20:51 +00003855
3856SymbolContextScope *
3857ValueObject::GetSymbolContextScope()
3858{
3859 if (m_parent)
3860 {
3861 if (!m_parent->IsPointerOrReferenceType())
3862 return m_parent->GetSymbolContextScope();
3863 }
3864 return NULL;
3865}
Enrico Granatab2698cd2012-09-13 18:27:09 +00003866
3867lldb::ValueObjectSP
3868ValueObject::CreateValueObjectFromExpression (const char* name,
3869 const char* expression,
3870 const ExecutionContext& exe_ctx)
3871{
3872 lldb::ValueObjectSP retval_sp;
3873 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
3874 if (!target_sp)
3875 return retval_sp;
3876 if (!expression || !*expression)
3877 return retval_sp;
3878 target_sp->EvaluateExpression (expression,
3879 exe_ctx.GetFrameSP().get(),
3880 retval_sp);
3881 if (retval_sp && name && *name)
3882 retval_sp->SetName(ConstString(name));
3883 return retval_sp;
3884}
3885
3886lldb::ValueObjectSP
3887ValueObject::CreateValueObjectFromAddress (const char* name,
3888 uint64_t address,
3889 const ExecutionContext& exe_ctx,
3890 ClangASTType type)
3891{
Greg Clayton57ee3062013-07-11 22:46:58 +00003892 if (type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00003893 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003894 ClangASTType pointer_type(type.GetPointerType());
3895 if (pointer_type)
3896 {
3897 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
3898 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3899 pointer_type,
3900 ConstString(name),
3901 buffer,
3902 lldb::endian::InlHostByteOrder(),
3903 exe_ctx.GetAddressByteSize()));
3904 if (ptr_result_valobj_sp)
3905 {
3906 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
3907 Error err;
3908 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
3909 if (ptr_result_valobj_sp && name && *name)
3910 ptr_result_valobj_sp->SetName(ConstString(name));
3911 }
3912 return ptr_result_valobj_sp;
3913 }
Enrico Granatab2698cd2012-09-13 18:27:09 +00003914 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003915 return lldb::ValueObjectSP();
Enrico Granatab2698cd2012-09-13 18:27:09 +00003916}
3917
3918lldb::ValueObjectSP
3919ValueObject::CreateValueObjectFromData (const char* name,
Enrico Granata7ca1c762014-03-31 23:02:25 +00003920 const DataExtractor& data,
Enrico Granatab2698cd2012-09-13 18:27:09 +00003921 const ExecutionContext& exe_ctx,
3922 ClangASTType type)
3923{
3924 lldb::ValueObjectSP new_value_sp;
3925 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00003926 type,
Enrico Granatab2698cd2012-09-13 18:27:09 +00003927 ConstString(name),
3928 data,
3929 LLDB_INVALID_ADDRESS);
3930 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
3931 if (new_value_sp && name && *name)
3932 new_value_sp->SetName(ConstString(name));
3933 return new_value_sp;
3934}
Enrico Granata4873e522013-04-11 22:48:58 +00003935
3936ModuleSP
3937ValueObject::GetModule ()
3938{
3939 ValueObject* root(GetRoot());
3940 if (root != this)
3941 return root->GetModule();
3942 return lldb::ModuleSP();
3943}
3944
3945ValueObject*
3946ValueObject::GetRoot ()
3947{
3948 if (m_root)
3949 return m_root;
3950 ValueObject* parent = m_parent;
3951 if (!parent)
3952 return (m_root = this);
3953 while (parent->m_parent)
3954 {
3955 if (parent->m_root)
3956 return (m_root = parent->m_root);
3957 parent = parent->m_parent;
3958 }
3959 return (m_root = parent);
3960}
3961
3962AddressType
3963ValueObject::GetAddressTypeOfChildren()
3964{
3965 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
3966 {
3967 ValueObject* root(GetRoot());
3968 if (root != this)
3969 return root->GetAddressTypeOfChildren();
3970 }
3971 return m_address_type_of_ptr_or_ref_children;
3972}
3973
3974lldb::DynamicValueType
3975ValueObject::GetDynamicValueType ()
3976{
3977 ValueObject* with_dv_info = this;
3978 while (with_dv_info)
3979 {
3980 if (with_dv_info->HasDynamicValueTypeInfo())
3981 return with_dv_info->GetDynamicValueTypeImpl();
3982 with_dv_info = with_dv_info->m_parent;
3983 }
3984 return lldb::eNoDynamicValues;
3985}
Enrico Granata39d51412013-05-31 17:43:40 +00003986
Enrico Granata4873e522013-04-11 22:48:58 +00003987lldb::Format
3988ValueObject::GetFormat () const
3989{
3990 const ValueObject* with_fmt_info = this;
3991 while (with_fmt_info)
3992 {
3993 if (with_fmt_info->m_format != lldb::eFormatDefault)
3994 return with_fmt_info->m_format;
3995 with_fmt_info = with_fmt_info->m_parent;
3996 }
3997 return m_format;
3998}