blob: fb3c9b3c06ca5bb553b05c4d6b4cfd1e42b631f3 [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"
37
Greg Clayton7fb56d02011-02-01 01:31:41 +000038#include "lldb/Host/Endian.h"
39
Enrico Granata61a80ba2011-08-12 16:42:31 +000040#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granataf2bbf712011-07-15 02:26:42 +000041#include "lldb/Interpreter/ScriptInterpreterPython.h"
42
Greg Claytone1a916a2010-07-21 22:12:05 +000043#include "lldb/Symbol/ClangASTType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000044#include "lldb/Symbol/ClangASTContext.h"
45#include "lldb/Symbol/Type.h"
46
Jim Ingham53c47f12010-09-10 23:12:17 +000047#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000048#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000049#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000050#include "lldb/Target/Process.h"
51#include "lldb/Target/RegisterContext.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000052#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054
55using namespace lldb;
56using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000057using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058
Greg Claytonafacd142011-09-02 01:15:17 +000059static user_id_t g_value_obj_uid = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060
61//----------------------------------------------------------------------
62// ValueObject constructor
63//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000064ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000066 m_parent (&parent),
Stephen Wilson71c21d12011-04-11 19:41:40 +000067 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000068 m_name (),
69 m_data (),
70 m_value (),
71 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000072 m_value_str (),
73 m_old_value_str (),
74 m_location_str (),
75 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000076 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +000077 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000078 m_children (),
79 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000080 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000081 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000082 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000083 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000084 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +000085 m_type_summary_sp(),
86 m_type_format_sp(),
87 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +000088 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +000089 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
Greg Clayton288bdf92010-09-02 02:59:18 +000090 m_value_is_valid (false),
91 m_value_did_change (false),
92 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000093 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +000094 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +000095 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +000096 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +000097 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +000098 m_is_getting_summary(false),
99 m_did_calculate_complete_objc_class_type(false)
Jim Ingham6035b672011-03-31 00:19:25 +0000100{
Jim Ingham58b59f92011-04-22 23:53:53 +0000101 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000102}
103
104//----------------------------------------------------------------------
105// ValueObject constructor
106//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000107ValueObject::ValueObject (ExecutionContextScope *exe_scope,
108 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000109 UserID (++g_value_obj_uid), // Unique identifier for every value object
110 m_parent (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000111 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000112 m_name (),
113 m_data (),
114 m_value (),
115 m_error (),
116 m_value_str (),
117 m_old_value_str (),
118 m_location_str (),
119 m_summary_str (),
120 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000121 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000122 m_children (),
123 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000124 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000125 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000126 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000127 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000128 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +0000129 m_type_summary_sp(),
130 m_type_format_sp(),
131 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000132 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000133 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Jim Ingham6035b672011-03-31 00:19:25 +0000134 m_value_is_valid (false),
135 m_value_did_change (false),
136 m_children_count_valid (false),
137 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000138 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000139 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000140 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000141 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000142 m_is_getting_summary(false),
143 m_did_calculate_complete_objc_class_type(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000144{
Jim Ingham58b59f92011-04-22 23:53:53 +0000145 m_manager = new ValueObjectManager();
146 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000147}
148
149//----------------------------------------------------------------------
150// Destructor
151//----------------------------------------------------------------------
152ValueObject::~ValueObject ()
153{
154}
155
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000156bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000157ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000158{
Enrico Granata4becb372011-06-29 22:27:15 +0000159
Enrico Granata9128ee22011-09-06 19:20:51 +0000160 bool did_change_formats = false;
161
Enrico Granata0a3958e2011-07-02 00:25:22 +0000162 if (update_format)
Enrico Granata5548cb52013-01-28 23:47:25 +0000163 did_change_formats = UpdateFormatsIfNeeded();
Enrico Granata4becb372011-06-29 22:27:15 +0000164
Greg Claytonb71f3842010-10-05 03:13:51 +0000165 // If this is a constant value, then our success is predicated on whether
166 // we have an error or not
167 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000168 {
169 // if you were asked to update your formatters, but did not get a chance to do it
170 // clear your own values (this serves the purpose of faking a stop-id for frozen
171 // objects (which are regarded as constant, but could have changes behind their backs
172 // because of the frozen-pointer depth limit)
173 // TODO: decouple summary from value and then remove this code and only force-clear the summary
174 if (update_format && !did_change_formats)
Enrico Granata86cc9822012-03-19 22:58:49 +0000175 ClearUserVisibleData(eClearUserVisibleDataItemsSummary);
Greg Claytonb71f3842010-10-05 03:13:51 +0000176 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000177 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000178
Jim Ingham6035b672011-03-31 00:19:25 +0000179 bool first_update = m_update_point.IsFirstEvaluation();
180
181 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000182 {
Jim Ingham6035b672011-03-31 00:19:25 +0000183 m_update_point.SetUpdated();
184
185 // Save the old value using swap to avoid a string copy which
186 // also will clear our m_value_str
187 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000188 {
Jim Ingham6035b672011-03-31 00:19:25 +0000189 m_old_value_valid = false;
190 }
191 else
192 {
193 m_old_value_valid = true;
194 m_old_value_str.swap (m_value_str);
Enrico Granata86cc9822012-03-19 22:58:49 +0000195 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham6035b672011-03-31 00:19:25 +0000196 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000197
Enrico Granataf2bbf712011-07-15 02:26:42 +0000198 ClearUserVisibleData();
199
Greg Claytonefbc7d22012-03-09 04:23:44 +0000200 if (IsInScope())
Jim Ingham6035b672011-03-31 00:19:25 +0000201 {
Greg Claytonefbc7d22012-03-09 04:23:44 +0000202 const bool value_was_valid = GetValueIsValid();
203 SetValueDidChange (false);
204
205 m_error.Clear();
206
207 // Call the pure virtual function to update the value
208 bool success = UpdateValue ();
209
210 SetValueIsValid (success);
211
212 if (first_update)
213 SetValueDidChange (false);
214 else if (!m_value_did_change && success == false)
215 {
216 // The value wasn't gotten successfully, so we mark this
217 // as changed if the value used to be valid and now isn't
218 SetValueDidChange (value_was_valid);
219 }
220 }
221 else
222 {
223 m_error.SetErrorString("out of scope");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000224 }
225 }
226 return m_error.Success();
227}
228
Enrico Granata9128ee22011-09-06 19:20:51 +0000229bool
Enrico Granata5548cb52013-01-28 23:47:25 +0000230ValueObject::UpdateFormatsIfNeeded()
Enrico Granata4becb372011-06-29 22:27:15 +0000231{
Enrico Granata6f3533f2011-07-29 19:53:35 +0000232 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
233 if (log)
Enrico Granatad2284832012-10-17 22:23:56 +0000234 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
Enrico Granata6f3533f2011-07-29 19:53:35 +0000235 GetName().GetCString(),
Enrico Granatad2284832012-10-17 22:23:56 +0000236 this,
Enrico Granata4becb372011-06-29 22:27:15 +0000237 m_last_format_mgr_revision,
Enrico Granata85933ed2011-08-18 16:38:26 +0000238 DataVisualization::GetCurrentRevision());
Enrico Granata9128ee22011-09-06 19:20:51 +0000239
240 bool any_change = false;
241
Enrico Granata5548cb52013-01-28 23:47:25 +0000242 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()))
Enrico Granata4becb372011-06-29 22:27:15 +0000243 {
Enrico Granata78d06382011-09-09 23:33:14 +0000244 SetValueFormat(DataVisualization::ValueFormats::GetFormat (*this, eNoDynamicValues));
Enrico Granata5548cb52013-01-28 23:47:25 +0000245 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000246#ifndef LLDB_DISABLE_PYTHON
Enrico Granata5548cb52013-01-28 23:47:25 +0000247 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000248#endif
Enrico Granata1490c6f2011-07-19 02:34:21 +0000249
Enrico Granata85933ed2011-08-18 16:38:26 +0000250 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
Enrico Granata855cd902011-09-06 22:59:55 +0000251
252 any_change = true;
Enrico Granata4becb372011-06-29 22:27:15 +0000253 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000254
255 return any_change;
256
Enrico Granata4becb372011-06-29 22:27:15 +0000257}
258
Jim Ingham16e0c682011-08-12 23:34:31 +0000259void
260ValueObject::SetNeedsUpdate ()
261{
262 m_update_point.SetNeedsUpdate();
263 // We have to clear the value string here so ConstResult children will notice if their values are
264 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000265 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000266}
267
Enrico Granata13ac0e22012-10-17 19:03:34 +0000268void
Enrico Granatae3e91512012-10-22 18:18:36 +0000269ValueObject::ClearDynamicTypeInformation ()
Enrico Granata13ac0e22012-10-17 19:03:34 +0000270{
271 m_did_calculate_complete_objc_class_type = false;
Enrico Granatae3e91512012-10-22 18:18:36 +0000272 m_last_format_mgr_revision = 0;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000273 m_override_type = ClangASTType();
Enrico Granatae3e91512012-10-22 18:18:36 +0000274 SetValueFormat(lldb::TypeFormatImplSP());
275 SetSummaryFormat(lldb::TypeSummaryImplSP());
276 SetSyntheticChildren(lldb::SyntheticChildrenSP());
Enrico Granata13ac0e22012-10-17 19:03:34 +0000277}
278
Sean Callanan72772842012-02-22 23:57:45 +0000279ClangASTType
280ValueObject::MaybeCalculateCompleteType ()
281{
282 ClangASTType ret(GetClangASTImpl(), GetClangTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000283
Sean Callanan72772842012-02-22 23:57:45 +0000284 if (m_did_calculate_complete_objc_class_type)
285 {
286 if (m_override_type.IsValid())
287 return m_override_type;
288 else
289 return ret;
290 }
291
292 clang_type_t ast_type(GetClangTypeImpl());
293 clang_type_t class_type;
294 bool is_pointer_type;
295
296 if (ClangASTContext::IsObjCObjectPointerType(ast_type, &class_type))
297 {
298 is_pointer_type = true;
299 }
300 else if (ClangASTContext::IsObjCClassType(ast_type))
301 {
302 is_pointer_type = false;
303 class_type = ast_type;
304 }
305 else
306 {
307 return ret;
308 }
309
310 m_did_calculate_complete_objc_class_type = true;
311
312 if (!class_type)
313 return ret;
314
315 std::string class_name;
316
317 if (!ClangASTContext::GetObjCClassName(class_type, class_name))
318 return ret;
319
320 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
321
322 if (!process_sp)
323 return ret;
324
325 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
326
327 if (!objc_language_runtime)
328 return ret;
329
330 ConstString class_name_cs(class_name.c_str());
331
332 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name_cs);
333
334 if (!complete_objc_class_type_sp)
335 return ret;
336
337 ClangASTType complete_class(complete_objc_class_type_sp->GetClangAST(),
338 complete_objc_class_type_sp->GetClangFullType());
339
340 if (!ClangASTContext::GetCompleteType(complete_class.GetASTContext(),
341 complete_class.GetOpaqueQualType()))
342 return ret;
343
344 if (is_pointer_type)
345 {
346 clang_type_t pointer_type = ClangASTContext::CreatePointerType(complete_class.GetASTContext(),
347 complete_class.GetOpaqueQualType());
348
349 m_override_type = ClangASTType(complete_class.GetASTContext(),
350 pointer_type);
351 }
352 else
353 {
354 m_override_type = complete_class;
355 }
356
Sean Callanan356e17c2012-03-30 02:04:38 +0000357 if (m_override_type.IsValid())
358 return m_override_type;
359 else
360 return ret;
Sean Callanan72772842012-02-22 23:57:45 +0000361}
362
363clang::ASTContext *
364ValueObject::GetClangAST ()
365{
366 ClangASTType type = MaybeCalculateCompleteType();
367
368 return type.GetASTContext();
369}
370
371lldb::clang_type_t
372ValueObject::GetClangType ()
373{
374 ClangASTType type = MaybeCalculateCompleteType();
375
376 return type.GetOpaqueQualType();
377}
378
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000379DataExtractor &
380ValueObject::GetDataExtractor ()
381{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000382 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000383 return m_data;
384}
385
386const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000387ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000388{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000389 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000390 return m_error;
391}
392
393const ConstString &
394ValueObject::GetName() const
395{
396 return m_name;
397}
398
399const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000400ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000401{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000402 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000403 {
404 if (m_location_str.empty())
405 {
406 StreamString sstr;
407
408 switch (m_value.GetValueType())
409 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000410 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +0000411 case Value::eValueTypeVector:
Greg Clayton526e5af2010-11-13 03:52:47 +0000412 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000413 {
414 RegisterInfo *reg_info = m_value.GetRegisterInfo();
415 if (reg_info)
416 {
417 if (reg_info->name)
418 m_location_str = reg_info->name;
419 else if (reg_info->alt_name)
420 m_location_str = reg_info->alt_name;
Greg Clayton0665a0f2012-10-30 18:18:43 +0000421
422 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000423 }
424 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000425 break;
426
427 case Value::eValueTypeLoadAddress:
428 case Value::eValueTypeFileAddress:
429 case Value::eValueTypeHostAddress:
430 {
431 uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2;
432 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
433 m_location_str.swap(sstr.GetString());
434 }
435 break;
436 }
437 }
438 }
439 return m_location_str.c_str();
440}
441
442Value &
443ValueObject::GetValue()
444{
445 return m_value;
446}
447
448const Value &
449ValueObject::GetValue() const
450{
451 return m_value;
452}
453
454bool
Jim Ingham6035b672011-03-31 00:19:25 +0000455ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000456{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000457 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
458 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000459 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000460 Value tmp_value(m_value);
461 scalar = tmp_value.ResolveValue(&exe_ctx, GetClangAST ());
Greg Claytondcad5022011-12-29 01:26:56 +0000462 if (scalar.IsValid())
463 {
464 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
465 if (bitfield_bit_size)
466 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
467 return true;
468 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000469 }
Greg Claytondcad5022011-12-29 01:26:56 +0000470 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000471}
472
473bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000474ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000475{
Greg Clayton288bdf92010-09-02 02:59:18 +0000476 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000477}
478
479
480void
481ValueObject::SetValueIsValid (bool b)
482{
Greg Clayton288bdf92010-09-02 02:59:18 +0000483 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000484}
485
486bool
Jim Ingham6035b672011-03-31 00:19:25 +0000487ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000488{
Jim Ingham6035b672011-03-31 00:19:25 +0000489 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000490 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000491}
492
493void
494ValueObject::SetValueDidChange (bool value_changed)
495{
Greg Clayton288bdf92010-09-02 02:59:18 +0000496 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000497}
498
499ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000500ValueObject::GetChildAtIndex (size_t idx, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000501{
502 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000503 // We may need to update our value if we are dynamic
504 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000505 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000506 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000507 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000508 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000509 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000510 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000511 // No we haven't created the child at this index, so lets have our
512 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000513 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000514 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000515
Enrico Granata9d60f602012-03-09 03:09:58 +0000516 ValueObject* child = m_children.GetChildAtIndex(idx);
517 if (child != NULL)
518 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000519 }
520 return child_sp;
521}
522
Enrico Granata3309d882013-01-12 01:00:22 +0000523ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000524ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
525 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000526{
527 if (idxs.size() == 0)
528 return GetSP();
529 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000530 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000531 {
532 root = root->GetChildAtIndex(idx, true);
533 if (!root)
534 {
535 if (index_of_error)
536 *index_of_error = idx;
537 return root;
538 }
539 }
540 return root;
541}
542
543ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000544ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
545 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000546{
547 if (idxs.size() == 0)
548 return GetSP();
549 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000550 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000551 {
552 root = root->GetChildAtIndex(idx.first, idx.second);
553 if (!root)
554 {
555 if (index_of_error)
556 *index_of_error = idx.first;
557 return root;
558 }
559 }
560 return root;
561}
562
563lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000564ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
565 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000566{
567 if (idxs.size() == 0)
568 return GetSP();
569 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000570 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000571 {
572 root = root->GetChildAtIndex(idx, true);
573 if (!root)
574 {
575 if (index_of_error)
576 *index_of_error = idx;
577 return root;
578 }
579 }
580 return root;
581}
582
583lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000584ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
585 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000586{
587 if (idxs.size() == 0)
588 return GetSP();
589 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000590 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000591 {
592 root = root->GetChildAtIndex(idx.first, idx.second);
593 if (!root)
594 {
595 if (index_of_error)
596 *index_of_error = idx.first;
597 return root;
598 }
599 }
600 return root;
601}
602
Greg Claytonc7bece562013-01-25 18:06:21 +0000603size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000604ValueObject::GetIndexOfChildWithName (const ConstString &name)
605{
606 bool omit_empty_base_classes = true;
607 return ClangASTContext::GetIndexOfChildWithName (GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +0000608 GetClangType(),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000609 name.GetCString(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000610 omit_empty_base_classes);
611}
612
613ValueObjectSP
614ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
615{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000616 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000617 // classes (which really aren't part of the expression path), so we
618 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000619 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000620
Greg Claytondea8cb42011-06-29 22:09:02 +0000621 // We may need to update our value if we are dynamic
622 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000623 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000624
625 std::vector<uint32_t> child_indexes;
626 clang::ASTContext *clang_ast = GetClangAST();
627 void *clang_type = GetClangType();
628 bool omit_empty_base_classes = true;
629 const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast,
630 clang_type,
631 name.GetCString(),
632 omit_empty_base_classes,
633 child_indexes);
634 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000635 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000636 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
637 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
638
639 child_sp = GetChildAtIndex(*pos, can_create);
640 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000641 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000642 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000643 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000644 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
645 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000646 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000647 else
648 {
649 child_sp.reset();
650 }
651
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000652 }
653 }
654 return child_sp;
655}
656
657
Greg Claytonc7bece562013-01-25 18:06:21 +0000658size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000659ValueObject::GetNumChildren ()
660{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000661 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000662 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000663 {
664 SetNumChildren (CalculateNumChildren());
665 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000666 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000667}
Greg Clayton4a792072012-10-23 01:50:10 +0000668
669bool
670ValueObject::MightHaveChildren()
671{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000672 bool has_children = false;
Greg Clayton2452ab72013-02-08 22:02:02 +0000673 const uint32_t type_info = GetTypeInfo();
674 if (type_info)
Greg Clayton4a792072012-10-23 01:50:10 +0000675 {
Greg Clayton4a792072012-10-23 01:50:10 +0000676 if (type_info & (ClangASTContext::eTypeHasChildren |
677 ClangASTContext::eTypeIsPointer |
678 ClangASTContext::eTypeIsReference))
679 has_children = true;
680 }
681 else
682 {
683 has_children = GetNumChildren () > 0;
684 }
685 return has_children;
686}
687
688// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000689void
Greg Claytonc7bece562013-01-25 18:06:21 +0000690ValueObject::SetNumChildren (size_t num_children)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000691{
Greg Clayton288bdf92010-09-02 02:59:18 +0000692 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000693 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000694}
695
696void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000697ValueObject::SetName (const ConstString &name)
698{
699 m_name = name;
700}
701
Jim Ingham58b59f92011-04-22 23:53:53 +0000702ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000703ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000704{
Jim Ingham2eec4872011-05-07 00:10:58 +0000705 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000706
Greg Claytondea8cb42011-06-29 22:09:02 +0000707 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000708 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000709 std::string child_name_str;
710 uint32_t child_byte_size = 0;
711 int32_t child_byte_offset = 0;
712 uint32_t child_bitfield_bit_size = 0;
713 uint32_t child_bitfield_bit_offset = 0;
714 bool child_is_base_class = false;
715 bool child_is_deref_of_parent = false;
716
717 const bool transparent_pointers = synthetic_array_member == false;
718 clang::ASTContext *clang_ast = GetClangAST();
719 clang_type_t clang_type = GetClangType();
720 clang_type_t child_clang_type;
721
Greg Claytoncc4d0142012-02-17 07:49:44 +0000722 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000723
724 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
725 clang_ast,
726 GetName().GetCString(),
727 clang_type,
728 idx,
729 transparent_pointers,
730 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +0000731 ignore_array_bounds,
Greg Claytondea8cb42011-06-29 22:09:02 +0000732 child_name_str,
733 child_byte_size,
734 child_byte_offset,
735 child_bitfield_bit_size,
736 child_bitfield_bit_offset,
737 child_is_base_class,
738 child_is_deref_of_parent);
Greg Clayton4ef877f2012-12-06 02:33:54 +0000739 if (child_clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000740 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000741 if (synthetic_index)
742 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000743
Greg Claytondea8cb42011-06-29 22:09:02 +0000744 ConstString child_name;
745 if (!child_name_str.empty())
746 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000747
Greg Claytondea8cb42011-06-29 22:09:02 +0000748 valobj = new ValueObjectChild (*this,
749 clang_ast,
750 child_clang_type,
751 child_name,
752 child_byte_size,
753 child_byte_offset,
754 child_bitfield_bit_size,
755 child_bitfield_bit_offset,
756 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000757 child_is_deref_of_parent,
758 eAddressTypeInvalid);
759 //if (valobj)
760 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
761 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000762
Jim Ingham58b59f92011-04-22 23:53:53 +0000763 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000764}
765
Enrico Granata0c489f52012-03-01 04:24:26 +0000766bool
767ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
768 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000769{
Enrico Granata0c489f52012-03-01 04:24:26 +0000770 destination.clear();
771
772 // ideally we would like to bail out if passing NULL, but if we do so
773 // we end up not providing the summary for function pointers anymore
774 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
775 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000776
777 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000778
779 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
780 // information that we might care to see in a crash log. might be useful in very specific situations though.
781 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
782 GetTypeName().GetCString(),
783 GetName().GetCString(),
784 summary_ptr->GetDescription().c_str());*/
785
Enrico Granata0c489f52012-03-01 04:24:26 +0000786 if (UpdateValueIfNeeded (false))
787 {
788 if (summary_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000789 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000790 if (HasSyntheticValue())
791 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
792 summary_ptr->FormatObject(this, destination);
Enrico Granata0c489f52012-03-01 04:24:26 +0000793 }
794 else
795 {
796 clang_type_t clang_type = GetClangType();
797
798 // Do some default printout for function pointers
799 if (clang_type)
Enrico Granata4becb372011-06-29 22:27:15 +0000800 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000801 StreamString sstr;
802 clang_type_t elem_or_pointee_clang_type;
803 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
804 GetClangAST(),
805 &elem_or_pointee_clang_type));
806
807 if (ClangASTContext::IsFunctionPointerType (clang_type))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000808 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000809 AddressType func_ptr_address_type = eAddressTypeInvalid;
810 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
811 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000812 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000813 switch (func_ptr_address_type)
Jim Ingham6035b672011-03-31 00:19:25 +0000814 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000815 case eAddressTypeInvalid:
816 case eAddressTypeFile:
817 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000818
Greg Claytoncc4d0142012-02-17 07:49:44 +0000819 case eAddressTypeLoad:
Enrico Granata0c489f52012-03-01 04:24:26 +0000820 {
821 ExecutionContext exe_ctx (GetExecutionContextRef());
822
823 Address so_addr;
824 Target *target = exe_ctx.GetTargetPtr();
825 if (target && target->GetSectionLoadList().IsEmpty() == false)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000826 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000827 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000828 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000829 so_addr.Dump (&sstr,
830 exe_ctx.GetBestExecutionContextScope(),
831 Address::DumpStyleResolvedDescription,
832 Address::DumpStyleSectionNameOffset);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000833 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000834 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000835 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000836 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000837
Greg Claytoncc4d0142012-02-17 07:49:44 +0000838 case eAddressTypeHost:
839 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +0000840 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000841 }
842 if (sstr.GetSize() > 0)
843 {
844 destination.assign (1, '(');
845 destination.append (sstr.GetData(), sstr.GetSize());
846 destination.append (1, ')');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000847 }
848 }
849 }
850 }
851 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000852 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000853 return !destination.empty();
854}
855
856const char *
857ValueObject::GetSummaryAsCString ()
858{
859 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
860 {
861 GetSummaryAsCString(GetSummaryFormat().get(),
862 m_summary_str);
863 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000864 if (m_summary_str.empty())
865 return NULL;
866 return m_summary_str.c_str();
867}
868
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000869bool
870ValueObject::IsCStringContainer(bool check_pointer)
871{
872 clang_type_t elem_or_pointee_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +0000873 const Flags type_flags (GetTypeInfo (&elem_or_pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000874 bool is_char_arr_ptr (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
Greg Clayton2452ab72013-02-08 22:02:02 +0000875 ClangASTContext::IsCharType (elem_or_pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000876 if (!is_char_arr_ptr)
877 return false;
878 if (!check_pointer)
879 return true;
880 if (type_flags.Test(ClangASTContext::eTypeIsArray))
881 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000882 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000883 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000884 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000885 return (cstr_address != LLDB_INVALID_ADDRESS);
886}
887
Enrico Granata9128ee22011-09-06 19:20:51 +0000888size_t
889ValueObject::GetPointeeData (DataExtractor& data,
890 uint32_t item_idx,
891 uint32_t item_count)
892{
Greg Clayton2452ab72013-02-08 22:02:02 +0000893 clang_type_t pointee_or_element_clang_type;
894 const uint32_t type_info = GetTypeInfo (&pointee_or_element_clang_type);
895 const bool is_pointer_type = type_info & ClangASTContext::eTypeIsPointer;
896 const bool is_array_type = type_info & ClangASTContext::eTypeIsArray;
897 if (!(is_pointer_type || is_array_type))
Enrico Granata9128ee22011-09-06 19:20:51 +0000898 return 0;
899
900 if (item_count == 0)
901 return 0;
902
Greg Clayton2452ab72013-02-08 22:02:02 +0000903 clang::ASTContext *ast = GetClangAST();
904 ClangASTType pointee_or_element_type(ast, pointee_or_element_clang_type);
Enrico Granata9128ee22011-09-06 19:20:51 +0000905
Greg Clayton2452ab72013-02-08 22:02:02 +0000906 const uint64_t item_type_size = pointee_or_element_type.GetClangTypeByteSize();
Enrico Granata9128ee22011-09-06 19:20:51 +0000907
908 const uint64_t bytes = item_count * item_type_size;
909
910 const uint64_t offset = item_idx * item_type_size;
911
912 if (item_idx == 0 && item_count == 1) // simply a deref
913 {
Greg Clayton2452ab72013-02-08 22:02:02 +0000914 if (is_pointer_type)
Enrico Granata9128ee22011-09-06 19:20:51 +0000915 {
916 Error error;
917 ValueObjectSP pointee_sp = Dereference(error);
918 if (error.Fail() || pointee_sp.get() == NULL)
919 return 0;
920 return pointee_sp->GetDataExtractor().Copy(data);
921 }
922 else
923 {
924 ValueObjectSP child_sp = GetChildAtIndex(0, true);
925 if (child_sp.get() == NULL)
926 return 0;
927 return child_sp->GetDataExtractor().Copy(data);
928 }
929 return true;
930 }
931 else /* (items > 1) */
932 {
933 Error error;
934 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
935 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
936
937 AddressType addr_type;
Greg Clayton2452ab72013-02-08 22:02:02 +0000938 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +0000939
Enrico Granata9128ee22011-09-06 19:20:51 +0000940 switch (addr_type)
941 {
942 case eAddressTypeFile:
943 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000944 ModuleSP module_sp (GetModule());
945 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000946 {
Enrico Granata9c2efe32012-08-07 01:49:34 +0000947 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +0000948 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +0000949 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000950 ExecutionContext exe_ctx (GetExecutionContextRef());
951 Target* target = exe_ctx.GetTargetPtr();
952 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +0000953 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000954 heap_buf_ptr->SetByteSize(bytes);
955 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
956 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +0000957 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000958 data.SetData(data_sp);
959 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +0000960 }
961 }
962 }
963 }
964 break;
965 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +0000966 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000967 ExecutionContext exe_ctx (GetExecutionContextRef());
968 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +0000969 if (process)
970 {
971 heap_buf_ptr->SetByteSize(bytes);
972 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
973 if (error.Success())
974 {
975 data.SetData(data_sp);
976 return bytes_read;
977 }
978 }
979 }
980 break;
981 case eAddressTypeHost:
982 {
Greg Clayton2452ab72013-02-08 22:02:02 +0000983 ClangASTType valobj_type(ast, GetClangType());
984 uint64_t max_bytes = valobj_type.GetClangTypeByteSize();
985 if (max_bytes > offset)
986 {
987 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
988 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
989 data.SetData(data_sp);
990 return bytes_read;
991 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000992 }
993 break;
994 case eAddressTypeInvalid:
Enrico Granata9128ee22011-09-06 19:20:51 +0000995 break;
996 }
997 }
998 return 0;
999}
1000
Greg Claytonfaac1112013-03-14 18:31:44 +00001001uint64_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001002ValueObject::GetData (DataExtractor& data)
1003{
1004 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001005 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytone72dfb32012-02-24 01:59:29 +00001006 Error error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001007 if (error.Fail())
1008 return 0;
1009 data.SetAddressByteSize(m_data.GetAddressByteSize());
1010 data.SetByteOrder(m_data.GetByteOrder());
1011 return data.GetByteSize();
1012}
1013
1014// will compute strlen(str), but without consuming more than
1015// maxlen bytes out of str (this serves the purpose of reading
1016// chunks of a string without having to worry about
1017// missing NULL terminators in the chunk)
1018// of course, if strlen(str) > maxlen, the function will return
1019// maxlen_value (which should be != maxlen, because that allows you
1020// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1021static uint32_t
1022strlen_or_inf (const char* str,
1023 uint32_t maxlen,
1024 uint32_t maxlen_value)
1025{
1026 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +00001027 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +00001028 {
Greg Clayton8dd5c172011-10-05 22:19:51 +00001029 while(*str)
1030 {
1031 len++;str++;
Greg Clayton2452ab72013-02-08 22:02:02 +00001032 if (len >= maxlen)
Greg Clayton8dd5c172011-10-05 22:19:51 +00001033 return maxlen_value;
1034 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001035 }
1036 return len;
1037}
1038
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001039size_t
Greg Claytoncc4d0142012-02-17 07:49:44 +00001040ValueObject::ReadPointedString (Stream& s,
1041 Error& error,
1042 uint32_t max_length,
1043 bool honor_array,
1044 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001045{
Greg Claytoncc4d0142012-02-17 07:49:44 +00001046 ExecutionContext exe_ctx (GetExecutionContextRef());
1047 Target* target = exe_ctx.GetTargetPtr();
1048
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001049 if (!target)
1050 {
1051 s << "<no target to read from>";
1052 error.SetErrorString("no target to read from");
1053 return 0;
1054 }
1055
1056 if (max_length == 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001057 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001058
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001059 size_t bytes_read = 0;
1060 size_t total_bytes_read = 0;
1061
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001062 clang_type_t clang_type = GetClangType();
1063 clang_type_t elem_or_pointee_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001064 const Flags type_flags (GetTypeInfo (&elem_or_pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001065 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
1066 ClangASTContext::IsCharType (elem_or_pointee_clang_type))
1067 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001068 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1069 AddressType cstr_address_type = eAddressTypeInvalid;
1070
1071 size_t cstr_len = 0;
1072 bool capped_data = false;
1073 if (type_flags.Test (ClangASTContext::eTypeIsArray))
Greg Claytoncc4d0142012-02-17 07:49:44 +00001074 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001075 // We have an array
1076 cstr_len = ClangASTContext::GetArraySize (clang_type);
1077 if (cstr_len > max_length)
1078 {
1079 capped_data = true;
1080 cstr_len = max_length;
1081 }
1082 cstr_address = GetAddressOf (true, &cstr_address_type);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001083 }
1084 else
1085 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001086 // We have a pointer
1087 cstr_address = GetPointerValue (&cstr_address_type);
1088 }
1089
1090 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1091 {
1092 s << "<invalid address>";
1093 error.SetErrorString("invalid address");
1094 return 0;
1095 }
1096
1097 Address cstr_so_addr (cstr_address);
1098 DataExtractor data;
1099 if (cstr_len > 0 && honor_array)
1100 {
1101 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1102 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1103 GetPointeeData(data, 0, cstr_len);
1104
1105 if ((bytes_read = data.GetByteSize()) > 0)
1106 {
1107 total_bytes_read = bytes_read;
1108 s << '"';
1109 data.Dump (&s,
1110 0, // Start offset in "data"
1111 item_format,
1112 1, // Size of item (1 byte for a char!)
1113 bytes_read, // How many bytes to print?
1114 UINT32_MAX, // num per line
1115 LLDB_INVALID_ADDRESS,// base address
1116 0, // bitfield bit size
1117 0); // bitfield bit offset
1118 if (capped_data)
1119 s << "...";
1120 s << '"';
1121 }
1122 }
1123 else
1124 {
1125 cstr_len = max_length;
1126 const size_t k_max_buf_size = 64;
1127
1128 size_t offset = 0;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001129
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001130 int cstr_len_displayed = -1;
1131 bool capped_cstr = false;
1132 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1133 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1134 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001135 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001136 total_bytes_read += bytes_read;
1137 const char *cstr = data.PeekCStr(0);
1138 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1139 if (len > k_max_buf_size)
1140 len = k_max_buf_size;
1141 if (cstr && cstr_len_displayed < 0)
1142 s << '"';
1143
1144 if (cstr_len_displayed < 0)
1145 cstr_len_displayed = len;
1146
1147 if (len == 0)
1148 break;
1149 cstr_len_displayed += len;
1150 if (len > bytes_read)
1151 len = bytes_read;
1152 if (len > cstr_len)
1153 len = cstr_len;
1154
1155 data.Dump (&s,
1156 0, // Start offset in "data"
1157 item_format,
1158 1, // Size of item (1 byte for a char!)
1159 len, // How many bytes to print?
1160 UINT32_MAX, // num per line
1161 LLDB_INVALID_ADDRESS,// base address
1162 0, // bitfield bit size
1163 0); // bitfield bit offset
1164
1165 if (len < k_max_buf_size)
1166 break;
1167
1168 if (len >= cstr_len)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001169 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001170 capped_cstr = true;
1171 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001172 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001173
1174 cstr_len -= len;
1175 offset += len;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001176 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001177
1178 if (cstr_len_displayed >= 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001179 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001180 s << '"';
1181 if (capped_cstr)
1182 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001183 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001184 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001185 }
1186 else
1187 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001188 error.SetErrorString("not a string object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001189 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001190 }
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001191 return total_bytes_read;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001192}
1193
Jim Ingham53c47f12010-09-10 23:12:17 +00001194const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001195ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001196{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001197
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001198 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001199 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001200
1201 if (!m_object_desc_str.empty())
1202 return m_object_desc_str.c_str();
1203
Greg Claytoncc4d0142012-02-17 07:49:44 +00001204 ExecutionContext exe_ctx (GetExecutionContextRef());
1205 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001206 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001207 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001208
Jim Ingham53c47f12010-09-10 23:12:17 +00001209 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001210
Greg Claytonafacd142011-09-02 01:15:17 +00001211 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001212 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1213
Jim Inghama2cf2632010-12-23 02:29:54 +00001214 if (runtime == NULL)
1215 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001216 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Jim Inghama2cf2632010-12-23 02:29:54 +00001217 clang_type_t opaque_qual_type = GetClangType();
1218 if (opaque_qual_type != NULL)
1219 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001220 bool is_signed;
1221 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed)
1222 || ClangASTContext::IsPointerType (opaque_qual_type))
1223 {
Greg Claytonafacd142011-09-02 01:15:17 +00001224 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001225 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001226 }
1227 }
1228
Jim Ingham8d543de2011-03-31 23:01:21 +00001229 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001230 {
1231 m_object_desc_str.append (s.GetData());
1232 }
Sean Callanan672ad942010-10-23 00:18:49 +00001233
1234 if (m_object_desc_str.empty())
1235 return NULL;
1236 else
1237 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001238}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001239
Enrico Granata0c489f52012-03-01 04:24:26 +00001240bool
1241ValueObject::GetValueAsCString (lldb::Format format,
1242 std::string& destination)
1243{
1244 if (ClangASTContext::IsAggregateType (GetClangType()) == false &&
1245 UpdateValueIfNeeded(false))
1246 {
1247 const Value::ContextType context_type = m_value.GetContextType();
1248
1249 switch (context_type)
1250 {
1251 case Value::eContextTypeClangType:
1252 case Value::eContextTypeLLDBType:
1253 case Value::eContextTypeVariable:
1254 {
1255 clang_type_t clang_type = GetClangType ();
1256 if (clang_type)
1257 {
1258 StreamString sstr;
1259 ExecutionContext exe_ctx (GetExecutionContextRef());
1260 ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
1261 clang_type, // The clang type to display
1262 &sstr,
1263 format, // Format to display this type with
1264 m_data, // Data to extract from
1265 0, // Byte offset into "m_data"
1266 GetByteSize(), // Byte size of item in "m_data"
1267 GetBitfieldBitSize(), // Bitfield bit size
1268 GetBitfieldBitOffset(), // Bitfield bit offset
1269 exe_ctx.GetBestExecutionContextScope());
1270 // Don't set the m_error to anything here otherwise
1271 // we won't be able to re-format as anything else. The
1272 // code for ClangASTType::DumpTypeValue() should always
1273 // return something, even if that something contains
1274 // an error messsage. "m_error" is used to detect errors
1275 // when reading the valid object, not for formatting errors.
1276 if (sstr.GetString().empty())
1277 destination.clear();
1278 else
1279 destination.swap(sstr.GetString());
1280 }
1281 }
1282 break;
1283
1284 case Value::eContextTypeRegisterInfo:
1285 {
1286 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1287 if (reg_info)
1288 {
1289 ExecutionContext exe_ctx (GetExecutionContextRef());
1290
1291 StreamString reg_sstr;
1292 m_data.Dump (&reg_sstr,
1293 0,
1294 format,
1295 reg_info->byte_size,
1296 1,
1297 UINT32_MAX,
1298 LLDB_INVALID_ADDRESS,
1299 0,
1300 0,
1301 exe_ctx.GetBestExecutionContextScope());
1302 destination.swap(reg_sstr.GetString());
1303 }
1304 }
1305 break;
1306
1307 default:
1308 break;
1309 }
1310 return !destination.empty();
1311 }
1312 else
1313 return false;
1314}
1315
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001316const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001317ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001318{
Enrico Granata0c489f52012-03-01 04:24:26 +00001319 if (UpdateValueIfNeeded(true) && m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001320 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001321 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001322 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001323 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001324 if (m_type_format_sp)
1325 my_format = m_type_format_sp->GetFormat();
1326 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001327 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001328 if (m_is_bitfield_for_scalar)
1329 my_format = eFormatUnsigned;
1330 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001331 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001332 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001333 {
1334 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1335 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001336 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001337 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001338 else
1339 {
1340 clang_type_t clang_type = GetClangType ();
1341 my_format = ClangASTType::GetFormat(clang_type);
1342 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001343 }
1344 }
1345 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001346 if (GetValueAsCString(my_format, m_value_str))
1347 {
1348 if (!m_value_did_change && m_old_value_valid)
1349 {
1350 // The value was gotten successfully, so we consider the
1351 // value as changed if the value string differs
1352 SetValueDidChange (m_old_value_str != m_value_str);
1353 }
1354 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001355 }
1356 if (m_value_str.empty())
1357 return NULL;
1358 return m_value_str.c_str();
1359}
1360
Enrico Granatac3e320a2011-08-02 17:27:39 +00001361// if > 8bytes, 0 is returned. this method should mostly be used
1362// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001363uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001364ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001365{
1366 // If our byte size is zero this is an aggregate type that has children
1367 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
1368 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001369 Scalar scalar;
1370 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001371 {
1372 if (success)
1373 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001374 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001375 }
1376 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001377 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001378
1379 if (success)
1380 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001381 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001382}
1383
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001384// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1385// this call up to date by returning true for your new special cases. We will eventually move
1386// to checking this call result before trying to display special cases
1387bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001388ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1389 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001390{
1391 clang_type_t elem_or_pointee_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001392 Flags flags(GetTypeInfo(&elem_or_pointee_type));
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001393
1394 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001395 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001396 {
1397 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001398 (custom_format == eFormatCString ||
1399 custom_format == eFormatCharArray ||
1400 custom_format == eFormatChar ||
1401 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001402 return true;
1403
1404 if (flags.Test(ClangASTContext::eTypeIsArray))
1405 {
Greg Claytonafacd142011-09-02 01:15:17 +00001406 if ((custom_format == eFormatBytes) ||
1407 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001408 return true;
1409
Greg Claytonafacd142011-09-02 01:15:17 +00001410 if ((custom_format == eFormatVectorOfChar) ||
1411 (custom_format == eFormatVectorOfFloat32) ||
1412 (custom_format == eFormatVectorOfFloat64) ||
1413 (custom_format == eFormatVectorOfSInt16) ||
1414 (custom_format == eFormatVectorOfSInt32) ||
1415 (custom_format == eFormatVectorOfSInt64) ||
1416 (custom_format == eFormatVectorOfSInt8) ||
1417 (custom_format == eFormatVectorOfUInt128) ||
1418 (custom_format == eFormatVectorOfUInt16) ||
1419 (custom_format == eFormatVectorOfUInt32) ||
1420 (custom_format == eFormatVectorOfUInt64) ||
1421 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001422 return true;
1423 }
1424 }
1425 return false;
1426}
1427
Enrico Granata9fc19442011-07-06 02:13:41 +00001428bool
1429ValueObject::DumpPrintableRepresentation(Stream& s,
1430 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001431 Format custom_format,
Enrico Granata86cc9822012-03-19 22:58:49 +00001432 PrintableRepresentationSpecialCases special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001433{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001434
1435 clang_type_t elem_or_pointee_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001436 Flags flags(GetTypeInfo(&elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001437
Enrico Granata86cc9822012-03-19 22:58:49 +00001438 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1439 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1440
1441 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001442 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001443 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1444 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001445 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001446 // when being asked to get a printable display an array or pointer type directly,
1447 // try to "do the right thing"
1448
1449 if (IsCStringContainer(true) &&
1450 (custom_format == eFormatCString ||
1451 custom_format == eFormatCharArray ||
1452 custom_format == eFormatChar ||
1453 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001454 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001455 Error error;
1456 ReadPointedString(s,
1457 error,
1458 0,
1459 (custom_format == eFormatVectorOfChar) ||
1460 (custom_format == eFormatCharArray));
1461 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001462 }
1463
Enrico Granata86cc9822012-03-19 22:58:49 +00001464 if (custom_format == eFormatEnum)
1465 return false;
1466
1467 // this only works for arrays, because I have no way to know when
1468 // the pointed memory ends, and no special \0 end of data marker
1469 if (flags.Test(ClangASTContext::eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001470 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001471 if ((custom_format == eFormatBytes) ||
1472 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001473 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001474 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001475
1476 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001477 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001478 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001479
1480 if (low)
1481 s << ',';
1482
1483 ValueObjectSP child = GetChildAtIndex(low,true);
1484 if (!child.get())
1485 {
1486 s << "<invalid child>";
1487 continue;
1488 }
1489 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1490 }
1491
1492 s << ']';
1493
1494 return true;
1495 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001496
Enrico Granata86cc9822012-03-19 22:58:49 +00001497 if ((custom_format == eFormatVectorOfChar) ||
1498 (custom_format == eFormatVectorOfFloat32) ||
1499 (custom_format == eFormatVectorOfFloat64) ||
1500 (custom_format == eFormatVectorOfSInt16) ||
1501 (custom_format == eFormatVectorOfSInt32) ||
1502 (custom_format == eFormatVectorOfSInt64) ||
1503 (custom_format == eFormatVectorOfSInt8) ||
1504 (custom_format == eFormatVectorOfUInt128) ||
1505 (custom_format == eFormatVectorOfUInt16) ||
1506 (custom_format == eFormatVectorOfUInt32) ||
1507 (custom_format == eFormatVectorOfUInt64) ||
1508 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1509 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001510 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001511
1512 Format format = FormatManager::GetSingleItemFormat(custom_format);
1513
1514 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001515 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001516 {
1517
1518 if (low)
1519 s << ',';
1520
1521 ValueObjectSP child = GetChildAtIndex(low,true);
1522 if (!child.get())
1523 {
1524 s << "<invalid child>";
1525 continue;
1526 }
1527 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1528 }
1529
1530 s << ']';
1531
1532 return true;
1533 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001534 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001535
1536 if ((custom_format == eFormatBoolean) ||
1537 (custom_format == eFormatBinary) ||
1538 (custom_format == eFormatChar) ||
1539 (custom_format == eFormatCharPrintable) ||
1540 (custom_format == eFormatComplexFloat) ||
1541 (custom_format == eFormatDecimal) ||
1542 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001543 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001544 (custom_format == eFormatFloat) ||
1545 (custom_format == eFormatOctal) ||
1546 (custom_format == eFormatOSType) ||
1547 (custom_format == eFormatUnicode16) ||
1548 (custom_format == eFormatUnicode32) ||
1549 (custom_format == eFormatUnsigned) ||
1550 (custom_format == eFormatPointer) ||
1551 (custom_format == eFormatComplexInteger) ||
1552 (custom_format == eFormatComplex) ||
1553 (custom_format == eFormatDefault)) // use the [] operator
1554 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001555 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001556 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001557
1558 if (only_special)
1559 return false;
1560
Enrico Granata86cc9822012-03-19 22:58:49 +00001561 bool var_success = false;
1562
1563 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001564 const char *cstr = NULL;
1565 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001566
1567 if (custom_format != eFormatInvalid)
1568 SetFormat(custom_format);
1569
1570 switch(val_obj_display)
1571 {
1572 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001573 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001574 break;
1575
1576 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001577 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001578 break;
1579
1580 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001581 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001582 break;
1583
1584 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001585 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001586 break;
1587
1588 case eValueObjectRepresentationStyleChildrenCount:
Greg Claytonc7bece562013-01-25 18:06:21 +00001589 strm.Printf("%zu", GetNumChildren());
1590 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001591 break;
1592
1593 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001594 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001595 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001596 }
1597
Greg Claytonc7bece562013-01-25 18:06:21 +00001598 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001599 {
1600 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001601 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001602 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1603 {
1604 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1605 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001606 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1607 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001608 }
1609 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001610 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001611 }
1612 }
1613
Greg Claytonc7bece562013-01-25 18:06:21 +00001614 if (cstr)
1615 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001616 else
1617 {
1618 if (m_error.Fail())
1619 s.Printf("<%s>", m_error.AsCString());
1620 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1621 s.PutCString("<no summary available>");
1622 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1623 s.PutCString("<no value available>");
1624 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1625 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1626 else
1627 s.PutCString("<no printable representation>");
1628 }
1629
1630 // we should only return false here if we could not do *anything*
1631 // even if we have an error message as output, that's a success
1632 // from our callers' perspective, so return true
1633 var_success = true;
1634
1635 if (custom_format != eFormatInvalid)
1636 SetFormat(eFormatDefault);
1637 }
1638
Enrico Granataf4efecd2011-07-12 22:56:10 +00001639 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001640}
1641
Greg Clayton737b9322010-09-13 03:32:57 +00001642addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001643ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001644{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001645 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001646 return LLDB_INVALID_ADDRESS;
1647
Greg Clayton73b472d2010-10-27 03:32:59 +00001648 switch (m_value.GetValueType())
1649 {
1650 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001651 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001652 if (scalar_is_load_address)
1653 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001654 if(address_type)
1655 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001656 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1657 }
1658 break;
1659
1660 case Value::eValueTypeLoadAddress:
1661 case Value::eValueTypeFileAddress:
1662 case Value::eValueTypeHostAddress:
1663 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001664 if(address_type)
1665 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001666 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1667 }
1668 break;
1669 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001670 if (address_type)
1671 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001672 return LLDB_INVALID_ADDRESS;
1673}
1674
1675addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001676ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001677{
Greg Claytonafacd142011-09-02 01:15:17 +00001678 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001679 if(address_type)
1680 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001681
Enrico Granatac3e320a2011-08-02 17:27:39 +00001682 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001683 return address;
1684
Greg Clayton73b472d2010-10-27 03:32:59 +00001685 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001686 {
1687 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001688 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001689 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001690 break;
1691
Enrico Granata9128ee22011-09-06 19:20:51 +00001692 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001693 case Value::eValueTypeLoadAddress:
1694 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001695 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001696 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001697 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001698 }
1699 break;
1700 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001701
Enrico Granata9128ee22011-09-06 19:20:51 +00001702 if (address_type)
1703 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001704
Greg Clayton737b9322010-09-13 03:32:57 +00001705 return address;
1706}
1707
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001708bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001709ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001710{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001711 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001712 // Make sure our value is up to date first so that our location and location
1713 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001714 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001715 {
1716 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001717 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001718 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001719
Greg Claytonfaac1112013-03-14 18:31:44 +00001720 uint64_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001721 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001722
Greg Claytonb1320972010-07-14 00:18:15 +00001723 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001724
Jim Ingham16e0c682011-08-12 23:34:31 +00001725 Value::ValueType value_type = m_value.GetValueType();
1726
1727 if (value_type == Value::eValueTypeScalar)
1728 {
1729 // If the value is already a scalar, then let the scalar change itself:
1730 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1731 }
1732 else if (byte_size <= Scalar::GetMaxByteSize())
1733 {
1734 // If the value fits in a scalar, then make a new scalar and again let the
1735 // scalar code do the conversion, then figure out where to put the new value.
1736 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001737 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1738 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001739 {
Jim Ingham4b536182011-08-09 02:12:22 +00001740 switch (value_type)
1741 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001742 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001743 {
1744 // If it is a load address, then the scalar value is the storage location
1745 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001746 ExecutionContext exe_ctx (GetExecutionContextRef());
1747 Process *process = exe_ctx.GetProcessPtr();
1748 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001749 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001750 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001751 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1752 new_scalar,
1753 byte_size,
1754 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001755 if (!error.Success())
1756 return false;
1757 if (bytes_written != byte_size)
1758 {
1759 error.SetErrorString("unable to write value to memory");
1760 return false;
1761 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001762 }
1763 }
Jim Ingham4b536182011-08-09 02:12:22 +00001764 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001765 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001766 {
1767 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1768 DataExtractor new_data;
1769 new_data.SetByteOrder (m_data.GetByteOrder());
1770
1771 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1772 m_data.SetData(buffer_sp, 0);
1773 bool success = new_scalar.GetData(new_data);
1774 if (success)
1775 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001776 new_data.CopyByteOrderedData (0,
1777 byte_size,
1778 const_cast<uint8_t *>(m_data.GetDataStart()),
1779 byte_size,
1780 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001781 }
1782 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1783
1784 }
Jim Ingham4b536182011-08-09 02:12:22 +00001785 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001786 case Value::eValueTypeFileAddress:
1787 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001788 case Value::eValueTypeVector:
1789 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001790 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001791 }
1792 else
1793 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001794 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001795 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001796 }
1797 else
1798 {
1799 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001800 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001801 return false;
1802 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001803
1804 // If we have reached this point, then we have successfully changed the value.
1805 SetNeedsUpdate();
1806 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001807}
1808
Greg Clayton81e871e2012-02-04 02:27:34 +00001809bool
1810ValueObject::GetDeclaration (Declaration &decl)
1811{
1812 decl.Clear();
1813 return false;
1814}
1815
Greg Clayton84db9102012-03-26 23:03:23 +00001816ConstString
1817ValueObject::GetTypeName()
1818{
1819 return ClangASTType::GetConstTypeName (GetClangAST(), GetClangType());
1820}
1821
1822ConstString
1823ValueObject::GetQualifiedTypeName()
1824{
1825 return ClangASTType::GetConstQualifiedTypeName (GetClangAST(), GetClangType());
1826}
1827
1828
Greg Claytonafacd142011-09-02 01:15:17 +00001829LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001830ValueObject::GetObjectRuntimeLanguage ()
1831{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001832 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1833 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001834}
1835
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001836void
Jim Ingham58b59f92011-04-22 23:53:53 +00001837ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001838{
Jim Ingham58b59f92011-04-22 23:53:53 +00001839 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001840}
1841
1842ValueObjectSP
1843ValueObject::GetSyntheticChild (const ConstString &key) const
1844{
1845 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001846 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001847 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001848 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001849 return synthetic_child_sp;
1850}
1851
Greg Clayton2452ab72013-02-08 22:02:02 +00001852uint32_t
1853ValueObject::GetTypeInfo (clang_type_t *pointee_or_element_clang_type)
1854{
1855 return ClangASTContext::GetTypeInfo (GetClangType(), GetClangAST(), pointee_or_element_clang_type);
1856}
1857
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001858bool
1859ValueObject::IsPointerType ()
1860{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001861 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001862}
1863
Jim Inghamb7603bb2011-03-18 00:05:18 +00001864bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001865ValueObject::IsArrayType ()
1866{
Greg Clayton4ef877f2012-12-06 02:33:54 +00001867 return ClangASTContext::IsArrayType (GetClangType(), NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00001868}
1869
1870bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001871ValueObject::IsScalarType ()
1872{
1873 return ClangASTContext::IsScalarType (GetClangType());
1874}
1875
1876bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001877ValueObject::IsIntegerType (bool &is_signed)
1878{
1879 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1880}
Greg Clayton73b472d2010-10-27 03:32:59 +00001881
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001882bool
1883ValueObject::IsPointerOrReferenceType ()
1884{
Greg Clayton007d5be2011-05-30 00:49:24 +00001885 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1886}
1887
1888bool
Greg Claytondea8cb42011-06-29 22:09:02 +00001889ValueObject::IsPossibleDynamicType ()
1890{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00001891 ExecutionContext exe_ctx (GetExecutionContextRef());
1892 Process *process = exe_ctx.GetProcessPtr();
1893 if (process)
1894 return process->IsPossibleDynamicValue(*this);
1895 else
Greg Clayton70364252012-08-31 18:56:24 +00001896 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType(), NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00001897}
1898
Enrico Granata9e7b3882012-12-13 23:50:33 +00001899bool
1900ValueObject::IsObjCNil ()
1901{
1902 bool isObjCpointer = ClangASTContext::IsObjCObjectPointerType(GetClangType(), NULL);
1903 bool canReadValue = true;
1904 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
1905 return canReadValue && isZero && isObjCpointer;
1906}
1907
Greg Claytonafacd142011-09-02 01:15:17 +00001908ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00001909ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001910{
Greg Clayton2452ab72013-02-08 22:02:02 +00001911 const uint32_t type_info = GetTypeInfo ();
1912 if (type_info & ClangASTContext::eTypeIsArray)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001913 return GetSyntheticArrayMemberFromArray(index, can_create);
1914
Greg Clayton2452ab72013-02-08 22:02:02 +00001915 if (type_info & ClangASTContext::eTypeIsPointer)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001916 return GetSyntheticArrayMemberFromPointer(index, can_create);
1917
1918 return ValueObjectSP();
1919
1920}
1921
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001922ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00001923ValueObject::GetSyntheticArrayMemberFromPointer (size_t index, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001924{
1925 ValueObjectSP synthetic_child_sp;
1926 if (IsPointerType ())
1927 {
1928 char index_str[64];
Greg Claytonc7bece562013-01-25 18:06:21 +00001929 snprintf(index_str, sizeof(index_str), "[%zu]", index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001930 ConstString index_const_str(index_str);
1931 // Check if we have already created a synthetic array member in this
1932 // valid object. If we have we will re-use it.
1933 synthetic_child_sp = GetSyntheticChild (index_const_str);
1934 if (!synthetic_child_sp)
1935 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001936 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001937 // We haven't made a synthetic array member for INDEX yet, so
1938 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001939 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001940
1941 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001942 if (synthetic_child)
1943 {
1944 AddSyntheticChild(index_const_str, synthetic_child);
1945 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001946 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001947 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001948 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001949 }
1950 }
1951 return synthetic_child_sp;
1952}
Jim Ingham22777012010-09-23 02:01:19 +00001953
Greg Claytondaf515f2011-07-09 20:12:33 +00001954// This allows you to create an array member using and index
1955// that doesn't not fall in the normal bounds of the array.
1956// Many times structure can be defined as:
1957// struct Collection
1958// {
1959// uint32_t item_count;
1960// Item item_array[0];
1961// };
1962// The size of the "item_array" is 1, but many times in practice
1963// there are more items in "item_array".
1964
1965ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00001966ValueObject::GetSyntheticArrayMemberFromArray (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00001967{
1968 ValueObjectSP synthetic_child_sp;
1969 if (IsArrayType ())
1970 {
1971 char index_str[64];
Greg Claytonc7bece562013-01-25 18:06:21 +00001972 snprintf(index_str, sizeof(index_str), "[%zu]", index);
Greg Claytondaf515f2011-07-09 20:12:33 +00001973 ConstString index_const_str(index_str);
1974 // Check if we have already created a synthetic array member in this
1975 // valid object. If we have we will re-use it.
1976 synthetic_child_sp = GetSyntheticChild (index_const_str);
1977 if (!synthetic_child_sp)
1978 {
1979 ValueObject *synthetic_child;
1980 // We haven't made a synthetic array member for INDEX yet, so
1981 // lets make one and cache it for any future reference.
1982 synthetic_child = CreateChildAtIndex(0, true, index);
1983
1984 // Cache the value if we got one back...
1985 if (synthetic_child)
1986 {
1987 AddSyntheticChild(index_const_str, synthetic_child);
1988 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001989 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001990 synthetic_child_sp->m_is_array_item_for_pointer = true;
1991 }
1992 }
1993 }
1994 return synthetic_child_sp;
1995}
1996
Enrico Granata9fc19442011-07-06 02:13:41 +00001997ValueObjectSP
1998ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1999{
2000 ValueObjectSP synthetic_child_sp;
2001 if (IsScalarType ())
2002 {
2003 char index_str[64];
2004 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2005 ConstString index_const_str(index_str);
2006 // Check if we have already created a synthetic array member in this
2007 // valid object. If we have we will re-use it.
2008 synthetic_child_sp = GetSyntheticChild (index_const_str);
2009 if (!synthetic_child_sp)
2010 {
2011 ValueObjectChild *synthetic_child;
2012 // We haven't made a synthetic array member for INDEX yet, so
2013 // lets make one and cache it for any future reference.
2014 synthetic_child = new ValueObjectChild(*this,
2015 GetClangAST(),
2016 GetClangType(),
2017 index_const_str,
2018 GetByteSize(),
2019 0,
2020 to-from+1,
2021 from,
2022 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002023 false,
2024 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002025
2026 // Cache the value if we got one back...
2027 if (synthetic_child)
2028 {
2029 AddSyntheticChild(index_const_str, synthetic_child);
2030 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002031 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002032 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2033 }
2034 }
2035 }
2036 return synthetic_child_sp;
2037}
2038
Greg Claytonafacd142011-09-02 01:15:17 +00002039ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00002040ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
2041{
2042
2043 ValueObjectSP synthetic_child_sp;
2044
2045 char name_str[64];
2046 snprintf(name_str, sizeof(name_str), "@%i", offset);
2047 ConstString name_const_str(name_str);
2048
2049 // Check if we have already created a synthetic array member in this
2050 // valid object. If we have we will re-use it.
2051 synthetic_child_sp = GetSyntheticChild (name_const_str);
2052
2053 if (synthetic_child_sp.get())
2054 return synthetic_child_sp;
2055
2056 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002057 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002058
2059 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2060 type.GetASTContext(),
2061 type.GetOpaqueQualType(),
2062 name_const_str,
2063 type.GetTypeByteSize(),
2064 offset,
2065 0,
2066 0,
2067 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002068 false,
2069 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002070 if (synthetic_child)
2071 {
2072 AddSyntheticChild(name_const_str, synthetic_child);
2073 synthetic_child_sp = synthetic_child->GetSP();
2074 synthetic_child_sp->SetName(name_const_str);
2075 synthetic_child_sp->m_is_child_at_offset = true;
2076 }
2077 return synthetic_child_sp;
2078}
2079
Enrico Granatad55546b2011-07-22 00:16:08 +00002080// your expression path needs to have a leading . or ->
2081// (unless it somehow "looks like" an array, in which case it has
2082// a leading [ symbol). while the [ is meaningful and should be shown
2083// to the user, . and -> are just parser design, but by no means
2084// added information for the user.. strip them off
2085static const char*
2086SkipLeadingExpressionPathSeparators(const char* expression)
2087{
2088 if (!expression || !expression[0])
2089 return expression;
2090 if (expression[0] == '.')
2091 return expression+1;
2092 if (expression[0] == '-' && expression[1] == '>')
2093 return expression+2;
2094 return expression;
2095}
2096
Greg Claytonafacd142011-09-02 01:15:17 +00002097ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002098ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2099{
2100 ValueObjectSP synthetic_child_sp;
2101 ConstString name_const_string(expression);
2102 // Check if we have already created a synthetic array member in this
2103 // valid object. If we have we will re-use it.
2104 synthetic_child_sp = GetSyntheticChild (name_const_string);
2105 if (!synthetic_child_sp)
2106 {
2107 // We haven't made a synthetic array member for expression yet, so
2108 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002109 synthetic_child_sp = GetValueForExpressionPath(expression,
2110 NULL, NULL, NULL,
2111 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
Enrico Granatad55546b2011-07-22 00:16:08 +00002112
2113 // Cache the value if we got one back...
2114 if (synthetic_child_sp.get())
2115 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002116 // 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 +00002117 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002118 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002119 }
2120 }
2121 return synthetic_child_sp;
2122}
2123
2124void
Enrico Granata86cc9822012-03-19 22:58:49 +00002125ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002126{
Enrico Granata86cc9822012-03-19 22:58:49 +00002127 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002128 return;
2129
Enrico Granatac5bc4122012-03-27 02:35:13 +00002130 TargetSP target_sp(GetTargetSP());
2131 if (target_sp && (target_sp->GetEnableSyntheticValue() == false || target_sp->GetSuppressSyntheticValue() == true))
2132 {
2133 m_synthetic_value = NULL;
2134 return;
2135 }
2136
Enrico Granatae3e91512012-10-22 18:18:36 +00002137 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2138
Enrico Granata5548cb52013-01-28 23:47:25 +00002139 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002140 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002141
Enrico Granata0c489f52012-03-01 04:24:26 +00002142 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002143 return;
2144
Enrico Granatae3e91512012-10-22 18:18:36 +00002145 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2146 return;
2147
Enrico Granata86cc9822012-03-19 22:58:49 +00002148 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002149}
2150
Jim Ingham78a685a2011-04-16 00:01:13 +00002151void
Greg Claytonafacd142011-09-02 01:15:17 +00002152ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002153{
Greg Claytonafacd142011-09-02 01:15:17 +00002154 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002155 return;
2156
Jim Ingham58b59f92011-04-22 23:53:53 +00002157 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002158 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002159 ExecutionContext exe_ctx (GetExecutionContextRef());
2160 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002161 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002162 {
2163 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002164 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002165 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002166 }
2167}
2168
Jim Ingham58b59f92011-04-22 23:53:53 +00002169ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002170ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002171{
Greg Claytonafacd142011-09-02 01:15:17 +00002172 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002173 return ValueObjectSP();
2174
2175 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002176 {
Jim Ingham2837b762011-05-04 03:43:18 +00002177 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002178 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002179 if (m_dynamic_value)
2180 return m_dynamic_value->GetSP();
2181 else
2182 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002183}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002184
Jim Ingham60dbabb2011-12-08 19:44:08 +00002185ValueObjectSP
2186ValueObject::GetStaticValue()
2187{
2188 return GetSP();
2189}
2190
Enrico Granata886147f2012-05-08 18:47:08 +00002191lldb::ValueObjectSP
2192ValueObject::GetNonSyntheticValue ()
2193{
2194 return GetSP();
2195}
2196
Enrico Granatad55546b2011-07-22 00:16:08 +00002197ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002198ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002199{
Enrico Granata86cc9822012-03-19 22:58:49 +00002200 if (use_synthetic == false)
2201 return ValueObjectSP();
2202
Enrico Granatad55546b2011-07-22 00:16:08 +00002203 CalculateSyntheticValue(use_synthetic);
2204
2205 if (m_synthetic_value)
2206 return m_synthetic_value->GetSP();
2207 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002208 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002209}
2210
Greg Claytone221f822011-01-21 01:59:00 +00002211bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002212ValueObject::HasSyntheticValue()
2213{
Enrico Granata5548cb52013-01-28 23:47:25 +00002214 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002215
Enrico Granata0c489f52012-03-01 04:24:26 +00002216 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002217 return false;
2218
Enrico Granata86cc9822012-03-19 22:58:49 +00002219 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002220
2221 if (m_synthetic_value)
2222 return true;
2223 else
2224 return false;
2225}
2226
2227bool
Greg Claytone221f822011-01-21 01:59:00 +00002228ValueObject::GetBaseClassPath (Stream &s)
2229{
2230 if (IsBaseClass())
2231 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002232 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00002233 clang_type_t clang_type = GetClangType();
2234 std::string cxx_class_name;
2235 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
2236 if (this_had_base_class)
2237 {
2238 if (parent_had_base_class)
2239 s.PutCString("::");
2240 s.PutCString(cxx_class_name.c_str());
2241 }
2242 return parent_had_base_class || this_had_base_class;
2243 }
2244 return false;
2245}
2246
2247
2248ValueObject *
2249ValueObject::GetNonBaseClassParent()
2250{
Jim Ingham78a685a2011-04-16 00:01:13 +00002251 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002252 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002253 if (GetParent()->IsBaseClass())
2254 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002255 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002256 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002257 }
2258 return NULL;
2259}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002260
2261void
Enrico Granata4becb372011-06-29 22:27:15 +00002262ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002263{
Greg Claytone221f822011-01-21 01:59:00 +00002264 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002265
Enrico Granata86cc9822012-03-19 22:58:49 +00002266 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002267 {
Enrico Granata4becb372011-06-29 22:27:15 +00002268 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2269 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2270 // the eHonorPointers mode is meant to produce strings in this latter format
2271 s.PutCString("*(");
2272 }
Greg Claytone221f822011-01-21 01:59:00 +00002273
Enrico Granata4becb372011-06-29 22:27:15 +00002274 ValueObject* parent = GetParent();
2275
2276 if (parent)
2277 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002278
2279 // if we are a deref_of_parent just because we are synthetic array
2280 // members made up to allow ptr[%d] syntax to work in variable
2281 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002282 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002283 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002284
Greg Claytone221f822011-01-21 01:59:00 +00002285 if (!IsBaseClass())
2286 {
2287 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002288 {
Greg Claytone221f822011-01-21 01:59:00 +00002289 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2290 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002291 {
Greg Claytone221f822011-01-21 01:59:00 +00002292 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2293 if (non_base_class_parent_clang_type)
2294 {
2295 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2296
Enrico Granata86cc9822012-03-19 22:58:49 +00002297 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002298 {
2299 s.PutCString("->");
2300 }
Enrico Granata4becb372011-06-29 22:27:15 +00002301 else
2302 {
2303 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2304 {
2305 s.PutCString("->");
2306 }
2307 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2308 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2309 {
2310 s.PutChar('.');
2311 }
Greg Claytone221f822011-01-21 01:59:00 +00002312 }
2313 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002314 }
Greg Claytone221f822011-01-21 01:59:00 +00002315
2316 const char *name = GetName().GetCString();
2317 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002318 {
Greg Claytone221f822011-01-21 01:59:00 +00002319 if (qualify_cxx_base_classes)
2320 {
2321 if (GetBaseClassPath (s))
2322 s.PutCString("::");
2323 }
2324 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002325 }
2326 }
2327 }
2328
Enrico Granata86cc9822012-03-19 22:58:49 +00002329 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002330 {
Greg Claytone221f822011-01-21 01:59:00 +00002331 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002332 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002333}
2334
Greg Claytonafacd142011-09-02 01:15:17 +00002335ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002336ValueObject::GetValueForExpressionPath(const char* expression,
2337 const char** first_unparsed,
2338 ExpressionPathScanEndReason* reason_to_stop,
2339 ExpressionPathEndResultType* final_value_type,
2340 const GetValueForExpressionPathOptions& options,
2341 ExpressionPathAftermath* final_task_on_target)
2342{
2343
2344 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002345 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2346 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002347 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002348
2349 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2350 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2351 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2352 final_value_type ? final_value_type : &dummy_final_value_type,
2353 options,
2354 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2355
Enrico Granata86cc9822012-03-19 22:58:49 +00002356 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002357 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002358
Enrico Granata86cc9822012-03-19 22:58:49 +00002359 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 +00002360 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002361 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002362 {
2363 Error error;
2364 ValueObjectSP final_value = ret_val->Dereference(error);
2365 if (error.Fail() || !final_value.get())
2366 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002367 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002368 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002369 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002370 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002371 return ValueObjectSP();
2372 }
2373 else
2374 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002375 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002376 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002377 return final_value;
2378 }
2379 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002380 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002381 {
2382 Error error;
2383 ValueObjectSP final_value = ret_val->AddressOf(error);
2384 if (error.Fail() || !final_value.get())
2385 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002386 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002387 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002388 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002389 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002390 return ValueObjectSP();
2391 }
2392 else
2393 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002394 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002395 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002396 return final_value;
2397 }
2398 }
2399 }
2400 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2401}
2402
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002403int
2404ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002405 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002406 const char** first_unparsed,
2407 ExpressionPathScanEndReason* reason_to_stop,
2408 ExpressionPathEndResultType* final_value_type,
2409 const GetValueForExpressionPathOptions& options,
2410 ExpressionPathAftermath* final_task_on_target)
2411{
2412 const char* dummy_first_unparsed;
2413 ExpressionPathScanEndReason dummy_reason_to_stop;
2414 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002415 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002416
2417 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2418 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2419 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2420 final_value_type ? final_value_type : &dummy_final_value_type,
2421 options,
2422 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2423
2424 if (!ret_val.get()) // if there are errors, I add nothing to the list
2425 return 0;
2426
Enrico Granata86ea8d82012-03-29 01:34:34 +00002427 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002428 {
2429 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002430 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002431 {
2432 list->Append(ret_val);
2433 return 1;
2434 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002435 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 +00002436 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002437 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002438 {
2439 Error error;
2440 ValueObjectSP final_value = ret_val->Dereference(error);
2441 if (error.Fail() || !final_value.get())
2442 {
Greg Clayton23f59502012-07-17 03:23:13 +00002443 if (reason_to_stop)
2444 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2445 if (final_value_type)
2446 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002447 return 0;
2448 }
2449 else
2450 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002451 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002452 list->Append(final_value);
2453 return 1;
2454 }
2455 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002456 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002457 {
2458 Error error;
2459 ValueObjectSP final_value = ret_val->AddressOf(error);
2460 if (error.Fail() || !final_value.get())
2461 {
Greg Clayton23f59502012-07-17 03:23:13 +00002462 if (reason_to_stop)
2463 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2464 if (final_value_type)
2465 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002466 return 0;
2467 }
2468 else
2469 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002470 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002471 list->Append(final_value);
2472 return 1;
2473 }
2474 }
2475 }
2476 }
2477 else
2478 {
2479 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2480 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2481 ret_val,
2482 list,
2483 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2484 final_value_type ? final_value_type : &dummy_final_value_type,
2485 options,
2486 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2487 }
2488 // in any non-covered case, just do the obviously right thing
2489 list->Append(ret_val);
2490 return 1;
2491}
2492
Greg Claytonafacd142011-09-02 01:15:17 +00002493ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002494ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2495 const char** first_unparsed,
2496 ExpressionPathScanEndReason* reason_to_stop,
2497 ExpressionPathEndResultType* final_result,
2498 const GetValueForExpressionPathOptions& options,
2499 ExpressionPathAftermath* what_next)
2500{
2501 ValueObjectSP root = GetSP();
2502
2503 if (!root.get())
2504 return ValueObjectSP();
2505
2506 *first_unparsed = expression_cstr;
2507
2508 while (true)
2509 {
2510
2511 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2512
Greg Claytonafacd142011-09-02 01:15:17 +00002513 clang_type_t root_clang_type = root->GetClangType();
2514 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002515 Flags root_clang_type_info,pointee_clang_type_info;
2516
2517 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2518 if (pointee_clang_type)
2519 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002520
2521 if (!expression_cstr || *expression_cstr == '\0')
2522 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002523 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002524 return root;
2525 }
2526
2527 switch (*expression_cstr)
2528 {
2529 case '-':
2530 {
2531 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002532 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) ) // if you are trying to use -> on a non-pointer and I must catch the error
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002533 {
2534 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002535 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2536 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002537 return ValueObjectSP();
2538 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002539 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2540 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002541 options.m_no_fragile_ivar)
2542 {
2543 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002544 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2545 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002546 return ValueObjectSP();
2547 }
2548 if (expression_cstr[1] != '>')
2549 {
2550 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002551 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2552 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002553 return ValueObjectSP();
2554 }
2555 expression_cstr++; // skip the -
2556 }
2557 case '.': // or fallthrough from ->
2558 {
2559 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002560 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if you are trying to use . on a pointer and I must catch the error
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002561 {
2562 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002563 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2564 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002565 return ValueObjectSP();
2566 }
2567 expression_cstr++; // skip .
2568 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2569 ConstString child_name;
2570 if (!next_separator) // if no other separator just expand this last layer
2571 {
2572 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002573 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2574
2575 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002576 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002577 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002578 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2579 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002580 return child_valobj_sp;
2581 }
2582 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2583 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002584 if (root->IsSynthetic())
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002585 {
2586 *first_unparsed = expression_cstr;
2587 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2588 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2589 return ValueObjectSP();
2590 }
2591
2592 child_valobj_sp = root->GetSyntheticValue();
Enrico Granata86cc9822012-03-19 22:58:49 +00002593 if (child_valobj_sp.get())
2594 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002595 }
2596
2597 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2598 // so we hit the "else" branch, and return an error
2599 if(child_valobj_sp.get()) // if it worked, just return
2600 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002601 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002602 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2603 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002604 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002605 }
2606 else
2607 {
2608 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002609 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2610 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002611 return ValueObjectSP();
2612 }
2613 }
2614 else // other layers do expand
2615 {
2616 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002617 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2618 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002619 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002620 root = child_valobj_sp;
2621 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002622 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002623 continue;
2624 }
2625 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2626 {
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002627 if (root->IsSynthetic())
2628 {
2629 *first_unparsed = expression_cstr;
2630 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2631 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2632 return ValueObjectSP();
2633 }
2634
Enrico Granata86cc9822012-03-19 22:58:49 +00002635 child_valobj_sp = root->GetSyntheticValue(true);
2636 if (child_valobj_sp)
2637 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002638 }
2639
2640 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2641 // so we hit the "else" branch, and return an error
2642 if(child_valobj_sp.get()) // if it worked, move on
2643 {
2644 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002645 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002646 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002647 continue;
2648 }
2649 else
2650 {
2651 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002652 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2653 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002654 return ValueObjectSP();
2655 }
2656 }
2657 break;
2658 }
2659 case '[':
2660 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002661 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002662 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002663 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002664 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002665 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2666 {
2667 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002668 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2669 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002670 return ValueObjectSP();
2671 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002672 }
2673 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2674 {
2675 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002676 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2677 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002678 return ValueObjectSP();
2679 }
2680 }
2681 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2682 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002683 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002684 {
2685 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002686 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2687 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002688 return ValueObjectSP();
2689 }
2690 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2691 {
2692 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002693 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2694 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002695 return root;
2696 }
2697 }
2698 const char *separator_position = ::strchr(expression_cstr+1,'-');
2699 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2700 if (!close_bracket_position) // if there is no ], this is a syntax error
2701 {
2702 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002703 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2704 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002705 return ValueObjectSP();
2706 }
2707 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2708 {
2709 char *end = NULL;
2710 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2711 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2712 {
2713 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002714 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2715 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002716 return ValueObjectSP();
2717 }
2718 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2719 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002720 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002721 {
2722 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002723 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2724 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002725 return root;
2726 }
2727 else
2728 {
2729 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002730 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2731 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002732 return ValueObjectSP();
2733 }
2734 }
2735 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002736 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002737 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002738 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2739 if (!child_valobj_sp)
2740 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002741 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002742 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2743 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002744 if (child_valobj_sp)
2745 {
2746 root = child_valobj_sp;
2747 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002748 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002749 continue;
2750 }
2751 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002752 {
2753 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002754 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2755 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002756 return ValueObjectSP();
2757 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002758 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002759 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002760 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002761 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 Granataf9fa6ee2011-07-12 00:18:11 +00002762 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002763 {
2764 Error error;
2765 root = root->Dereference(error);
2766 if (error.Fail() || !root.get())
2767 {
2768 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002769 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2770 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002771 return ValueObjectSP();
2772 }
2773 else
2774 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002775 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002776 continue;
2777 }
2778 }
2779 else
2780 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002781 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Clayton84db9102012-03-26 23:03:23 +00002782 root->GetClangType()) == eLanguageTypeObjC
2783 && ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2784 && root->HasSyntheticValue()
2785 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002786 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002787 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002788 }
2789 else
2790 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002791 if (!root.get())
2792 {
2793 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002794 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2795 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002796 return ValueObjectSP();
2797 }
2798 else
2799 {
2800 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002801 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002802 continue;
2803 }
2804 }
2805 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002806 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002807 {
2808 root = root->GetSyntheticBitFieldChild(index, index, true);
2809 if (!root.get())
2810 {
2811 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002812 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2813 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002814 return ValueObjectSP();
2815 }
2816 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2817 {
2818 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002819 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2820 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002821 return root;
2822 }
2823 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002824 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002825 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002826 if (root->HasSyntheticValue())
2827 root = root->GetSyntheticValue();
2828 else if (!root->IsSynthetic())
2829 {
2830 *first_unparsed = expression_cstr;
2831 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2832 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2833 return ValueObjectSP();
2834 }
2835 // if we are here, then root itself is a synthetic VO.. should be good to go
2836
Enrico Granata27b625e2011-08-09 01:04:56 +00002837 if (!root.get())
2838 {
2839 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002840 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2841 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2842 return ValueObjectSP();
2843 }
2844 root = root->GetChildAtIndex(index, true);
2845 if (!root.get())
2846 {
2847 *first_unparsed = expression_cstr;
2848 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2849 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002850 return ValueObjectSP();
2851 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002852 else
2853 {
2854 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002855 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002856 continue;
2857 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002858 }
2859 else
2860 {
2861 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002862 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2863 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002864 return ValueObjectSP();
2865 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002866 }
2867 else // we have a low and a high index
2868 {
2869 char *end = NULL;
2870 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2871 if (!end || end != separator_position) // if something weird is in our way return an error
2872 {
2873 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002874 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2875 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002876 return ValueObjectSP();
2877 }
2878 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2879 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2880 {
2881 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002882 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2883 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002884 return ValueObjectSP();
2885 }
2886 if (index_lower > index_higher) // swap indices if required
2887 {
2888 unsigned long temp = index_lower;
2889 index_lower = index_higher;
2890 index_higher = temp;
2891 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002892 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002893 {
2894 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2895 if (!root.get())
2896 {
2897 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002898 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2899 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002900 return ValueObjectSP();
2901 }
2902 else
2903 {
2904 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002905 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2906 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002907 return root;
2908 }
2909 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002910 else if (root_clang_type_info.Test(ClangASTContext::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 +00002911 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002912 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002913 {
2914 Error error;
2915 root = root->Dereference(error);
2916 if (error.Fail() || !root.get())
2917 {
2918 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002919 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2920 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002921 return ValueObjectSP();
2922 }
2923 else
2924 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002925 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002926 continue;
2927 }
2928 }
2929 else
2930 {
2931 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002932 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2933 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002934 return root;
2935 }
2936 }
2937 break;
2938 }
2939 default: // some non-separator is in the way
2940 {
2941 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002942 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2943 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002944 return ValueObjectSP();
2945 break;
2946 }
2947 }
2948 }
2949}
2950
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002951int
2952ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2953 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002954 ValueObjectSP root,
2955 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002956 ExpressionPathScanEndReason* reason_to_stop,
2957 ExpressionPathEndResultType* final_result,
2958 const GetValueForExpressionPathOptions& options,
2959 ExpressionPathAftermath* what_next)
2960{
2961 if (!root.get())
2962 return 0;
2963
2964 *first_unparsed = expression_cstr;
2965
2966 while (true)
2967 {
2968
2969 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2970
Greg Claytonafacd142011-09-02 01:15:17 +00002971 clang_type_t root_clang_type = root->GetClangType();
2972 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002973 Flags root_clang_type_info,pointee_clang_type_info;
2974
2975 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2976 if (pointee_clang_type)
2977 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2978
2979 if (!expression_cstr || *expression_cstr == '\0')
2980 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002981 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002982 list->Append(root);
2983 return 1;
2984 }
2985
2986 switch (*expression_cstr)
2987 {
2988 case '[':
2989 {
2990 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2991 {
2992 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2993 {
2994 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002995 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2996 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002997 return 0;
2998 }
2999 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3000 {
3001 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003002 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3003 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003004 return 0;
3005 }
3006 }
3007 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3008 {
3009 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3010 {
3011 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003012 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3013 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003014 return 0;
3015 }
3016 else // expand this into list
3017 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003018 const size_t max_index = root->GetNumChildren() - 1;
3019 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003020 {
3021 ValueObjectSP child =
3022 root->GetChildAtIndex(index, true);
3023 list->Append(child);
3024 }
3025 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003026 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3027 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003028 return max_index; // tell me number of items I added to the VOList
3029 }
3030 }
3031 const char *separator_position = ::strchr(expression_cstr+1,'-');
3032 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3033 if (!close_bracket_position) // if there is no ], this is a syntax error
3034 {
3035 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003036 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3037 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003038 return 0;
3039 }
3040 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3041 {
3042 char *end = NULL;
3043 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3044 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3045 {
3046 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003047 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3048 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003049 return 0;
3050 }
3051 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3052 {
3053 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3054 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003055 const size_t max_index = root->GetNumChildren() - 1;
3056 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003057 {
3058 ValueObjectSP child =
3059 root->GetChildAtIndex(index, true);
3060 list->Append(child);
3061 }
3062 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003063 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3064 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003065 return max_index; // tell me number of items I added to the VOList
3066 }
3067 else
3068 {
3069 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003070 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3071 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003072 return 0;
3073 }
3074 }
3075 // from here on we do have a valid index
3076 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3077 {
3078 root = root->GetChildAtIndex(index, true);
3079 if (!root.get())
3080 {
3081 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003082 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3083 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003084 return 0;
3085 }
3086 else
3087 {
3088 list->Append(root);
3089 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003090 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3091 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003092 return 1;
3093 }
3094 }
3095 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
3096 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003097 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 Granataf9fa6ee2011-07-12 00:18:11 +00003098 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3099 {
3100 Error error;
3101 root = root->Dereference(error);
3102 if (error.Fail() || !root.get())
3103 {
3104 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003105 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3106 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003107 return 0;
3108 }
3109 else
3110 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003111 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003112 continue;
3113 }
3114 }
3115 else
3116 {
3117 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3118 if (!root.get())
3119 {
3120 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003121 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3122 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003123 return 0;
3124 }
3125 else
3126 {
3127 list->Append(root);
3128 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003129 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3130 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003131 return 1;
3132 }
3133 }
3134 }
3135 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3136 {
3137 root = root->GetSyntheticBitFieldChild(index, index, true);
3138 if (!root.get())
3139 {
3140 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003141 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3142 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003143 return 0;
3144 }
3145 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3146 {
3147 list->Append(root);
3148 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003149 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3150 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003151 return 1;
3152 }
3153 }
3154 }
3155 else // we have a low and a high index
3156 {
3157 char *end = NULL;
3158 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3159 if (!end || end != separator_position) // if something weird is in our way return an error
3160 {
3161 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003162 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3163 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003164 return 0;
3165 }
3166 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3167 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3168 {
3169 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003170 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3171 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003172 return 0;
3173 }
3174 if (index_lower > index_higher) // swap indices if required
3175 {
3176 unsigned long temp = index_lower;
3177 index_lower = index_higher;
3178 index_higher = temp;
3179 }
3180 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
3181 {
3182 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3183 if (!root.get())
3184 {
3185 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003186 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3187 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003188 return 0;
3189 }
3190 else
3191 {
3192 list->Append(root);
3193 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003194 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3195 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003196 return 1;
3197 }
3198 }
3199 else if (root_clang_type_info.Test(ClangASTContext::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 +00003200 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003201 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3202 {
3203 Error error;
3204 root = root->Dereference(error);
3205 if (error.Fail() || !root.get())
3206 {
3207 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003208 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3209 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003210 return 0;
3211 }
3212 else
3213 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003214 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003215 continue;
3216 }
3217 }
3218 else
3219 {
Johnny Chen44805302011-07-19 19:48:13 +00003220 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003221 index <= index_higher; index++)
3222 {
3223 ValueObjectSP child =
3224 root->GetChildAtIndex(index, true);
3225 list->Append(child);
3226 }
3227 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003228 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3229 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003230 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3231 }
3232 }
3233 break;
3234 }
3235 default: // some non-[ separator, or something entirely wrong, is in the way
3236 {
3237 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003238 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3239 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003240 return 0;
3241 break;
3242 }
3243 }
3244 }
3245}
3246
Enrico Granata0c489f52012-03-01 04:24:26 +00003247static void
3248DumpValueObject_Impl (Stream &s,
3249 ValueObject *valobj,
3250 const ValueObject::DumpValueObjectOptions& options,
3251 uint32_t ptr_depth,
3252 uint32_t curr_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003253{
Greg Clayton007d5be2011-05-30 00:49:24 +00003254 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003255 {
Enrico Granata5548cb52013-01-28 23:47:25 +00003256 bool update_success = valobj->UpdateValueIfNeeded (true);
Greg Clayton007d5be2011-05-30 00:49:24 +00003257
Enrico Granata0c489f52012-03-01 04:24:26 +00003258 const char *root_valobj_name =
3259 options.m_root_valobj_name.empty() ?
3260 valobj->GetName().AsCString() :
3261 options.m_root_valobj_name.c_str();
3262
3263 if (update_success && options.m_use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00003264 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003265 ValueObject *dynamic_value = valobj->GetDynamicValue(options.m_use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003266 if (dynamic_value)
3267 valobj = dynamic_value;
3268 }
3269
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003270 clang_type_t clang_type = valobj->GetClangType();
3271
Greg Clayton73b472d2010-10-27 03:32:59 +00003272 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003273 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00003274 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
3275 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003276
Enrico Granata0c489f52012-03-01 04:24:26 +00003277 const bool print_valobj = options.m_flat_output == false || has_value;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003278
3279 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003280 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003281 if (options.m_show_location)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003282 {
Jim Ingham6035b672011-03-31 00:19:25 +00003283 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003284 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003285
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003286 s.Indent();
Enrico Granata2b2631c2012-08-09 16:51:25 +00003287
3288 bool show_type = true;
3289 // if we are at the root-level and been asked to hide the root's type, then hide it
3290 if (curr_depth == 0 && options.m_hide_root_type)
3291 show_type = false;
3292 else
3293 // otherwise decide according to the usual rules (asked to show types - always at the root level)
3294 show_type = options.m_show_types || (curr_depth == 0 && !options.m_flat_output);
3295
3296 if (show_type)
Enrico Granataf7b1a342013-01-23 01:17:27 +00003297 s.Printf("(%s) ", valobj->GetQualifiedTypeName().AsCString("<invalid type>"));
Greg Clayton1d3afba2010-10-05 00:00:42 +00003298
Enrico Granata0c489f52012-03-01 04:24:26 +00003299 if (options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003300 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003301 // If we are showing types, also qualify the C++ base classes
Enrico Granata0c489f52012-03-01 04:24:26 +00003302 const bool qualify_cxx_base_classes = options.m_show_types;
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003303 if (!options.m_hide_name)
3304 {
3305 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
3306 s.PutCString(" =");
3307 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003308 }
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003309 else if (!options.m_hide_name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003310 {
3311 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3312 s.Printf ("%s =", name_cstr);
3313 }
3314
Enrico Granata0c489f52012-03-01 04:24:26 +00003315 if (!options.m_scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003316 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003317 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003318 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003319 }
3320
Enrico Granata0c489f52012-03-01 04:24:26 +00003321 std::string summary_str;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003322 std::string value_str;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003323 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003324 const char *sum_cstr = NULL;
Enrico Granata0c489f52012-03-01 04:24:26 +00003325 TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003326
Enrico Granata0c489f52012-03-01 04:24:26 +00003327 if (options.m_omit_summary_depth > 0)
Enrico Granata0c5ef692011-07-16 01:22:04 +00003328 entry = NULL;
3329
Enrico Granata9e7b3882012-12-13 23:50:33 +00003330 bool is_nil = valobj->IsObjCNil();
3331
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003332 if (err_cstr == NULL)
3333 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003334 if (options.m_format != eFormatDefault && options.m_format != valobj->GetFormat())
Greg Clayton6efba4f2012-01-26 21:08:30 +00003335 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003336 valobj->GetValueAsCString(options.m_format,
3337 value_str);
Greg Clayton6efba4f2012-01-26 21:08:30 +00003338 }
Enrico Granata0c489f52012-03-01 04:24:26 +00003339 else
Greg Clayton6efba4f2012-01-26 21:08:30 +00003340 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003341 val_cstr = valobj->GetValueAsCString();
3342 if (val_cstr)
3343 value_str = val_cstr;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003344 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003345 err_cstr = valobj->GetError().AsCString();
3346 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003347
3348 if (err_cstr)
3349 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003350 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003351 }
3352 else
3353 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003354 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003355 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003356 {
Enrico Granata9e7b3882012-12-13 23:50:33 +00003357 if (is_nil)
3358 sum_cstr = "nil";
3359 else if (options.m_omit_summary_depth == 0)
Enrico Granata0c489f52012-03-01 04:24:26 +00003360 {
3361 if (options.m_summary_sp)
3362 {
3363 valobj->GetSummaryAsCString(entry, summary_str);
3364 sum_cstr = summary_str.c_str();
3365 }
3366 else
3367 sum_cstr = valobj->GetSummaryAsCString();
3368 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003369
Greg Clayton6efba4f2012-01-26 21:08:30 +00003370 // Make sure we have a value and make sure the summary didn't
Enrico Granata9e7b3882012-12-13 23:50:33 +00003371 // specify that the value should not be printed - and do not print
3372 // the value if this thing is nil
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003373 if (!is_nil && !value_str.empty() && (entry == NULL || entry->DoesPrintValue() || sum_cstr == NULL) && !options.m_hide_value)
Greg Clayton6efba4f2012-01-26 21:08:30 +00003374 s.Printf(" %s", value_str.c_str());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003375
Enrico Granata9dd75c82011-07-15 23:30:15 +00003376 if (sum_cstr)
Enrico Granata0c489f52012-03-01 04:24:26 +00003377 s.Printf(" %s", sum_cstr);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003378
Enrico Granata9e7b3882012-12-13 23:50:33 +00003379 // let's avoid the overly verbose no description error for a nil thing
3380 if (options.m_use_objc && !is_nil)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003381 {
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003382 if (!options.m_hide_value || !options.m_hide_name)
3383 s.Printf(" ");
Jim Ingham6035b672011-03-31 00:19:25 +00003384 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003385 if (object_desc)
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003386 s.Printf("%s\n", object_desc);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003387 else
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003388 s.Printf ("[no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003389 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003390 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003391 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003392
Enrico Granata0c489f52012-03-01 04:24:26 +00003393 if (curr_depth < options.m_max_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003394 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003395 // We will show children for all concrete types. We won't show
3396 // pointer contents unless a pointer depth has been specified.
3397 // We won't reference contents unless the reference is the
3398 // root object (depth of zero).
3399 bool print_children = true;
3400
3401 // Use a new temporary pointer depth in case we override the
3402 // current pointer depth below...
3403 uint32_t curr_ptr_depth = ptr_depth;
3404
3405 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3406 if (is_ptr || is_ref)
3407 {
3408 // We have a pointer or reference whose value is an address.
3409 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003410 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003411 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003412 print_children = false;
3413
3414 else if (is_ref && curr_depth == 0)
3415 {
3416 // If this is the root object (depth is zero) that we are showing
3417 // and it is a reference, and no pointer depth has been supplied
3418 // print out what it references. Don't do this at deeper depths
3419 // otherwise we can end up with infinite recursion...
3420 curr_ptr_depth = 1;
3421 }
3422
3423 if (curr_ptr_depth == 0)
3424 print_children = false;
3425 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003426
Enrico Granata0a3958e2011-07-02 00:25:22 +00003427 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003428 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003429 ValueObject* synth_valobj;
3430 ValueObjectSP synth_valobj_sp = valobj->GetSyntheticValue (options.m_use_synthetic);
3431 synth_valobj = (synth_valobj_sp ? synth_valobj_sp.get() : valobj);
Enrico Granatac5bc4122012-03-27 02:35:13 +00003432
Greg Claytonc7bece562013-01-25 18:06:21 +00003433 size_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003434 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003435 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003436 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003437 if (options.m_flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003438 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003439 if (print_valobj)
3440 s.EOL();
3441 }
3442 else
3443 {
3444 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003445 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003446 s.IndentMore();
3447 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003448
Greg Claytonc7bece562013-01-25 18:06:21 +00003449 const size_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00003450
Enrico Granata0c489f52012-03-01 04:24:26 +00003451 if (num_children > max_num_children && !options.m_ignore_cap)
Enrico Granata22c55d12011-08-12 02:00:06 +00003452 {
3453 num_children = max_num_children;
3454 print_dotdotdot = true;
3455 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003456
Enrico Granata0c489f52012-03-01 04:24:26 +00003457 ValueObject::DumpValueObjectOptions child_options(options);
Enrico Granatac953a6a2012-12-11 02:17:22 +00003458 child_options.SetFormat(options.m_format).SetSummary().SetRootValueObjectName();
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003459 child_options.SetScopeChecked(true).SetHideName(options.m_hide_name).SetHideValue(options.m_hide_value)
Enrico Granata0c489f52012-03-01 04:24:26 +00003460 .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0);
Greg Claytonc7bece562013-01-25 18:06:21 +00003461 for (size_t idx=0; idx<num_children; ++idx)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003462 {
Enrico Granatac482a192011-08-17 22:13:59 +00003463 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003464 if (child_sp.get())
3465 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003466 DumpValueObject_Impl (s,
3467 child_sp.get(),
3468 child_options,
3469 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
3470 curr_depth + 1);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003471 }
3472 }
3473
Enrico Granata0c489f52012-03-01 04:24:26 +00003474 if (!options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003475 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003476 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003477 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003478 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3479 Target *target = exe_ctx.GetTargetPtr();
3480 if (target)
3481 target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003482 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003483 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003484 s.IndentLess();
3485 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003486 }
3487 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003488 else if (has_children)
3489 {
3490 // Aggregate, no children...
3491 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003492 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003493 }
3494 else
3495 {
3496 if (print_valobj)
3497 s.EOL();
3498 }
3499
Greg Clayton1d3afba2010-10-05 00:00:42 +00003500 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003501 else
3502 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003503 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003504 }
3505 }
3506 else
3507 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003508 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003509 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003510 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003511 }
3512 }
3513 }
3514 }
3515}
3516
Enrico Granata0c489f52012-03-01 04:24:26 +00003517void
Greg Claytonf830dbb2012-03-22 18:15:37 +00003518ValueObject::LogValueObject (Log *log,
3519 ValueObject *valobj)
3520{
3521 if (log && valobj)
3522 return LogValueObject (log, valobj, DumpValueObjectOptions::DefaultOptions());
3523}
3524
3525void
3526ValueObject::LogValueObject (Log *log,
3527 ValueObject *valobj,
3528 const DumpValueObjectOptions& options)
3529{
3530 if (log && valobj)
3531 {
3532 StreamString s;
3533 ValueObject::DumpValueObject (s, valobj, options);
3534 if (s.GetSize())
3535 log->PutCString(s.GetData());
3536 }
3537}
3538
3539void
Enrico Granata0c489f52012-03-01 04:24:26 +00003540ValueObject::DumpValueObject (Stream &s,
3541 ValueObject *valobj)
3542{
3543
3544 if (!valobj)
3545 return;
3546
3547 DumpValueObject_Impl(s,
3548 valobj,
3549 DumpValueObjectOptions::DefaultOptions(),
3550 0,
3551 0);
3552}
3553
3554void
3555ValueObject::DumpValueObject (Stream &s,
3556 ValueObject *valobj,
3557 const DumpValueObjectOptions& options)
3558{
3559 DumpValueObject_Impl(s,
3560 valobj,
3561 options,
3562 options.m_max_ptr_depth, // max pointer depth allowed, we will go down from here
3563 0 // current object depth is 0 since we are just starting
3564 );
3565}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003566
3567ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003568ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003569{
3570 ValueObjectSP valobj_sp;
3571
Enrico Granatac3e320a2011-08-02 17:27:39 +00003572 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003573 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003574 ExecutionContext exe_ctx (GetExecutionContextRef());
3575 clang::ASTContext *ast = GetClangAST ();
3576
3577 DataExtractor data;
3578 data.SetByteOrder (m_data.GetByteOrder());
3579 data.SetAddressByteSize(m_data.GetAddressByteSize());
3580
Enrico Granata9f1e2042012-04-24 22:15:37 +00003581 if (IsBitfield())
3582 {
3583 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
3584 m_error = v.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
3585 }
3586 else
3587 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003588
3589 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3590 ast,
3591 GetClangType(),
3592 name,
3593 data,
3594 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003595 }
Jim Ingham6035b672011-03-31 00:19:25 +00003596
3597 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003598 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003599 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003600 }
3601 return valobj_sp;
3602}
3603
Greg Claytonafacd142011-09-02 01:15:17 +00003604ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003605ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003606{
Jim Ingham58b59f92011-04-22 23:53:53 +00003607 if (m_deref_valobj)
3608 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003609
Greg Clayton54979cd2010-12-15 05:08:08 +00003610 const bool is_pointer_type = IsPointerType();
3611 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003612 {
3613 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003614 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003615
3616 std::string child_name_str;
3617 uint32_t child_byte_size = 0;
3618 int32_t child_byte_offset = 0;
3619 uint32_t child_bitfield_bit_size = 0;
3620 uint32_t child_bitfield_bit_offset = 0;
3621 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003622 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003623 const bool transparent_pointers = false;
3624 clang::ASTContext *clang_ast = GetClangAST();
3625 clang_type_t clang_type = GetClangType();
3626 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003627
Greg Claytoncc4d0142012-02-17 07:49:44 +00003628 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003629
3630 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3631 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003632 GetName().GetCString(),
3633 clang_type,
3634 0,
3635 transparent_pointers,
3636 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003637 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003638 child_name_str,
3639 child_byte_size,
3640 child_byte_offset,
3641 child_bitfield_bit_size,
3642 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003643 child_is_base_class,
3644 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003645 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003646 {
3647 ConstString child_name;
3648 if (!child_name_str.empty())
3649 child_name.SetCString (child_name_str.c_str());
3650
Jim Ingham58b59f92011-04-22 23:53:53 +00003651 m_deref_valobj = new ValueObjectChild (*this,
3652 clang_ast,
3653 child_clang_type,
3654 child_name,
3655 child_byte_size,
3656 child_byte_offset,
3657 child_bitfield_bit_size,
3658 child_bitfield_bit_offset,
3659 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003660 child_is_deref_of_parent,
3661 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003662 }
3663 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003664
Jim Ingham58b59f92011-04-22 23:53:53 +00003665 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003666 {
3667 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003668 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003669 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003670 else
3671 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003672 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003673 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003674
3675 if (is_pointer_type)
3676 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3677 else
3678 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003679 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003680 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003681}
3682
Greg Claytonafacd142011-09-02 01:15:17 +00003683ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003684ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003685{
Jim Ingham78a685a2011-04-16 00:01:13 +00003686 if (m_addr_of_valobj_sp)
3687 return m_addr_of_valobj_sp;
3688
Greg Claytone0d378b2011-03-24 21:19:54 +00003689 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003690 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003691 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003692 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003693 if (addr != LLDB_INVALID_ADDRESS)
3694 {
3695 switch (address_type)
3696 {
3697 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003698 {
3699 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003700 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003701 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3702 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003703 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003704
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003705 case eAddressTypeFile:
3706 case eAddressTypeLoad:
3707 case eAddressTypeHost:
3708 {
3709 clang::ASTContext *ast = GetClangAST();
3710 clang_type_t clang_type = GetClangType();
3711 if (ast && clang_type)
3712 {
3713 std::string name (1, '&');
3714 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003715 ExecutionContext exe_ctx (GetExecutionContextRef());
3716 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003717 ast,
3718 ClangASTContext::CreatePointerType (ast, clang_type),
3719 ConstString (name.c_str()),
3720 addr,
3721 eAddressTypeInvalid,
3722 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003723 }
3724 }
3725 break;
3726 }
3727 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003728 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003729}
3730
Greg Clayton9a142cf2012-02-03 05:34:10 +00003731ValueObjectSP
3732ValueObject::Cast (const ClangASTType &clang_ast_type)
3733{
Greg Clayton81e871e2012-02-04 02:27:34 +00003734 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003735}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003736
Greg Claytonafacd142011-09-02 01:15:17 +00003737ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003738ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3739{
Greg Claytonafacd142011-09-02 01:15:17 +00003740 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003741 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003742 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003743
3744 if (ptr_value != LLDB_INVALID_ADDRESS)
3745 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003746 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003747 ExecutionContext exe_ctx (GetExecutionContextRef());
3748 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003749 name,
3750 ptr_addr,
3751 clang_ast_type);
3752 }
3753 return valobj_sp;
3754}
3755
Greg Claytonafacd142011-09-02 01:15:17 +00003756ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003757ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3758{
Greg Claytonafacd142011-09-02 01:15:17 +00003759 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003760 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003761 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003762
3763 if (ptr_value != LLDB_INVALID_ADDRESS)
3764 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003765 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003766 ExecutionContext exe_ctx (GetExecutionContextRef());
3767 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003768 name,
3769 ptr_addr,
3770 type_sp);
3771 }
3772 return valobj_sp;
3773}
3774
Jim Ingham6035b672011-03-31 00:19:25 +00003775ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003776 m_mod_id(),
3777 m_exe_ctx_ref(),
3778 m_needs_update (true),
3779 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003780{
3781}
3782
3783ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003784 m_mod_id(),
3785 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003786 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003787 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003788{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003789 ExecutionContext exe_ctx(exe_scope);
3790 TargetSP target_sp (exe_ctx.GetTargetSP());
3791 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003792 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003793 m_exe_ctx_ref.SetTargetSP (target_sp);
3794 ProcessSP process_sp (exe_ctx.GetProcessSP());
3795 if (!process_sp)
3796 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003797
Greg Claytoncc4d0142012-02-17 07:49:44 +00003798 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003799 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003800 m_mod_id = process_sp->GetModID();
3801 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003802
Greg Claytoncc4d0142012-02-17 07:49:44 +00003803 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003804
Greg Claytoncc4d0142012-02-17 07:49:44 +00003805 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003806 {
3807 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003808 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003809 }
Jim Ingham6035b672011-03-31 00:19:25 +00003810
Greg Claytoncc4d0142012-02-17 07:49:44 +00003811 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003812 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003813 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003814
Greg Claytoncc4d0142012-02-17 07:49:44 +00003815 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3816 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003817 {
3818 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003819 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003820 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003821 if (frame_sp)
3822 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003823 }
3824 }
3825 }
Jim Ingham6035b672011-03-31 00:19:25 +00003826}
3827
3828ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003829 m_mod_id(),
3830 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3831 m_needs_update (true),
3832 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003833{
3834}
3835
3836ValueObject::EvaluationPoint::~EvaluationPoint ()
3837{
3838}
3839
Jim Ingham6035b672011-03-31 00:19:25 +00003840// This function checks the EvaluationPoint against the current process state. If the current
3841// state matches the evaluation point, or the evaluation point is already invalid, then we return
3842// false, meaning "no change". If the current state is different, we update our state, and return
3843// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3844// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003845// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003846
3847bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003848ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003849{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003850
3851 // Start with the target, if it is NULL, then we're obviously not going to get any further:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003852 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00003853
Greg Claytoncc4d0142012-02-17 07:49:44 +00003854 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003855 return false;
3856
Jim Ingham6035b672011-03-31 00:19:25 +00003857 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003858 Process *process = exe_ctx.GetProcessPtr();
3859 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003860 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003861
Jim Ingham6035b672011-03-31 00:19:25 +00003862 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003863 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003864
Jim Ingham78a685a2011-04-16 00:01:13 +00003865 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3866 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003867 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003868 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003869
Greg Clayton23f59502012-07-17 03:23:13 +00003870 bool changed = false;
3871 const bool was_valid = m_mod_id.IsValid();
3872 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003873 {
3874 if (m_mod_id == current_mod_id)
3875 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003876 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003877 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003878 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003879 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003880 else
3881 {
3882 m_mod_id = current_mod_id;
3883 m_needs_update = true;
3884 changed = true;
3885 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003886 }
Jim Ingham6035b672011-03-31 00:19:25 +00003887
Jim Ingham73ca05a2011-12-17 01:35:57 +00003888 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3889 // That way we'll be sure to return a valid exe_scope.
3890 // 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 +00003891
Greg Claytoncc4d0142012-02-17 07:49:44 +00003892 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003893 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003894 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3895 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003896 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003897 if (m_exe_ctx_ref.HasFrameRef())
3898 {
3899 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3900 if (!frame_sp)
3901 {
3902 // We used to have a frame, but now it is gone
3903 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003904 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00003905 }
3906 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003907 }
Jim Ingham6035b672011-03-31 00:19:25 +00003908 else
3909 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003910 // We used to have a thread, but now it is gone
3911 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003912 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00003913 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003914
Jim Ingham6035b672011-03-31 00:19:25 +00003915 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003916 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003917}
3918
Jim Ingham61be0902011-05-02 18:13:59 +00003919void
3920ValueObject::EvaluationPoint::SetUpdated ()
3921{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003922 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3923 if (process_sp)
3924 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003925 m_first_update = false;
3926 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003927}
3928
3929
Greg Claytoncc4d0142012-02-17 07:49:44 +00003930//bool
3931//ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3932//{
3933// if (!IsValid())
3934// return false;
3935//
3936// bool needs_update = false;
3937//
3938// // The target has to be non-null, and the
3939// Target *target = exe_scope->CalculateTarget();
3940// if (target != NULL)
3941// {
3942// Target *old_target = m_target_sp.get();
3943// assert (target == old_target);
3944// Process *process = exe_scope->CalculateProcess();
3945// if (process != NULL)
3946// {
3947// // FOR NOW - assume you can't update variable objects across process boundaries.
3948// Process *old_process = m_process_sp.get();
3949// assert (process == old_process);
3950// ProcessModID current_mod_id = process->GetModID();
3951// if (m_mod_id != current_mod_id)
3952// {
3953// needs_update = true;
3954// m_mod_id = current_mod_id;
3955// }
3956// // See if we're switching the thread or stack context. If no thread is given, this is
3957// // being evaluated in a global context.
3958// Thread *thread = exe_scope->CalculateThread();
3959// if (thread != NULL)
3960// {
3961// user_id_t new_thread_index = thread->GetIndexID();
3962// if (new_thread_index != m_thread_id)
3963// {
3964// needs_update = true;
3965// m_thread_id = new_thread_index;
3966// m_stack_id.Clear();
3967// }
3968//
3969// StackFrame *new_frame = exe_scope->CalculateStackFrame();
3970// if (new_frame != NULL)
3971// {
3972// if (new_frame->GetStackID() != m_stack_id)
3973// {
3974// needs_update = true;
3975// m_stack_id = new_frame->GetStackID();
3976// }
3977// }
3978// else
3979// {
3980// m_stack_id.Clear();
3981// needs_update = true;
3982// }
3983// }
3984// else
3985// {
3986// // If this had been given a thread, and now there is none, we should update.
3987// // Otherwise we don't have to do anything.
3988// if (m_thread_id != LLDB_INVALID_UID)
3989// {
3990// m_thread_id = LLDB_INVALID_UID;
3991// m_stack_id.Clear();
3992// needs_update = true;
3993// }
3994// }
3995// }
3996// else
3997// {
3998// // If there is no process, then we don't need to update anything.
3999// // But if we're switching from having a process to not, we should try to update.
4000// if (m_process_sp.get() != NULL)
4001// {
4002// needs_update = true;
4003// m_process_sp.reset();
4004// m_thread_id = LLDB_INVALID_UID;
4005// m_stack_id.Clear();
4006// }
4007// }
4008// }
4009// else
4010// {
4011// // If there's no target, nothing can change so we don't need to update anything.
4012// // But if we're switching from having a target to not, we should try to update.
4013// if (m_target_sp.get() != NULL)
4014// {
4015// needs_update = true;
4016// m_target_sp.reset();
4017// m_process_sp.reset();
4018// m_thread_id = LLDB_INVALID_UID;
4019// m_stack_id.Clear();
4020// }
4021// }
4022// if (!m_needs_update)
4023// m_needs_update = needs_update;
4024//
4025// return needs_update;
4026//}
Enrico Granataf2bbf712011-07-15 02:26:42 +00004027
4028void
Enrico Granata86cc9822012-03-19 22:58:49 +00004029ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004030{
Enrico Granata86cc9822012-03-19 22:58:49 +00004031 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4032 m_value_str.clear();
4033
4034 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4035 m_location_str.clear();
4036
4037 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
4038 {
Enrico Granata86cc9822012-03-19 22:58:49 +00004039 m_summary_str.clear();
4040 }
4041
4042 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4043 m_object_desc_str.clear();
4044
4045 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4046 {
4047 if (m_synthetic_value)
4048 m_synthetic_value = NULL;
4049 }
Johnny Chen44805302011-07-19 19:48:13 +00004050}
Enrico Granata9128ee22011-09-06 19:20:51 +00004051
4052SymbolContextScope *
4053ValueObject::GetSymbolContextScope()
4054{
4055 if (m_parent)
4056 {
4057 if (!m_parent->IsPointerOrReferenceType())
4058 return m_parent->GetSymbolContextScope();
4059 }
4060 return NULL;
4061}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004062
4063lldb::ValueObjectSP
4064ValueObject::CreateValueObjectFromExpression (const char* name,
4065 const char* expression,
4066 const ExecutionContext& exe_ctx)
4067{
4068 lldb::ValueObjectSP retval_sp;
4069 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4070 if (!target_sp)
4071 return retval_sp;
4072 if (!expression || !*expression)
4073 return retval_sp;
4074 target_sp->EvaluateExpression (expression,
4075 exe_ctx.GetFrameSP().get(),
4076 retval_sp);
4077 if (retval_sp && name && *name)
4078 retval_sp->SetName(ConstString(name));
4079 return retval_sp;
4080}
4081
4082lldb::ValueObjectSP
4083ValueObject::CreateValueObjectFromAddress (const char* name,
4084 uint64_t address,
4085 const ExecutionContext& exe_ctx,
4086 ClangASTType type)
4087{
4088 ClangASTType pointer_type(type.GetASTContext(),type.GetPointerType());
4089 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4090 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4091 pointer_type.GetASTContext(),
4092 pointer_type.GetOpaqueQualType(),
4093 ConstString(name),
4094 buffer,
4095 lldb::endian::InlHostByteOrder(),
4096 exe_ctx.GetAddressByteSize()));
4097 if (ptr_result_valobj_sp)
4098 {
4099 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4100 Error err;
4101 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4102 if (ptr_result_valobj_sp && name && *name)
4103 ptr_result_valobj_sp->SetName(ConstString(name));
4104 }
4105 return ptr_result_valobj_sp;
4106}
4107
4108lldb::ValueObjectSP
4109ValueObject::CreateValueObjectFromData (const char* name,
4110 DataExtractor& data,
4111 const ExecutionContext& exe_ctx,
4112 ClangASTType type)
4113{
4114 lldb::ValueObjectSP new_value_sp;
4115 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4116 type.GetASTContext() ,
4117 type.GetOpaqueQualType(),
4118 ConstString(name),
4119 data,
4120 LLDB_INVALID_ADDRESS);
4121 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4122 if (new_value_sp && name && *name)
4123 new_value_sp->SetName(ConstString(name));
4124 return new_value_sp;
4125}