blob: b1adf0b78b6c31f536aa8b7bb72ac2d0ab2022b3 [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 Granata2206b482014-10-30 18:27:31 +000037#include "lldb/DataFormatters/StringPrinter.h"
Enrico Granata4d93b8c2013-09-30 19:11:51 +000038#include "lldb/DataFormatters/ValueObjectPrinter.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000039
Greg Clayton7fb56d02011-02-01 01:31:41 +000040#include "lldb/Host/Endian.h"
41
Enrico Granata61a80ba2011-08-12 16:42:31 +000042#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granataf2bbf712011-07-15 02:26:42 +000043#include "lldb/Interpreter/ScriptInterpreterPython.h"
44
Greg Claytone1a916a2010-07-21 22:12:05 +000045#include "lldb/Symbol/ClangASTType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046#include "lldb/Symbol/ClangASTContext.h"
47#include "lldb/Symbol/Type.h"
48
Jim Ingham53c47f12010-09-10 23:12:17 +000049#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000050#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000051#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052#include "lldb/Target/Process.h"
53#include "lldb/Target/RegisterContext.h"
Greg Claytond5944cd2013-12-06 01:12:00 +000054#include "lldb/Target/SectionLoadList.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000055#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057
58using namespace lldb;
59using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000060using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061
Greg Claytonafacd142011-09-02 01:15:17 +000062static user_id_t g_value_obj_uid = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063
64//----------------------------------------------------------------------
65// ValueObject constructor
66//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000067ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000068 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000069 m_parent (&parent),
Enrico Granata4873e522013-04-11 22:48:58 +000070 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +000071 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000072 m_name (),
73 m_data (),
74 m_value (),
75 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000076 m_value_str (),
77 m_old_value_str (),
78 m_location_str (),
79 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000080 m_object_desc_str (),
Enrico Granata744794a2014-09-05 21:46:22 +000081 m_validation_result(),
Jim Ingham58b59f92011-04-22 23:53:53 +000082 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000083 m_children (),
84 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000085 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000086 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000087 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000088 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +000089 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000090 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +000091 m_type_summary_sp(),
92 m_type_format_sp(),
93 m_synthetic_children_sp(),
Enrico Granata744794a2014-09-05 21:46:22 +000094 m_type_validator_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +000095 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +000096 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
Greg Clayton288bdf92010-09-02 02:59:18 +000097 m_value_is_valid (false),
98 m_value_did_change (false),
99 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000100 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000101 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000102 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000103 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000104 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000105 m_is_getting_summary(false),
106 m_did_calculate_complete_objc_class_type(false)
Jim Ingham6035b672011-03-31 00:19:25 +0000107{
Jim Ingham58b59f92011-04-22 23:53:53 +0000108 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000109}
110
111//----------------------------------------------------------------------
112// ValueObject constructor
113//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000114ValueObject::ValueObject (ExecutionContextScope *exe_scope,
115 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000116 UserID (++g_value_obj_uid), // Unique identifier for every value object
117 m_parent (NULL),
Enrico Granata4873e522013-04-11 22:48:58 +0000118 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000119 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000120 m_name (),
121 m_data (),
122 m_value (),
123 m_error (),
124 m_value_str (),
125 m_old_value_str (),
126 m_location_str (),
127 m_summary_str (),
128 m_object_desc_str (),
Enrico Granata744794a2014-09-05 21:46:22 +0000129 m_validation_result(),
Jim Ingham58b59f92011-04-22 23:53:53 +0000130 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000131 m_children (),
132 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000133 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000134 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000135 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000136 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +0000137 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000138 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +0000139 m_type_summary_sp(),
140 m_type_format_sp(),
141 m_synthetic_children_sp(),
Enrico Granata744794a2014-09-05 21:46:22 +0000142 m_type_validator_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000143 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000144 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Jim Ingham6035b672011-03-31 00:19:25 +0000145 m_value_is_valid (false),
146 m_value_did_change (false),
147 m_children_count_valid (false),
148 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000149 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000150 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000151 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000152 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000153 m_is_getting_summary(false),
154 m_did_calculate_complete_objc_class_type(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000155{
Jim Ingham58b59f92011-04-22 23:53:53 +0000156 m_manager = new ValueObjectManager();
157 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000158}
159
160//----------------------------------------------------------------------
161// Destructor
162//----------------------------------------------------------------------
163ValueObject::~ValueObject ()
164{
165}
166
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000167bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000168ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000169{
Enrico Granata4becb372011-06-29 22:27:15 +0000170
Enrico Granata9128ee22011-09-06 19:20:51 +0000171 bool did_change_formats = false;
172
Enrico Granata0a3958e2011-07-02 00:25:22 +0000173 if (update_format)
Enrico Granata5548cb52013-01-28 23:47:25 +0000174 did_change_formats = UpdateFormatsIfNeeded();
Enrico Granata4becb372011-06-29 22:27:15 +0000175
Greg Claytonb71f3842010-10-05 03:13:51 +0000176 // If this is a constant value, then our success is predicated on whether
177 // we have an error or not
178 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000179 {
Enrico Granatab1c6c482013-10-09 00:33:55 +0000180 // if you are constant, things might still have changed behind your back
181 // (e.g. you are a frozen object and things have changed deeper than you cared to freeze-dry yourself)
182 // in this case, your value has not changed, but "computed" entries might have, so you might now have
183 // a different summary, or a different object description. clear these so we will recompute them
Enrico Granata9128ee22011-09-06 19:20:51 +0000184 if (update_format && !did_change_formats)
Enrico Granatab1c6c482013-10-09 00:33:55 +0000185 ClearUserVisibleData(eClearUserVisibleDataItemsSummary | eClearUserVisibleDataItemsDescription);
Greg Claytonb71f3842010-10-05 03:13:51 +0000186 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000187 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000188
Jim Ingham6035b672011-03-31 00:19:25 +0000189 bool first_update = m_update_point.IsFirstEvaluation();
190
191 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000192 {
Jim Ingham6035b672011-03-31 00:19:25 +0000193 m_update_point.SetUpdated();
194
195 // Save the old value using swap to avoid a string copy which
196 // also will clear our m_value_str
197 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000198 {
Jim Ingham6035b672011-03-31 00:19:25 +0000199 m_old_value_valid = false;
200 }
201 else
202 {
203 m_old_value_valid = true;
204 m_old_value_str.swap (m_value_str);
Enrico Granata86cc9822012-03-19 22:58:49 +0000205 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham6035b672011-03-31 00:19:25 +0000206 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000207
Enrico Granataf2bbf712011-07-15 02:26:42 +0000208 ClearUserVisibleData();
209
Greg Claytonefbc7d22012-03-09 04:23:44 +0000210 if (IsInScope())
Jim Ingham6035b672011-03-31 00:19:25 +0000211 {
Greg Claytonefbc7d22012-03-09 04:23:44 +0000212 const bool value_was_valid = GetValueIsValid();
213 SetValueDidChange (false);
214
215 m_error.Clear();
216
217 // Call the pure virtual function to update the value
218 bool success = UpdateValue ();
219
220 SetValueIsValid (success);
221
222 if (first_update)
223 SetValueDidChange (false);
224 else if (!m_value_did_change && success == false)
225 {
226 // The value wasn't gotten successfully, so we mark this
227 // as changed if the value used to be valid and now isn't
228 SetValueDidChange (value_was_valid);
229 }
230 }
231 else
232 {
233 m_error.SetErrorString("out of scope");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000234 }
235 }
236 return m_error.Success();
237}
238
Enrico Granata9128ee22011-09-06 19:20:51 +0000239bool
Enrico Granata5548cb52013-01-28 23:47:25 +0000240ValueObject::UpdateFormatsIfNeeded()
Enrico Granata4becb372011-06-29 22:27:15 +0000241{
Greg Clayton5160ce52013-03-27 23:08:40 +0000242 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000243 if (log)
Enrico Granatad2284832012-10-17 22:23:56 +0000244 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000245 GetName().GetCString(), static_cast<void*>(this),
246 m_last_format_mgr_revision,
247 DataVisualization::GetCurrentRevision());
248
Enrico Granata9128ee22011-09-06 19:20:51 +0000249 bool any_change = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000250
Enrico Granata5548cb52013-01-28 23:47:25 +0000251 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()))
Enrico Granata4becb372011-06-29 22:27:15 +0000252 {
Enrico Granataa0db6ed2014-04-09 21:06:11 +0000253 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
254 any_change = true;
255
Enrico Granata852cc952013-10-08 19:03:22 +0000256 SetValueFormat(DataVisualization::GetFormat (*this, eNoDynamicValues));
Enrico Granata5548cb52013-01-28 23:47:25 +0000257 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000258#ifndef LLDB_DISABLE_PYTHON
Enrico Granata5548cb52013-01-28 23:47:25 +0000259 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000260#endif
Enrico Granata744794a2014-09-05 21:46:22 +0000261 SetValidator(DataVisualization::GetValidator(*this, GetDynamicValueType()));
Enrico Granata4becb372011-06-29 22:27:15 +0000262 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000263
Enrico Granata9128ee22011-09-06 19:20:51 +0000264 return any_change;
Enrico Granata4becb372011-06-29 22:27:15 +0000265}
266
Jim Ingham16e0c682011-08-12 23:34:31 +0000267void
268ValueObject::SetNeedsUpdate ()
269{
270 m_update_point.SetNeedsUpdate();
271 // We have to clear the value string here so ConstResult children will notice if their values are
272 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000273 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000274}
275
Enrico Granata13ac0e22012-10-17 19:03:34 +0000276void
Enrico Granatae3e91512012-10-22 18:18:36 +0000277ValueObject::ClearDynamicTypeInformation ()
Enrico Granata13ac0e22012-10-17 19:03:34 +0000278{
Enrico Granata38c54632013-10-30 00:04:29 +0000279 m_children_count_valid = false;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000280 m_did_calculate_complete_objc_class_type = false;
Enrico Granatae3e91512012-10-22 18:18:36 +0000281 m_last_format_mgr_revision = 0;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000282 m_override_type = ClangASTType();
Enrico Granatae3e91512012-10-22 18:18:36 +0000283 SetValueFormat(lldb::TypeFormatImplSP());
284 SetSummaryFormat(lldb::TypeSummaryImplSP());
285 SetSyntheticChildren(lldb::SyntheticChildrenSP());
Enrico Granata13ac0e22012-10-17 19:03:34 +0000286}
287
Sean Callanan72772842012-02-22 23:57:45 +0000288ClangASTType
289ValueObject::MaybeCalculateCompleteType ()
290{
Greg Clayton57ee3062013-07-11 22:46:58 +0000291 ClangASTType clang_type(GetClangTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000292
Sean Callanan72772842012-02-22 23:57:45 +0000293 if (m_did_calculate_complete_objc_class_type)
294 {
295 if (m_override_type.IsValid())
296 return m_override_type;
297 else
Greg Clayton57ee3062013-07-11 22:46:58 +0000298 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000299 }
300
Greg Clayton57ee3062013-07-11 22:46:58 +0000301 ClangASTType class_type;
302 bool is_pointer_type = false;
Sean Callanan72772842012-02-22 23:57:45 +0000303
Greg Clayton57ee3062013-07-11 22:46:58 +0000304 if (clang_type.IsObjCObjectPointerType(&class_type))
Sean Callanan72772842012-02-22 23:57:45 +0000305 {
306 is_pointer_type = true;
307 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000308 else if (clang_type.IsObjCObjectOrInterfaceType())
Sean Callanan72772842012-02-22 23:57:45 +0000309 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000310 class_type = clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000311 }
312 else
313 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000314 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000315 }
316
317 m_did_calculate_complete_objc_class_type = true;
318
Greg Clayton57ee3062013-07-11 22:46:58 +0000319 if (class_type)
Sean Callanan72772842012-02-22 23:57:45 +0000320 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000321 ConstString class_name (class_type.GetConstTypeName());
Sean Callanan72772842012-02-22 23:57:45 +0000322
Greg Clayton57ee3062013-07-11 22:46:58 +0000323 if (class_name)
324 {
325 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
326
327 if (process_sp)
328 {
329 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
330
331 if (objc_language_runtime)
332 {
333 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name);
334
335 if (complete_objc_class_type_sp)
336 {
337 ClangASTType complete_class(complete_objc_class_type_sp->GetClangFullType());
338
339 if (complete_class.GetCompleteType())
340 {
341 if (is_pointer_type)
342 {
343 m_override_type = complete_class.GetPointerType();
344 }
345 else
346 {
347 m_override_type = complete_class;
348 }
349
350 if (m_override_type.IsValid())
351 return m_override_type;
352 }
353 }
354 }
355 }
356 }
Sean Callanan72772842012-02-22 23:57:45 +0000357 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000358 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000359}
360
Greg Clayton57ee3062013-07-11 22:46:58 +0000361ClangASTType
Sean Callanan72772842012-02-22 23:57:45 +0000362ValueObject::GetClangType ()
363{
Greg Clayton57ee3062013-07-11 22:46:58 +0000364 return MaybeCalculateCompleteType();
Sean Callanan72772842012-02-22 23:57:45 +0000365}
366
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000367TypeImpl
368ValueObject::GetTypeImpl ()
369{
370 return TypeImpl(GetClangType());
371}
372
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000373DataExtractor &
374ValueObject::GetDataExtractor ()
375{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000376 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000377 return m_data;
378}
379
380const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000381ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000382{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000383 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000384 return m_error;
385}
386
387const ConstString &
388ValueObject::GetName() const
389{
390 return m_name;
391}
392
393const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000394ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000395{
Enrico Granata82fabf82013-04-30 20:45:04 +0000396 return GetLocationAsCStringImpl(m_value,
397 m_data);
398}
399
400const char *
401ValueObject::GetLocationAsCStringImpl (const Value& value,
402 const DataExtractor& data)
403{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000404 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000405 {
406 if (m_location_str.empty())
407 {
408 StreamString sstr;
Enrico Granata82fabf82013-04-30 20:45:04 +0000409
410 Value::ValueType value_type = value.GetValueType();
411
412 switch (value_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000413 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000414 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +0000415 case Value::eValueTypeVector:
Enrico Granata82fabf82013-04-30 20:45:04 +0000416 if (value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000417 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000418 RegisterInfo *reg_info = value.GetRegisterInfo();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000419 if (reg_info)
420 {
421 if (reg_info->name)
422 m_location_str = reg_info->name;
423 else if (reg_info->alt_name)
424 m_location_str = reg_info->alt_name;
Enrico Granata82fabf82013-04-30 20:45:04 +0000425 if (m_location_str.empty())
426 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000427 }
428 }
Enrico Granata82fabf82013-04-30 20:45:04 +0000429 if (m_location_str.empty())
430 m_location_str = (value_type == Value::eValueTypeVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000431 break;
432
433 case Value::eValueTypeLoadAddress:
434 case Value::eValueTypeFileAddress:
435 case Value::eValueTypeHostAddress:
436 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000437 uint32_t addr_nibble_size = data.GetAddressByteSize() * 2;
438 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000439 m_location_str.swap(sstr.GetString());
440 }
441 break;
442 }
443 }
444 }
445 return m_location_str.c_str();
446}
447
448Value &
449ValueObject::GetValue()
450{
451 return m_value;
452}
453
454const Value &
455ValueObject::GetValue() const
456{
457 return m_value;
458}
459
460bool
Jim Ingham6035b672011-03-31 00:19:25 +0000461ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000462{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000463 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
464 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000465 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000466 Value tmp_value(m_value);
Greg Clayton57ee3062013-07-11 22:46:58 +0000467 scalar = tmp_value.ResolveValue(&exe_ctx);
Greg Claytondcad5022011-12-29 01:26:56 +0000468 if (scalar.IsValid())
469 {
470 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
471 if (bitfield_bit_size)
472 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
473 return true;
474 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000475 }
Greg Claytondcad5022011-12-29 01:26:56 +0000476 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000477}
478
479bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000480ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000481{
Greg Clayton288bdf92010-09-02 02:59:18 +0000482 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000483}
484
485
486void
487ValueObject::SetValueIsValid (bool b)
488{
Greg Clayton288bdf92010-09-02 02:59:18 +0000489 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000490}
491
492bool
Jim Ingham6035b672011-03-31 00:19:25 +0000493ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000494{
Jim Ingham6035b672011-03-31 00:19:25 +0000495 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000496 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000497}
498
499void
500ValueObject::SetValueDidChange (bool value_changed)
501{
Greg Clayton288bdf92010-09-02 02:59:18 +0000502 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000503}
504
505ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000506ValueObject::GetChildAtIndex (size_t idx, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000507{
508 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000509 // We may need to update our value if we are dynamic
510 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000511 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000512 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000513 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000514 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000515 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000516 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000517 // No we haven't created the child at this index, so lets have our
518 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000519 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000520 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000521
Enrico Granata9d60f602012-03-09 03:09:58 +0000522 ValueObject* child = m_children.GetChildAtIndex(idx);
523 if (child != NULL)
524 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000525 }
526 return child_sp;
527}
528
Enrico Granata3309d882013-01-12 01:00:22 +0000529ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000530ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
531 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000532{
533 if (idxs.size() == 0)
534 return GetSP();
535 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000536 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000537 {
538 root = root->GetChildAtIndex(idx, true);
539 if (!root)
540 {
541 if (index_of_error)
542 *index_of_error = idx;
543 return root;
544 }
545 }
546 return root;
547}
548
549ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000550ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
551 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000552{
553 if (idxs.size() == 0)
554 return GetSP();
555 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000556 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000557 {
558 root = root->GetChildAtIndex(idx.first, idx.second);
559 if (!root)
560 {
561 if (index_of_error)
562 *index_of_error = idx.first;
563 return root;
564 }
565 }
566 return root;
567}
568
569lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000570ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
571 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000572{
573 if (idxs.size() == 0)
574 return GetSP();
575 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000576 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000577 {
578 root = root->GetChildAtIndex(idx, true);
579 if (!root)
580 {
581 if (index_of_error)
582 *index_of_error = idx;
583 return root;
584 }
585 }
586 return root;
587}
588
589lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000590ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
591 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000592{
593 if (idxs.size() == 0)
594 return GetSP();
595 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000596 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000597 {
598 root = root->GetChildAtIndex(idx.first, idx.second);
599 if (!root)
600 {
601 if (index_of_error)
602 *index_of_error = idx.first;
603 return root;
604 }
605 }
606 return root;
607}
608
Enrico Granatae2e220a2013-09-12 00:48:47 +0000609lldb::ValueObjectSP
610ValueObject::GetChildAtNamePath (const std::initializer_list<ConstString> &names,
611 ConstString* name_of_error)
612{
613 if (names.size() == 0)
614 return GetSP();
615 ValueObjectSP root(GetSP());
616 for (ConstString name : names)
617 {
618 root = root->GetChildMemberWithName(name, true);
619 if (!root)
620 {
621 if (name_of_error)
622 *name_of_error = name;
623 return root;
624 }
625 }
626 return root;
627}
628
629lldb::ValueObjectSP
630ValueObject::GetChildAtNamePath (const std::vector<ConstString> &names,
631 ConstString* name_of_error)
632{
633 if (names.size() == 0)
634 return GetSP();
635 ValueObjectSP root(GetSP());
636 for (ConstString name : names)
637 {
638 root = root->GetChildMemberWithName(name, true);
639 if (!root)
640 {
641 if (name_of_error)
642 *name_of_error = name;
643 return root;
644 }
645 }
646 return root;
647}
648
649lldb::ValueObjectSP
650ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names,
651 ConstString* name_of_error)
652{
653 if (names.size() == 0)
654 return GetSP();
655 ValueObjectSP root(GetSP());
656 for (std::pair<ConstString, bool> name : names)
657 {
658 root = root->GetChildMemberWithName(name.first, name.second);
659 if (!root)
660 {
661 if (name_of_error)
662 *name_of_error = name.first;
663 return root;
664 }
665 }
666 return root;
667}
668
669lldb::ValueObjectSP
670ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names,
671 ConstString* name_of_error)
672{
673 if (names.size() == 0)
674 return GetSP();
675 ValueObjectSP root(GetSP());
676 for (std::pair<ConstString, bool> name : names)
677 {
678 root = root->GetChildMemberWithName(name.first, name.second);
679 if (!root)
680 {
681 if (name_of_error)
682 *name_of_error = name.first;
683 return root;
684 }
685 }
686 return root;
687}
688
Greg Claytonc7bece562013-01-25 18:06:21 +0000689size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000690ValueObject::GetIndexOfChildWithName (const ConstString &name)
691{
692 bool omit_empty_base_classes = true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000693 return GetClangType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000694}
695
696ValueObjectSP
697ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
698{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000699 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000700 // classes (which really aren't part of the expression path), so we
701 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000702 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000703
Greg Claytondea8cb42011-06-29 22:09:02 +0000704 // We may need to update our value if we are dynamic
705 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000706 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000707
708 std::vector<uint32_t> child_indexes;
Greg Claytondea8cb42011-06-29 22:09:02 +0000709 bool omit_empty_base_classes = true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000710 const size_t num_child_indexes = GetClangType().GetIndexOfChildMemberWithName (name.GetCString(),
711 omit_empty_base_classes,
712 child_indexes);
Greg Claytondea8cb42011-06-29 22:09:02 +0000713 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000714 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000715 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
716 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
717
718 child_sp = GetChildAtIndex(*pos, can_create);
719 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000720 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000721 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000722 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000723 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
724 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000725 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000726 else
727 {
728 child_sp.reset();
729 }
730
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000731 }
732 }
733 return child_sp;
734}
735
736
Greg Claytonc7bece562013-01-25 18:06:21 +0000737size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000738ValueObject::GetNumChildren ()
739{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000740 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000741 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000742 {
743 SetNumChildren (CalculateNumChildren());
744 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000745 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000746}
Greg Clayton4a792072012-10-23 01:50:10 +0000747
748bool
749ValueObject::MightHaveChildren()
750{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000751 bool has_children = false;
Greg Clayton2452ab72013-02-08 22:02:02 +0000752 const uint32_t type_info = GetTypeInfo();
753 if (type_info)
Greg Clayton4a792072012-10-23 01:50:10 +0000754 {
Enrico Granata622be232014-10-21 20:52:14 +0000755 if (type_info & (eTypeHasChildren |
756 eTypeIsPointer |
757 eTypeIsReference))
Greg Clayton4a792072012-10-23 01:50:10 +0000758 has_children = true;
759 }
760 else
761 {
762 has_children = GetNumChildren () > 0;
763 }
764 return has_children;
765}
766
767// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000768void
Greg Claytonc7bece562013-01-25 18:06:21 +0000769ValueObject::SetNumChildren (size_t num_children)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000770{
Greg Clayton288bdf92010-09-02 02:59:18 +0000771 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000772 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000773}
774
775void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000776ValueObject::SetName (const ConstString &name)
777{
778 m_name = name;
779}
780
Jim Ingham58b59f92011-04-22 23:53:53 +0000781ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000782ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000783{
Jim Ingham2eec4872011-05-07 00:10:58 +0000784 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000785
Greg Claytondea8cb42011-06-29 22:09:02 +0000786 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000787 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000788 std::string child_name_str;
789 uint32_t child_byte_size = 0;
790 int32_t child_byte_offset = 0;
791 uint32_t child_bitfield_bit_size = 0;
792 uint32_t child_bitfield_bit_offset = 0;
793 bool child_is_base_class = false;
794 bool child_is_deref_of_parent = false;
795
796 const bool transparent_pointers = synthetic_array_member == false;
Greg Clayton57ee3062013-07-11 22:46:58 +0000797 ClangASTType child_clang_type;
Greg Claytondea8cb42011-06-29 22:09:02 +0000798
Greg Claytoncc4d0142012-02-17 07:49:44 +0000799 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000800
Greg Clayton57ee3062013-07-11 22:46:58 +0000801 child_clang_type = GetClangType().GetChildClangTypeAtIndex (&exe_ctx,
Greg Clayton57ee3062013-07-11 22:46:58 +0000802 idx,
803 transparent_pointers,
804 omit_empty_base_classes,
805 ignore_array_bounds,
806 child_name_str,
807 child_byte_size,
808 child_byte_offset,
809 child_bitfield_bit_size,
810 child_bitfield_bit_offset,
811 child_is_base_class,
Greg Clayton759e7442014-07-19 00:12:57 +0000812 child_is_deref_of_parent,
813 this);
Greg Clayton4ef877f2012-12-06 02:33:54 +0000814 if (child_clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000815 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000816 if (synthetic_index)
817 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000818
Greg Claytondea8cb42011-06-29 22:09:02 +0000819 ConstString child_name;
820 if (!child_name_str.empty())
821 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000822
Greg Claytondea8cb42011-06-29 22:09:02 +0000823 valobj = new ValueObjectChild (*this,
Greg Claytondea8cb42011-06-29 22:09:02 +0000824 child_clang_type,
825 child_name,
826 child_byte_size,
827 child_byte_offset,
828 child_bitfield_bit_size,
829 child_bitfield_bit_offset,
830 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000831 child_is_deref_of_parent,
832 eAddressTypeInvalid);
833 //if (valobj)
834 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
835 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000836
Jim Ingham58b59f92011-04-22 23:53:53 +0000837 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000838}
839
Enrico Granata0c489f52012-03-01 04:24:26 +0000840bool
841ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
842 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000843{
Enrico Granata0c489f52012-03-01 04:24:26 +0000844 destination.clear();
845
846 // ideally we would like to bail out if passing NULL, but if we do so
847 // we end up not providing the summary for function pointers anymore
848 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
849 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000850
851 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000852
853 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
854 // information that we might care to see in a crash log. might be useful in very specific situations though.
855 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
856 GetTypeName().GetCString(),
857 GetName().GetCString(),
858 summary_ptr->GetDescription().c_str());*/
859
Enrico Granata0c489f52012-03-01 04:24:26 +0000860 if (UpdateValueIfNeeded (false))
861 {
862 if (summary_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000863 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000864 if (HasSyntheticValue())
865 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
866 summary_ptr->FormatObject(this, destination);
Enrico Granata0c489f52012-03-01 04:24:26 +0000867 }
868 else
869 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000870 ClangASTType clang_type = GetClangType();
Enrico Granata0c489f52012-03-01 04:24:26 +0000871
872 // Do some default printout for function pointers
873 if (clang_type)
Enrico Granata4becb372011-06-29 22:27:15 +0000874 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000875 if (clang_type.IsFunctionPointerType ())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000876 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000877 StreamString sstr;
Enrico Granata0c489f52012-03-01 04:24:26 +0000878 AddressType func_ptr_address_type = eAddressTypeInvalid;
879 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
880 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000881 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000882 switch (func_ptr_address_type)
Jim Ingham6035b672011-03-31 00:19:25 +0000883 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000884 case eAddressTypeInvalid:
885 case eAddressTypeFile:
886 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000887
Greg Claytoncc4d0142012-02-17 07:49:44 +0000888 case eAddressTypeLoad:
Enrico Granata0c489f52012-03-01 04:24:26 +0000889 {
890 ExecutionContext exe_ctx (GetExecutionContextRef());
891
892 Address so_addr;
893 Target *target = exe_ctx.GetTargetPtr();
894 if (target && target->GetSectionLoadList().IsEmpty() == false)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000895 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000896 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000897 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000898 so_addr.Dump (&sstr,
899 exe_ctx.GetBestExecutionContextScope(),
900 Address::DumpStyleResolvedDescription,
901 Address::DumpStyleSectionNameOffset);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000902 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000903 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000904 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000905 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000906
Greg Claytoncc4d0142012-02-17 07:49:44 +0000907 case eAddressTypeHost:
908 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +0000909 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000910 }
911 if (sstr.GetSize() > 0)
912 {
913 destination.assign (1, '(');
914 destination.append (sstr.GetData(), sstr.GetSize());
915 destination.append (1, ')');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000916 }
917 }
918 }
919 }
920 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000921 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000922 return !destination.empty();
923}
924
925const char *
926ValueObject::GetSummaryAsCString ()
927{
928 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
929 {
930 GetSummaryAsCString(GetSummaryFormat().get(),
931 m_summary_str);
932 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000933 if (m_summary_str.empty())
934 return NULL;
935 return m_summary_str.c_str();
936}
937
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000938bool
939ValueObject::IsCStringContainer(bool check_pointer)
940{
Greg Clayton57ee3062013-07-11 22:46:58 +0000941 ClangASTType pointee_or_element_clang_type;
942 const Flags type_flags (GetTypeInfo (&pointee_or_element_clang_type));
Enrico Granata622be232014-10-21 20:52:14 +0000943 bool is_char_arr_ptr (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Greg Clayton57ee3062013-07-11 22:46:58 +0000944 pointee_or_element_clang_type.IsCharType ());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000945 if (!is_char_arr_ptr)
946 return false;
947 if (!check_pointer)
948 return true;
Enrico Granata622be232014-10-21 20:52:14 +0000949 if (type_flags.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000950 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000951 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000952 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000953 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000954 return (cstr_address != LLDB_INVALID_ADDRESS);
955}
956
Enrico Granata9128ee22011-09-06 19:20:51 +0000957size_t
958ValueObject::GetPointeeData (DataExtractor& data,
959 uint32_t item_idx,
960 uint32_t item_count)
961{
Greg Clayton57ee3062013-07-11 22:46:58 +0000962 ClangASTType pointee_or_element_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +0000963 const uint32_t type_info = GetTypeInfo (&pointee_or_element_clang_type);
Enrico Granata622be232014-10-21 20:52:14 +0000964 const bool is_pointer_type = type_info & eTypeIsPointer;
965 const bool is_array_type = type_info & eTypeIsArray;
Greg Clayton2452ab72013-02-08 22:02:02 +0000966 if (!(is_pointer_type || is_array_type))
Enrico Granata9128ee22011-09-06 19:20:51 +0000967 return 0;
968
969 if (item_count == 0)
970 return 0;
971
Greg Clayton57ee3062013-07-11 22:46:58 +0000972 const uint64_t item_type_size = pointee_or_element_clang_type.GetByteSize();
Enrico Granata9128ee22011-09-06 19:20:51 +0000973 const uint64_t bytes = item_count * item_type_size;
Enrico Granata9128ee22011-09-06 19:20:51 +0000974 const uint64_t offset = item_idx * item_type_size;
975
976 if (item_idx == 0 && item_count == 1) // simply a deref
977 {
Greg Clayton2452ab72013-02-08 22:02:02 +0000978 if (is_pointer_type)
Enrico Granata9128ee22011-09-06 19:20:51 +0000979 {
980 Error error;
981 ValueObjectSP pointee_sp = Dereference(error);
982 if (error.Fail() || pointee_sp.get() == NULL)
983 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +0000984 return pointee_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +0000985 }
986 else
987 {
988 ValueObjectSP child_sp = GetChildAtIndex(0, true);
989 if (child_sp.get() == NULL)
990 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +0000991 Error error;
992 return child_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +0000993 }
994 return true;
995 }
996 else /* (items > 1) */
997 {
998 Error error;
999 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
1000 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
1001
1002 AddressType addr_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001003 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001004
Enrico Granata9128ee22011-09-06 19:20:51 +00001005 switch (addr_type)
1006 {
1007 case eAddressTypeFile:
1008 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001009 ModuleSP module_sp (GetModule());
1010 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001011 {
Enrico Granata9c2efe32012-08-07 01:49:34 +00001012 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +00001013 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001014 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001015 ExecutionContext exe_ctx (GetExecutionContextRef());
1016 Target* target = exe_ctx.GetTargetPtr();
1017 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +00001018 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001019 heap_buf_ptr->SetByteSize(bytes);
1020 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
1021 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +00001022 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001023 data.SetData(data_sp);
1024 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +00001025 }
1026 }
1027 }
1028 }
1029 break;
1030 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +00001031 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001032 ExecutionContext exe_ctx (GetExecutionContextRef());
1033 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +00001034 if (process)
1035 {
1036 heap_buf_ptr->SetByteSize(bytes);
1037 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
Enrico Granata5e1480c2013-10-30 17:52:44 +00001038 if (error.Success() || bytes_read > 0)
Enrico Granata9128ee22011-09-06 19:20:51 +00001039 {
1040 data.SetData(data_sp);
1041 return bytes_read;
1042 }
1043 }
1044 }
1045 break;
1046 case eAddressTypeHost:
1047 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001048 const uint64_t max_bytes = GetClangType().GetByteSize();
Greg Clayton2452ab72013-02-08 22:02:02 +00001049 if (max_bytes > offset)
1050 {
1051 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
1052 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
1053 data.SetData(data_sp);
1054 return bytes_read;
1055 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001056 }
1057 break;
1058 case eAddressTypeInvalid:
Enrico Granata9128ee22011-09-06 19:20:51 +00001059 break;
1060 }
1061 }
1062 return 0;
1063}
1064
Greg Claytonfaac1112013-03-14 18:31:44 +00001065uint64_t
Sean Callanan866e91c2014-02-28 22:27:53 +00001066ValueObject::GetData (DataExtractor& data, Error &error)
Enrico Granata9128ee22011-09-06 19:20:51 +00001067{
1068 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001069 ExecutionContext exe_ctx (GetExecutionContextRef());
Sean Callanan866e91c2014-02-28 22:27:53 +00001070 error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001071 if (error.Fail())
Sean Callananed185ab2013-04-19 19:47:32 +00001072 {
1073 if (m_data.GetByteSize())
1074 {
1075 data = m_data;
1076 return data.GetByteSize();
1077 }
1078 else
1079 {
1080 return 0;
1081 }
1082 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001083 data.SetAddressByteSize(m_data.GetAddressByteSize());
1084 data.SetByteOrder(m_data.GetByteOrder());
1085 return data.GetByteSize();
1086}
1087
Sean Callanan389823e2013-04-13 01:21:23 +00001088bool
1089ValueObject::SetData (DataExtractor &data, Error &error)
1090{
1091 error.Clear();
1092 // Make sure our value is up to date first so that our location and location
1093 // type is valid.
1094 if (!UpdateValueIfNeeded(false))
1095 {
1096 error.SetErrorString("unable to read value");
1097 return false;
1098 }
1099
1100 uint64_t count = 0;
Greg Clayton57ee3062013-07-11 22:46:58 +00001101 const Encoding encoding = GetClangType().GetEncoding(count);
Sean Callanan389823e2013-04-13 01:21:23 +00001102
1103 const size_t byte_size = GetByteSize();
1104
1105 Value::ValueType value_type = m_value.GetValueType();
1106
1107 switch (value_type)
1108 {
1109 case Value::eValueTypeScalar:
1110 {
1111 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1112
1113 if (!set_error.Success())
1114 {
1115 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1116 return false;
1117 }
1118 }
1119 break;
1120 case Value::eValueTypeLoadAddress:
1121 {
1122 // If it is a load address, then the scalar value is the storage location
1123 // of the data, and we have to shove this value down to that load location.
1124 ExecutionContext exe_ctx (GetExecutionContextRef());
1125 Process *process = exe_ctx.GetProcessPtr();
1126 if (process)
1127 {
1128 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1129 size_t bytes_written = process->WriteMemory(target_addr,
1130 data.GetDataStart(),
1131 byte_size,
1132 error);
1133 if (!error.Success())
1134 return false;
1135 if (bytes_written != byte_size)
1136 {
1137 error.SetErrorString("unable to write value to memory");
1138 return false;
1139 }
1140 }
1141 }
1142 break;
1143 case Value::eValueTypeHostAddress:
1144 {
1145 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1146 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1147 m_data.SetData(buffer_sp, 0);
1148 data.CopyByteOrderedData (0,
1149 byte_size,
1150 const_cast<uint8_t *>(m_data.GetDataStart()),
1151 byte_size,
1152 m_data.GetByteOrder());
1153 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1154 }
1155 break;
1156 case Value::eValueTypeFileAddress:
1157 case Value::eValueTypeVector:
1158 break;
1159 }
1160
1161 // If we have reached this point, then we have successfully changed the value.
1162 SetNeedsUpdate();
1163 return true;
1164}
1165
Enrico Granata9128ee22011-09-06 19:20:51 +00001166// will compute strlen(str), but without consuming more than
1167// maxlen bytes out of str (this serves the purpose of reading
1168// chunks of a string without having to worry about
1169// missing NULL terminators in the chunk)
1170// of course, if strlen(str) > maxlen, the function will return
1171// maxlen_value (which should be != maxlen, because that allows you
1172// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1173static uint32_t
1174strlen_or_inf (const char* str,
1175 uint32_t maxlen,
1176 uint32_t maxlen_value)
1177{
1178 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +00001179 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +00001180 {
Greg Clayton8dd5c172011-10-05 22:19:51 +00001181 while(*str)
1182 {
1183 len++;str++;
Greg Clayton2452ab72013-02-08 22:02:02 +00001184 if (len >= maxlen)
Greg Clayton8dd5c172011-10-05 22:19:51 +00001185 return maxlen_value;
1186 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001187 }
1188 return len;
1189}
1190
Enrico Granata2206b482014-10-30 18:27:31 +00001191static bool
1192CopyStringDataToBufferSP(const StreamString& source,
1193 lldb::DataBufferSP& destination)
1194{
1195 destination.reset(new DataBufferHeap(source.GetSize()+1,0));
1196 memcpy(destination->GetBytes(), source.GetString().c_str(), source.GetSize());
1197 return true;
1198}
1199
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001200size_t
Enrico Granata2206b482014-10-30 18:27:31 +00001201ValueObject::ReadPointedString (lldb::DataBufferSP& buffer_sp,
Greg Claytoncc4d0142012-02-17 07:49:44 +00001202 Error& error,
1203 uint32_t max_length,
1204 bool honor_array,
1205 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001206{
Enrico Granata2206b482014-10-30 18:27:31 +00001207 StreamString s;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001208 ExecutionContext exe_ctx (GetExecutionContextRef());
1209 Target* target = exe_ctx.GetTargetPtr();
Enrico Granata2206b482014-10-30 18:27:31 +00001210
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001211 if (!target)
1212 {
1213 s << "<no target to read from>";
1214 error.SetErrorString("no target to read from");
Enrico Granata2206b482014-10-30 18:27:31 +00001215 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001216 return 0;
1217 }
1218
1219 if (max_length == 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001220 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001221
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001222 size_t bytes_read = 0;
1223 size_t total_bytes_read = 0;
1224
Greg Clayton57ee3062013-07-11 22:46:58 +00001225 ClangASTType clang_type = GetClangType();
1226 ClangASTType elem_or_pointee_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001227 const Flags type_flags (GetTypeInfo (&elem_or_pointee_clang_type));
Enrico Granata622be232014-10-21 20:52:14 +00001228 if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Greg Clayton57ee3062013-07-11 22:46:58 +00001229 elem_or_pointee_clang_type.IsCharType ())
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001230 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001231 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1232 AddressType cstr_address_type = eAddressTypeInvalid;
1233
1234 size_t cstr_len = 0;
1235 bool capped_data = false;
Enrico Granata622be232014-10-21 20:52:14 +00001236 if (type_flags.Test (eTypeIsArray))
Greg Claytoncc4d0142012-02-17 07:49:44 +00001237 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001238 // We have an array
Greg Clayton57ee3062013-07-11 22:46:58 +00001239 uint64_t array_size = 0;
1240 if (clang_type.IsArrayType(NULL, &array_size, NULL))
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001241 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001242 cstr_len = array_size;
1243 if (cstr_len > max_length)
1244 {
1245 capped_data = true;
1246 cstr_len = max_length;
1247 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001248 }
1249 cstr_address = GetAddressOf (true, &cstr_address_type);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001250 }
1251 else
1252 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001253 // We have a pointer
1254 cstr_address = GetPointerValue (&cstr_address_type);
1255 }
1256
1257 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1258 {
1259 s << "<invalid address>";
1260 error.SetErrorString("invalid address");
Enrico Granata2206b482014-10-30 18:27:31 +00001261 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001262 return 0;
1263 }
Enrico Granata2206b482014-10-30 18:27:31 +00001264
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001265 Address cstr_so_addr (cstr_address);
1266 DataExtractor data;
1267 if (cstr_len > 0 && honor_array)
1268 {
1269 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1270 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1271 GetPointeeData(data, 0, cstr_len);
Enrico Granata2206b482014-10-30 18:27:31 +00001272
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001273 if ((bytes_read = data.GetByteSize()) > 0)
1274 {
1275 total_bytes_read = bytes_read;
Enrico Granata2206b482014-10-30 18:27:31 +00001276 for (size_t offset = 0; offset < bytes_read; offset++)
1277 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001278 if (capped_data)
1279 s << "...";
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001280 }
1281 }
1282 else
1283 {
1284 cstr_len = max_length;
1285 const size_t k_max_buf_size = 64;
Enrico Granata2206b482014-10-30 18:27:31 +00001286
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001287 size_t offset = 0;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001288
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001289 int cstr_len_displayed = -1;
1290 bool capped_cstr = false;
1291 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1292 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1293 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001294 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001295 total_bytes_read += bytes_read;
1296 const char *cstr = data.PeekCStr(0);
1297 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1298 if (len > k_max_buf_size)
1299 len = k_max_buf_size;
Enrico Granata2206b482014-10-30 18:27:31 +00001300
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001301 if (cstr_len_displayed < 0)
1302 cstr_len_displayed = len;
Enrico Granata2206b482014-10-30 18:27:31 +00001303
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001304 if (len == 0)
1305 break;
1306 cstr_len_displayed += len;
1307 if (len > bytes_read)
1308 len = bytes_read;
1309 if (len > cstr_len)
1310 len = cstr_len;
1311
Enrico Granata2206b482014-10-30 18:27:31 +00001312 for (size_t offset = 0; offset < bytes_read; offset++)
1313 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001314
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 Granata2206b482014-10-30 18:27:31 +00001323
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001324 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 if (capped_cstr)
1331 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001332 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001333 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001334 }
1335 else
1336 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001337 error.SetErrorString("not a string object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001338 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001339 }
Enrico Granata2206b482014-10-30 18:27:31 +00001340 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001341 return total_bytes_read;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001342}
1343
Enrico Granata744794a2014-09-05 21:46:22 +00001344std::pair<TypeValidatorResult, std::string>
1345ValueObject::GetValidationStatus ()
1346{
1347 if (!UpdateValueIfNeeded(true))
1348 return {TypeValidatorResult::Success,""}; // not the validator's job to discuss update problems
1349
1350 if (m_validation_result.hasValue())
1351 return m_validation_result.getValue();
1352
1353 if (!m_type_validator_sp)
1354 return {TypeValidatorResult::Success,""}; // no validator no failure
1355
1356 auto outcome = m_type_validator_sp->FormatObject(this);
1357
1358 return (m_validation_result = {outcome.m_result,outcome.m_message}).getValue();
1359}
1360
Jim Ingham53c47f12010-09-10 23:12:17 +00001361const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001362ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001363{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001364
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001365 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001366 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001367
1368 if (!m_object_desc_str.empty())
1369 return m_object_desc_str.c_str();
1370
Greg Claytoncc4d0142012-02-17 07:49:44 +00001371 ExecutionContext exe_ctx (GetExecutionContextRef());
1372 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001373 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001374 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001375
Jim Ingham53c47f12010-09-10 23:12:17 +00001376 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001377
Greg Claytonafacd142011-09-02 01:15:17 +00001378 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001379 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1380
Jim Inghama2cf2632010-12-23 02:29:54 +00001381 if (runtime == NULL)
1382 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001383 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Greg Clayton57ee3062013-07-11 22:46:58 +00001384 ClangASTType clang_type = GetClangType();
1385 if (clang_type)
Jim Inghama2cf2632010-12-23 02:29:54 +00001386 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001387 bool is_signed;
Greg Clayton57ee3062013-07-11 22:46:58 +00001388 if (clang_type.IsIntegerType (is_signed) || clang_type.IsPointerType ())
Jim Inghamb7603bb2011-03-18 00:05:18 +00001389 {
Greg Claytonafacd142011-09-02 01:15:17 +00001390 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001391 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001392 }
1393 }
1394
Jim Ingham8d543de2011-03-31 23:01:21 +00001395 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001396 {
1397 m_object_desc_str.append (s.GetData());
1398 }
Sean Callanan672ad942010-10-23 00:18:49 +00001399
1400 if (m_object_desc_str.empty())
1401 return NULL;
1402 else
1403 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001404}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001405
Enrico Granata0c489f52012-03-01 04:24:26 +00001406bool
Enrico Granata4939b982013-12-22 09:24:22 +00001407ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format,
1408 std::string& destination)
1409{
1410 if (UpdateValueIfNeeded(false))
1411 return format.FormatObject(this,destination);
1412 else
1413 return false;
1414}
1415
1416bool
Enrico Granata0c489f52012-03-01 04:24:26 +00001417ValueObject::GetValueAsCString (lldb::Format format,
1418 std::string& destination)
1419{
Enrico Granata30f287f2013-12-28 08:44:02 +00001420 return GetValueAsCString(TypeFormatImpl_Format(format),destination);
Enrico Granata0c489f52012-03-01 04:24:26 +00001421}
1422
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001423const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001424ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001425{
Enrico Granatab294fd22013-05-31 19:18:19 +00001426 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001427 {
Enrico Granata4939b982013-12-22 09:24:22 +00001428 lldb::TypeFormatImplSP format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001429 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001430 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001431 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001432 if (m_type_format_sp)
Enrico Granata4939b982013-12-22 09:24:22 +00001433 format_sp = m_type_format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001434 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001435 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001436 if (m_is_bitfield_for_scalar)
1437 my_format = eFormatUnsigned;
1438 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001439 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001440 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001441 {
1442 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1443 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001444 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001445 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001446 else
1447 {
Enrico Granatad07cfd32014-10-08 18:27:36 +00001448 my_format = GetValue().GetClangType().GetFormat();
Enrico Granata0c489f52012-03-01 04:24:26 +00001449 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001450 }
1451 }
1452 }
Enrico Granatab294fd22013-05-31 19:18:19 +00001453 if (my_format != m_last_format || m_value_str.empty())
Enrico Granata297e69f2012-03-06 23:21:16 +00001454 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001455 m_last_format = my_format;
Enrico Granata4939b982013-12-22 09:24:22 +00001456 if (!format_sp)
Enrico Granata30f287f2013-12-28 08:44:02 +00001457 format_sp.reset(new TypeFormatImpl_Format(my_format));
Enrico Granata4939b982013-12-22 09:24:22 +00001458 if (GetValueAsCString(*format_sp.get(), m_value_str))
Enrico Granata297e69f2012-03-06 23:21:16 +00001459 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001460 if (!m_value_did_change && m_old_value_valid)
1461 {
1462 // The value was gotten successfully, so we consider the
1463 // value as changed if the value string differs
1464 SetValueDidChange (m_old_value_str != m_value_str);
1465 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001466 }
1467 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001468 }
1469 if (m_value_str.empty())
1470 return NULL;
1471 return m_value_str.c_str();
1472}
1473
Enrico Granatac3e320a2011-08-02 17:27:39 +00001474// if > 8bytes, 0 is returned. this method should mostly be used
1475// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001476uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001477ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001478{
1479 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001480 if (CanProvideValue())
Enrico Granatac3e320a2011-08-02 17:27:39 +00001481 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001482 Scalar scalar;
1483 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001484 {
1485 if (success)
1486 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001487 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001488 }
1489 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001490 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001491
1492 if (success)
1493 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001494 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001495}
1496
Enrico Granatad7373f62013-10-31 18:57:50 +00001497int64_t
1498ValueObject::GetValueAsSigned (int64_t fail_value, bool *success)
1499{
1500 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001501 if (CanProvideValue())
Enrico Granatad7373f62013-10-31 18:57:50 +00001502 {
1503 Scalar scalar;
1504 if (ResolveValue (scalar))
1505 {
1506 if (success)
1507 *success = true;
1508 return scalar.SLongLong(fail_value);
1509 }
1510 // fallthrough, otherwise...
1511 }
1512
1513 if (success)
1514 *success = false;
1515 return fail_value;
1516}
1517
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001518// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1519// this call up to date by returning true for your new special cases. We will eventually move
1520// to checking this call result before trying to display special cases
1521bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001522ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1523 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001524{
Greg Clayton57ee3062013-07-11 22:46:58 +00001525 Flags flags(GetTypeInfo());
Enrico Granata622be232014-10-21 20:52:14 +00001526 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001527 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001528 {
1529 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001530 (custom_format == eFormatCString ||
1531 custom_format == eFormatCharArray ||
1532 custom_format == eFormatChar ||
1533 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001534 return true;
1535
Enrico Granata622be232014-10-21 20:52:14 +00001536 if (flags.Test(eTypeIsArray))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001537 {
Greg Claytonafacd142011-09-02 01:15:17 +00001538 if ((custom_format == eFormatBytes) ||
1539 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001540 return true;
1541
Greg Claytonafacd142011-09-02 01:15:17 +00001542 if ((custom_format == eFormatVectorOfChar) ||
1543 (custom_format == eFormatVectorOfFloat32) ||
1544 (custom_format == eFormatVectorOfFloat64) ||
1545 (custom_format == eFormatVectorOfSInt16) ||
1546 (custom_format == eFormatVectorOfSInt32) ||
1547 (custom_format == eFormatVectorOfSInt64) ||
1548 (custom_format == eFormatVectorOfSInt8) ||
1549 (custom_format == eFormatVectorOfUInt128) ||
1550 (custom_format == eFormatVectorOfUInt16) ||
1551 (custom_format == eFormatVectorOfUInt32) ||
1552 (custom_format == eFormatVectorOfUInt64) ||
1553 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001554 return true;
1555 }
1556 }
1557 return false;
1558}
1559
Enrico Granata9fc19442011-07-06 02:13:41 +00001560bool
1561ValueObject::DumpPrintableRepresentation(Stream& s,
1562 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001563 Format custom_format,
Enrico Granata0dba9b32014-01-08 01:36:59 +00001564 PrintableRepresentationSpecialCases special,
1565 bool do_dump_error)
Enrico Granata9fc19442011-07-06 02:13:41 +00001566{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001567
Greg Clayton57ee3062013-07-11 22:46:58 +00001568 Flags flags(GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001569
Enrico Granata86cc9822012-03-19 22:58:49 +00001570 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1571 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1572
1573 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001574 {
Enrico Granata622be232014-10-21 20:52:14 +00001575 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001576 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001577 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001578 // when being asked to get a printable display an array or pointer type directly,
1579 // try to "do the right thing"
1580
1581 if (IsCStringContainer(true) &&
1582 (custom_format == eFormatCString ||
1583 custom_format == eFormatCharArray ||
1584 custom_format == eFormatChar ||
1585 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001586 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001587 Error error;
Enrico Granata2206b482014-10-30 18:27:31 +00001588 lldb::DataBufferSP buffer_sp;
1589 ReadPointedString(buffer_sp,
Enrico Granata86cc9822012-03-19 22:58:49 +00001590 error,
1591 0,
1592 (custom_format == eFormatVectorOfChar) ||
1593 (custom_format == eFormatCharArray));
Enrico Granata2206b482014-10-30 18:27:31 +00001594 lldb_private::formatters::ReadBufferAndDumpToStreamOptions options;
1595 options.SetData(DataExtractor(buffer_sp, lldb::eByteOrderInvalid, 8)); // none of this matters for a string - pass some defaults
1596 options.SetStream(&s);
1597 options.SetPrefixToken(0);
1598 options.SetQuote('"');
1599 options.SetSourceSize(buffer_sp->GetByteSize());
1600 options.SetEscapeNonPrintables(true);
1601 lldb_private::formatters::ReadBufferAndDumpToStream<lldb_private::formatters::StringElementType::ASCII>(options);
Enrico Granata86cc9822012-03-19 22:58:49 +00001602 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001603 }
1604
Enrico Granata86cc9822012-03-19 22:58:49 +00001605 if (custom_format == eFormatEnum)
1606 return false;
1607
1608 // this only works for arrays, because I have no way to know when
1609 // the pointed memory ends, and no special \0 end of data marker
Enrico Granata622be232014-10-21 20:52:14 +00001610 if (flags.Test(eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001611 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001612 if ((custom_format == eFormatBytes) ||
1613 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001614 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001615 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001616
1617 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001618 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001619 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001620
1621 if (low)
1622 s << ',';
1623
1624 ValueObjectSP child = GetChildAtIndex(low,true);
1625 if (!child.get())
1626 {
1627 s << "<invalid child>";
1628 continue;
1629 }
1630 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1631 }
1632
1633 s << ']';
1634
1635 return true;
1636 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001637
Enrico Granata86cc9822012-03-19 22:58:49 +00001638 if ((custom_format == eFormatVectorOfChar) ||
1639 (custom_format == eFormatVectorOfFloat32) ||
1640 (custom_format == eFormatVectorOfFloat64) ||
1641 (custom_format == eFormatVectorOfSInt16) ||
1642 (custom_format == eFormatVectorOfSInt32) ||
1643 (custom_format == eFormatVectorOfSInt64) ||
1644 (custom_format == eFormatVectorOfSInt8) ||
1645 (custom_format == eFormatVectorOfUInt128) ||
1646 (custom_format == eFormatVectorOfUInt16) ||
1647 (custom_format == eFormatVectorOfUInt32) ||
1648 (custom_format == eFormatVectorOfUInt64) ||
1649 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1650 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001651 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001652
1653 Format format = FormatManager::GetSingleItemFormat(custom_format);
1654
1655 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001656 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001657 {
1658
1659 if (low)
1660 s << ',';
1661
1662 ValueObjectSP child = GetChildAtIndex(low,true);
1663 if (!child.get())
1664 {
1665 s << "<invalid child>";
1666 continue;
1667 }
1668 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1669 }
1670
1671 s << ']';
1672
1673 return true;
1674 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001675 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001676
1677 if ((custom_format == eFormatBoolean) ||
1678 (custom_format == eFormatBinary) ||
1679 (custom_format == eFormatChar) ||
1680 (custom_format == eFormatCharPrintable) ||
1681 (custom_format == eFormatComplexFloat) ||
1682 (custom_format == eFormatDecimal) ||
1683 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001684 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001685 (custom_format == eFormatFloat) ||
1686 (custom_format == eFormatOctal) ||
1687 (custom_format == eFormatOSType) ||
1688 (custom_format == eFormatUnicode16) ||
1689 (custom_format == eFormatUnicode32) ||
1690 (custom_format == eFormatUnsigned) ||
1691 (custom_format == eFormatPointer) ||
1692 (custom_format == eFormatComplexInteger) ||
1693 (custom_format == eFormatComplex) ||
1694 (custom_format == eFormatDefault)) // use the [] operator
1695 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001696 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001697 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001698
1699 if (only_special)
1700 return false;
1701
Enrico Granata86cc9822012-03-19 22:58:49 +00001702 bool var_success = false;
1703
1704 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001705 const char *cstr = NULL;
Enrico Granata2c75f112013-06-21 00:04:51 +00001706
1707 // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1708 // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1709 // area for cases where our desired output is not backed by some other longer-term storage
Greg Claytonc7bece562013-01-25 18:06:21 +00001710 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001711
Enrico Granata465f4bc2014-02-15 01:24:44 +00001712 if (custom_format != eFormatInvalid)
Enrico Granata86cc9822012-03-19 22:58:49 +00001713 SetFormat(custom_format);
1714
1715 switch(val_obj_display)
1716 {
1717 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001718 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001719 break;
1720
1721 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001722 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001723 break;
1724
1725 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001726 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001727 break;
1728
1729 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001730 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001731 break;
1732
1733 case eValueObjectRepresentationStyleChildrenCount:
Deepak Panickal99fbc072014-03-03 15:39:47 +00001734 strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren());
Greg Claytonc7bece562013-01-25 18:06:21 +00001735 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001736 break;
1737
1738 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001739 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001740 break;
Enrico Granata2c75f112013-06-21 00:04:51 +00001741
1742 case eValueObjectRepresentationStyleName:
1743 cstr = GetName().AsCString();
1744 break;
1745
1746 case eValueObjectRepresentationStyleExpressionPath:
1747 GetExpressionPath(strm, false);
1748 cstr = strm.GetString().c_str();
1749 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001750 }
1751
Greg Claytonc7bece562013-01-25 18:06:21 +00001752 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001753 {
1754 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001755 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001756 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1757 {
Enrico Granatad07cfd32014-10-08 18:27:36 +00001758 if (!CanProvideValue())
Enrico Granata86cc9822012-03-19 22:58:49 +00001759 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001760 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1761 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001762 }
1763 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001764 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001765 }
1766 }
1767
Greg Claytonc7bece562013-01-25 18:06:21 +00001768 if (cstr)
1769 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001770 else
1771 {
1772 if (m_error.Fail())
Enrico Granata0dba9b32014-01-08 01:36:59 +00001773 {
1774 if (do_dump_error)
1775 s.Printf("<%s>", m_error.AsCString());
1776 else
1777 return false;
1778 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001779 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1780 s.PutCString("<no summary available>");
1781 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1782 s.PutCString("<no value available>");
1783 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1784 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1785 else
1786 s.PutCString("<no printable representation>");
1787 }
1788
1789 // we should only return false here if we could not do *anything*
1790 // even if we have an error message as output, that's a success
1791 // from our callers' perspective, so return true
1792 var_success = true;
Enrico Granata465f4bc2014-02-15 01:24:44 +00001793
1794 if (custom_format != eFormatInvalid)
1795 SetFormat(eFormatDefault);
Enrico Granata86cc9822012-03-19 22:58:49 +00001796 }
1797
Enrico Granataf4efecd2011-07-12 22:56:10 +00001798 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001799}
1800
Greg Clayton737b9322010-09-13 03:32:57 +00001801addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001802ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001803{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001804 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001805 return LLDB_INVALID_ADDRESS;
1806
Greg Clayton73b472d2010-10-27 03:32:59 +00001807 switch (m_value.GetValueType())
1808 {
1809 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001810 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001811 if (scalar_is_load_address)
1812 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001813 if(address_type)
1814 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001815 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1816 }
1817 break;
1818
1819 case Value::eValueTypeLoadAddress:
1820 case Value::eValueTypeFileAddress:
1821 case Value::eValueTypeHostAddress:
1822 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001823 if(address_type)
1824 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001825 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1826 }
1827 break;
1828 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001829 if (address_type)
1830 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001831 return LLDB_INVALID_ADDRESS;
1832}
1833
1834addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001835ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001836{
Greg Claytonafacd142011-09-02 01:15:17 +00001837 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001838 if(address_type)
1839 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001840
Enrico Granatac3e320a2011-08-02 17:27:39 +00001841 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001842 return address;
1843
Greg Clayton73b472d2010-10-27 03:32:59 +00001844 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001845 {
1846 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001847 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001848 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001849 break;
1850
Enrico Granata9128ee22011-09-06 19:20:51 +00001851 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001852 case Value::eValueTypeLoadAddress:
1853 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001854 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001855 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001856 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001857 }
1858 break;
1859 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001860
Enrico Granata9128ee22011-09-06 19:20:51 +00001861 if (address_type)
1862 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001863
Greg Clayton737b9322010-09-13 03:32:57 +00001864 return address;
1865}
1866
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001867bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001868ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001869{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001870 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001871 // Make sure our value is up to date first so that our location and location
1872 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001873 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001874 {
1875 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001876 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001877 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001878
Greg Claytonfaac1112013-03-14 18:31:44 +00001879 uint64_t count = 0;
Greg Clayton57ee3062013-07-11 22:46:58 +00001880 const Encoding encoding = GetClangType().GetEncoding (count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001881
Greg Claytonb1320972010-07-14 00:18:15 +00001882 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001883
Jim Ingham16e0c682011-08-12 23:34:31 +00001884 Value::ValueType value_type = m_value.GetValueType();
1885
1886 if (value_type == Value::eValueTypeScalar)
1887 {
1888 // If the value is already a scalar, then let the scalar change itself:
1889 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1890 }
1891 else if (byte_size <= Scalar::GetMaxByteSize())
1892 {
1893 // If the value fits in a scalar, then make a new scalar and again let the
1894 // scalar code do the conversion, then figure out where to put the new value.
1895 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001896 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1897 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001898 {
Jim Ingham4b536182011-08-09 02:12:22 +00001899 switch (value_type)
1900 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001901 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001902 {
1903 // If it is a load address, then the scalar value is the storage location
1904 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001905 ExecutionContext exe_ctx (GetExecutionContextRef());
1906 Process *process = exe_ctx.GetProcessPtr();
1907 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001908 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001909 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001910 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1911 new_scalar,
1912 byte_size,
1913 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001914 if (!error.Success())
1915 return false;
1916 if (bytes_written != byte_size)
1917 {
1918 error.SetErrorString("unable to write value to memory");
1919 return false;
1920 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001921 }
1922 }
Jim Ingham4b536182011-08-09 02:12:22 +00001923 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001924 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001925 {
1926 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1927 DataExtractor new_data;
1928 new_data.SetByteOrder (m_data.GetByteOrder());
1929
1930 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1931 m_data.SetData(buffer_sp, 0);
1932 bool success = new_scalar.GetData(new_data);
1933 if (success)
1934 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001935 new_data.CopyByteOrderedData (0,
1936 byte_size,
1937 const_cast<uint8_t *>(m_data.GetDataStart()),
1938 byte_size,
1939 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001940 }
1941 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1942
1943 }
Jim Ingham4b536182011-08-09 02:12:22 +00001944 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001945 case Value::eValueTypeFileAddress:
1946 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001947 case Value::eValueTypeVector:
1948 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001949 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001950 }
1951 else
1952 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001953 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001954 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001955 }
1956 else
1957 {
1958 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001959 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001960 return false;
1961 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001962
1963 // If we have reached this point, then we have successfully changed the value.
1964 SetNeedsUpdate();
1965 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001966}
1967
Greg Clayton81e871e2012-02-04 02:27:34 +00001968bool
1969ValueObject::GetDeclaration (Declaration &decl)
1970{
1971 decl.Clear();
1972 return false;
1973}
1974
Greg Clayton84db9102012-03-26 23:03:23 +00001975ConstString
1976ValueObject::GetTypeName()
1977{
Greg Clayton57ee3062013-07-11 22:46:58 +00001978 return GetClangType().GetConstTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00001979}
1980
1981ConstString
Enrico Granatae8daa2f2014-05-17 19:14:17 +00001982ValueObject::GetDisplayTypeName()
1983{
1984 return GetTypeName();
1985}
1986
1987ConstString
Greg Clayton84db9102012-03-26 23:03:23 +00001988ValueObject::GetQualifiedTypeName()
1989{
Greg Clayton57ee3062013-07-11 22:46:58 +00001990 return GetClangType().GetConstQualifiedTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00001991}
1992
1993
Greg Claytonafacd142011-09-02 01:15:17 +00001994LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001995ValueObject::GetObjectRuntimeLanguage ()
1996{
Greg Clayton57ee3062013-07-11 22:46:58 +00001997 return GetClangType().GetMinimumLanguage ();
Jim Ingham5a369122010-09-28 01:25:32 +00001998}
1999
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002000void
Jim Ingham58b59f92011-04-22 23:53:53 +00002001ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002002{
Jim Ingham58b59f92011-04-22 23:53:53 +00002003 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002004}
2005
2006ValueObjectSP
2007ValueObject::GetSyntheticChild (const ConstString &key) const
2008{
2009 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00002010 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002011 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00002012 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002013 return synthetic_child_sp;
2014}
2015
Greg Clayton2452ab72013-02-08 22:02:02 +00002016uint32_t
Greg Clayton57ee3062013-07-11 22:46:58 +00002017ValueObject::GetTypeInfo (ClangASTType *pointee_or_element_clang_type)
Greg Clayton2452ab72013-02-08 22:02:02 +00002018{
Greg Clayton57ee3062013-07-11 22:46:58 +00002019 return GetClangType().GetTypeInfo (pointee_or_element_clang_type);
Greg Clayton2452ab72013-02-08 22:02:02 +00002020}
2021
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002022bool
2023ValueObject::IsPointerType ()
2024{
Greg Clayton57ee3062013-07-11 22:46:58 +00002025 return GetClangType().IsPointerType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002026}
2027
Jim Inghamb7603bb2011-03-18 00:05:18 +00002028bool
Greg Claytondaf515f2011-07-09 20:12:33 +00002029ValueObject::IsArrayType ()
2030{
Greg Clayton57ee3062013-07-11 22:46:58 +00002031 return GetClangType().IsArrayType (NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00002032}
2033
2034bool
Enrico Granata9fc19442011-07-06 02:13:41 +00002035ValueObject::IsScalarType ()
2036{
Greg Clayton57ee3062013-07-11 22:46:58 +00002037 return GetClangType().IsScalarType ();
Enrico Granata9fc19442011-07-06 02:13:41 +00002038}
2039
2040bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00002041ValueObject::IsIntegerType (bool &is_signed)
2042{
Greg Clayton57ee3062013-07-11 22:46:58 +00002043 return GetClangType().IsIntegerType (is_signed);
Jim Inghamb7603bb2011-03-18 00:05:18 +00002044}
Greg Clayton73b472d2010-10-27 03:32:59 +00002045
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002046bool
2047ValueObject::IsPointerOrReferenceType ()
2048{
Greg Clayton57ee3062013-07-11 22:46:58 +00002049 return GetClangType().IsPointerOrReferenceType ();
Greg Clayton007d5be2011-05-30 00:49:24 +00002050}
2051
2052bool
Greg Claytondea8cb42011-06-29 22:09:02 +00002053ValueObject::IsPossibleDynamicType ()
2054{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002055 ExecutionContext exe_ctx (GetExecutionContextRef());
2056 Process *process = exe_ctx.GetProcessPtr();
2057 if (process)
2058 return process->IsPossibleDynamicValue(*this);
2059 else
Greg Clayton57ee3062013-07-11 22:46:58 +00002060 return GetClangType().IsPossibleDynamicType (NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00002061}
2062
Enrico Granata9e7b3882012-12-13 23:50:33 +00002063bool
2064ValueObject::IsObjCNil ()
2065{
Enrico Granata622be232014-10-21 20:52:14 +00002066 const uint32_t mask = eTypeIsObjC | eTypeIsPointer;
Greg Clayton57ee3062013-07-11 22:46:58 +00002067 bool isObjCpointer = (((GetClangType().GetTypeInfo(NULL)) & mask) == mask);
Enrico Granata7277d202013-03-15 23:33:15 +00002068 if (!isObjCpointer)
2069 return false;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002070 bool canReadValue = true;
2071 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
Enrico Granata7277d202013-03-15 23:33:15 +00002072 return canReadValue && isZero;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002073}
2074
Greg Claytonafacd142011-09-02 01:15:17 +00002075ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002076ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002077{
Greg Clayton2452ab72013-02-08 22:02:02 +00002078 const uint32_t type_info = GetTypeInfo ();
Enrico Granata622be232014-10-21 20:52:14 +00002079 if (type_info & eTypeIsArray)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002080 return GetSyntheticArrayMemberFromArray(index, can_create);
2081
Enrico Granata622be232014-10-21 20:52:14 +00002082 if (type_info & eTypeIsPointer)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002083 return GetSyntheticArrayMemberFromPointer(index, can_create);
2084
2085 return ValueObjectSP();
2086
2087}
2088
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002089ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002090ValueObject::GetSyntheticArrayMemberFromPointer (size_t index, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002091{
2092 ValueObjectSP synthetic_child_sp;
2093 if (IsPointerType ())
2094 {
2095 char index_str[64];
Deepak Panickal99fbc072014-03-03 15:39:47 +00002096 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002097 ConstString index_const_str(index_str);
2098 // Check if we have already created a synthetic array member in this
2099 // valid object. If we have we will re-use it.
2100 synthetic_child_sp = GetSyntheticChild (index_const_str);
2101 if (!synthetic_child_sp)
2102 {
Jim Ingham58b59f92011-04-22 23:53:53 +00002103 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002104 // We haven't made a synthetic array member for INDEX yet, so
2105 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00002106 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002107
2108 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00002109 if (synthetic_child)
2110 {
2111 AddSyntheticChild(index_const_str, synthetic_child);
2112 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002113 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00002114 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00002115 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002116 }
2117 }
2118 return synthetic_child_sp;
2119}
Jim Ingham22777012010-09-23 02:01:19 +00002120
Greg Claytondaf515f2011-07-09 20:12:33 +00002121// This allows you to create an array member using and index
2122// that doesn't not fall in the normal bounds of the array.
2123// Many times structure can be defined as:
2124// struct Collection
2125// {
2126// uint32_t item_count;
2127// Item item_array[0];
2128// };
2129// The size of the "item_array" is 1, but many times in practice
2130// there are more items in "item_array".
2131
2132ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002133ValueObject::GetSyntheticArrayMemberFromArray (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00002134{
2135 ValueObjectSP synthetic_child_sp;
2136 if (IsArrayType ())
2137 {
2138 char index_str[64];
Deepak Panickal99fbc072014-03-03 15:39:47 +00002139 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
Greg Claytondaf515f2011-07-09 20:12:33 +00002140 ConstString index_const_str(index_str);
2141 // Check if we have already created a synthetic array member in this
2142 // valid object. If we have we will re-use it.
2143 synthetic_child_sp = GetSyntheticChild (index_const_str);
2144 if (!synthetic_child_sp)
2145 {
2146 ValueObject *synthetic_child;
2147 // We haven't made a synthetic array member for INDEX yet, so
2148 // lets make one and cache it for any future reference.
2149 synthetic_child = CreateChildAtIndex(0, true, index);
2150
2151 // Cache the value if we got one back...
2152 if (synthetic_child)
2153 {
2154 AddSyntheticChild(index_const_str, synthetic_child);
2155 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002156 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00002157 synthetic_child_sp->m_is_array_item_for_pointer = true;
2158 }
2159 }
2160 }
2161 return synthetic_child_sp;
2162}
2163
Enrico Granata9fc19442011-07-06 02:13:41 +00002164ValueObjectSP
2165ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2166{
2167 ValueObjectSP synthetic_child_sp;
2168 if (IsScalarType ())
2169 {
2170 char index_str[64];
2171 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2172 ConstString index_const_str(index_str);
2173 // Check if we have already created a synthetic array member in this
2174 // valid object. If we have we will re-use it.
2175 synthetic_child_sp = GetSyntheticChild (index_const_str);
2176 if (!synthetic_child_sp)
2177 {
Enrico Granata9fc19442011-07-06 02:13:41 +00002178 // We haven't made a synthetic array member for INDEX yet, so
2179 // lets make one and cache it for any future reference.
Greg Clayton57ee3062013-07-11 22:46:58 +00002180 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
2181 GetClangType(),
2182 index_const_str,
2183 GetByteSize(),
2184 0,
2185 to-from+1,
2186 from,
2187 false,
2188 false,
2189 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002190
2191 // Cache the value if we got one back...
2192 if (synthetic_child)
2193 {
2194 AddSyntheticChild(index_const_str, synthetic_child);
2195 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002196 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002197 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2198 }
2199 }
2200 }
2201 return synthetic_child_sp;
2202}
2203
Greg Claytonafacd142011-09-02 01:15:17 +00002204ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00002205ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
2206{
2207
2208 ValueObjectSP synthetic_child_sp;
2209
2210 char name_str[64];
2211 snprintf(name_str, sizeof(name_str), "@%i", offset);
2212 ConstString name_const_str(name_str);
2213
2214 // Check if we have already created a synthetic array member in this
2215 // valid object. If we have we will re-use it.
2216 synthetic_child_sp = GetSyntheticChild (name_const_str);
2217
2218 if (synthetic_child_sp.get())
2219 return synthetic_child_sp;
2220
2221 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002222 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002223
2224 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
Greg Clayton57ee3062013-07-11 22:46:58 +00002225 type,
Enrico Granata6f3533f2011-07-29 19:53:35 +00002226 name_const_str,
Greg Clayton57ee3062013-07-11 22:46:58 +00002227 type.GetByteSize(),
Enrico Granata6f3533f2011-07-29 19:53:35 +00002228 offset,
2229 0,
2230 0,
2231 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002232 false,
2233 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002234 if (synthetic_child)
2235 {
2236 AddSyntheticChild(name_const_str, synthetic_child);
2237 synthetic_child_sp = synthetic_child->GetSP();
2238 synthetic_child_sp->SetName(name_const_str);
2239 synthetic_child_sp->m_is_child_at_offset = true;
2240 }
2241 return synthetic_child_sp;
2242}
2243
Enrico Granata32556cd2014-08-26 20:54:04 +00002244ValueObjectSP
Enrico Granata59953f02014-08-26 21:35:30 +00002245ValueObject::GetSyntheticBase (uint32_t offset, const ClangASTType& type, bool can_create)
Enrico Granata32556cd2014-08-26 20:54:04 +00002246{
2247 ValueObjectSP synthetic_child_sp;
2248
2249 char name_str[64];
2250 snprintf(name_str, sizeof(name_str), "%s", type.GetTypeName().AsCString("<unknown>"));
2251 ConstString name_const_str(name_str);
2252
2253 // Check if we have already created a synthetic array member in this
2254 // valid object. If we have we will re-use it.
2255 synthetic_child_sp = GetSyntheticChild (name_const_str);
2256
2257 if (synthetic_child_sp.get())
2258 return synthetic_child_sp;
2259
2260 if (!can_create)
2261 return ValueObjectSP();
2262
Enrico Granata32556cd2014-08-26 20:54:04 +00002263 const bool is_base_class = true;
2264
2265 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2266 type,
2267 name_const_str,
2268 type.GetByteSize(),
2269 offset,
2270 0,
2271 0,
2272 is_base_class,
2273 false,
2274 eAddressTypeInvalid);
2275 if (synthetic_child)
2276 {
2277 AddSyntheticChild(name_const_str, synthetic_child);
2278 synthetic_child_sp = synthetic_child->GetSP();
2279 synthetic_child_sp->SetName(name_const_str);
2280 }
2281 return synthetic_child_sp;
2282}
2283
2284
Enrico Granatad55546b2011-07-22 00:16:08 +00002285// your expression path needs to have a leading . or ->
2286// (unless it somehow "looks like" an array, in which case it has
2287// a leading [ symbol). while the [ is meaningful and should be shown
2288// to the user, . and -> are just parser design, but by no means
2289// added information for the user.. strip them off
2290static const char*
2291SkipLeadingExpressionPathSeparators(const char* expression)
2292{
2293 if (!expression || !expression[0])
2294 return expression;
2295 if (expression[0] == '.')
2296 return expression+1;
2297 if (expression[0] == '-' && expression[1] == '>')
2298 return expression+2;
2299 return expression;
2300}
2301
Greg Claytonafacd142011-09-02 01:15:17 +00002302ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002303ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2304{
2305 ValueObjectSP synthetic_child_sp;
2306 ConstString name_const_string(expression);
2307 // Check if we have already created a synthetic array member in this
2308 // valid object. If we have we will re-use it.
2309 synthetic_child_sp = GetSyntheticChild (name_const_string);
2310 if (!synthetic_child_sp)
2311 {
2312 // We haven't made a synthetic array member for expression yet, so
2313 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002314 synthetic_child_sp = GetValueForExpressionPath(expression,
2315 NULL, NULL, NULL,
2316 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
Enrico Granatad55546b2011-07-22 00:16:08 +00002317
2318 // Cache the value if we got one back...
2319 if (synthetic_child_sp.get())
2320 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002321 // 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 +00002322 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002323 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002324 }
2325 }
2326 return synthetic_child_sp;
2327}
2328
2329void
Enrico Granata86cc9822012-03-19 22:58:49 +00002330ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002331{
Enrico Granata86cc9822012-03-19 22:58:49 +00002332 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002333 return;
2334
Enrico Granatac5bc4122012-03-27 02:35:13 +00002335 TargetSP target_sp(GetTargetSP());
Enrico Granata5d5f60c2013-09-24 22:58:37 +00002336 if (target_sp && target_sp->GetEnableSyntheticValue() == false)
Enrico Granatac5bc4122012-03-27 02:35:13 +00002337 {
2338 m_synthetic_value = NULL;
2339 return;
2340 }
2341
Enrico Granatae3e91512012-10-22 18:18:36 +00002342 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2343
Enrico Granata5548cb52013-01-28 23:47:25 +00002344 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002345 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002346
Enrico Granata0c489f52012-03-01 04:24:26 +00002347 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002348 return;
2349
Enrico Granatae3e91512012-10-22 18:18:36 +00002350 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2351 return;
2352
Enrico Granata86cc9822012-03-19 22:58:49 +00002353 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002354}
2355
Jim Ingham78a685a2011-04-16 00:01:13 +00002356void
Greg Claytonafacd142011-09-02 01:15:17 +00002357ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002358{
Greg Claytonafacd142011-09-02 01:15:17 +00002359 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002360 return;
2361
Jim Ingham58b59f92011-04-22 23:53:53 +00002362 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002363 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002364 ExecutionContext exe_ctx (GetExecutionContextRef());
2365 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002366 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002367 {
2368 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002369 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002370 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002371 }
2372}
2373
Jim Ingham58b59f92011-04-22 23:53:53 +00002374ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002375ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002376{
Greg Claytonafacd142011-09-02 01:15:17 +00002377 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002378 return ValueObjectSP();
2379
2380 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002381 {
Jim Ingham2837b762011-05-04 03:43:18 +00002382 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002383 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002384 if (m_dynamic_value)
2385 return m_dynamic_value->GetSP();
2386 else
2387 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002388}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002389
Jim Ingham60dbabb2011-12-08 19:44:08 +00002390ValueObjectSP
2391ValueObject::GetStaticValue()
2392{
2393 return GetSP();
2394}
2395
Enrico Granata886147f2012-05-08 18:47:08 +00002396lldb::ValueObjectSP
2397ValueObject::GetNonSyntheticValue ()
2398{
2399 return GetSP();
2400}
2401
Enrico Granatad55546b2011-07-22 00:16:08 +00002402ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002403ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002404{
Enrico Granata86cc9822012-03-19 22:58:49 +00002405 if (use_synthetic == false)
2406 return ValueObjectSP();
2407
Enrico Granatad55546b2011-07-22 00:16:08 +00002408 CalculateSyntheticValue(use_synthetic);
2409
2410 if (m_synthetic_value)
2411 return m_synthetic_value->GetSP();
2412 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002413 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002414}
2415
Greg Claytone221f822011-01-21 01:59:00 +00002416bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002417ValueObject::HasSyntheticValue()
2418{
Enrico Granata5548cb52013-01-28 23:47:25 +00002419 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002420
Enrico Granata0c489f52012-03-01 04:24:26 +00002421 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002422 return false;
2423
Enrico Granata86cc9822012-03-19 22:58:49 +00002424 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002425
2426 if (m_synthetic_value)
2427 return true;
2428 else
2429 return false;
2430}
2431
2432bool
Greg Claytone221f822011-01-21 01:59:00 +00002433ValueObject::GetBaseClassPath (Stream &s)
2434{
2435 if (IsBaseClass())
2436 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002437 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Clayton57ee3062013-07-11 22:46:58 +00002438 ClangASTType clang_type = GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002439 std::string cxx_class_name;
Greg Clayton57ee3062013-07-11 22:46:58 +00002440 bool this_had_base_class = clang_type.GetCXXClassName (cxx_class_name);
Greg Claytone221f822011-01-21 01:59:00 +00002441 if (this_had_base_class)
2442 {
2443 if (parent_had_base_class)
2444 s.PutCString("::");
2445 s.PutCString(cxx_class_name.c_str());
2446 }
2447 return parent_had_base_class || this_had_base_class;
2448 }
2449 return false;
2450}
2451
2452
2453ValueObject *
2454ValueObject::GetNonBaseClassParent()
2455{
Jim Ingham78a685a2011-04-16 00:01:13 +00002456 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002457 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002458 if (GetParent()->IsBaseClass())
2459 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002460 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002461 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002462 }
2463 return NULL;
2464}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002465
Enrico Granataa3c8f042014-08-19 22:29:08 +00002466
2467bool
2468ValueObject::IsBaseClass (uint32_t& depth)
2469{
2470 if (!IsBaseClass())
2471 {
2472 depth = 0;
2473 return false;
2474 }
2475 if (GetParent())
2476 {
2477 GetParent()->IsBaseClass(depth);
2478 depth = depth + 1;
2479 return true;
2480 }
2481 // TODO: a base of no parent? weird..
2482 depth = 1;
2483 return true;
2484}
2485
Greg Clayton1d3afba2010-10-05 00:00:42 +00002486void
Enrico Granata4becb372011-06-29 22:27:15 +00002487ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002488{
Greg Claytone221f822011-01-21 01:59:00 +00002489 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002490
Enrico Granata86cc9822012-03-19 22:58:49 +00002491 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002492 {
Enrico Granata4becb372011-06-29 22:27:15 +00002493 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2494 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2495 // the eHonorPointers mode is meant to produce strings in this latter format
2496 s.PutCString("*(");
2497 }
Greg Claytone221f822011-01-21 01:59:00 +00002498
Enrico Granata4becb372011-06-29 22:27:15 +00002499 ValueObject* parent = GetParent();
2500
2501 if (parent)
2502 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002503
2504 // if we are a deref_of_parent just because we are synthetic array
2505 // members made up to allow ptr[%d] syntax to work in variable
2506 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002507 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002508 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002509
Greg Claytone221f822011-01-21 01:59:00 +00002510 if (!IsBaseClass())
2511 {
2512 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002513 {
Greg Claytone221f822011-01-21 01:59:00 +00002514 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2515 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002516 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002517 ClangASTType non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002518 if (non_base_class_parent_clang_type)
2519 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002520 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002521 {
2522 s.PutCString("->");
2523 }
Enrico Granata4becb372011-06-29 22:27:15 +00002524 else
2525 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002526 const uint32_t non_base_class_parent_type_info = non_base_class_parent_clang_type.GetTypeInfo();
2527
Enrico Granata622be232014-10-21 20:52:14 +00002528 if (non_base_class_parent_type_info & eTypeIsPointer)
Enrico Granata4becb372011-06-29 22:27:15 +00002529 {
2530 s.PutCString("->");
2531 }
Enrico Granata622be232014-10-21 20:52:14 +00002532 else if ((non_base_class_parent_type_info & eTypeHasChildren) &&
2533 !(non_base_class_parent_type_info & eTypeIsArray))
Enrico Granata4becb372011-06-29 22:27:15 +00002534 {
2535 s.PutChar('.');
2536 }
Greg Claytone221f822011-01-21 01:59:00 +00002537 }
2538 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002539 }
Greg Claytone221f822011-01-21 01:59:00 +00002540
2541 const char *name = GetName().GetCString();
2542 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002543 {
Greg Claytone221f822011-01-21 01:59:00 +00002544 if (qualify_cxx_base_classes)
2545 {
2546 if (GetBaseClassPath (s))
2547 s.PutCString("::");
2548 }
2549 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002550 }
2551 }
2552 }
2553
Enrico Granata86cc9822012-03-19 22:58:49 +00002554 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002555 {
Greg Claytone221f822011-01-21 01:59:00 +00002556 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002557 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002558}
2559
Greg Claytonafacd142011-09-02 01:15:17 +00002560ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002561ValueObject::GetValueForExpressionPath(const char* expression,
2562 const char** first_unparsed,
2563 ExpressionPathScanEndReason* reason_to_stop,
2564 ExpressionPathEndResultType* final_value_type,
2565 const GetValueForExpressionPathOptions& options,
2566 ExpressionPathAftermath* final_task_on_target)
2567{
2568
2569 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002570 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2571 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002572 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002573
2574 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2575 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2576 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2577 final_value_type ? final_value_type : &dummy_final_value_type,
2578 options,
2579 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2580
Enrico Granata86cc9822012-03-19 22:58:49 +00002581 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002582 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002583
Enrico Granata86cc9822012-03-19 22:58:49 +00002584 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 +00002585 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002586 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002587 {
2588 Error error;
2589 ValueObjectSP final_value = ret_val->Dereference(error);
2590 if (error.Fail() || !final_value.get())
2591 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002592 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002593 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002594 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002595 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002596 return ValueObjectSP();
2597 }
2598 else
2599 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002600 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002601 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002602 return final_value;
2603 }
2604 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002605 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002606 {
2607 Error error;
2608 ValueObjectSP final_value = ret_val->AddressOf(error);
2609 if (error.Fail() || !final_value.get())
2610 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002611 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002612 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002613 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002614 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002615 return ValueObjectSP();
2616 }
2617 else
2618 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002619 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002620 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002621 return final_value;
2622 }
2623 }
2624 }
2625 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2626}
2627
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002628int
2629ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002630 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002631 const char** first_unparsed,
2632 ExpressionPathScanEndReason* reason_to_stop,
2633 ExpressionPathEndResultType* final_value_type,
2634 const GetValueForExpressionPathOptions& options,
2635 ExpressionPathAftermath* final_task_on_target)
2636{
2637 const char* dummy_first_unparsed;
2638 ExpressionPathScanEndReason dummy_reason_to_stop;
2639 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002640 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002641
2642 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2643 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2644 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2645 final_value_type ? final_value_type : &dummy_final_value_type,
2646 options,
2647 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2648
2649 if (!ret_val.get()) // if there are errors, I add nothing to the list
2650 return 0;
2651
Enrico Granata86ea8d82012-03-29 01:34:34 +00002652 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002653 {
2654 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002655 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002656 {
2657 list->Append(ret_val);
2658 return 1;
2659 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002660 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 +00002661 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002662 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002663 {
2664 Error error;
2665 ValueObjectSP final_value = ret_val->Dereference(error);
2666 if (error.Fail() || !final_value.get())
2667 {
Greg Clayton23f59502012-07-17 03:23:13 +00002668 if (reason_to_stop)
2669 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2670 if (final_value_type)
2671 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002672 return 0;
2673 }
2674 else
2675 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002676 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002677 list->Append(final_value);
2678 return 1;
2679 }
2680 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002681 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002682 {
2683 Error error;
2684 ValueObjectSP final_value = ret_val->AddressOf(error);
2685 if (error.Fail() || !final_value.get())
2686 {
Greg Clayton23f59502012-07-17 03:23:13 +00002687 if (reason_to_stop)
2688 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2689 if (final_value_type)
2690 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002691 return 0;
2692 }
2693 else
2694 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002695 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002696 list->Append(final_value);
2697 return 1;
2698 }
2699 }
2700 }
2701 }
2702 else
2703 {
2704 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2705 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2706 ret_val,
2707 list,
2708 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2709 final_value_type ? final_value_type : &dummy_final_value_type,
2710 options,
2711 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2712 }
2713 // in any non-covered case, just do the obviously right thing
2714 list->Append(ret_val);
2715 return 1;
2716}
2717
Greg Claytonafacd142011-09-02 01:15:17 +00002718ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002719ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2720 const char** first_unparsed,
2721 ExpressionPathScanEndReason* reason_to_stop,
2722 ExpressionPathEndResultType* final_result,
2723 const GetValueForExpressionPathOptions& options,
2724 ExpressionPathAftermath* what_next)
2725{
2726 ValueObjectSP root = GetSP();
2727
2728 if (!root.get())
2729 return ValueObjectSP();
2730
2731 *first_unparsed = expression_cstr;
2732
2733 while (true)
2734 {
2735
2736 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2737
Greg Clayton57ee3062013-07-11 22:46:58 +00002738 ClangASTType root_clang_type = root->GetClangType();
2739 ClangASTType pointee_clang_type;
2740 Flags pointee_clang_type_info;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002741
Greg Clayton57ee3062013-07-11 22:46:58 +00002742 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002743 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00002744 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002745
2746 if (!expression_cstr || *expression_cstr == '\0')
2747 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002748 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002749 return root;
2750 }
2751
2752 switch (*expression_cstr)
2753 {
2754 case '-':
2755 {
2756 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granata622be232014-10-21 20:52:14 +00002757 root_clang_type_info.Test(eTypeIsPointer) ) // if you are trying to use -> on a non-pointer and I must catch the error
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002758 {
2759 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002760 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2761 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002762 return ValueObjectSP();
2763 }
Enrico Granata622be232014-10-21 20:52:14 +00002764 if (root_clang_type_info.Test(eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2765 root_clang_type_info.Test(eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002766 options.m_no_fragile_ivar)
2767 {
2768 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002769 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2770 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002771 return ValueObjectSP();
2772 }
2773 if (expression_cstr[1] != '>')
2774 {
2775 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002776 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2777 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002778 return ValueObjectSP();
2779 }
2780 expression_cstr++; // skip the -
2781 }
2782 case '.': // or fallthrough from ->
2783 {
2784 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granata622be232014-10-21 20:52:14 +00002785 root_clang_type_info.Test(eTypeIsPointer)) // if you are trying to use . on a pointer and I must catch the error
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002786 {
2787 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002788 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2789 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002790 return ValueObjectSP();
2791 }
2792 expression_cstr++; // skip .
2793 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2794 ConstString child_name;
2795 if (!next_separator) // if no other separator just expand this last layer
2796 {
2797 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002798 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2799
2800 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002801 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002802 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002803 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2804 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002805 return child_valobj_sp;
2806 }
2807 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2808 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002809 if (root->IsSynthetic())
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002810 {
2811 *first_unparsed = expression_cstr;
Enrico Granatad07cfd32014-10-08 18:27:36 +00002812 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchSyntheticChild;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002813 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2814 return ValueObjectSP();
2815 }
2816
2817 child_valobj_sp = root->GetSyntheticValue();
Enrico Granata86cc9822012-03-19 22:58:49 +00002818 if (child_valobj_sp.get())
2819 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002820 }
2821
2822 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2823 // so we hit the "else" branch, and return an error
2824 if(child_valobj_sp.get()) // if it worked, just return
2825 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002826 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002827 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2828 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002829 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002830 }
2831 else
2832 {
2833 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002834 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2835 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002836 return ValueObjectSP();
2837 }
2838 }
2839 else // other layers do expand
2840 {
2841 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002842 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2843 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002844 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002845 root = child_valobj_sp;
2846 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002847 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002848 continue;
2849 }
2850 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2851 {
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002852 if (root->IsSynthetic())
2853 {
2854 *first_unparsed = expression_cstr;
2855 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2856 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2857 return ValueObjectSP();
2858 }
2859
Enrico Granata86cc9822012-03-19 22:58:49 +00002860 child_valobj_sp = root->GetSyntheticValue(true);
2861 if (child_valobj_sp)
2862 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002863 }
2864
2865 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2866 // so we hit the "else" branch, and return an error
2867 if(child_valobj_sp.get()) // if it worked, move on
2868 {
2869 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002870 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002871 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002872 continue;
2873 }
2874 else
2875 {
2876 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002877 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2878 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002879 return ValueObjectSP();
2880 }
2881 }
2882 break;
2883 }
2884 case '[':
2885 {
Enrico Granata622be232014-10-21 20:52:14 +00002886 if (!root_clang_type_info.Test(eTypeIsArray) && !root_clang_type_info.Test(eTypeIsPointer) && !root_clang_type_info.Test(eTypeIsVector)) // if this is not a T[] nor a T*
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002887 {
Enrico Granata622be232014-10-21 20:52:14 +00002888 if (!root_clang_type_info.Test(eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002889 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002890 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2891 {
2892 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002893 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2894 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002895 return ValueObjectSP();
2896 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002897 }
2898 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2899 {
2900 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002901 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2902 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002903 return ValueObjectSP();
2904 }
2905 }
2906 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2907 {
Enrico Granata622be232014-10-21 20:52:14 +00002908 if (!root_clang_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002909 {
2910 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002911 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2912 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002913 return ValueObjectSP();
2914 }
2915 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2916 {
2917 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002918 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2919 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002920 return root;
2921 }
2922 }
2923 const char *separator_position = ::strchr(expression_cstr+1,'-');
2924 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2925 if (!close_bracket_position) // if there is no ], this is a syntax error
2926 {
2927 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002928 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2929 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002930 return ValueObjectSP();
2931 }
2932 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2933 {
2934 char *end = NULL;
2935 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2936 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2937 {
2938 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002939 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2940 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002941 return ValueObjectSP();
2942 }
2943 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2944 {
Enrico Granata622be232014-10-21 20:52:14 +00002945 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002946 {
2947 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002948 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2949 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002950 return root;
2951 }
2952 else
2953 {
2954 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002955 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2956 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002957 return ValueObjectSP();
2958 }
2959 }
2960 // from here on we do have a valid index
Enrico Granata622be232014-10-21 20:52:14 +00002961 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002962 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002963 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2964 if (!child_valobj_sp)
2965 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002966 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002967 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2968 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002969 if (child_valobj_sp)
2970 {
2971 root = child_valobj_sp;
2972 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002973 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002974 continue;
2975 }
2976 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002977 {
2978 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002979 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2980 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002981 return ValueObjectSP();
2982 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002983 }
Enrico Granata622be232014-10-21 20:52:14 +00002984 else if (root_clang_type_info.Test(eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002985 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002986 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
Enrico Granata622be232014-10-21 20:52:14 +00002987 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002988 {
2989 Error error;
2990 root = root->Dereference(error);
2991 if (error.Fail() || !root.get())
2992 {
2993 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002994 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2995 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002996 return ValueObjectSP();
2997 }
2998 else
2999 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003000 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003001 continue;
3002 }
3003 }
3004 else
3005 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003006 if (root->GetClangType().GetMinimumLanguage() == eLanguageTypeObjC
Enrico Granata622be232014-10-21 20:52:14 +00003007 && pointee_clang_type_info.AllClear(eTypeIsPointer)
Greg Clayton84db9102012-03-26 23:03:23 +00003008 && root->HasSyntheticValue()
3009 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00003010 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003011 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003012 }
3013 else
3014 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003015 if (!root.get())
3016 {
3017 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003018 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3019 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003020 return ValueObjectSP();
3021 }
3022 else
3023 {
3024 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003025 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003026 continue;
3027 }
3028 }
3029 }
Enrico Granata622be232014-10-21 20:52:14 +00003030 else if (root_clang_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003031 {
3032 root = root->GetSyntheticBitFieldChild(index, index, true);
3033 if (!root.get())
3034 {
3035 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003036 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3037 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003038 return ValueObjectSP();
3039 }
3040 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3041 {
3042 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003043 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3044 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003045 return root;
3046 }
3047 }
Enrico Granata622be232014-10-21 20:52:14 +00003048 else if (root_clang_type_info.Test(eTypeIsVector))
Enrico Granata08a1bb82013-06-19 00:00:45 +00003049 {
3050 root = root->GetChildAtIndex(index, true);
3051 if (!root.get())
3052 {
3053 *first_unparsed = expression_cstr;
3054 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3055 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3056 return ValueObjectSP();
3057 }
3058 else
3059 {
3060 *first_unparsed = end+1; // skip ]
3061 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3062 continue;
3063 }
3064 }
Enrico Granata86cc9822012-03-19 22:58:49 +00003065 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00003066 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003067 if (root->HasSyntheticValue())
3068 root = root->GetSyntheticValue();
3069 else if (!root->IsSynthetic())
3070 {
3071 *first_unparsed = expression_cstr;
3072 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3073 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3074 return ValueObjectSP();
3075 }
3076 // if we are here, then root itself is a synthetic VO.. should be good to go
3077
Enrico Granata27b625e2011-08-09 01:04:56 +00003078 if (!root.get())
3079 {
3080 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003081 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3082 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3083 return ValueObjectSP();
3084 }
3085 root = root->GetChildAtIndex(index, true);
3086 if (!root.get())
3087 {
3088 *first_unparsed = expression_cstr;
3089 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3090 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003091 return ValueObjectSP();
3092 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00003093 else
3094 {
3095 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003096 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00003097 continue;
3098 }
Enrico Granata27b625e2011-08-09 01:04:56 +00003099 }
3100 else
3101 {
3102 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003103 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3104 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003105 return ValueObjectSP();
3106 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003107 }
3108 else // we have a low and a high index
3109 {
3110 char *end = NULL;
3111 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3112 if (!end || end != separator_position) // if something weird is in our way return an error
3113 {
3114 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003115 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3116 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003117 return ValueObjectSP();
3118 }
3119 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3120 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3121 {
3122 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003123 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3124 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003125 return ValueObjectSP();
3126 }
3127 if (index_lower > index_higher) // swap indices if required
3128 {
3129 unsigned long temp = index_lower;
3130 index_lower = index_higher;
3131 index_higher = temp;
3132 }
Enrico Granata622be232014-10-21 20:52:14 +00003133 if (root_clang_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003134 {
3135 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3136 if (!root.get())
3137 {
3138 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003139 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3140 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003141 return ValueObjectSP();
3142 }
3143 else
3144 {
3145 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003146 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3147 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003148 return root;
3149 }
3150 }
Enrico Granata622be232014-10-21 20:52:14 +00003151 else if (root_clang_type_info.Test(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 +00003152 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granata622be232014-10-21 20:52:14 +00003153 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003154 {
3155 Error error;
3156 root = root->Dereference(error);
3157 if (error.Fail() || !root.get())
3158 {
3159 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003160 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3161 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003162 return ValueObjectSP();
3163 }
3164 else
3165 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003166 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003167 continue;
3168 }
3169 }
3170 else
3171 {
3172 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003173 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3174 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003175 return root;
3176 }
3177 }
3178 break;
3179 }
3180 default: // some non-separator is in the way
3181 {
3182 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003183 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3184 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003185 return ValueObjectSP();
3186 break;
3187 }
3188 }
3189 }
3190}
3191
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003192int
3193ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3194 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00003195 ValueObjectSP root,
3196 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003197 ExpressionPathScanEndReason* reason_to_stop,
3198 ExpressionPathEndResultType* final_result,
3199 const GetValueForExpressionPathOptions& options,
3200 ExpressionPathAftermath* what_next)
3201{
3202 if (!root.get())
3203 return 0;
3204
3205 *first_unparsed = expression_cstr;
3206
3207 while (true)
3208 {
3209
3210 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3211
Greg Clayton57ee3062013-07-11 22:46:58 +00003212 ClangASTType root_clang_type = root->GetClangType();
3213 ClangASTType pointee_clang_type;
3214 Flags pointee_clang_type_info;
3215 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003216 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00003217 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003218
3219 if (!expression_cstr || *expression_cstr == '\0')
3220 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003221 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003222 list->Append(root);
3223 return 1;
3224 }
3225
3226 switch (*expression_cstr)
3227 {
3228 case '[':
3229 {
Enrico Granata622be232014-10-21 20:52:14 +00003230 if (!root_clang_type_info.Test(eTypeIsArray) && !root_clang_type_info.Test(eTypeIsPointer)) // if this is not a T[] nor a T*
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003231 {
Enrico Granata622be232014-10-21 20:52:14 +00003232 if (!root_clang_type_info.Test(eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003233 {
3234 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003235 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3236 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003237 return 0;
3238 }
3239 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3240 {
3241 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003242 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3243 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003244 return 0;
3245 }
3246 }
3247 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3248 {
Enrico Granata622be232014-10-21 20:52:14 +00003249 if (!root_clang_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003250 {
3251 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003252 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3253 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003254 return 0;
3255 }
3256 else // expand this into list
3257 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003258 const size_t max_index = root->GetNumChildren() - 1;
3259 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003260 {
3261 ValueObjectSP child =
3262 root->GetChildAtIndex(index, true);
3263 list->Append(child);
3264 }
3265 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003266 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3267 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003268 return max_index; // tell me number of items I added to the VOList
3269 }
3270 }
3271 const char *separator_position = ::strchr(expression_cstr+1,'-');
3272 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3273 if (!close_bracket_position) // if there is no ], this is a syntax error
3274 {
3275 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003276 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3277 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003278 return 0;
3279 }
3280 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3281 {
3282 char *end = NULL;
3283 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3284 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3285 {
3286 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003287 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3288 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003289 return 0;
3290 }
3291 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3292 {
Enrico Granata622be232014-10-21 20:52:14 +00003293 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003294 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003295 const size_t max_index = root->GetNumChildren() - 1;
3296 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003297 {
3298 ValueObjectSP child =
3299 root->GetChildAtIndex(index, true);
3300 list->Append(child);
3301 }
3302 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003303 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3304 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003305 return max_index; // tell me number of items I added to the VOList
3306 }
3307 else
3308 {
3309 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003310 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3311 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003312 return 0;
3313 }
3314 }
3315 // from here on we do have a valid index
Enrico Granata622be232014-10-21 20:52:14 +00003316 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003317 {
3318 root = root->GetChildAtIndex(index, true);
3319 if (!root.get())
3320 {
3321 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003322 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3323 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003324 return 0;
3325 }
3326 else
3327 {
3328 list->Append(root);
3329 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003330 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3331 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003332 return 1;
3333 }
3334 }
Enrico Granata622be232014-10-21 20:52:14 +00003335 else if (root_clang_type_info.Test(eTypeIsPointer))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003336 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003337 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
Enrico Granata622be232014-10-21 20:52:14 +00003338 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003339 {
3340 Error error;
3341 root = root->Dereference(error);
3342 if (error.Fail() || !root.get())
3343 {
3344 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003345 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3346 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003347 return 0;
3348 }
3349 else
3350 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003351 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003352 continue;
3353 }
3354 }
3355 else
3356 {
3357 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3358 if (!root.get())
3359 {
3360 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003361 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3362 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003363 return 0;
3364 }
3365 else
3366 {
3367 list->Append(root);
3368 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003369 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3370 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003371 return 1;
3372 }
3373 }
3374 }
3375 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3376 {
3377 root = root->GetSyntheticBitFieldChild(index, index, true);
3378 if (!root.get())
3379 {
3380 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003381 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3382 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003383 return 0;
3384 }
3385 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3386 {
3387 list->Append(root);
3388 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003389 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3390 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003391 return 1;
3392 }
3393 }
3394 }
3395 else // we have a low and a high index
3396 {
3397 char *end = NULL;
3398 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3399 if (!end || end != separator_position) // if something weird is in our way return an error
3400 {
3401 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003402 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3403 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003404 return 0;
3405 }
3406 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3407 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3408 {
3409 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003410 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3411 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003412 return 0;
3413 }
3414 if (index_lower > index_higher) // swap indices if required
3415 {
3416 unsigned long temp = index_lower;
3417 index_lower = index_higher;
3418 index_higher = temp;
3419 }
Enrico Granata622be232014-10-21 20:52:14 +00003420 if (root_clang_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003421 {
3422 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3423 if (!root.get())
3424 {
3425 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003426 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3427 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003428 return 0;
3429 }
3430 else
3431 {
3432 list->Append(root);
3433 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003434 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3435 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003436 return 1;
3437 }
3438 }
Enrico Granata622be232014-10-21 20:52:14 +00003439 else if (root_clang_type_info.Test(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 +00003440 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granata622be232014-10-21 20:52:14 +00003441 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003442 {
3443 Error error;
3444 root = root->Dereference(error);
3445 if (error.Fail() || !root.get())
3446 {
3447 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003448 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3449 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003450 return 0;
3451 }
3452 else
3453 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003454 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003455 continue;
3456 }
3457 }
3458 else
3459 {
Johnny Chen44805302011-07-19 19:48:13 +00003460 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003461 index <= index_higher; index++)
3462 {
3463 ValueObjectSP child =
3464 root->GetChildAtIndex(index, true);
3465 list->Append(child);
3466 }
3467 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003468 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3469 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003470 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3471 }
3472 }
3473 break;
3474 }
3475 default: // some non-[ separator, or something entirely wrong, is in the way
3476 {
3477 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003478 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3479 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003480 return 0;
3481 break;
3482 }
3483 }
3484 }
3485}
3486
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003487void
3488ValueObject::LogValueObject (Log *log)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003489{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003490 if (log)
3491 return LogValueObject (log, DumpValueObjectOptions::DefaultOptions());
Greg Clayton1d3afba2010-10-05 00:00:42 +00003492}
3493
Enrico Granata0c489f52012-03-01 04:24:26 +00003494void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003495ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003496{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003497 if (log)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003498 {
3499 StreamString s;
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003500 Dump (s, options);
Greg Claytonf830dbb2012-03-22 18:15:37 +00003501 if (s.GetSize())
3502 log->PutCString(s.GetData());
3503 }
3504}
3505
3506void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003507ValueObject::Dump (Stream &s)
Enrico Granata0c489f52012-03-01 04:24:26 +00003508{
3509
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003510 ValueObjectPrinter printer(this,&s,DumpValueObjectOptions::DefaultOptions());
3511 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003512}
3513
3514void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003515ValueObject::Dump (Stream &s,
3516 const DumpValueObjectOptions& options)
Enrico Granata0c489f52012-03-01 04:24:26 +00003517{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003518 ValueObjectPrinter printer(this,&s,options);
3519 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003520}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003521
3522ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003523ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003524{
3525 ValueObjectSP valobj_sp;
3526
Enrico Granatac3e320a2011-08-02 17:27:39 +00003527 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003528 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003529 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003530
3531 DataExtractor data;
3532 data.SetByteOrder (m_data.GetByteOrder());
3533 data.SetAddressByteSize(m_data.GetAddressByteSize());
3534
Enrico Granata9f1e2042012-04-24 22:15:37 +00003535 if (IsBitfield())
3536 {
3537 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
Greg Clayton57ee3062013-07-11 22:46:58 +00003538 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Enrico Granata9f1e2042012-04-24 22:15:37 +00003539 }
3540 else
Greg Clayton57ee3062013-07-11 22:46:58 +00003541 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003542
3543 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003544 GetClangType(),
3545 name,
3546 data,
3547 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003548 }
Jim Ingham6035b672011-03-31 00:19:25 +00003549
3550 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003551 {
Greg Claytoneeb15652013-12-10 23:16:40 +00003552 ExecutionContext exe_ctx (GetExecutionContextRef());
3553 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003554 }
3555 return valobj_sp;
3556}
3557
Enrico Granata538a88a2014-10-09 18:24:30 +00003558ValueObjectSP
3559ValueObject::GetQualifiedRepresentationIfAvailable (lldb::DynamicValueType dynValue,
3560 bool synthValue)
3561{
3562 ValueObjectSP result_sp(GetSP());
3563
3564 switch (dynValue)
3565 {
3566 case lldb::eDynamicCanRunTarget:
3567 case lldb::eDynamicDontRunTarget:
3568 {
3569 if (!result_sp->IsDynamic())
3570 {
3571 if (result_sp->GetDynamicValue(dynValue))
3572 result_sp = result_sp->GetDynamicValue(dynValue);
3573 }
3574 }
3575 break;
3576 case lldb::eNoDynamicValues:
Enrico Granata538a88a2014-10-09 18:24:30 +00003577 {
3578 if (result_sp->IsDynamic())
3579 {
3580 if (result_sp->GetStaticValue())
3581 result_sp = result_sp->GetStaticValue();
3582 }
3583 }
3584 break;
3585 }
3586
3587 if (synthValue)
3588 {
3589 if (!result_sp->IsSynthetic())
3590 {
3591 if (result_sp->GetSyntheticValue())
3592 result_sp = result_sp->GetSyntheticValue();
3593 }
3594 }
3595 else
3596 {
3597 if (result_sp->IsSynthetic())
3598 {
3599 if (result_sp->GetNonSyntheticValue())
3600 result_sp = result_sp->GetNonSyntheticValue();
3601 }
3602 }
3603
3604 return result_sp;
3605}
3606
Greg Clayton759e7442014-07-19 00:12:57 +00003607lldb::addr_t
3608ValueObject::GetCPPVTableAddress (AddressType &address_type)
3609{
3610 ClangASTType pointee_type;
3611 ClangASTType this_type(GetClangType());
3612 uint32_t type_info = this_type.GetTypeInfo(&pointee_type);
3613 if (type_info)
3614 {
3615 bool ptr_or_ref = false;
Enrico Granata622be232014-10-21 20:52:14 +00003616 if (type_info & (eTypeIsPointer | eTypeIsReference))
Greg Clayton759e7442014-07-19 00:12:57 +00003617 {
3618 ptr_or_ref = true;
3619 type_info = pointee_type.GetTypeInfo();
3620 }
3621
Enrico Granata622be232014-10-21 20:52:14 +00003622 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus;
Greg Clayton759e7442014-07-19 00:12:57 +00003623 if ((type_info & cpp_class) == cpp_class)
3624 {
3625 if (ptr_or_ref)
3626 {
3627 address_type = GetAddressTypeOfChildren();
3628 return GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
3629 }
3630 else
3631 return GetAddressOf (false, &address_type);
3632 }
3633 }
3634
3635 address_type = eAddressTypeInvalid;
3636 return LLDB_INVALID_ADDRESS;
3637}
3638
Greg Claytonafacd142011-09-02 01:15:17 +00003639ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003640ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003641{
Jim Ingham58b59f92011-04-22 23:53:53 +00003642 if (m_deref_valobj)
3643 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003644
Greg Clayton54979cd2010-12-15 05:08:08 +00003645 const bool is_pointer_type = IsPointerType();
3646 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003647 {
3648 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003649 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003650
3651 std::string child_name_str;
3652 uint32_t child_byte_size = 0;
3653 int32_t child_byte_offset = 0;
3654 uint32_t child_bitfield_bit_size = 0;
3655 uint32_t child_bitfield_bit_offset = 0;
3656 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003657 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003658 const bool transparent_pointers = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00003659 ClangASTType clang_type = GetClangType();
3660 ClangASTType child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003661
Greg Claytoncc4d0142012-02-17 07:49:44 +00003662 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003663
Greg Clayton57ee3062013-07-11 22:46:58 +00003664 child_clang_type = clang_type.GetChildClangTypeAtIndex (&exe_ctx,
Greg Clayton57ee3062013-07-11 22:46:58 +00003665 0,
3666 transparent_pointers,
3667 omit_empty_base_classes,
3668 ignore_array_bounds,
3669 child_name_str,
3670 child_byte_size,
3671 child_byte_offset,
3672 child_bitfield_bit_size,
3673 child_bitfield_bit_offset,
3674 child_is_base_class,
Greg Clayton759e7442014-07-19 00:12:57 +00003675 child_is_deref_of_parent,
3676 this);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003677 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003678 {
3679 ConstString child_name;
3680 if (!child_name_str.empty())
3681 child_name.SetCString (child_name_str.c_str());
3682
Jim Ingham58b59f92011-04-22 23:53:53 +00003683 m_deref_valobj = new ValueObjectChild (*this,
Jim Ingham58b59f92011-04-22 23:53:53 +00003684 child_clang_type,
3685 child_name,
3686 child_byte_size,
3687 child_byte_offset,
3688 child_bitfield_bit_size,
3689 child_bitfield_bit_offset,
3690 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003691 child_is_deref_of_parent,
3692 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003693 }
3694 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003695
Jim Ingham58b59f92011-04-22 23:53:53 +00003696 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003697 {
3698 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003699 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003700 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003701 else
3702 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003703 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003704 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003705
3706 if (is_pointer_type)
3707 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3708 else
3709 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003710 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003711 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003712}
3713
Greg Claytonafacd142011-09-02 01:15:17 +00003714ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003715ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003716{
Jim Ingham78a685a2011-04-16 00:01:13 +00003717 if (m_addr_of_valobj_sp)
3718 return m_addr_of_valobj_sp;
3719
Greg Claytone0d378b2011-03-24 21:19:54 +00003720 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003721 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003722 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003723 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003724 if (addr != LLDB_INVALID_ADDRESS)
3725 {
3726 switch (address_type)
3727 {
3728 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003729 {
3730 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003731 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003732 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3733 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003734 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003735
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003736 case eAddressTypeFile:
3737 case eAddressTypeLoad:
3738 case eAddressTypeHost:
3739 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003740 ClangASTType clang_type = GetClangType();
3741 if (clang_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003742 {
3743 std::string name (1, '&');
3744 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003745 ExecutionContext exe_ctx (GetExecutionContextRef());
3746 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00003747 clang_type.GetPointerType(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003748 ConstString (name.c_str()),
3749 addr,
3750 eAddressTypeInvalid,
3751 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003752 }
3753 }
3754 break;
3755 }
3756 }
Sean Callananed185ab2013-04-19 19:47:32 +00003757 else
3758 {
3759 StreamString expr_path_strm;
3760 GetExpressionPath(expr_path_strm, true);
3761 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3762 }
3763
Jim Ingham78a685a2011-04-16 00:01:13 +00003764 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003765}
3766
Greg Clayton9a142cf2012-02-03 05:34:10 +00003767ValueObjectSP
3768ValueObject::Cast (const ClangASTType &clang_ast_type)
3769{
Greg Clayton81e871e2012-02-04 02:27:34 +00003770 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003771}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003772
Greg Claytonafacd142011-09-02 01:15:17 +00003773ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003774ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3775{
Greg Claytonafacd142011-09-02 01:15:17 +00003776 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003777 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003778 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003779
3780 if (ptr_value != LLDB_INVALID_ADDRESS)
3781 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003782 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003783 ExecutionContext exe_ctx (GetExecutionContextRef());
3784 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003785 name,
3786 ptr_addr,
3787 clang_ast_type);
3788 }
3789 return valobj_sp;
3790}
3791
Greg Claytonafacd142011-09-02 01:15:17 +00003792ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003793ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3794{
Greg Claytonafacd142011-09-02 01:15:17 +00003795 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003796 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003797 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003798
3799 if (ptr_value != LLDB_INVALID_ADDRESS)
3800 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003801 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003802 ExecutionContext exe_ctx (GetExecutionContextRef());
3803 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003804 name,
3805 ptr_addr,
3806 type_sp);
3807 }
3808 return valobj_sp;
3809}
3810
Jim Ingham6035b672011-03-31 00:19:25 +00003811ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003812 m_mod_id(),
3813 m_exe_ctx_ref(),
3814 m_needs_update (true),
3815 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003816{
3817}
3818
3819ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003820 m_mod_id(),
3821 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003822 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003823 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003824{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003825 ExecutionContext exe_ctx(exe_scope);
3826 TargetSP target_sp (exe_ctx.GetTargetSP());
3827 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003828 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003829 m_exe_ctx_ref.SetTargetSP (target_sp);
3830 ProcessSP process_sp (exe_ctx.GetProcessSP());
3831 if (!process_sp)
3832 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003833
Greg Claytoncc4d0142012-02-17 07:49:44 +00003834 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003835 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003836 m_mod_id = process_sp->GetModID();
3837 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003838
Greg Claytoncc4d0142012-02-17 07:49:44 +00003839 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003840
Greg Claytoncc4d0142012-02-17 07:49:44 +00003841 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003842 {
3843 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003844 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003845 }
Jim Ingham6035b672011-03-31 00:19:25 +00003846
Greg Claytoncc4d0142012-02-17 07:49:44 +00003847 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003848 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003849 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003850
Jason Molendab57e4a12013-11-04 09:33:30 +00003851 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003852 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003853 {
3854 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003855 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003856 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003857 if (frame_sp)
3858 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003859 }
3860 }
3861 }
Jim Ingham6035b672011-03-31 00:19:25 +00003862}
3863
3864ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003865 m_mod_id(),
3866 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3867 m_needs_update (true),
3868 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003869{
3870}
3871
3872ValueObject::EvaluationPoint::~EvaluationPoint ()
3873{
3874}
3875
Jim Ingham6035b672011-03-31 00:19:25 +00003876// This function checks the EvaluationPoint against the current process state. If the current
3877// state matches the evaluation point, or the evaluation point is already invalid, then we return
3878// false, meaning "no change". If the current state is different, we update our state, and return
3879// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3880// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003881// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003882
3883bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003884ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003885{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003886
3887 // Start with the target, if it is NULL, then we're obviously not going to get any further:
Greg Clayton44d93782014-01-27 23:43:24 +00003888 const bool thread_and_frame_only_if_stopped = true;
3889 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
Jim Ingham73ca05a2011-12-17 01:35:57 +00003890
Greg Claytoncc4d0142012-02-17 07:49:44 +00003891 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003892 return false;
3893
Jim Ingham6035b672011-03-31 00:19:25 +00003894 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003895 Process *process = exe_ctx.GetProcessPtr();
3896 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003897 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003898
Jim Ingham6035b672011-03-31 00:19:25 +00003899 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003900 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003901
Jim Ingham78a685a2011-04-16 00:01:13 +00003902 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3903 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003904 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003905 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003906
Greg Clayton23f59502012-07-17 03:23:13 +00003907 bool changed = false;
3908 const bool was_valid = m_mod_id.IsValid();
3909 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003910 {
3911 if (m_mod_id == current_mod_id)
3912 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003913 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003914 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003915 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003916 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003917 else
3918 {
3919 m_mod_id = current_mod_id;
3920 m_needs_update = true;
3921 changed = true;
3922 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003923 }
Jim Ingham6035b672011-03-31 00:19:25 +00003924
Jim Ingham73ca05a2011-12-17 01:35:57 +00003925 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3926 // That way we'll be sure to return a valid exe_scope.
3927 // 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 +00003928
Greg Claytoncc4d0142012-02-17 07:49:44 +00003929 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003930 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003931 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3932 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003933 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003934 if (m_exe_ctx_ref.HasFrameRef())
3935 {
Jason Molendab57e4a12013-11-04 09:33:30 +00003936 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003937 if (!frame_sp)
3938 {
3939 // We used to have a frame, but now it is gone
3940 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003941 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00003942 }
3943 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003944 }
Jim Ingham6035b672011-03-31 00:19:25 +00003945 else
3946 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003947 // We used to have a thread, but now it is gone
3948 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003949 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00003950 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003951
Jim Ingham6035b672011-03-31 00:19:25 +00003952 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003953 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003954}
3955
Jim Ingham61be0902011-05-02 18:13:59 +00003956void
3957ValueObject::EvaluationPoint::SetUpdated ()
3958{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003959 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3960 if (process_sp)
3961 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003962 m_first_update = false;
3963 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003964}
3965
3966
Enrico Granataf2bbf712011-07-15 02:26:42 +00003967
3968void
Enrico Granata86cc9822012-03-19 22:58:49 +00003969ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00003970{
Enrico Granata86cc9822012-03-19 22:58:49 +00003971 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
3972 m_value_str.clear();
3973
3974 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
3975 m_location_str.clear();
3976
3977 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
Enrico Granata86cc9822012-03-19 22:58:49 +00003978 m_summary_str.clear();
Enrico Granata86cc9822012-03-19 22:58:49 +00003979
3980 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
3981 m_object_desc_str.clear();
3982
3983 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
3984 {
3985 if (m_synthetic_value)
3986 m_synthetic_value = NULL;
3987 }
Enrico Granata744794a2014-09-05 21:46:22 +00003988
3989 if ((clear_mask & eClearUserVisibleDataItemsValidator) == eClearUserVisibleDataItemsValidator)
3990 m_validation_result.reset();
Johnny Chen44805302011-07-19 19:48:13 +00003991}
Enrico Granata9128ee22011-09-06 19:20:51 +00003992
3993SymbolContextScope *
3994ValueObject::GetSymbolContextScope()
3995{
3996 if (m_parent)
3997 {
3998 if (!m_parent->IsPointerOrReferenceType())
3999 return m_parent->GetSymbolContextScope();
4000 }
4001 return NULL;
4002}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004003
4004lldb::ValueObjectSP
4005ValueObject::CreateValueObjectFromExpression (const char* name,
4006 const char* expression,
4007 const ExecutionContext& exe_ctx)
4008{
4009 lldb::ValueObjectSP retval_sp;
4010 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4011 if (!target_sp)
4012 return retval_sp;
4013 if (!expression || !*expression)
4014 return retval_sp;
4015 target_sp->EvaluateExpression (expression,
4016 exe_ctx.GetFrameSP().get(),
4017 retval_sp);
4018 if (retval_sp && name && *name)
4019 retval_sp->SetName(ConstString(name));
4020 return retval_sp;
4021}
4022
4023lldb::ValueObjectSP
4024ValueObject::CreateValueObjectFromAddress (const char* name,
4025 uint64_t address,
4026 const ExecutionContext& exe_ctx,
4027 ClangASTType type)
4028{
Greg Clayton57ee3062013-07-11 22:46:58 +00004029 if (type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004030 {
Greg Clayton57ee3062013-07-11 22:46:58 +00004031 ClangASTType pointer_type(type.GetPointerType());
4032 if (pointer_type)
4033 {
4034 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4035 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4036 pointer_type,
4037 ConstString(name),
4038 buffer,
4039 lldb::endian::InlHostByteOrder(),
4040 exe_ctx.GetAddressByteSize()));
4041 if (ptr_result_valobj_sp)
4042 {
4043 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4044 Error err;
4045 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4046 if (ptr_result_valobj_sp && name && *name)
4047 ptr_result_valobj_sp->SetName(ConstString(name));
4048 }
4049 return ptr_result_valobj_sp;
4050 }
Enrico Granatab2698cd2012-09-13 18:27:09 +00004051 }
Greg Clayton57ee3062013-07-11 22:46:58 +00004052 return lldb::ValueObjectSP();
Enrico Granatab2698cd2012-09-13 18:27:09 +00004053}
4054
4055lldb::ValueObjectSP
4056ValueObject::CreateValueObjectFromData (const char* name,
Enrico Granata7ca1c762014-03-31 23:02:25 +00004057 const DataExtractor& data,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004058 const ExecutionContext& exe_ctx,
4059 ClangASTType type)
4060{
4061 lldb::ValueObjectSP new_value_sp;
4062 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004063 type,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004064 ConstString(name),
4065 data,
4066 LLDB_INVALID_ADDRESS);
4067 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4068 if (new_value_sp && name && *name)
4069 new_value_sp->SetName(ConstString(name));
4070 return new_value_sp;
4071}
Enrico Granata4873e522013-04-11 22:48:58 +00004072
4073ModuleSP
4074ValueObject::GetModule ()
4075{
4076 ValueObject* root(GetRoot());
4077 if (root != this)
4078 return root->GetModule();
4079 return lldb::ModuleSP();
4080}
4081
4082ValueObject*
4083ValueObject::GetRoot ()
4084{
4085 if (m_root)
4086 return m_root;
4087 ValueObject* parent = m_parent;
4088 if (!parent)
4089 return (m_root = this);
4090 while (parent->m_parent)
4091 {
4092 if (parent->m_root)
4093 return (m_root = parent->m_root);
4094 parent = parent->m_parent;
4095 }
4096 return (m_root = parent);
4097}
4098
4099AddressType
4100ValueObject::GetAddressTypeOfChildren()
4101{
4102 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
4103 {
4104 ValueObject* root(GetRoot());
4105 if (root != this)
4106 return root->GetAddressTypeOfChildren();
4107 }
4108 return m_address_type_of_ptr_or_ref_children;
4109}
4110
4111lldb::DynamicValueType
4112ValueObject::GetDynamicValueType ()
4113{
4114 ValueObject* with_dv_info = this;
4115 while (with_dv_info)
4116 {
4117 if (with_dv_info->HasDynamicValueTypeInfo())
4118 return with_dv_info->GetDynamicValueTypeImpl();
4119 with_dv_info = with_dv_info->m_parent;
4120 }
4121 return lldb::eNoDynamicValues;
4122}
Enrico Granata39d51412013-05-31 17:43:40 +00004123
Enrico Granata4873e522013-04-11 22:48:58 +00004124lldb::Format
4125ValueObject::GetFormat () const
4126{
4127 const ValueObject* with_fmt_info = this;
4128 while (with_fmt_info)
4129 {
4130 if (with_fmt_info->m_format != lldb::eFormatDefault)
4131 return with_fmt_info->m_format;
4132 with_fmt_info = with_fmt_info->m_parent;
4133 }
4134 return m_format;
4135}
Enrico Granatad07cfd32014-10-08 18:27:36 +00004136
4137bool
4138ValueObject::CanProvideValue ()
4139{
4140 return (false == GetClangType().IsAggregateType());
4141}