blob: e1f3b8a647005d3e421de6e853500773ccebdff6 [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 Claytonf5e56de2010-09-14 23:36:40 +000053#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000055
56using namespace lldb;
57using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000058using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000059
Greg Claytonafacd142011-09-02 01:15:17 +000060static user_id_t g_value_obj_uid = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061
62//----------------------------------------------------------------------
63// ValueObject constructor
64//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000065ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000067 m_parent (&parent),
Enrico Granata4873e522013-04-11 22:48:58 +000068 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +000069 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000070 m_name (),
71 m_data (),
72 m_value (),
73 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000074 m_value_str (),
75 m_old_value_str (),
76 m_location_str (),
77 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000078 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +000079 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000080 m_children (),
81 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000082 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000083 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000084 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000085 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +000086 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000087 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +000088 m_type_summary_sp(),
89 m_type_format_sp(),
90 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +000091 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +000092 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
Greg Clayton288bdf92010-09-02 02:59:18 +000093 m_value_is_valid (false),
94 m_value_did_change (false),
95 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000096 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +000097 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +000098 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +000099 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000100 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000101 m_is_getting_summary(false),
102 m_did_calculate_complete_objc_class_type(false)
Jim Ingham6035b672011-03-31 00:19:25 +0000103{
Jim Ingham58b59f92011-04-22 23:53:53 +0000104 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000105}
106
107//----------------------------------------------------------------------
108// ValueObject constructor
109//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000110ValueObject::ValueObject (ExecutionContextScope *exe_scope,
111 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000112 UserID (++g_value_obj_uid), // Unique identifier for every value object
113 m_parent (NULL),
Enrico Granata4873e522013-04-11 22:48:58 +0000114 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000115 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000116 m_name (),
117 m_data (),
118 m_value (),
119 m_error (),
120 m_value_str (),
121 m_old_value_str (),
122 m_location_str (),
123 m_summary_str (),
124 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000125 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000126 m_children (),
127 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000128 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000129 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000130 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000131 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +0000132 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000133 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +0000134 m_type_summary_sp(),
135 m_type_format_sp(),
136 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000137 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000138 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Jim Ingham6035b672011-03-31 00:19:25 +0000139 m_value_is_valid (false),
140 m_value_did_change (false),
141 m_children_count_valid (false),
142 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000143 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000144 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000145 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000146 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000147 m_is_getting_summary(false),
148 m_did_calculate_complete_objc_class_type(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000149{
Jim Ingham58b59f92011-04-22 23:53:53 +0000150 m_manager = new ValueObjectManager();
151 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000152}
153
154//----------------------------------------------------------------------
155// Destructor
156//----------------------------------------------------------------------
157ValueObject::~ValueObject ()
158{
159}
160
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000161bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000162ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000163{
Enrico Granata4becb372011-06-29 22:27:15 +0000164
Enrico Granata9128ee22011-09-06 19:20:51 +0000165 bool did_change_formats = false;
166
Enrico Granata0a3958e2011-07-02 00:25:22 +0000167 if (update_format)
Enrico Granata5548cb52013-01-28 23:47:25 +0000168 did_change_formats = UpdateFormatsIfNeeded();
Enrico Granata4becb372011-06-29 22:27:15 +0000169
Greg Claytonb71f3842010-10-05 03:13:51 +0000170 // If this is a constant value, then our success is predicated on whether
171 // we have an error or not
172 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000173 {
Enrico Granatab1c6c482013-10-09 00:33:55 +0000174 // if you are constant, things might still have changed behind your back
175 // (e.g. you are a frozen object and things have changed deeper than you cared to freeze-dry yourself)
176 // in this case, your value has not changed, but "computed" entries might have, so you might now have
177 // a different summary, or a different object description. clear these so we will recompute them
Enrico Granata9128ee22011-09-06 19:20:51 +0000178 if (update_format && !did_change_formats)
Enrico Granatab1c6c482013-10-09 00:33:55 +0000179 ClearUserVisibleData(eClearUserVisibleDataItemsSummary | eClearUserVisibleDataItemsDescription);
Greg Claytonb71f3842010-10-05 03:13:51 +0000180 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000181 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000182
Jim Ingham6035b672011-03-31 00:19:25 +0000183 bool first_update = m_update_point.IsFirstEvaluation();
184
185 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000186 {
Jim Ingham6035b672011-03-31 00:19:25 +0000187 m_update_point.SetUpdated();
188
189 // Save the old value using swap to avoid a string copy which
190 // also will clear our m_value_str
191 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000192 {
Jim Ingham6035b672011-03-31 00:19:25 +0000193 m_old_value_valid = false;
194 }
195 else
196 {
197 m_old_value_valid = true;
198 m_old_value_str.swap (m_value_str);
Enrico Granata86cc9822012-03-19 22:58:49 +0000199 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham6035b672011-03-31 00:19:25 +0000200 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000201
Enrico Granataf2bbf712011-07-15 02:26:42 +0000202 ClearUserVisibleData();
203
Greg Claytonefbc7d22012-03-09 04:23:44 +0000204 if (IsInScope())
Jim Ingham6035b672011-03-31 00:19:25 +0000205 {
Greg Claytonefbc7d22012-03-09 04:23:44 +0000206 const bool value_was_valid = GetValueIsValid();
207 SetValueDidChange (false);
208
209 m_error.Clear();
210
211 // Call the pure virtual function to update the value
212 bool success = UpdateValue ();
213
214 SetValueIsValid (success);
215
216 if (first_update)
217 SetValueDidChange (false);
218 else if (!m_value_did_change && success == false)
219 {
220 // The value wasn't gotten successfully, so we mark this
221 // as changed if the value used to be valid and now isn't
222 SetValueDidChange (value_was_valid);
223 }
224 }
225 else
226 {
227 m_error.SetErrorString("out of scope");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000228 }
229 }
230 return m_error.Success();
231}
232
Enrico Granata9128ee22011-09-06 19:20:51 +0000233bool
Enrico Granata5548cb52013-01-28 23:47:25 +0000234ValueObject::UpdateFormatsIfNeeded()
Enrico Granata4becb372011-06-29 22:27:15 +0000235{
Greg Clayton5160ce52013-03-27 23:08:40 +0000236 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000237 if (log)
Enrico Granatad2284832012-10-17 22:23:56 +0000238 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
Enrico Granata6f3533f2011-07-29 19:53:35 +0000239 GetName().GetCString(),
Enrico Granatad2284832012-10-17 22:23:56 +0000240 this,
Enrico Granata4becb372011-06-29 22:27:15 +0000241 m_last_format_mgr_revision,
Enrico Granata85933ed2011-08-18 16:38:26 +0000242 DataVisualization::GetCurrentRevision());
Enrico Granata9128ee22011-09-06 19:20:51 +0000243
244 bool any_change = false;
245
Enrico Granata5548cb52013-01-28 23:47:25 +0000246 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()))
Enrico Granata4becb372011-06-29 22:27:15 +0000247 {
Enrico Granata852cc952013-10-08 19:03:22 +0000248 SetValueFormat(DataVisualization::GetFormat (*this, eNoDynamicValues));
Enrico Granata5548cb52013-01-28 23:47:25 +0000249 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000250#ifndef LLDB_DISABLE_PYTHON
Enrico Granata5548cb52013-01-28 23:47:25 +0000251 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000252#endif
Enrico Granata1490c6f2011-07-19 02:34:21 +0000253
Enrico Granata85933ed2011-08-18 16:38:26 +0000254 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
Enrico Granata855cd902011-09-06 22:59:55 +0000255
256 any_change = true;
Enrico Granata4becb372011-06-29 22:27:15 +0000257 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000258
259 return any_change;
260
Enrico Granata4becb372011-06-29 22:27:15 +0000261}
262
Jim Ingham16e0c682011-08-12 23:34:31 +0000263void
264ValueObject::SetNeedsUpdate ()
265{
266 m_update_point.SetNeedsUpdate();
267 // We have to clear the value string here so ConstResult children will notice if their values are
268 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000269 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000270}
271
Enrico Granata13ac0e22012-10-17 19:03:34 +0000272void
Enrico Granatae3e91512012-10-22 18:18:36 +0000273ValueObject::ClearDynamicTypeInformation ()
Enrico Granata13ac0e22012-10-17 19:03:34 +0000274{
275 m_did_calculate_complete_objc_class_type = false;
Enrico Granatae3e91512012-10-22 18:18:36 +0000276 m_last_format_mgr_revision = 0;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000277 m_override_type = ClangASTType();
Enrico Granatae3e91512012-10-22 18:18:36 +0000278 SetValueFormat(lldb::TypeFormatImplSP());
279 SetSummaryFormat(lldb::TypeSummaryImplSP());
280 SetSyntheticChildren(lldb::SyntheticChildrenSP());
Enrico Granata13ac0e22012-10-17 19:03:34 +0000281}
282
Sean Callanan72772842012-02-22 23:57:45 +0000283ClangASTType
284ValueObject::MaybeCalculateCompleteType ()
285{
Greg Clayton57ee3062013-07-11 22:46:58 +0000286 ClangASTType clang_type(GetClangTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000287
Sean Callanan72772842012-02-22 23:57:45 +0000288 if (m_did_calculate_complete_objc_class_type)
289 {
290 if (m_override_type.IsValid())
291 return m_override_type;
292 else
Greg Clayton57ee3062013-07-11 22:46:58 +0000293 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000294 }
295
Greg Clayton57ee3062013-07-11 22:46:58 +0000296 ClangASTType class_type;
297 bool is_pointer_type = false;
Sean Callanan72772842012-02-22 23:57:45 +0000298
Greg Clayton57ee3062013-07-11 22:46:58 +0000299 if (clang_type.IsObjCObjectPointerType(&class_type))
Sean Callanan72772842012-02-22 23:57:45 +0000300 {
301 is_pointer_type = true;
302 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000303 else if (clang_type.IsObjCObjectOrInterfaceType())
Sean Callanan72772842012-02-22 23:57:45 +0000304 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000305 class_type = clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000306 }
307 else
308 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000309 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000310 }
311
312 m_did_calculate_complete_objc_class_type = true;
313
Greg Clayton57ee3062013-07-11 22:46:58 +0000314 if (class_type)
Sean Callanan72772842012-02-22 23:57:45 +0000315 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000316 ConstString class_name (class_type.GetConstTypeName());
Sean Callanan72772842012-02-22 23:57:45 +0000317
Greg Clayton57ee3062013-07-11 22:46:58 +0000318 if (class_name)
319 {
320 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
321
322 if (process_sp)
323 {
324 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
325
326 if (objc_language_runtime)
327 {
328 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name);
329
330 if (complete_objc_class_type_sp)
331 {
332 ClangASTType complete_class(complete_objc_class_type_sp->GetClangFullType());
333
334 if (complete_class.GetCompleteType())
335 {
336 if (is_pointer_type)
337 {
338 m_override_type = complete_class.GetPointerType();
339 }
340 else
341 {
342 m_override_type = complete_class;
343 }
344
345 if (m_override_type.IsValid())
346 return m_override_type;
347 }
348 }
349 }
350 }
351 }
Sean Callanan72772842012-02-22 23:57:45 +0000352 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000353 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000354}
355
Greg Clayton57ee3062013-07-11 22:46:58 +0000356ClangASTType
Sean Callanan72772842012-02-22 23:57:45 +0000357ValueObject::GetClangType ()
358{
Greg Clayton57ee3062013-07-11 22:46:58 +0000359 return MaybeCalculateCompleteType();
Sean Callanan72772842012-02-22 23:57:45 +0000360}
361
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000362TypeImpl
363ValueObject::GetTypeImpl ()
364{
365 return TypeImpl(GetClangType());
366}
367
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000368DataExtractor &
369ValueObject::GetDataExtractor ()
370{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000371 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000372 return m_data;
373}
374
375const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000376ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000377{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000378 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000379 return m_error;
380}
381
382const ConstString &
383ValueObject::GetName() const
384{
385 return m_name;
386}
387
388const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000389ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000390{
Enrico Granata82fabf82013-04-30 20:45:04 +0000391 return GetLocationAsCStringImpl(m_value,
392 m_data);
393}
394
395const char *
396ValueObject::GetLocationAsCStringImpl (const Value& value,
397 const DataExtractor& data)
398{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000399 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000400 {
401 if (m_location_str.empty())
402 {
403 StreamString sstr;
Enrico Granata82fabf82013-04-30 20:45:04 +0000404
405 Value::ValueType value_type = value.GetValueType();
406
407 switch (value_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000408 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000409 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +0000410 case Value::eValueTypeVector:
Enrico Granata82fabf82013-04-30 20:45:04 +0000411 if (value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000412 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000413 RegisterInfo *reg_info = value.GetRegisterInfo();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000414 if (reg_info)
415 {
416 if (reg_info->name)
417 m_location_str = reg_info->name;
418 else if (reg_info->alt_name)
419 m_location_str = reg_info->alt_name;
Enrico Granata82fabf82013-04-30 20:45:04 +0000420 if (m_location_str.empty())
421 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000422 }
423 }
Enrico Granata82fabf82013-04-30 20:45:04 +0000424 if (m_location_str.empty())
425 m_location_str = (value_type == Value::eValueTypeVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000426 break;
427
428 case Value::eValueTypeLoadAddress:
429 case Value::eValueTypeFileAddress:
430 case Value::eValueTypeHostAddress:
431 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000432 uint32_t addr_nibble_size = data.GetAddressByteSize() * 2;
433 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000434 m_location_str.swap(sstr.GetString());
435 }
436 break;
437 }
438 }
439 }
440 return m_location_str.c_str();
441}
442
443Value &
444ValueObject::GetValue()
445{
446 return m_value;
447}
448
449const Value &
450ValueObject::GetValue() const
451{
452 return m_value;
453}
454
455bool
Jim Ingham6035b672011-03-31 00:19:25 +0000456ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000457{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000458 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
459 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000460 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000461 Value tmp_value(m_value);
Greg Clayton57ee3062013-07-11 22:46:58 +0000462 scalar = tmp_value.ResolveValue(&exe_ctx);
Greg Claytondcad5022011-12-29 01:26:56 +0000463 if (scalar.IsValid())
464 {
465 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
466 if (bitfield_bit_size)
467 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
468 return true;
469 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000470 }
Greg Claytondcad5022011-12-29 01:26:56 +0000471 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000472}
473
474bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000475ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000476{
Greg Clayton288bdf92010-09-02 02:59:18 +0000477 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000478}
479
480
481void
482ValueObject::SetValueIsValid (bool b)
483{
Greg Clayton288bdf92010-09-02 02:59:18 +0000484 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000485}
486
487bool
Jim Ingham6035b672011-03-31 00:19:25 +0000488ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000489{
Jim Ingham6035b672011-03-31 00:19:25 +0000490 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000491 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000492}
493
494void
495ValueObject::SetValueDidChange (bool value_changed)
496{
Greg Clayton288bdf92010-09-02 02:59:18 +0000497 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000498}
499
500ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000501ValueObject::GetChildAtIndex (size_t idx, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000502{
503 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000504 // We may need to update our value if we are dynamic
505 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000506 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000507 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000508 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000509 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000510 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000511 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000512 // No we haven't created the child at this index, so lets have our
513 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000514 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000515 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000516
Enrico Granata9d60f602012-03-09 03:09:58 +0000517 ValueObject* child = m_children.GetChildAtIndex(idx);
518 if (child != NULL)
519 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000520 }
521 return child_sp;
522}
523
Enrico Granata3309d882013-01-12 01:00:22 +0000524ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000525ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
526 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000527{
528 if (idxs.size() == 0)
529 return GetSP();
530 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000531 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000532 {
533 root = root->GetChildAtIndex(idx, true);
534 if (!root)
535 {
536 if (index_of_error)
537 *index_of_error = idx;
538 return root;
539 }
540 }
541 return root;
542}
543
544ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000545ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
546 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000547{
548 if (idxs.size() == 0)
549 return GetSP();
550 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000551 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000552 {
553 root = root->GetChildAtIndex(idx.first, idx.second);
554 if (!root)
555 {
556 if (index_of_error)
557 *index_of_error = idx.first;
558 return root;
559 }
560 }
561 return root;
562}
563
564lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000565ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
566 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000567{
568 if (idxs.size() == 0)
569 return GetSP();
570 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000571 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000572 {
573 root = root->GetChildAtIndex(idx, true);
574 if (!root)
575 {
576 if (index_of_error)
577 *index_of_error = idx;
578 return root;
579 }
580 }
581 return root;
582}
583
584lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000585ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
586 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000587{
588 if (idxs.size() == 0)
589 return GetSP();
590 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000591 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000592 {
593 root = root->GetChildAtIndex(idx.first, idx.second);
594 if (!root)
595 {
596 if (index_of_error)
597 *index_of_error = idx.first;
598 return root;
599 }
600 }
601 return root;
602}
603
Enrico Granatae2e220a2013-09-12 00:48:47 +0000604lldb::ValueObjectSP
605ValueObject::GetChildAtNamePath (const std::initializer_list<ConstString> &names,
606 ConstString* name_of_error)
607{
608 if (names.size() == 0)
609 return GetSP();
610 ValueObjectSP root(GetSP());
611 for (ConstString name : names)
612 {
613 root = root->GetChildMemberWithName(name, true);
614 if (!root)
615 {
616 if (name_of_error)
617 *name_of_error = name;
618 return root;
619 }
620 }
621 return root;
622}
623
624lldb::ValueObjectSP
625ValueObject::GetChildAtNamePath (const std::vector<ConstString> &names,
626 ConstString* name_of_error)
627{
628 if (names.size() == 0)
629 return GetSP();
630 ValueObjectSP root(GetSP());
631 for (ConstString name : names)
632 {
633 root = root->GetChildMemberWithName(name, true);
634 if (!root)
635 {
636 if (name_of_error)
637 *name_of_error = name;
638 return root;
639 }
640 }
641 return root;
642}
643
644lldb::ValueObjectSP
645ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names,
646 ConstString* name_of_error)
647{
648 if (names.size() == 0)
649 return GetSP();
650 ValueObjectSP root(GetSP());
651 for (std::pair<ConstString, bool> name : names)
652 {
653 root = root->GetChildMemberWithName(name.first, name.second);
654 if (!root)
655 {
656 if (name_of_error)
657 *name_of_error = name.first;
658 return root;
659 }
660 }
661 return root;
662}
663
664lldb::ValueObjectSP
665ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names,
666 ConstString* name_of_error)
667{
668 if (names.size() == 0)
669 return GetSP();
670 ValueObjectSP root(GetSP());
671 for (std::pair<ConstString, bool> name : names)
672 {
673 root = root->GetChildMemberWithName(name.first, name.second);
674 if (!root)
675 {
676 if (name_of_error)
677 *name_of_error = name.first;
678 return root;
679 }
680 }
681 return root;
682}
683
Greg Claytonc7bece562013-01-25 18:06:21 +0000684size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000685ValueObject::GetIndexOfChildWithName (const ConstString &name)
686{
687 bool omit_empty_base_classes = true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000688 return GetClangType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000689}
690
691ValueObjectSP
692ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
693{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000694 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000695 // classes (which really aren't part of the expression path), so we
696 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000697 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000698
Greg Claytondea8cb42011-06-29 22:09:02 +0000699 // We may need to update our value if we are dynamic
700 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000701 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000702
703 std::vector<uint32_t> child_indexes;
Greg Claytondea8cb42011-06-29 22:09:02 +0000704 bool omit_empty_base_classes = true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000705 const size_t num_child_indexes = GetClangType().GetIndexOfChildMemberWithName (name.GetCString(),
706 omit_empty_base_classes,
707 child_indexes);
Greg Claytondea8cb42011-06-29 22:09:02 +0000708 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000709 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000710 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
711 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
712
713 child_sp = GetChildAtIndex(*pos, can_create);
714 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000715 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000716 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000717 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000718 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
719 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000720 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000721 else
722 {
723 child_sp.reset();
724 }
725
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000726 }
727 }
728 return child_sp;
729}
730
731
Greg Claytonc7bece562013-01-25 18:06:21 +0000732size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000733ValueObject::GetNumChildren ()
734{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000735 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000736 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000737 {
738 SetNumChildren (CalculateNumChildren());
739 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000740 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000741}
Greg Clayton4a792072012-10-23 01:50:10 +0000742
743bool
744ValueObject::MightHaveChildren()
745{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000746 bool has_children = false;
Greg Clayton2452ab72013-02-08 22:02:02 +0000747 const uint32_t type_info = GetTypeInfo();
748 if (type_info)
Greg Clayton4a792072012-10-23 01:50:10 +0000749 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000750 if (type_info & (ClangASTType::eTypeHasChildren |
751 ClangASTType::eTypeIsPointer |
752 ClangASTType::eTypeIsReference))
Greg Clayton4a792072012-10-23 01:50:10 +0000753 has_children = true;
754 }
755 else
756 {
757 has_children = GetNumChildren () > 0;
758 }
759 return has_children;
760}
761
762// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000763void
Greg Claytonc7bece562013-01-25 18:06:21 +0000764ValueObject::SetNumChildren (size_t num_children)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000765{
Greg Clayton288bdf92010-09-02 02:59:18 +0000766 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000767 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000768}
769
770void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000771ValueObject::SetName (const ConstString &name)
772{
773 m_name = name;
774}
775
Jim Ingham58b59f92011-04-22 23:53:53 +0000776ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000777ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000778{
Jim Ingham2eec4872011-05-07 00:10:58 +0000779 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000780
Greg Claytondea8cb42011-06-29 22:09:02 +0000781 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000782 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000783 std::string child_name_str;
784 uint32_t child_byte_size = 0;
785 int32_t child_byte_offset = 0;
786 uint32_t child_bitfield_bit_size = 0;
787 uint32_t child_bitfield_bit_offset = 0;
788 bool child_is_base_class = false;
789 bool child_is_deref_of_parent = false;
790
791 const bool transparent_pointers = synthetic_array_member == false;
Greg Clayton57ee3062013-07-11 22:46:58 +0000792 ClangASTType child_clang_type;
Greg Claytondea8cb42011-06-29 22:09:02 +0000793
Greg Claytoncc4d0142012-02-17 07:49:44 +0000794 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000795
Greg Clayton57ee3062013-07-11 22:46:58 +0000796 child_clang_type = GetClangType().GetChildClangTypeAtIndex (&exe_ctx,
797 GetName().GetCString(),
798 idx,
799 transparent_pointers,
800 omit_empty_base_classes,
801 ignore_array_bounds,
802 child_name_str,
803 child_byte_size,
804 child_byte_offset,
805 child_bitfield_bit_size,
806 child_bitfield_bit_offset,
807 child_is_base_class,
808 child_is_deref_of_parent);
Greg Clayton4ef877f2012-12-06 02:33:54 +0000809 if (child_clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000810 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000811 if (synthetic_index)
812 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000813
Greg Claytondea8cb42011-06-29 22:09:02 +0000814 ConstString child_name;
815 if (!child_name_str.empty())
816 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000817
Greg Claytondea8cb42011-06-29 22:09:02 +0000818 valobj = new ValueObjectChild (*this,
Greg Claytondea8cb42011-06-29 22:09:02 +0000819 child_clang_type,
820 child_name,
821 child_byte_size,
822 child_byte_offset,
823 child_bitfield_bit_size,
824 child_bitfield_bit_offset,
825 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000826 child_is_deref_of_parent,
827 eAddressTypeInvalid);
828 //if (valobj)
829 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
830 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000831
Jim Ingham58b59f92011-04-22 23:53:53 +0000832 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000833}
834
Enrico Granata0c489f52012-03-01 04:24:26 +0000835bool
836ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
837 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000838{
Enrico Granata0c489f52012-03-01 04:24:26 +0000839 destination.clear();
840
841 // ideally we would like to bail out if passing NULL, but if we do so
842 // we end up not providing the summary for function pointers anymore
843 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
844 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000845
846 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000847
848 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
849 // information that we might care to see in a crash log. might be useful in very specific situations though.
850 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
851 GetTypeName().GetCString(),
852 GetName().GetCString(),
853 summary_ptr->GetDescription().c_str());*/
854
Enrico Granata0c489f52012-03-01 04:24:26 +0000855 if (UpdateValueIfNeeded (false))
856 {
857 if (summary_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000858 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000859 if (HasSyntheticValue())
860 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
861 summary_ptr->FormatObject(this, destination);
Enrico Granata0c489f52012-03-01 04:24:26 +0000862 }
863 else
864 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000865 ClangASTType clang_type = GetClangType();
Enrico Granata0c489f52012-03-01 04:24:26 +0000866
867 // Do some default printout for function pointers
868 if (clang_type)
Enrico Granata4becb372011-06-29 22:27:15 +0000869 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000870 if (clang_type.IsFunctionPointerType ())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000871 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000872 StreamString sstr;
Enrico Granata0c489f52012-03-01 04:24:26 +0000873 AddressType func_ptr_address_type = eAddressTypeInvalid;
874 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
875 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000876 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000877 switch (func_ptr_address_type)
Jim Ingham6035b672011-03-31 00:19:25 +0000878 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000879 case eAddressTypeInvalid:
880 case eAddressTypeFile:
881 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000882
Greg Claytoncc4d0142012-02-17 07:49:44 +0000883 case eAddressTypeLoad:
Enrico Granata0c489f52012-03-01 04:24:26 +0000884 {
885 ExecutionContext exe_ctx (GetExecutionContextRef());
886
887 Address so_addr;
888 Target *target = exe_ctx.GetTargetPtr();
889 if (target && target->GetSectionLoadList().IsEmpty() == false)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000890 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000891 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000892 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000893 so_addr.Dump (&sstr,
894 exe_ctx.GetBestExecutionContextScope(),
895 Address::DumpStyleResolvedDescription,
896 Address::DumpStyleSectionNameOffset);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000897 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000898 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000899 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000900 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000901
Greg Claytoncc4d0142012-02-17 07:49:44 +0000902 case eAddressTypeHost:
903 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +0000904 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000905 }
906 if (sstr.GetSize() > 0)
907 {
908 destination.assign (1, '(');
909 destination.append (sstr.GetData(), sstr.GetSize());
910 destination.append (1, ')');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000911 }
912 }
913 }
914 }
915 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000916 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000917 return !destination.empty();
918}
919
920const char *
921ValueObject::GetSummaryAsCString ()
922{
923 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
924 {
925 GetSummaryAsCString(GetSummaryFormat().get(),
926 m_summary_str);
927 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000928 if (m_summary_str.empty())
929 return NULL;
930 return m_summary_str.c_str();
931}
932
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000933bool
934ValueObject::IsCStringContainer(bool check_pointer)
935{
Greg Clayton57ee3062013-07-11 22:46:58 +0000936 ClangASTType pointee_or_element_clang_type;
937 const Flags type_flags (GetTypeInfo (&pointee_or_element_clang_type));
938 bool is_char_arr_ptr (type_flags.AnySet (ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer) &&
939 pointee_or_element_clang_type.IsCharType ());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000940 if (!is_char_arr_ptr)
941 return false;
942 if (!check_pointer)
943 return true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000944 if (type_flags.Test(ClangASTType::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000945 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000946 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000947 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000948 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000949 return (cstr_address != LLDB_INVALID_ADDRESS);
950}
951
Enrico Granata9128ee22011-09-06 19:20:51 +0000952size_t
953ValueObject::GetPointeeData (DataExtractor& data,
954 uint32_t item_idx,
955 uint32_t item_count)
956{
Greg Clayton57ee3062013-07-11 22:46:58 +0000957 ClangASTType pointee_or_element_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +0000958 const uint32_t type_info = GetTypeInfo (&pointee_or_element_clang_type);
Greg Clayton57ee3062013-07-11 22:46:58 +0000959 const bool is_pointer_type = type_info & ClangASTType::eTypeIsPointer;
960 const bool is_array_type = type_info & ClangASTType::eTypeIsArray;
Greg Clayton2452ab72013-02-08 22:02:02 +0000961 if (!(is_pointer_type || is_array_type))
Enrico Granata9128ee22011-09-06 19:20:51 +0000962 return 0;
963
964 if (item_count == 0)
965 return 0;
966
Greg Clayton57ee3062013-07-11 22:46:58 +0000967 const uint64_t item_type_size = pointee_or_element_clang_type.GetByteSize();
Enrico Granata9128ee22011-09-06 19:20:51 +0000968 const uint64_t bytes = item_count * item_type_size;
Enrico Granata9128ee22011-09-06 19:20:51 +0000969 const uint64_t offset = item_idx * item_type_size;
970
971 if (item_idx == 0 && item_count == 1) // simply a deref
972 {
Greg Clayton2452ab72013-02-08 22:02:02 +0000973 if (is_pointer_type)
Enrico Granata9128ee22011-09-06 19:20:51 +0000974 {
975 Error error;
976 ValueObjectSP pointee_sp = Dereference(error);
977 if (error.Fail() || pointee_sp.get() == NULL)
978 return 0;
979 return pointee_sp->GetDataExtractor().Copy(data);
980 }
981 else
982 {
983 ValueObjectSP child_sp = GetChildAtIndex(0, true);
984 if (child_sp.get() == NULL)
985 return 0;
986 return child_sp->GetDataExtractor().Copy(data);
987 }
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);
1032 if (error.Success())
1033 {
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
Enrico Granata9128ee22011-09-06 19:20:51 +00001060ValueObject::GetData (DataExtractor& data)
1061{
1062 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001063 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Clayton57ee3062013-07-11 22:46:58 +00001064 Error 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
1390ValueObject::GetValueAsCString (lldb::Format format,
1391 std::string& destination)
1392{
Greg Clayton57ee3062013-07-11 22:46:58 +00001393 if (GetClangType().IsAggregateType () == false && UpdateValueIfNeeded(false))
Enrico Granata0c489f52012-03-01 04:24:26 +00001394 {
1395 const Value::ContextType context_type = m_value.GetContextType();
1396
Greg Clayton57ee3062013-07-11 22:46:58 +00001397 if (context_type == Value::eContextTypeRegisterInfo)
Enrico Granata0c489f52012-03-01 04:24:26 +00001398 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001399 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1400 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001401 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001402 ExecutionContext exe_ctx (GetExecutionContextRef());
1403
1404 StreamString reg_sstr;
1405 m_data.Dump (&reg_sstr,
1406 0,
1407 format,
1408 reg_info->byte_size,
1409 1,
1410 UINT32_MAX,
1411 LLDB_INVALID_ADDRESS,
1412 0,
1413 0,
1414 exe_ctx.GetBestExecutionContextScope());
1415 destination.swap(reg_sstr.GetString());
1416 }
1417 }
1418 else
1419 {
1420 ClangASTType clang_type = GetClangType ();
1421 if (clang_type)
1422 {
1423 // put custom bytes to display in this DataExtractor to override the default value logic
1424 lldb_private::DataExtractor special_format_data;
1425 if (format == eFormatCString)
Enrico Granata0c489f52012-03-01 04:24:26 +00001426 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001427 Flags type_flags(clang_type.GetTypeInfo(NULL));
1428 if (type_flags.Test(ClangASTType::eTypeIsPointer) && !type_flags.Test(ClangASTType::eTypeIsObjC))
Enrico Granata852cce72013-03-23 01:12:38 +00001429 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001430 // if we are dumping a pointer as a c-string, get the pointee data as a string
1431 TargetSP target_sp(GetTargetSP());
1432 if (target_sp)
Enrico Granata852cce72013-03-23 01:12:38 +00001433 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001434 size_t max_len = target_sp->GetMaximumSizeOfStringSummary();
1435 Error error;
1436 DataBufferSP buffer_sp(new DataBufferHeap(max_len+1,0));
1437 Address address(GetPointerValue());
1438 if (target_sp->ReadCStringFromMemory(address, (char*)buffer_sp->GetBytes(), max_len, error) && error.Success())
1439 special_format_data.SetData(buffer_sp);
Enrico Granata852cce72013-03-23 01:12:38 +00001440 }
1441 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001442 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001443
Greg Clayton57ee3062013-07-11 22:46:58 +00001444 StreamString sstr;
1445 ExecutionContext exe_ctx (GetExecutionContextRef());
1446 clang_type.DumpTypeValue (&sstr, // The stream to use for display
1447 format, // Format to display this type with
1448 special_format_data.GetByteSize() ?
1449 special_format_data: m_data, // Data to extract from
1450 0, // Byte offset into "m_data"
1451 GetByteSize(), // Byte size of item in "m_data"
1452 GetBitfieldBitSize(), // Bitfield bit size
1453 GetBitfieldBitOffset(), // Bitfield bit offset
1454 exe_ctx.GetBestExecutionContextScope());
1455 // Don't set the m_error to anything here otherwise
1456 // we won't be able to re-format as anything else. The
1457 // code for ClangASTType::DumpTypeValue() should always
1458 // return something, even if that something contains
1459 // an error messsage. "m_error" is used to detect errors
1460 // when reading the valid object, not for formatting errors.
1461 if (sstr.GetString().empty())
1462 destination.clear();
1463 else
1464 destination.swap(sstr.GetString());
Enrico Granata0c489f52012-03-01 04:24:26 +00001465 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001466 }
1467 return !destination.empty();
1468 }
1469 else
1470 return false;
1471}
1472
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001473const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001474ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001475{
Enrico Granatab294fd22013-05-31 19:18:19 +00001476 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001477 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001478 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001479 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001480 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001481 if (m_type_format_sp)
1482 my_format = m_type_format_sp->GetFormat();
1483 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001484 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001485 if (m_is_bitfield_for_scalar)
1486 my_format = eFormatUnsigned;
1487 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001488 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001489 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001490 {
1491 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1492 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001493 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001494 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001495 else
1496 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001497 my_format = GetClangType().GetFormat();
Enrico Granata0c489f52012-03-01 04:24:26 +00001498 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001499 }
1500 }
1501 }
Enrico Granatab294fd22013-05-31 19:18:19 +00001502 if (my_format != m_last_format || m_value_str.empty())
Enrico Granata297e69f2012-03-06 23:21:16 +00001503 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001504 m_last_format = my_format;
1505 if (GetValueAsCString(my_format, m_value_str))
Enrico Granata297e69f2012-03-06 23:21:16 +00001506 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001507 if (!m_value_did_change && m_old_value_valid)
1508 {
1509 // The value was gotten successfully, so we consider the
1510 // value as changed if the value string differs
1511 SetValueDidChange (m_old_value_str != m_value_str);
1512 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001513 }
1514 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001515 }
1516 if (m_value_str.empty())
1517 return NULL;
1518 return m_value_str.c_str();
1519}
1520
Enrico Granatac3e320a2011-08-02 17:27:39 +00001521// if > 8bytes, 0 is returned. this method should mostly be used
1522// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001523uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001524ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001525{
1526 // If our byte size is zero this is an aggregate type that has children
Greg Clayton57ee3062013-07-11 22:46:58 +00001527 if (!GetClangType().IsAggregateType())
Enrico Granatac3e320a2011-08-02 17:27:39 +00001528 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001529 Scalar scalar;
1530 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001531 {
1532 if (success)
1533 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001534 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001535 }
1536 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001537 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001538
1539 if (success)
1540 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001541 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001542}
1543
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001544// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1545// this call up to date by returning true for your new special cases. We will eventually move
1546// to checking this call result before trying to display special cases
1547bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001548ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1549 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001550{
Greg Clayton57ee3062013-07-11 22:46:58 +00001551 Flags flags(GetTypeInfo());
1552 if (flags.AnySet(ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001553 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001554 {
1555 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001556 (custom_format == eFormatCString ||
1557 custom_format == eFormatCharArray ||
1558 custom_format == eFormatChar ||
1559 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001560 return true;
1561
Greg Clayton57ee3062013-07-11 22:46:58 +00001562 if (flags.Test(ClangASTType::eTypeIsArray))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001563 {
Greg Claytonafacd142011-09-02 01:15:17 +00001564 if ((custom_format == eFormatBytes) ||
1565 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001566 return true;
1567
Greg Claytonafacd142011-09-02 01:15:17 +00001568 if ((custom_format == eFormatVectorOfChar) ||
1569 (custom_format == eFormatVectorOfFloat32) ||
1570 (custom_format == eFormatVectorOfFloat64) ||
1571 (custom_format == eFormatVectorOfSInt16) ||
1572 (custom_format == eFormatVectorOfSInt32) ||
1573 (custom_format == eFormatVectorOfSInt64) ||
1574 (custom_format == eFormatVectorOfSInt8) ||
1575 (custom_format == eFormatVectorOfUInt128) ||
1576 (custom_format == eFormatVectorOfUInt16) ||
1577 (custom_format == eFormatVectorOfUInt32) ||
1578 (custom_format == eFormatVectorOfUInt64) ||
1579 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001580 return true;
1581 }
1582 }
1583 return false;
1584}
1585
Enrico Granata9fc19442011-07-06 02:13:41 +00001586bool
1587ValueObject::DumpPrintableRepresentation(Stream& s,
1588 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001589 Format custom_format,
Enrico Granata86cc9822012-03-19 22:58:49 +00001590 PrintableRepresentationSpecialCases special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001591{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001592
Greg Clayton57ee3062013-07-11 22:46:58 +00001593 Flags flags(GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001594
Enrico Granata86cc9822012-03-19 22:58:49 +00001595 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1596 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1597
1598 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001599 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001600 if (flags.AnySet(ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001601 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001602 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001603 // when being asked to get a printable display an array or pointer type directly,
1604 // try to "do the right thing"
1605
1606 if (IsCStringContainer(true) &&
1607 (custom_format == eFormatCString ||
1608 custom_format == eFormatCharArray ||
1609 custom_format == eFormatChar ||
1610 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001611 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001612 Error error;
1613 ReadPointedString(s,
1614 error,
1615 0,
1616 (custom_format == eFormatVectorOfChar) ||
1617 (custom_format == eFormatCharArray));
1618 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001619 }
1620
Enrico Granata86cc9822012-03-19 22:58:49 +00001621 if (custom_format == eFormatEnum)
1622 return false;
1623
1624 // this only works for arrays, because I have no way to know when
1625 // the pointed memory ends, and no special \0 end of data marker
Greg Clayton57ee3062013-07-11 22:46:58 +00001626 if (flags.Test(ClangASTType::eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001627 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001628 if ((custom_format == eFormatBytes) ||
1629 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001630 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001631 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001632
1633 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001634 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001635 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001636
1637 if (low)
1638 s << ',';
1639
1640 ValueObjectSP child = GetChildAtIndex(low,true);
1641 if (!child.get())
1642 {
1643 s << "<invalid child>";
1644 continue;
1645 }
1646 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1647 }
1648
1649 s << ']';
1650
1651 return true;
1652 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001653
Enrico Granata86cc9822012-03-19 22:58:49 +00001654 if ((custom_format == eFormatVectorOfChar) ||
1655 (custom_format == eFormatVectorOfFloat32) ||
1656 (custom_format == eFormatVectorOfFloat64) ||
1657 (custom_format == eFormatVectorOfSInt16) ||
1658 (custom_format == eFormatVectorOfSInt32) ||
1659 (custom_format == eFormatVectorOfSInt64) ||
1660 (custom_format == eFormatVectorOfSInt8) ||
1661 (custom_format == eFormatVectorOfUInt128) ||
1662 (custom_format == eFormatVectorOfUInt16) ||
1663 (custom_format == eFormatVectorOfUInt32) ||
1664 (custom_format == eFormatVectorOfUInt64) ||
1665 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1666 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001667 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001668
1669 Format format = FormatManager::GetSingleItemFormat(custom_format);
1670
1671 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001672 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001673 {
1674
1675 if (low)
1676 s << ',';
1677
1678 ValueObjectSP child = GetChildAtIndex(low,true);
1679 if (!child.get())
1680 {
1681 s << "<invalid child>";
1682 continue;
1683 }
1684 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1685 }
1686
1687 s << ']';
1688
1689 return true;
1690 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001691 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001692
1693 if ((custom_format == eFormatBoolean) ||
1694 (custom_format == eFormatBinary) ||
1695 (custom_format == eFormatChar) ||
1696 (custom_format == eFormatCharPrintable) ||
1697 (custom_format == eFormatComplexFloat) ||
1698 (custom_format == eFormatDecimal) ||
1699 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001700 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001701 (custom_format == eFormatFloat) ||
1702 (custom_format == eFormatOctal) ||
1703 (custom_format == eFormatOSType) ||
1704 (custom_format == eFormatUnicode16) ||
1705 (custom_format == eFormatUnicode32) ||
1706 (custom_format == eFormatUnsigned) ||
1707 (custom_format == eFormatPointer) ||
1708 (custom_format == eFormatComplexInteger) ||
1709 (custom_format == eFormatComplex) ||
1710 (custom_format == eFormatDefault)) // use the [] operator
1711 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001712 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001713 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001714
1715 if (only_special)
1716 return false;
1717
Enrico Granata86cc9822012-03-19 22:58:49 +00001718 bool var_success = false;
1719
1720 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001721 const char *cstr = NULL;
Enrico Granata2c75f112013-06-21 00:04:51 +00001722
1723 // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1724 // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1725 // area for cases where our desired output is not backed by some other longer-term storage
Greg Claytonc7bece562013-01-25 18:06:21 +00001726 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001727
1728 if (custom_format != eFormatInvalid)
1729 SetFormat(custom_format);
1730
1731 switch(val_obj_display)
1732 {
1733 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001734 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001735 break;
1736
1737 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001738 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001739 break;
1740
1741 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001742 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001743 break;
1744
1745 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001746 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001747 break;
1748
1749 case eValueObjectRepresentationStyleChildrenCount:
Greg Claytonc7bece562013-01-25 18:06:21 +00001750 strm.Printf("%zu", GetNumChildren());
1751 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001752 break;
1753
1754 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001755 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001756 break;
Enrico Granata2c75f112013-06-21 00:04:51 +00001757
1758 case eValueObjectRepresentationStyleName:
1759 cstr = GetName().AsCString();
1760 break;
1761
1762 case eValueObjectRepresentationStyleExpressionPath:
1763 GetExpressionPath(strm, false);
1764 cstr = strm.GetString().c_str();
1765 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001766 }
1767
Greg Claytonc7bece562013-01-25 18:06:21 +00001768 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001769 {
1770 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001771 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001772 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1773 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001774 if (GetClangType().IsAggregateType())
Enrico Granata86cc9822012-03-19 22:58:49 +00001775 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001776 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1777 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001778 }
1779 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001780 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001781 }
1782 }
1783
Greg Claytonc7bece562013-01-25 18:06:21 +00001784 if (cstr)
1785 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001786 else
1787 {
1788 if (m_error.Fail())
1789 s.Printf("<%s>", m_error.AsCString());
1790 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1791 s.PutCString("<no summary available>");
1792 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1793 s.PutCString("<no value available>");
1794 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1795 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1796 else
1797 s.PutCString("<no printable representation>");
1798 }
1799
1800 // we should only return false here if we could not do *anything*
1801 // even if we have an error message as output, that's a success
1802 // from our callers' perspective, so return true
1803 var_success = true;
1804
1805 if (custom_format != eFormatInvalid)
1806 SetFormat(eFormatDefault);
1807 }
1808
Enrico Granataf4efecd2011-07-12 22:56:10 +00001809 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001810}
1811
Greg Clayton737b9322010-09-13 03:32:57 +00001812addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001813ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001814{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001815 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001816 return LLDB_INVALID_ADDRESS;
1817
Greg Clayton73b472d2010-10-27 03:32:59 +00001818 switch (m_value.GetValueType())
1819 {
1820 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001821 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001822 if (scalar_is_load_address)
1823 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001824 if(address_type)
1825 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001826 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1827 }
1828 break;
1829
1830 case Value::eValueTypeLoadAddress:
1831 case Value::eValueTypeFileAddress:
1832 case Value::eValueTypeHostAddress:
1833 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001834 if(address_type)
1835 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001836 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1837 }
1838 break;
1839 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001840 if (address_type)
1841 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001842 return LLDB_INVALID_ADDRESS;
1843}
1844
1845addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001846ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001847{
Greg Claytonafacd142011-09-02 01:15:17 +00001848 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001849 if(address_type)
1850 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001851
Enrico Granatac3e320a2011-08-02 17:27:39 +00001852 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001853 return address;
1854
Greg Clayton73b472d2010-10-27 03:32:59 +00001855 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001856 {
1857 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001858 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001859 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001860 break;
1861
Enrico Granata9128ee22011-09-06 19:20:51 +00001862 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001863 case Value::eValueTypeLoadAddress:
1864 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001865 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001866 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001867 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001868 }
1869 break;
1870 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001871
Enrico Granata9128ee22011-09-06 19:20:51 +00001872 if (address_type)
1873 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001874
Greg Clayton737b9322010-09-13 03:32:57 +00001875 return address;
1876}
1877
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001878bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001879ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001880{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001881 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001882 // Make sure our value is up to date first so that our location and location
1883 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001884 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001885 {
1886 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001887 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001888 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001889
Greg Claytonfaac1112013-03-14 18:31:44 +00001890 uint64_t count = 0;
Greg Clayton57ee3062013-07-11 22:46:58 +00001891 const Encoding encoding = GetClangType().GetEncoding (count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001892
Greg Claytonb1320972010-07-14 00:18:15 +00001893 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001894
Jim Ingham16e0c682011-08-12 23:34:31 +00001895 Value::ValueType value_type = m_value.GetValueType();
1896
1897 if (value_type == Value::eValueTypeScalar)
1898 {
1899 // If the value is already a scalar, then let the scalar change itself:
1900 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1901 }
1902 else if (byte_size <= Scalar::GetMaxByteSize())
1903 {
1904 // If the value fits in a scalar, then make a new scalar and again let the
1905 // scalar code do the conversion, then figure out where to put the new value.
1906 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001907 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1908 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001909 {
Jim Ingham4b536182011-08-09 02:12:22 +00001910 switch (value_type)
1911 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001912 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001913 {
1914 // If it is a load address, then the scalar value is the storage location
1915 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001916 ExecutionContext exe_ctx (GetExecutionContextRef());
1917 Process *process = exe_ctx.GetProcessPtr();
1918 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001919 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001920 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001921 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1922 new_scalar,
1923 byte_size,
1924 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001925 if (!error.Success())
1926 return false;
1927 if (bytes_written != byte_size)
1928 {
1929 error.SetErrorString("unable to write value to memory");
1930 return false;
1931 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001932 }
1933 }
Jim Ingham4b536182011-08-09 02:12:22 +00001934 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001935 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001936 {
1937 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1938 DataExtractor new_data;
1939 new_data.SetByteOrder (m_data.GetByteOrder());
1940
1941 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1942 m_data.SetData(buffer_sp, 0);
1943 bool success = new_scalar.GetData(new_data);
1944 if (success)
1945 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001946 new_data.CopyByteOrderedData (0,
1947 byte_size,
1948 const_cast<uint8_t *>(m_data.GetDataStart()),
1949 byte_size,
1950 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001951 }
1952 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1953
1954 }
Jim Ingham4b536182011-08-09 02:12:22 +00001955 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001956 case Value::eValueTypeFileAddress:
1957 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001958 case Value::eValueTypeVector:
1959 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001960 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001961 }
1962 else
1963 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001964 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001965 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001966 }
1967 else
1968 {
1969 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001970 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001971 return false;
1972 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001973
1974 // If we have reached this point, then we have successfully changed the value.
1975 SetNeedsUpdate();
1976 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001977}
1978
Greg Clayton81e871e2012-02-04 02:27:34 +00001979bool
1980ValueObject::GetDeclaration (Declaration &decl)
1981{
1982 decl.Clear();
1983 return false;
1984}
1985
Greg Clayton84db9102012-03-26 23:03:23 +00001986ConstString
1987ValueObject::GetTypeName()
1988{
Greg Clayton57ee3062013-07-11 22:46:58 +00001989 return GetClangType().GetConstTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00001990}
1991
1992ConstString
1993ValueObject::GetQualifiedTypeName()
1994{
Greg Clayton57ee3062013-07-11 22:46:58 +00001995 return GetClangType().GetConstQualifiedTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00001996}
1997
1998
Greg Claytonafacd142011-09-02 01:15:17 +00001999LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00002000ValueObject::GetObjectRuntimeLanguage ()
2001{
Greg Clayton57ee3062013-07-11 22:46:58 +00002002 return GetClangType().GetMinimumLanguage ();
Jim Ingham5a369122010-09-28 01:25:32 +00002003}
2004
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002005void
Jim Ingham58b59f92011-04-22 23:53:53 +00002006ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002007{
Jim Ingham58b59f92011-04-22 23:53:53 +00002008 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002009}
2010
2011ValueObjectSP
2012ValueObject::GetSyntheticChild (const ConstString &key) const
2013{
2014 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00002015 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002016 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00002017 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002018 return synthetic_child_sp;
2019}
2020
Greg Clayton2452ab72013-02-08 22:02:02 +00002021uint32_t
Greg Clayton57ee3062013-07-11 22:46:58 +00002022ValueObject::GetTypeInfo (ClangASTType *pointee_or_element_clang_type)
Greg Clayton2452ab72013-02-08 22:02:02 +00002023{
Greg Clayton57ee3062013-07-11 22:46:58 +00002024 return GetClangType().GetTypeInfo (pointee_or_element_clang_type);
Greg Clayton2452ab72013-02-08 22:02:02 +00002025}
2026
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002027bool
2028ValueObject::IsPointerType ()
2029{
Greg Clayton57ee3062013-07-11 22:46:58 +00002030 return GetClangType().IsPointerType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002031}
2032
Jim Inghamb7603bb2011-03-18 00:05:18 +00002033bool
Greg Claytondaf515f2011-07-09 20:12:33 +00002034ValueObject::IsArrayType ()
2035{
Greg Clayton57ee3062013-07-11 22:46:58 +00002036 return GetClangType().IsArrayType (NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00002037}
2038
2039bool
Enrico Granata9fc19442011-07-06 02:13:41 +00002040ValueObject::IsScalarType ()
2041{
Greg Clayton57ee3062013-07-11 22:46:58 +00002042 return GetClangType().IsScalarType ();
Enrico Granata9fc19442011-07-06 02:13:41 +00002043}
2044
2045bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00002046ValueObject::IsIntegerType (bool &is_signed)
2047{
Greg Clayton57ee3062013-07-11 22:46:58 +00002048 return GetClangType().IsIntegerType (is_signed);
Jim Inghamb7603bb2011-03-18 00:05:18 +00002049}
Greg Clayton73b472d2010-10-27 03:32:59 +00002050
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002051bool
2052ValueObject::IsPointerOrReferenceType ()
2053{
Greg Clayton57ee3062013-07-11 22:46:58 +00002054 return GetClangType().IsPointerOrReferenceType ();
Greg Clayton007d5be2011-05-30 00:49:24 +00002055}
2056
2057bool
Greg Claytondea8cb42011-06-29 22:09:02 +00002058ValueObject::IsPossibleDynamicType ()
2059{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002060 ExecutionContext exe_ctx (GetExecutionContextRef());
2061 Process *process = exe_ctx.GetProcessPtr();
2062 if (process)
2063 return process->IsPossibleDynamicValue(*this);
2064 else
Greg Clayton57ee3062013-07-11 22:46:58 +00002065 return GetClangType().IsPossibleDynamicType (NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00002066}
2067
Enrico Granata9e7b3882012-12-13 23:50:33 +00002068bool
2069ValueObject::IsObjCNil ()
2070{
Greg Clayton57ee3062013-07-11 22:46:58 +00002071 const uint32_t mask = ClangASTType::eTypeIsObjC | ClangASTType::eTypeIsPointer;
2072 bool isObjCpointer = (((GetClangType().GetTypeInfo(NULL)) & mask) == mask);
Enrico Granata7277d202013-03-15 23:33:15 +00002073 if (!isObjCpointer)
2074 return false;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002075 bool canReadValue = true;
2076 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
Enrico Granata7277d202013-03-15 23:33:15 +00002077 return canReadValue && isZero;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002078}
2079
Greg Claytonafacd142011-09-02 01:15:17 +00002080ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002081ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002082{
Greg Clayton2452ab72013-02-08 22:02:02 +00002083 const uint32_t type_info = GetTypeInfo ();
Greg Clayton57ee3062013-07-11 22:46:58 +00002084 if (type_info & ClangASTType::eTypeIsArray)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002085 return GetSyntheticArrayMemberFromArray(index, can_create);
2086
Greg Clayton57ee3062013-07-11 22:46:58 +00002087 if (type_info & ClangASTType::eTypeIsPointer)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002088 return GetSyntheticArrayMemberFromPointer(index, can_create);
2089
2090 return ValueObjectSP();
2091
2092}
2093
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002094ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002095ValueObject::GetSyntheticArrayMemberFromPointer (size_t index, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002096{
2097 ValueObjectSP synthetic_child_sp;
2098 if (IsPointerType ())
2099 {
2100 char index_str[64];
Greg Claytonc7bece562013-01-25 18:06:21 +00002101 snprintf(index_str, sizeof(index_str), "[%zu]", index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002102 ConstString index_const_str(index_str);
2103 // Check if we have already created a synthetic array member in this
2104 // valid object. If we have we will re-use it.
2105 synthetic_child_sp = GetSyntheticChild (index_const_str);
2106 if (!synthetic_child_sp)
2107 {
Jim Ingham58b59f92011-04-22 23:53:53 +00002108 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002109 // We haven't made a synthetic array member for INDEX yet, so
2110 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00002111 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002112
2113 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00002114 if (synthetic_child)
2115 {
2116 AddSyntheticChild(index_const_str, synthetic_child);
2117 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002118 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00002119 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00002120 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002121 }
2122 }
2123 return synthetic_child_sp;
2124}
Jim Ingham22777012010-09-23 02:01:19 +00002125
Greg Claytondaf515f2011-07-09 20:12:33 +00002126// This allows you to create an array member using and index
2127// that doesn't not fall in the normal bounds of the array.
2128// Many times structure can be defined as:
2129// struct Collection
2130// {
2131// uint32_t item_count;
2132// Item item_array[0];
2133// };
2134// The size of the "item_array" is 1, but many times in practice
2135// there are more items in "item_array".
2136
2137ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002138ValueObject::GetSyntheticArrayMemberFromArray (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00002139{
2140 ValueObjectSP synthetic_child_sp;
2141 if (IsArrayType ())
2142 {
2143 char index_str[64];
Greg Claytonc7bece562013-01-25 18:06:21 +00002144 snprintf(index_str, sizeof(index_str), "[%zu]", index);
Greg Claytondaf515f2011-07-09 20:12:33 +00002145 ConstString index_const_str(index_str);
2146 // Check if we have already created a synthetic array member in this
2147 // valid object. If we have we will re-use it.
2148 synthetic_child_sp = GetSyntheticChild (index_const_str);
2149 if (!synthetic_child_sp)
2150 {
2151 ValueObject *synthetic_child;
2152 // We haven't made a synthetic array member for INDEX yet, so
2153 // lets make one and cache it for any future reference.
2154 synthetic_child = CreateChildAtIndex(0, true, index);
2155
2156 // Cache the value if we got one back...
2157 if (synthetic_child)
2158 {
2159 AddSyntheticChild(index_const_str, synthetic_child);
2160 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002161 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00002162 synthetic_child_sp->m_is_array_item_for_pointer = true;
2163 }
2164 }
2165 }
2166 return synthetic_child_sp;
2167}
2168
Enrico Granata9fc19442011-07-06 02:13:41 +00002169ValueObjectSP
2170ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2171{
2172 ValueObjectSP synthetic_child_sp;
2173 if (IsScalarType ())
2174 {
2175 char index_str[64];
2176 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2177 ConstString index_const_str(index_str);
2178 // Check if we have already created a synthetic array member in this
2179 // valid object. If we have we will re-use it.
2180 synthetic_child_sp = GetSyntheticChild (index_const_str);
2181 if (!synthetic_child_sp)
2182 {
Enrico Granata9fc19442011-07-06 02:13:41 +00002183 // We haven't made a synthetic array member for INDEX yet, so
2184 // lets make one and cache it for any future reference.
Greg Clayton57ee3062013-07-11 22:46:58 +00002185 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
2186 GetClangType(),
2187 index_const_str,
2188 GetByteSize(),
2189 0,
2190 to-from+1,
2191 from,
2192 false,
2193 false,
2194 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002195
2196 // Cache the value if we got one back...
2197 if (synthetic_child)
2198 {
2199 AddSyntheticChild(index_const_str, synthetic_child);
2200 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002201 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002202 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2203 }
2204 }
2205 }
2206 return synthetic_child_sp;
2207}
2208
Greg Claytonafacd142011-09-02 01:15:17 +00002209ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00002210ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
2211{
2212
2213 ValueObjectSP synthetic_child_sp;
2214
2215 char name_str[64];
2216 snprintf(name_str, sizeof(name_str), "@%i", offset);
2217 ConstString name_const_str(name_str);
2218
2219 // Check if we have already created a synthetic array member in this
2220 // valid object. If we have we will re-use it.
2221 synthetic_child_sp = GetSyntheticChild (name_const_str);
2222
2223 if (synthetic_child_sp.get())
2224 return synthetic_child_sp;
2225
2226 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002227 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002228
2229 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
Greg Clayton57ee3062013-07-11 22:46:58 +00002230 type,
Enrico Granata6f3533f2011-07-29 19:53:35 +00002231 name_const_str,
Greg Clayton57ee3062013-07-11 22:46:58 +00002232 type.GetByteSize(),
Enrico Granata6f3533f2011-07-29 19:53:35 +00002233 offset,
2234 0,
2235 0,
2236 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002237 false,
2238 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002239 if (synthetic_child)
2240 {
2241 AddSyntheticChild(name_const_str, synthetic_child);
2242 synthetic_child_sp = synthetic_child->GetSP();
2243 synthetic_child_sp->SetName(name_const_str);
2244 synthetic_child_sp->m_is_child_at_offset = true;
2245 }
2246 return synthetic_child_sp;
2247}
2248
Enrico Granatad55546b2011-07-22 00:16:08 +00002249// your expression path needs to have a leading . or ->
2250// (unless it somehow "looks like" an array, in which case it has
2251// a leading [ symbol). while the [ is meaningful and should be shown
2252// to the user, . and -> are just parser design, but by no means
2253// added information for the user.. strip them off
2254static const char*
2255SkipLeadingExpressionPathSeparators(const char* expression)
2256{
2257 if (!expression || !expression[0])
2258 return expression;
2259 if (expression[0] == '.')
2260 return expression+1;
2261 if (expression[0] == '-' && expression[1] == '>')
2262 return expression+2;
2263 return expression;
2264}
2265
Greg Claytonafacd142011-09-02 01:15:17 +00002266ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002267ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2268{
2269 ValueObjectSP synthetic_child_sp;
2270 ConstString name_const_string(expression);
2271 // Check if we have already created a synthetic array member in this
2272 // valid object. If we have we will re-use it.
2273 synthetic_child_sp = GetSyntheticChild (name_const_string);
2274 if (!synthetic_child_sp)
2275 {
2276 // We haven't made a synthetic array member for expression yet, so
2277 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002278 synthetic_child_sp = GetValueForExpressionPath(expression,
2279 NULL, NULL, NULL,
2280 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
Enrico Granatad55546b2011-07-22 00:16:08 +00002281
2282 // Cache the value if we got one back...
2283 if (synthetic_child_sp.get())
2284 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002285 // 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 +00002286 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002287 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002288 }
2289 }
2290 return synthetic_child_sp;
2291}
2292
2293void
Enrico Granata86cc9822012-03-19 22:58:49 +00002294ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002295{
Enrico Granata86cc9822012-03-19 22:58:49 +00002296 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002297 return;
2298
Enrico Granatac5bc4122012-03-27 02:35:13 +00002299 TargetSP target_sp(GetTargetSP());
Enrico Granata5d5f60c2013-09-24 22:58:37 +00002300 if (target_sp && target_sp->GetEnableSyntheticValue() == false)
Enrico Granatac5bc4122012-03-27 02:35:13 +00002301 {
2302 m_synthetic_value = NULL;
2303 return;
2304 }
2305
Enrico Granatae3e91512012-10-22 18:18:36 +00002306 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2307
Enrico Granata5548cb52013-01-28 23:47:25 +00002308 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002309 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002310
Enrico Granata0c489f52012-03-01 04:24:26 +00002311 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002312 return;
2313
Enrico Granatae3e91512012-10-22 18:18:36 +00002314 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2315 return;
2316
Enrico Granata86cc9822012-03-19 22:58:49 +00002317 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002318}
2319
Jim Ingham78a685a2011-04-16 00:01:13 +00002320void
Greg Claytonafacd142011-09-02 01:15:17 +00002321ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002322{
Greg Claytonafacd142011-09-02 01:15:17 +00002323 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002324 return;
2325
Jim Ingham58b59f92011-04-22 23:53:53 +00002326 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002327 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002328 ExecutionContext exe_ctx (GetExecutionContextRef());
2329 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002330 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002331 {
2332 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002333 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002334 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002335 }
2336}
2337
Jim Ingham58b59f92011-04-22 23:53:53 +00002338ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002339ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002340{
Greg Claytonafacd142011-09-02 01:15:17 +00002341 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002342 return ValueObjectSP();
2343
2344 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002345 {
Jim Ingham2837b762011-05-04 03:43:18 +00002346 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002347 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002348 if (m_dynamic_value)
2349 return m_dynamic_value->GetSP();
2350 else
2351 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002352}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002353
Jim Ingham60dbabb2011-12-08 19:44:08 +00002354ValueObjectSP
2355ValueObject::GetStaticValue()
2356{
2357 return GetSP();
2358}
2359
Enrico Granata886147f2012-05-08 18:47:08 +00002360lldb::ValueObjectSP
2361ValueObject::GetNonSyntheticValue ()
2362{
2363 return GetSP();
2364}
2365
Enrico Granatad55546b2011-07-22 00:16:08 +00002366ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002367ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002368{
Enrico Granata86cc9822012-03-19 22:58:49 +00002369 if (use_synthetic == false)
2370 return ValueObjectSP();
2371
Enrico Granatad55546b2011-07-22 00:16:08 +00002372 CalculateSyntheticValue(use_synthetic);
2373
2374 if (m_synthetic_value)
2375 return m_synthetic_value->GetSP();
2376 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002377 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002378}
2379
Greg Claytone221f822011-01-21 01:59:00 +00002380bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002381ValueObject::HasSyntheticValue()
2382{
Enrico Granata5548cb52013-01-28 23:47:25 +00002383 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002384
Enrico Granata0c489f52012-03-01 04:24:26 +00002385 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002386 return false;
2387
Enrico Granata86cc9822012-03-19 22:58:49 +00002388 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002389
2390 if (m_synthetic_value)
2391 return true;
2392 else
2393 return false;
2394}
2395
2396bool
Greg Claytone221f822011-01-21 01:59:00 +00002397ValueObject::GetBaseClassPath (Stream &s)
2398{
2399 if (IsBaseClass())
2400 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002401 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Clayton57ee3062013-07-11 22:46:58 +00002402 ClangASTType clang_type = GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002403 std::string cxx_class_name;
Greg Clayton57ee3062013-07-11 22:46:58 +00002404 bool this_had_base_class = clang_type.GetCXXClassName (cxx_class_name);
Greg Claytone221f822011-01-21 01:59:00 +00002405 if (this_had_base_class)
2406 {
2407 if (parent_had_base_class)
2408 s.PutCString("::");
2409 s.PutCString(cxx_class_name.c_str());
2410 }
2411 return parent_had_base_class || this_had_base_class;
2412 }
2413 return false;
2414}
2415
2416
2417ValueObject *
2418ValueObject::GetNonBaseClassParent()
2419{
Jim Ingham78a685a2011-04-16 00:01:13 +00002420 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002421 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002422 if (GetParent()->IsBaseClass())
2423 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002424 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002425 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002426 }
2427 return NULL;
2428}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002429
2430void
Enrico Granata4becb372011-06-29 22:27:15 +00002431ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002432{
Greg Claytone221f822011-01-21 01:59:00 +00002433 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002434
Enrico Granata86cc9822012-03-19 22:58:49 +00002435 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002436 {
Enrico Granata4becb372011-06-29 22:27:15 +00002437 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2438 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2439 // the eHonorPointers mode is meant to produce strings in this latter format
2440 s.PutCString("*(");
2441 }
Greg Claytone221f822011-01-21 01:59:00 +00002442
Enrico Granata4becb372011-06-29 22:27:15 +00002443 ValueObject* parent = GetParent();
2444
2445 if (parent)
2446 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002447
2448 // if we are a deref_of_parent just because we are synthetic array
2449 // members made up to allow ptr[%d] syntax to work in variable
2450 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002451 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002452 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002453
Greg Claytone221f822011-01-21 01:59:00 +00002454 if (!IsBaseClass())
2455 {
2456 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002457 {
Greg Claytone221f822011-01-21 01:59:00 +00002458 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2459 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002460 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002461 ClangASTType non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002462 if (non_base_class_parent_clang_type)
2463 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002464 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002465 {
2466 s.PutCString("->");
2467 }
Enrico Granata4becb372011-06-29 22:27:15 +00002468 else
2469 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002470 const uint32_t non_base_class_parent_type_info = non_base_class_parent_clang_type.GetTypeInfo();
2471
2472 if (non_base_class_parent_type_info & ClangASTType::eTypeIsPointer)
Enrico Granata4becb372011-06-29 22:27:15 +00002473 {
2474 s.PutCString("->");
2475 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002476 else if ((non_base_class_parent_type_info & ClangASTType::eTypeHasChildren) &&
2477 !(non_base_class_parent_type_info & ClangASTType::eTypeIsArray))
Enrico Granata4becb372011-06-29 22:27:15 +00002478 {
2479 s.PutChar('.');
2480 }
Greg Claytone221f822011-01-21 01:59:00 +00002481 }
2482 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002483 }
Greg Claytone221f822011-01-21 01:59:00 +00002484
2485 const char *name = GetName().GetCString();
2486 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002487 {
Greg Claytone221f822011-01-21 01:59:00 +00002488 if (qualify_cxx_base_classes)
2489 {
2490 if (GetBaseClassPath (s))
2491 s.PutCString("::");
2492 }
2493 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002494 }
2495 }
2496 }
2497
Enrico Granata86cc9822012-03-19 22:58:49 +00002498 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002499 {
Greg Claytone221f822011-01-21 01:59:00 +00002500 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002501 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002502}
2503
Greg Claytonafacd142011-09-02 01:15:17 +00002504ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002505ValueObject::GetValueForExpressionPath(const char* expression,
2506 const char** first_unparsed,
2507 ExpressionPathScanEndReason* reason_to_stop,
2508 ExpressionPathEndResultType* final_value_type,
2509 const GetValueForExpressionPathOptions& options,
2510 ExpressionPathAftermath* final_task_on_target)
2511{
2512
2513 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002514 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2515 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002516 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002517
2518 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2519 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2520 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2521 final_value_type ? final_value_type : &dummy_final_value_type,
2522 options,
2523 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2524
Enrico Granata86cc9822012-03-19 22:58:49 +00002525 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002526 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002527
Enrico Granata86cc9822012-03-19 22:58:49 +00002528 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 +00002529 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002530 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002531 {
2532 Error error;
2533 ValueObjectSP final_value = ret_val->Dereference(error);
2534 if (error.Fail() || !final_value.get())
2535 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002536 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002537 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002538 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002539 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002540 return ValueObjectSP();
2541 }
2542 else
2543 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002544 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002545 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002546 return final_value;
2547 }
2548 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002549 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002550 {
2551 Error error;
2552 ValueObjectSP final_value = ret_val->AddressOf(error);
2553 if (error.Fail() || !final_value.get())
2554 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002555 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002556 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002557 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002558 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002559 return ValueObjectSP();
2560 }
2561 else
2562 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002563 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002564 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002565 return final_value;
2566 }
2567 }
2568 }
2569 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2570}
2571
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002572int
2573ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002574 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002575 const char** first_unparsed,
2576 ExpressionPathScanEndReason* reason_to_stop,
2577 ExpressionPathEndResultType* final_value_type,
2578 const GetValueForExpressionPathOptions& options,
2579 ExpressionPathAftermath* final_task_on_target)
2580{
2581 const char* dummy_first_unparsed;
2582 ExpressionPathScanEndReason dummy_reason_to_stop;
2583 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002584 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002585
2586 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2587 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2588 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2589 final_value_type ? final_value_type : &dummy_final_value_type,
2590 options,
2591 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2592
2593 if (!ret_val.get()) // if there are errors, I add nothing to the list
2594 return 0;
2595
Enrico Granata86ea8d82012-03-29 01:34:34 +00002596 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002597 {
2598 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002599 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002600 {
2601 list->Append(ret_val);
2602 return 1;
2603 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002604 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 +00002605 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002606 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002607 {
2608 Error error;
2609 ValueObjectSP final_value = ret_val->Dereference(error);
2610 if (error.Fail() || !final_value.get())
2611 {
Greg Clayton23f59502012-07-17 03:23:13 +00002612 if (reason_to_stop)
2613 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2614 if (final_value_type)
2615 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002616 return 0;
2617 }
2618 else
2619 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002620 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002621 list->Append(final_value);
2622 return 1;
2623 }
2624 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002625 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002626 {
2627 Error error;
2628 ValueObjectSP final_value = ret_val->AddressOf(error);
2629 if (error.Fail() || !final_value.get())
2630 {
Greg Clayton23f59502012-07-17 03:23:13 +00002631 if (reason_to_stop)
2632 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2633 if (final_value_type)
2634 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002635 return 0;
2636 }
2637 else
2638 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002639 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002640 list->Append(final_value);
2641 return 1;
2642 }
2643 }
2644 }
2645 }
2646 else
2647 {
2648 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2649 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2650 ret_val,
2651 list,
2652 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2653 final_value_type ? final_value_type : &dummy_final_value_type,
2654 options,
2655 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2656 }
2657 // in any non-covered case, just do the obviously right thing
2658 list->Append(ret_val);
2659 return 1;
2660}
2661
Greg Claytonafacd142011-09-02 01:15:17 +00002662ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002663ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2664 const char** first_unparsed,
2665 ExpressionPathScanEndReason* reason_to_stop,
2666 ExpressionPathEndResultType* final_result,
2667 const GetValueForExpressionPathOptions& options,
2668 ExpressionPathAftermath* what_next)
2669{
2670 ValueObjectSP root = GetSP();
2671
2672 if (!root.get())
2673 return ValueObjectSP();
2674
2675 *first_unparsed = expression_cstr;
2676
2677 while (true)
2678 {
2679
2680 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2681
Greg Clayton57ee3062013-07-11 22:46:58 +00002682 ClangASTType root_clang_type = root->GetClangType();
2683 ClangASTType pointee_clang_type;
2684 Flags pointee_clang_type_info;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002685
Greg Clayton57ee3062013-07-11 22:46:58 +00002686 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002687 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00002688 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002689
2690 if (!expression_cstr || *expression_cstr == '\0')
2691 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002692 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002693 return root;
2694 }
2695
2696 switch (*expression_cstr)
2697 {
2698 case '-':
2699 {
2700 if (options.m_check_dot_vs_arrow_syntax &&
Greg Clayton57ee3062013-07-11 22:46:58 +00002701 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 +00002702 {
2703 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002704 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2705 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002706 return ValueObjectSP();
2707 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002708 if (root_clang_type_info.Test(ClangASTType::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2709 root_clang_type_info.Test(ClangASTType::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002710 options.m_no_fragile_ivar)
2711 {
2712 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002713 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2714 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002715 return ValueObjectSP();
2716 }
2717 if (expression_cstr[1] != '>')
2718 {
2719 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002720 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2721 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002722 return ValueObjectSP();
2723 }
2724 expression_cstr++; // skip the -
2725 }
2726 case '.': // or fallthrough from ->
2727 {
2728 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Greg Clayton57ee3062013-07-11 22:46:58 +00002729 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 +00002730 {
2731 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002732 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2733 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002734 return ValueObjectSP();
2735 }
2736 expression_cstr++; // skip .
2737 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2738 ConstString child_name;
2739 if (!next_separator) // if no other separator just expand this last layer
2740 {
2741 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002742 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2743
2744 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002745 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002746 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002747 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2748 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002749 return child_valobj_sp;
2750 }
2751 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2752 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002753 if (root->IsSynthetic())
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002754 {
2755 *first_unparsed = expression_cstr;
2756 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2757 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2758 return ValueObjectSP();
2759 }
2760
2761 child_valobj_sp = root->GetSyntheticValue();
Enrico Granata86cc9822012-03-19 22:58:49 +00002762 if (child_valobj_sp.get())
2763 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002764 }
2765
2766 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2767 // so we hit the "else" branch, and return an error
2768 if(child_valobj_sp.get()) // if it worked, just return
2769 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002770 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002771 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2772 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002773 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002774 }
2775 else
2776 {
2777 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002778 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2779 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002780 return ValueObjectSP();
2781 }
2782 }
2783 else // other layers do expand
2784 {
2785 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002786 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2787 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002788 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002789 root = child_valobj_sp;
2790 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002791 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002792 continue;
2793 }
2794 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2795 {
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002796 if (root->IsSynthetic())
2797 {
2798 *first_unparsed = expression_cstr;
2799 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2800 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2801 return ValueObjectSP();
2802 }
2803
Enrico Granata86cc9822012-03-19 22:58:49 +00002804 child_valobj_sp = root->GetSyntheticValue(true);
2805 if (child_valobj_sp)
2806 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002807 }
2808
2809 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2810 // so we hit the "else" branch, and return an error
2811 if(child_valobj_sp.get()) // if it worked, move on
2812 {
2813 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002814 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002815 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002816 continue;
2817 }
2818 else
2819 {
2820 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002821 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2822 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002823 return ValueObjectSP();
2824 }
2825 }
2826 break;
2827 }
2828 case '[':
2829 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002830 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 +00002831 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002832 if (!root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002833 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002834 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2835 {
2836 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002837 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2838 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002839 return ValueObjectSP();
2840 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002841 }
2842 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2843 {
2844 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002845 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2846 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002847 return ValueObjectSP();
2848 }
2849 }
2850 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2851 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002852 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002853 {
2854 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002855 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2856 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002857 return ValueObjectSP();
2858 }
2859 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2860 {
2861 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002862 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2863 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002864 return root;
2865 }
2866 }
2867 const char *separator_position = ::strchr(expression_cstr+1,'-');
2868 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2869 if (!close_bracket_position) // if there is no ], this is a syntax error
2870 {
2871 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002872 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2873 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002874 return ValueObjectSP();
2875 }
2876 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2877 {
2878 char *end = NULL;
2879 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2880 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2881 {
2882 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002883 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2884 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002885 return ValueObjectSP();
2886 }
2887 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2888 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002889 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002890 {
2891 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002892 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2893 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002894 return root;
2895 }
2896 else
2897 {
2898 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002899 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2900 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002901 return ValueObjectSP();
2902 }
2903 }
2904 // from here on we do have a valid index
Greg Clayton57ee3062013-07-11 22:46:58 +00002905 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002906 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002907 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2908 if (!child_valobj_sp)
2909 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002910 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002911 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2912 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002913 if (child_valobj_sp)
2914 {
2915 root = child_valobj_sp;
2916 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002917 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002918 continue;
2919 }
2920 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002921 {
2922 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002923 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2924 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002925 return ValueObjectSP();
2926 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002927 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002928 else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002929 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002930 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 +00002931 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002932 {
2933 Error error;
2934 root = root->Dereference(error);
2935 if (error.Fail() || !root.get())
2936 {
2937 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002938 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2939 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002940 return ValueObjectSP();
2941 }
2942 else
2943 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002944 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002945 continue;
2946 }
2947 }
2948 else
2949 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002950 if (root->GetClangType().GetMinimumLanguage() == eLanguageTypeObjC
2951 && pointee_clang_type_info.AllClear(ClangASTType::eTypeIsPointer)
Greg Clayton84db9102012-03-26 23:03:23 +00002952 && root->HasSyntheticValue()
2953 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002954 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002955 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002956 }
2957 else
2958 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002959 if (!root.get())
2960 {
2961 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002962 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2963 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002964 return ValueObjectSP();
2965 }
2966 else
2967 {
2968 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002969 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002970 continue;
2971 }
2972 }
2973 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002974 else if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002975 {
2976 root = root->GetSyntheticBitFieldChild(index, index, true);
2977 if (!root.get())
2978 {
2979 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002980 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2981 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002982 return ValueObjectSP();
2983 }
2984 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2985 {
2986 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002987 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2988 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002989 return root;
2990 }
2991 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002992 else if (root_clang_type_info.Test(ClangASTType::eTypeIsVector))
Enrico Granata08a1bb82013-06-19 00:00:45 +00002993 {
2994 root = root->GetChildAtIndex(index, true);
2995 if (!root.get())
2996 {
2997 *first_unparsed = expression_cstr;
2998 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2999 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3000 return ValueObjectSP();
3001 }
3002 else
3003 {
3004 *first_unparsed = end+1; // skip ]
3005 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3006 continue;
3007 }
3008 }
Enrico Granata86cc9822012-03-19 22:58:49 +00003009 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00003010 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003011 if (root->HasSyntheticValue())
3012 root = root->GetSyntheticValue();
3013 else if (!root->IsSynthetic())
3014 {
3015 *first_unparsed = expression_cstr;
3016 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3017 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3018 return ValueObjectSP();
3019 }
3020 // if we are here, then root itself is a synthetic VO.. should be good to go
3021
Enrico Granata27b625e2011-08-09 01:04:56 +00003022 if (!root.get())
3023 {
3024 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003025 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3026 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3027 return ValueObjectSP();
3028 }
3029 root = root->GetChildAtIndex(index, true);
3030 if (!root.get())
3031 {
3032 *first_unparsed = expression_cstr;
3033 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3034 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003035 return ValueObjectSP();
3036 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00003037 else
3038 {
3039 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003040 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00003041 continue;
3042 }
Enrico Granata27b625e2011-08-09 01:04:56 +00003043 }
3044 else
3045 {
3046 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003047 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3048 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003049 return ValueObjectSP();
3050 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003051 }
3052 else // we have a low and a high index
3053 {
3054 char *end = NULL;
3055 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3056 if (!end || end != separator_position) // if something weird is in our way return an error
3057 {
3058 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003059 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3060 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003061 return ValueObjectSP();
3062 }
3063 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3064 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3065 {
3066 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003067 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3068 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003069 return ValueObjectSP();
3070 }
3071 if (index_lower > index_higher) // swap indices if required
3072 {
3073 unsigned long temp = index_lower;
3074 index_lower = index_higher;
3075 index_higher = temp;
3076 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003077 if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003078 {
3079 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3080 if (!root.get())
3081 {
3082 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003083 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3084 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003085 return ValueObjectSP();
3086 }
3087 else
3088 {
3089 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003090 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3091 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003092 return root;
3093 }
3094 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003095 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 +00003096 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Greg Clayton57ee3062013-07-11 22:46:58 +00003097 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003098 {
3099 Error error;
3100 root = root->Dereference(error);
3101 if (error.Fail() || !root.get())
3102 {
3103 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003104 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3105 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003106 return ValueObjectSP();
3107 }
3108 else
3109 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003110 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003111 continue;
3112 }
3113 }
3114 else
3115 {
3116 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003117 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3118 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003119 return root;
3120 }
3121 }
3122 break;
3123 }
3124 default: // some non-separator is in the way
3125 {
3126 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003127 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3128 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003129 return ValueObjectSP();
3130 break;
3131 }
3132 }
3133 }
3134}
3135
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003136int
3137ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3138 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00003139 ValueObjectSP root,
3140 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003141 ExpressionPathScanEndReason* reason_to_stop,
3142 ExpressionPathEndResultType* final_result,
3143 const GetValueForExpressionPathOptions& options,
3144 ExpressionPathAftermath* what_next)
3145{
3146 if (!root.get())
3147 return 0;
3148
3149 *first_unparsed = expression_cstr;
3150
3151 while (true)
3152 {
3153
3154 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3155
Greg Clayton57ee3062013-07-11 22:46:58 +00003156 ClangASTType root_clang_type = root->GetClangType();
3157 ClangASTType pointee_clang_type;
3158 Flags pointee_clang_type_info;
3159 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003160 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00003161 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003162
3163 if (!expression_cstr || *expression_cstr == '\0')
3164 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003165 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003166 list->Append(root);
3167 return 1;
3168 }
3169
3170 switch (*expression_cstr)
3171 {
3172 case '[':
3173 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003174 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 +00003175 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003176 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 +00003177 {
3178 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003179 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3180 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003181 return 0;
3182 }
3183 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3184 {
3185 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003186 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3187 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003188 return 0;
3189 }
3190 }
3191 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3192 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003193 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003194 {
3195 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003196 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3197 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003198 return 0;
3199 }
3200 else // expand this into list
3201 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003202 const size_t max_index = root->GetNumChildren() - 1;
3203 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003204 {
3205 ValueObjectSP child =
3206 root->GetChildAtIndex(index, true);
3207 list->Append(child);
3208 }
3209 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003210 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3211 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003212 return max_index; // tell me number of items I added to the VOList
3213 }
3214 }
3215 const char *separator_position = ::strchr(expression_cstr+1,'-');
3216 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3217 if (!close_bracket_position) // if there is no ], this is a syntax error
3218 {
3219 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003220 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3221 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003222 return 0;
3223 }
3224 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3225 {
3226 char *end = NULL;
3227 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3228 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3229 {
3230 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003231 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3232 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003233 return 0;
3234 }
3235 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3236 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003237 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003238 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003239 const size_t max_index = root->GetNumChildren() - 1;
3240 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003241 {
3242 ValueObjectSP child =
3243 root->GetChildAtIndex(index, true);
3244 list->Append(child);
3245 }
3246 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003247 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3248 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003249 return max_index; // tell me number of items I added to the VOList
3250 }
3251 else
3252 {
3253 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003254 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3255 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003256 return 0;
3257 }
3258 }
3259 // from here on we do have a valid index
Greg Clayton57ee3062013-07-11 22:46:58 +00003260 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003261 {
3262 root = root->GetChildAtIndex(index, true);
3263 if (!root.get())
3264 {
3265 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003266 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3267 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003268 return 0;
3269 }
3270 else
3271 {
3272 list->Append(root);
3273 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003274 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3275 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003276 return 1;
3277 }
3278 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003279 else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003280 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003281 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 +00003282 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003283 {
3284 Error error;
3285 root = root->Dereference(error);
3286 if (error.Fail() || !root.get())
3287 {
3288 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003289 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3290 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003291 return 0;
3292 }
3293 else
3294 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003295 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003296 continue;
3297 }
3298 }
3299 else
3300 {
3301 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3302 if (!root.get())
3303 {
3304 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003305 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3306 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003307 return 0;
3308 }
3309 else
3310 {
3311 list->Append(root);
3312 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003313 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3314 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003315 return 1;
3316 }
3317 }
3318 }
3319 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3320 {
3321 root = root->GetSyntheticBitFieldChild(index, index, true);
3322 if (!root.get())
3323 {
3324 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003325 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3326 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003327 return 0;
3328 }
3329 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3330 {
3331 list->Append(root);
3332 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003333 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3334 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003335 return 1;
3336 }
3337 }
3338 }
3339 else // we have a low and a high index
3340 {
3341 char *end = NULL;
3342 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3343 if (!end || end != separator_position) // if something weird is in our way return an error
3344 {
3345 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003346 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3347 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003348 return 0;
3349 }
3350 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3351 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3352 {
3353 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003354 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3355 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003356 return 0;
3357 }
3358 if (index_lower > index_higher) // swap indices if required
3359 {
3360 unsigned long temp = index_lower;
3361 index_lower = index_higher;
3362 index_higher = temp;
3363 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003364 if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // expansion only works for scalars
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003365 {
3366 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3367 if (!root.get())
3368 {
3369 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003370 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3371 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003372 return 0;
3373 }
3374 else
3375 {
3376 list->Append(root);
3377 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003378 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3379 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003380 return 1;
3381 }
3382 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003383 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 +00003384 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Greg Clayton57ee3062013-07-11 22:46:58 +00003385 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003386 {
3387 Error error;
3388 root = root->Dereference(error);
3389 if (error.Fail() || !root.get())
3390 {
3391 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003392 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3393 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003394 return 0;
3395 }
3396 else
3397 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003398 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003399 continue;
3400 }
3401 }
3402 else
3403 {
Johnny Chen44805302011-07-19 19:48:13 +00003404 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003405 index <= index_higher; index++)
3406 {
3407 ValueObjectSP child =
3408 root->GetChildAtIndex(index, true);
3409 list->Append(child);
3410 }
3411 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003412 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3413 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003414 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3415 }
3416 }
3417 break;
3418 }
3419 default: // some non-[ separator, or something entirely wrong, is in the way
3420 {
3421 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003422 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3423 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003424 return 0;
3425 break;
3426 }
3427 }
3428 }
3429}
3430
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003431void
3432ValueObject::LogValueObject (Log *log)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003433{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003434 if (log)
3435 return LogValueObject (log, DumpValueObjectOptions::DefaultOptions());
Greg Clayton1d3afba2010-10-05 00:00:42 +00003436}
3437
Enrico Granata0c489f52012-03-01 04:24:26 +00003438void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003439ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003440{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003441 if (log)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003442 {
3443 StreamString s;
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003444 Dump (s, options);
Greg Claytonf830dbb2012-03-22 18:15:37 +00003445 if (s.GetSize())
3446 log->PutCString(s.GetData());
3447 }
3448}
3449
3450void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003451ValueObject::Dump (Stream &s)
Enrico Granata0c489f52012-03-01 04:24:26 +00003452{
3453
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003454 ValueObjectPrinter printer(this,&s,DumpValueObjectOptions::DefaultOptions());
3455 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003456}
3457
3458void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003459ValueObject::Dump (Stream &s,
3460 const DumpValueObjectOptions& options)
Enrico Granata0c489f52012-03-01 04:24:26 +00003461{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003462 ValueObjectPrinter printer(this,&s,options);
3463 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003464}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003465
3466ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003467ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003468{
3469 ValueObjectSP valobj_sp;
3470
Enrico Granatac3e320a2011-08-02 17:27:39 +00003471 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003472 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003473 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003474
3475 DataExtractor data;
3476 data.SetByteOrder (m_data.GetByteOrder());
3477 data.SetAddressByteSize(m_data.GetAddressByteSize());
3478
Enrico Granata9f1e2042012-04-24 22:15:37 +00003479 if (IsBitfield())
3480 {
3481 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
Greg Clayton57ee3062013-07-11 22:46:58 +00003482 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Enrico Granata9f1e2042012-04-24 22:15:37 +00003483 }
3484 else
Greg Clayton57ee3062013-07-11 22:46:58 +00003485 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003486
3487 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003488 GetClangType(),
3489 name,
3490 data,
3491 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003492 }
Jim Ingham6035b672011-03-31 00:19:25 +00003493
3494 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003495 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003496 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003497 }
3498 return valobj_sp;
3499}
3500
Greg Claytonafacd142011-09-02 01:15:17 +00003501ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003502ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003503{
Jim Ingham58b59f92011-04-22 23:53:53 +00003504 if (m_deref_valobj)
3505 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003506
Greg Clayton54979cd2010-12-15 05:08:08 +00003507 const bool is_pointer_type = IsPointerType();
3508 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003509 {
3510 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003511 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003512
3513 std::string child_name_str;
3514 uint32_t child_byte_size = 0;
3515 int32_t child_byte_offset = 0;
3516 uint32_t child_bitfield_bit_size = 0;
3517 uint32_t child_bitfield_bit_offset = 0;
3518 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003519 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003520 const bool transparent_pointers = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00003521 ClangASTType clang_type = GetClangType();
3522 ClangASTType child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003523
Greg Claytoncc4d0142012-02-17 07:49:44 +00003524 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003525
Greg Clayton57ee3062013-07-11 22:46:58 +00003526 child_clang_type = clang_type.GetChildClangTypeAtIndex (&exe_ctx,
3527 GetName().GetCString(),
3528 0,
3529 transparent_pointers,
3530 omit_empty_base_classes,
3531 ignore_array_bounds,
3532 child_name_str,
3533 child_byte_size,
3534 child_byte_offset,
3535 child_bitfield_bit_size,
3536 child_bitfield_bit_offset,
3537 child_is_base_class,
3538 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003539 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003540 {
3541 ConstString child_name;
3542 if (!child_name_str.empty())
3543 child_name.SetCString (child_name_str.c_str());
3544
Jim Ingham58b59f92011-04-22 23:53:53 +00003545 m_deref_valobj = new ValueObjectChild (*this,
Jim Ingham58b59f92011-04-22 23:53:53 +00003546 child_clang_type,
3547 child_name,
3548 child_byte_size,
3549 child_byte_offset,
3550 child_bitfield_bit_size,
3551 child_bitfield_bit_offset,
3552 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003553 child_is_deref_of_parent,
3554 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003555 }
3556 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003557
Jim Ingham58b59f92011-04-22 23:53:53 +00003558 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003559 {
3560 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003561 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003562 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003563 else
3564 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003565 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003566 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003567
3568 if (is_pointer_type)
3569 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3570 else
3571 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003572 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003573 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003574}
3575
Greg Claytonafacd142011-09-02 01:15:17 +00003576ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003577ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003578{
Jim Ingham78a685a2011-04-16 00:01:13 +00003579 if (m_addr_of_valobj_sp)
3580 return m_addr_of_valobj_sp;
3581
Greg Claytone0d378b2011-03-24 21:19:54 +00003582 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003583 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003584 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003585 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003586 if (addr != LLDB_INVALID_ADDRESS)
3587 {
3588 switch (address_type)
3589 {
3590 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003591 {
3592 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003593 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003594 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3595 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003596 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003597
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003598 case eAddressTypeFile:
3599 case eAddressTypeLoad:
3600 case eAddressTypeHost:
3601 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003602 ClangASTType clang_type = GetClangType();
3603 if (clang_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003604 {
3605 std::string name (1, '&');
3606 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003607 ExecutionContext exe_ctx (GetExecutionContextRef());
3608 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00003609 clang_type.GetPointerType(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003610 ConstString (name.c_str()),
3611 addr,
3612 eAddressTypeInvalid,
3613 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003614 }
3615 }
3616 break;
3617 }
3618 }
Sean Callananed185ab2013-04-19 19:47:32 +00003619 else
3620 {
3621 StreamString expr_path_strm;
3622 GetExpressionPath(expr_path_strm, true);
3623 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3624 }
3625
Jim Ingham78a685a2011-04-16 00:01:13 +00003626 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003627}
3628
Greg Clayton9a142cf2012-02-03 05:34:10 +00003629ValueObjectSP
3630ValueObject::Cast (const ClangASTType &clang_ast_type)
3631{
Greg Clayton81e871e2012-02-04 02:27:34 +00003632 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003633}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003634
Greg Claytonafacd142011-09-02 01:15:17 +00003635ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003636ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3637{
Greg Claytonafacd142011-09-02 01:15:17 +00003638 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003639 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003640 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003641
3642 if (ptr_value != LLDB_INVALID_ADDRESS)
3643 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003644 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003645 ExecutionContext exe_ctx (GetExecutionContextRef());
3646 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003647 name,
3648 ptr_addr,
3649 clang_ast_type);
3650 }
3651 return valobj_sp;
3652}
3653
Greg Claytonafacd142011-09-02 01:15:17 +00003654ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003655ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3656{
Greg Claytonafacd142011-09-02 01:15:17 +00003657 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003658 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003659 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003660
3661 if (ptr_value != LLDB_INVALID_ADDRESS)
3662 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003663 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003664 ExecutionContext exe_ctx (GetExecutionContextRef());
3665 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003666 name,
3667 ptr_addr,
3668 type_sp);
3669 }
3670 return valobj_sp;
3671}
3672
Jim Ingham6035b672011-03-31 00:19:25 +00003673ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003674 m_mod_id(),
3675 m_exe_ctx_ref(),
3676 m_needs_update (true),
3677 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003678{
3679}
3680
3681ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003682 m_mod_id(),
3683 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003684 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003685 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003686{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003687 ExecutionContext exe_ctx(exe_scope);
3688 TargetSP target_sp (exe_ctx.GetTargetSP());
3689 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003690 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003691 m_exe_ctx_ref.SetTargetSP (target_sp);
3692 ProcessSP process_sp (exe_ctx.GetProcessSP());
3693 if (!process_sp)
3694 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003695
Greg Claytoncc4d0142012-02-17 07:49:44 +00003696 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003697 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003698 m_mod_id = process_sp->GetModID();
3699 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003700
Greg Claytoncc4d0142012-02-17 07:49:44 +00003701 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003702
Greg Claytoncc4d0142012-02-17 07:49:44 +00003703 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003704 {
3705 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003706 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003707 }
Jim Ingham6035b672011-03-31 00:19:25 +00003708
Greg Claytoncc4d0142012-02-17 07:49:44 +00003709 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003710 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003711 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003712
Greg Claytoncc4d0142012-02-17 07:49:44 +00003713 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3714 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003715 {
3716 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003717 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003718 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003719 if (frame_sp)
3720 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003721 }
3722 }
3723 }
Jim Ingham6035b672011-03-31 00:19:25 +00003724}
3725
3726ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003727 m_mod_id(),
3728 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3729 m_needs_update (true),
3730 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003731{
3732}
3733
3734ValueObject::EvaluationPoint::~EvaluationPoint ()
3735{
3736}
3737
Jim Ingham6035b672011-03-31 00:19:25 +00003738// This function checks the EvaluationPoint against the current process state. If the current
3739// state matches the evaluation point, or the evaluation point is already invalid, then we return
3740// false, meaning "no change". If the current state is different, we update our state, and return
3741// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3742// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003743// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003744
3745bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003746ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003747{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003748
3749 // Start with the target, if it is NULL, then we're obviously not going to get any further:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003750 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00003751
Greg Claytoncc4d0142012-02-17 07:49:44 +00003752 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003753 return false;
3754
Jim Ingham6035b672011-03-31 00:19:25 +00003755 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003756 Process *process = exe_ctx.GetProcessPtr();
3757 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003758 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003759
Jim Ingham6035b672011-03-31 00:19:25 +00003760 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003761 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003762
Jim Ingham78a685a2011-04-16 00:01:13 +00003763 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3764 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003765 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003766 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003767
Greg Clayton23f59502012-07-17 03:23:13 +00003768 bool changed = false;
3769 const bool was_valid = m_mod_id.IsValid();
3770 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003771 {
3772 if (m_mod_id == current_mod_id)
3773 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003774 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003775 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003776 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003777 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003778 else
3779 {
3780 m_mod_id = current_mod_id;
3781 m_needs_update = true;
3782 changed = true;
3783 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003784 }
Jim Ingham6035b672011-03-31 00:19:25 +00003785
Jim Ingham73ca05a2011-12-17 01:35:57 +00003786 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3787 // That way we'll be sure to return a valid exe_scope.
3788 // 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 +00003789
Greg Claytoncc4d0142012-02-17 07:49:44 +00003790 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003791 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003792 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3793 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003794 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003795 if (m_exe_ctx_ref.HasFrameRef())
3796 {
3797 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3798 if (!frame_sp)
3799 {
3800 // We used to have a frame, but now it is gone
3801 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003802 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00003803 }
3804 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003805 }
Jim Ingham6035b672011-03-31 00:19:25 +00003806 else
3807 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003808 // We used to have a thread, but now it is gone
3809 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003810 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00003811 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003812
Jim Ingham6035b672011-03-31 00:19:25 +00003813 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003814 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003815}
3816
Jim Ingham61be0902011-05-02 18:13:59 +00003817void
3818ValueObject::EvaluationPoint::SetUpdated ()
3819{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003820 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3821 if (process_sp)
3822 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003823 m_first_update = false;
3824 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003825}
3826
3827
Enrico Granataf2bbf712011-07-15 02:26:42 +00003828
3829void
Enrico Granata86cc9822012-03-19 22:58:49 +00003830ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00003831{
Enrico Granata86cc9822012-03-19 22:58:49 +00003832 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
3833 m_value_str.clear();
3834
3835 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
3836 m_location_str.clear();
3837
3838 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
3839 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003840 m_summary_str.clear();
3841 }
3842
3843 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
3844 m_object_desc_str.clear();
3845
3846 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
3847 {
3848 if (m_synthetic_value)
3849 m_synthetic_value = NULL;
3850 }
Johnny Chen44805302011-07-19 19:48:13 +00003851}
Enrico Granata9128ee22011-09-06 19:20:51 +00003852
3853SymbolContextScope *
3854ValueObject::GetSymbolContextScope()
3855{
3856 if (m_parent)
3857 {
3858 if (!m_parent->IsPointerOrReferenceType())
3859 return m_parent->GetSymbolContextScope();
3860 }
3861 return NULL;
3862}
Enrico Granatab2698cd2012-09-13 18:27:09 +00003863
3864lldb::ValueObjectSP
3865ValueObject::CreateValueObjectFromExpression (const char* name,
3866 const char* expression,
3867 const ExecutionContext& exe_ctx)
3868{
3869 lldb::ValueObjectSP retval_sp;
3870 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
3871 if (!target_sp)
3872 return retval_sp;
3873 if (!expression || !*expression)
3874 return retval_sp;
3875 target_sp->EvaluateExpression (expression,
3876 exe_ctx.GetFrameSP().get(),
3877 retval_sp);
3878 if (retval_sp && name && *name)
3879 retval_sp->SetName(ConstString(name));
3880 return retval_sp;
3881}
3882
3883lldb::ValueObjectSP
3884ValueObject::CreateValueObjectFromAddress (const char* name,
3885 uint64_t address,
3886 const ExecutionContext& exe_ctx,
3887 ClangASTType type)
3888{
Greg Clayton57ee3062013-07-11 22:46:58 +00003889 if (type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00003890 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003891 ClangASTType pointer_type(type.GetPointerType());
3892 if (pointer_type)
3893 {
3894 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
3895 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3896 pointer_type,
3897 ConstString(name),
3898 buffer,
3899 lldb::endian::InlHostByteOrder(),
3900 exe_ctx.GetAddressByteSize()));
3901 if (ptr_result_valobj_sp)
3902 {
3903 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
3904 Error err;
3905 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
3906 if (ptr_result_valobj_sp && name && *name)
3907 ptr_result_valobj_sp->SetName(ConstString(name));
3908 }
3909 return ptr_result_valobj_sp;
3910 }
Enrico Granatab2698cd2012-09-13 18:27:09 +00003911 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003912 return lldb::ValueObjectSP();
Enrico Granatab2698cd2012-09-13 18:27:09 +00003913}
3914
3915lldb::ValueObjectSP
3916ValueObject::CreateValueObjectFromData (const char* name,
3917 DataExtractor& data,
3918 const ExecutionContext& exe_ctx,
3919 ClangASTType type)
3920{
3921 lldb::ValueObjectSP new_value_sp;
3922 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00003923 type,
Enrico Granatab2698cd2012-09-13 18:27:09 +00003924 ConstString(name),
3925 data,
3926 LLDB_INVALID_ADDRESS);
3927 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
3928 if (new_value_sp && name && *name)
3929 new_value_sp->SetName(ConstString(name));
3930 return new_value_sp;
3931}
Enrico Granata4873e522013-04-11 22:48:58 +00003932
3933ModuleSP
3934ValueObject::GetModule ()
3935{
3936 ValueObject* root(GetRoot());
3937 if (root != this)
3938 return root->GetModule();
3939 return lldb::ModuleSP();
3940}
3941
3942ValueObject*
3943ValueObject::GetRoot ()
3944{
3945 if (m_root)
3946 return m_root;
3947 ValueObject* parent = m_parent;
3948 if (!parent)
3949 return (m_root = this);
3950 while (parent->m_parent)
3951 {
3952 if (parent->m_root)
3953 return (m_root = parent->m_root);
3954 parent = parent->m_parent;
3955 }
3956 return (m_root = parent);
3957}
3958
3959AddressType
3960ValueObject::GetAddressTypeOfChildren()
3961{
3962 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
3963 {
3964 ValueObject* root(GetRoot());
3965 if (root != this)
3966 return root->GetAddressTypeOfChildren();
3967 }
3968 return m_address_type_of_ptr_or_ref_children;
3969}
3970
3971lldb::DynamicValueType
3972ValueObject::GetDynamicValueType ()
3973{
3974 ValueObject* with_dv_info = this;
3975 while (with_dv_info)
3976 {
3977 if (with_dv_info->HasDynamicValueTypeInfo())
3978 return with_dv_info->GetDynamicValueTypeImpl();
3979 with_dv_info = with_dv_info->m_parent;
3980 }
3981 return lldb::eNoDynamicValues;
3982}
Enrico Granata39d51412013-05-31 17:43:40 +00003983
Enrico Granata4873e522013-04-11 22:48:58 +00003984lldb::Format
3985ValueObject::GetFormat () const
3986{
3987 const ValueObject* with_fmt_info = this;
3988 while (with_fmt_info)
3989 {
3990 if (with_fmt_info->m_format != lldb::eFormatDefault)
3991 return with_fmt_info->m_format;
3992 with_fmt_info = with_fmt_info->m_parent;
3993 }
3994 return m_format;
3995}