blob: 031d75463393415140c06f73cfc9a82eeab72db8 [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{
Enrico Granata7277d202013-03-15 23:33:15 +00001902 const uint32_t mask = ClangASTContext::eTypeIsObjC | ClangASTContext::eTypeIsPointer;
1903 bool isObjCpointer = ( ((ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), NULL)) & mask) == mask);
1904 if (!isObjCpointer)
1905 return false;
Enrico Granata9e7b3882012-12-13 23:50:33 +00001906 bool canReadValue = true;
1907 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
Enrico Granata7277d202013-03-15 23:33:15 +00001908 return canReadValue && isZero;
Enrico Granata9e7b3882012-12-13 23:50:33 +00001909}
1910
Greg Claytonafacd142011-09-02 01:15:17 +00001911ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00001912ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001913{
Greg Clayton2452ab72013-02-08 22:02:02 +00001914 const uint32_t type_info = GetTypeInfo ();
1915 if (type_info & ClangASTContext::eTypeIsArray)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001916 return GetSyntheticArrayMemberFromArray(index, can_create);
1917
Greg Clayton2452ab72013-02-08 22:02:02 +00001918 if (type_info & ClangASTContext::eTypeIsPointer)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001919 return GetSyntheticArrayMemberFromPointer(index, can_create);
1920
1921 return ValueObjectSP();
1922
1923}
1924
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001925ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00001926ValueObject::GetSyntheticArrayMemberFromPointer (size_t index, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001927{
1928 ValueObjectSP synthetic_child_sp;
1929 if (IsPointerType ())
1930 {
1931 char index_str[64];
Greg Claytonc7bece562013-01-25 18:06:21 +00001932 snprintf(index_str, sizeof(index_str), "[%zu]", index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001933 ConstString index_const_str(index_str);
1934 // Check if we have already created a synthetic array member in this
1935 // valid object. If we have we will re-use it.
1936 synthetic_child_sp = GetSyntheticChild (index_const_str);
1937 if (!synthetic_child_sp)
1938 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001939 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001940 // We haven't made a synthetic array member for INDEX yet, so
1941 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001942 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001943
1944 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001945 if (synthetic_child)
1946 {
1947 AddSyntheticChild(index_const_str, synthetic_child);
1948 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001949 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001950 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001951 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001952 }
1953 }
1954 return synthetic_child_sp;
1955}
Jim Ingham22777012010-09-23 02:01:19 +00001956
Greg Claytondaf515f2011-07-09 20:12:33 +00001957// This allows you to create an array member using and index
1958// that doesn't not fall in the normal bounds of the array.
1959// Many times structure can be defined as:
1960// struct Collection
1961// {
1962// uint32_t item_count;
1963// Item item_array[0];
1964// };
1965// The size of the "item_array" is 1, but many times in practice
1966// there are more items in "item_array".
1967
1968ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00001969ValueObject::GetSyntheticArrayMemberFromArray (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00001970{
1971 ValueObjectSP synthetic_child_sp;
1972 if (IsArrayType ())
1973 {
1974 char index_str[64];
Greg Claytonc7bece562013-01-25 18:06:21 +00001975 snprintf(index_str, sizeof(index_str), "[%zu]", index);
Greg Claytondaf515f2011-07-09 20:12:33 +00001976 ConstString index_const_str(index_str);
1977 // Check if we have already created a synthetic array member in this
1978 // valid object. If we have we will re-use it.
1979 synthetic_child_sp = GetSyntheticChild (index_const_str);
1980 if (!synthetic_child_sp)
1981 {
1982 ValueObject *synthetic_child;
1983 // We haven't made a synthetic array member for INDEX yet, so
1984 // lets make one and cache it for any future reference.
1985 synthetic_child = CreateChildAtIndex(0, true, index);
1986
1987 // Cache the value if we got one back...
1988 if (synthetic_child)
1989 {
1990 AddSyntheticChild(index_const_str, synthetic_child);
1991 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001992 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001993 synthetic_child_sp->m_is_array_item_for_pointer = true;
1994 }
1995 }
1996 }
1997 return synthetic_child_sp;
1998}
1999
Enrico Granata9fc19442011-07-06 02:13:41 +00002000ValueObjectSP
2001ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2002{
2003 ValueObjectSP synthetic_child_sp;
2004 if (IsScalarType ())
2005 {
2006 char index_str[64];
2007 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2008 ConstString index_const_str(index_str);
2009 // Check if we have already created a synthetic array member in this
2010 // valid object. If we have we will re-use it.
2011 synthetic_child_sp = GetSyntheticChild (index_const_str);
2012 if (!synthetic_child_sp)
2013 {
2014 ValueObjectChild *synthetic_child;
2015 // We haven't made a synthetic array member for INDEX yet, so
2016 // lets make one and cache it for any future reference.
2017 synthetic_child = new ValueObjectChild(*this,
2018 GetClangAST(),
2019 GetClangType(),
2020 index_const_str,
2021 GetByteSize(),
2022 0,
2023 to-from+1,
2024 from,
2025 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002026 false,
2027 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002028
2029 // Cache the value if we got one back...
2030 if (synthetic_child)
2031 {
2032 AddSyntheticChild(index_const_str, synthetic_child);
2033 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002034 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002035 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2036 }
2037 }
2038 }
2039 return synthetic_child_sp;
2040}
2041
Greg Claytonafacd142011-09-02 01:15:17 +00002042ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00002043ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
2044{
2045
2046 ValueObjectSP synthetic_child_sp;
2047
2048 char name_str[64];
2049 snprintf(name_str, sizeof(name_str), "@%i", offset);
2050 ConstString name_const_str(name_str);
2051
2052 // Check if we have already created a synthetic array member in this
2053 // valid object. If we have we will re-use it.
2054 synthetic_child_sp = GetSyntheticChild (name_const_str);
2055
2056 if (synthetic_child_sp.get())
2057 return synthetic_child_sp;
2058
2059 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002060 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002061
2062 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2063 type.GetASTContext(),
2064 type.GetOpaqueQualType(),
2065 name_const_str,
2066 type.GetTypeByteSize(),
2067 offset,
2068 0,
2069 0,
2070 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002071 false,
2072 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002073 if (synthetic_child)
2074 {
2075 AddSyntheticChild(name_const_str, synthetic_child);
2076 synthetic_child_sp = synthetic_child->GetSP();
2077 synthetic_child_sp->SetName(name_const_str);
2078 synthetic_child_sp->m_is_child_at_offset = true;
2079 }
2080 return synthetic_child_sp;
2081}
2082
Enrico Granatad55546b2011-07-22 00:16:08 +00002083// your expression path needs to have a leading . or ->
2084// (unless it somehow "looks like" an array, in which case it has
2085// a leading [ symbol). while the [ is meaningful and should be shown
2086// to the user, . and -> are just parser design, but by no means
2087// added information for the user.. strip them off
2088static const char*
2089SkipLeadingExpressionPathSeparators(const char* expression)
2090{
2091 if (!expression || !expression[0])
2092 return expression;
2093 if (expression[0] == '.')
2094 return expression+1;
2095 if (expression[0] == '-' && expression[1] == '>')
2096 return expression+2;
2097 return expression;
2098}
2099
Greg Claytonafacd142011-09-02 01:15:17 +00002100ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002101ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2102{
2103 ValueObjectSP synthetic_child_sp;
2104 ConstString name_const_string(expression);
2105 // Check if we have already created a synthetic array member in this
2106 // valid object. If we have we will re-use it.
2107 synthetic_child_sp = GetSyntheticChild (name_const_string);
2108 if (!synthetic_child_sp)
2109 {
2110 // We haven't made a synthetic array member for expression yet, so
2111 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002112 synthetic_child_sp = GetValueForExpressionPath(expression,
2113 NULL, NULL, NULL,
2114 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
Enrico Granatad55546b2011-07-22 00:16:08 +00002115
2116 // Cache the value if we got one back...
2117 if (synthetic_child_sp.get())
2118 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002119 // 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 +00002120 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002121 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002122 }
2123 }
2124 return synthetic_child_sp;
2125}
2126
2127void
Enrico Granata86cc9822012-03-19 22:58:49 +00002128ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002129{
Enrico Granata86cc9822012-03-19 22:58:49 +00002130 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002131 return;
2132
Enrico Granatac5bc4122012-03-27 02:35:13 +00002133 TargetSP target_sp(GetTargetSP());
2134 if (target_sp && (target_sp->GetEnableSyntheticValue() == false || target_sp->GetSuppressSyntheticValue() == true))
2135 {
2136 m_synthetic_value = NULL;
2137 return;
2138 }
2139
Enrico Granatae3e91512012-10-22 18:18:36 +00002140 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2141
Enrico Granata5548cb52013-01-28 23:47:25 +00002142 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002143 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002144
Enrico Granata0c489f52012-03-01 04:24:26 +00002145 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002146 return;
2147
Enrico Granatae3e91512012-10-22 18:18:36 +00002148 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2149 return;
2150
Enrico Granata86cc9822012-03-19 22:58:49 +00002151 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002152}
2153
Jim Ingham78a685a2011-04-16 00:01:13 +00002154void
Greg Claytonafacd142011-09-02 01:15:17 +00002155ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002156{
Greg Claytonafacd142011-09-02 01:15:17 +00002157 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002158 return;
2159
Jim Ingham58b59f92011-04-22 23:53:53 +00002160 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002161 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002162 ExecutionContext exe_ctx (GetExecutionContextRef());
2163 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002164 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002165 {
2166 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002167 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002168 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002169 }
2170}
2171
Jim Ingham58b59f92011-04-22 23:53:53 +00002172ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002173ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002174{
Greg Claytonafacd142011-09-02 01:15:17 +00002175 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002176 return ValueObjectSP();
2177
2178 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002179 {
Jim Ingham2837b762011-05-04 03:43:18 +00002180 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002181 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002182 if (m_dynamic_value)
2183 return m_dynamic_value->GetSP();
2184 else
2185 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002186}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002187
Jim Ingham60dbabb2011-12-08 19:44:08 +00002188ValueObjectSP
2189ValueObject::GetStaticValue()
2190{
2191 return GetSP();
2192}
2193
Enrico Granata886147f2012-05-08 18:47:08 +00002194lldb::ValueObjectSP
2195ValueObject::GetNonSyntheticValue ()
2196{
2197 return GetSP();
2198}
2199
Enrico Granatad55546b2011-07-22 00:16:08 +00002200ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002201ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002202{
Enrico Granata86cc9822012-03-19 22:58:49 +00002203 if (use_synthetic == false)
2204 return ValueObjectSP();
2205
Enrico Granatad55546b2011-07-22 00:16:08 +00002206 CalculateSyntheticValue(use_synthetic);
2207
2208 if (m_synthetic_value)
2209 return m_synthetic_value->GetSP();
2210 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002211 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002212}
2213
Greg Claytone221f822011-01-21 01:59:00 +00002214bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002215ValueObject::HasSyntheticValue()
2216{
Enrico Granata5548cb52013-01-28 23:47:25 +00002217 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002218
Enrico Granata0c489f52012-03-01 04:24:26 +00002219 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002220 return false;
2221
Enrico Granata86cc9822012-03-19 22:58:49 +00002222 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002223
2224 if (m_synthetic_value)
2225 return true;
2226 else
2227 return false;
2228}
2229
2230bool
Greg Claytone221f822011-01-21 01:59:00 +00002231ValueObject::GetBaseClassPath (Stream &s)
2232{
2233 if (IsBaseClass())
2234 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002235 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00002236 clang_type_t clang_type = GetClangType();
2237 std::string cxx_class_name;
2238 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
2239 if (this_had_base_class)
2240 {
2241 if (parent_had_base_class)
2242 s.PutCString("::");
2243 s.PutCString(cxx_class_name.c_str());
2244 }
2245 return parent_had_base_class || this_had_base_class;
2246 }
2247 return false;
2248}
2249
2250
2251ValueObject *
2252ValueObject::GetNonBaseClassParent()
2253{
Jim Ingham78a685a2011-04-16 00:01:13 +00002254 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002255 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002256 if (GetParent()->IsBaseClass())
2257 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002258 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002259 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002260 }
2261 return NULL;
2262}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002263
2264void
Enrico Granata4becb372011-06-29 22:27:15 +00002265ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002266{
Greg Claytone221f822011-01-21 01:59:00 +00002267 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002268
Enrico Granata86cc9822012-03-19 22:58:49 +00002269 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002270 {
Enrico Granata4becb372011-06-29 22:27:15 +00002271 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2272 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2273 // the eHonorPointers mode is meant to produce strings in this latter format
2274 s.PutCString("*(");
2275 }
Greg Claytone221f822011-01-21 01:59:00 +00002276
Enrico Granata4becb372011-06-29 22:27:15 +00002277 ValueObject* parent = GetParent();
2278
2279 if (parent)
2280 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002281
2282 // if we are a deref_of_parent just because we are synthetic array
2283 // members made up to allow ptr[%d] syntax to work in variable
2284 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002285 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002286 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002287
Greg Claytone221f822011-01-21 01:59:00 +00002288 if (!IsBaseClass())
2289 {
2290 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002291 {
Greg Claytone221f822011-01-21 01:59:00 +00002292 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2293 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002294 {
Greg Claytone221f822011-01-21 01:59:00 +00002295 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2296 if (non_base_class_parent_clang_type)
2297 {
2298 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2299
Enrico Granata86cc9822012-03-19 22:58:49 +00002300 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002301 {
2302 s.PutCString("->");
2303 }
Enrico Granata4becb372011-06-29 22:27:15 +00002304 else
2305 {
2306 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2307 {
2308 s.PutCString("->");
2309 }
2310 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2311 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2312 {
2313 s.PutChar('.');
2314 }
Greg Claytone221f822011-01-21 01:59:00 +00002315 }
2316 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002317 }
Greg Claytone221f822011-01-21 01:59:00 +00002318
2319 const char *name = GetName().GetCString();
2320 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002321 {
Greg Claytone221f822011-01-21 01:59:00 +00002322 if (qualify_cxx_base_classes)
2323 {
2324 if (GetBaseClassPath (s))
2325 s.PutCString("::");
2326 }
2327 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002328 }
2329 }
2330 }
2331
Enrico Granata86cc9822012-03-19 22:58:49 +00002332 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002333 {
Greg Claytone221f822011-01-21 01:59:00 +00002334 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002335 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002336}
2337
Greg Claytonafacd142011-09-02 01:15:17 +00002338ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002339ValueObject::GetValueForExpressionPath(const char* expression,
2340 const char** first_unparsed,
2341 ExpressionPathScanEndReason* reason_to_stop,
2342 ExpressionPathEndResultType* final_value_type,
2343 const GetValueForExpressionPathOptions& options,
2344 ExpressionPathAftermath* final_task_on_target)
2345{
2346
2347 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002348 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2349 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002350 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002351
2352 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2353 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2354 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2355 final_value_type ? final_value_type : &dummy_final_value_type,
2356 options,
2357 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2358
Enrico Granata86cc9822012-03-19 22:58:49 +00002359 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002360 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002361
Enrico Granata86cc9822012-03-19 22:58:49 +00002362 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 +00002363 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002364 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002365 {
2366 Error error;
2367 ValueObjectSP final_value = ret_val->Dereference(error);
2368 if (error.Fail() || !final_value.get())
2369 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002370 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002371 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002372 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002373 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002374 return ValueObjectSP();
2375 }
2376 else
2377 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002378 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002379 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002380 return final_value;
2381 }
2382 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002383 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002384 {
2385 Error error;
2386 ValueObjectSP final_value = ret_val->AddressOf(error);
2387 if (error.Fail() || !final_value.get())
2388 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002389 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002390 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002391 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002392 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002393 return ValueObjectSP();
2394 }
2395 else
2396 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002397 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002398 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002399 return final_value;
2400 }
2401 }
2402 }
2403 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2404}
2405
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002406int
2407ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002408 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002409 const char** first_unparsed,
2410 ExpressionPathScanEndReason* reason_to_stop,
2411 ExpressionPathEndResultType* final_value_type,
2412 const GetValueForExpressionPathOptions& options,
2413 ExpressionPathAftermath* final_task_on_target)
2414{
2415 const char* dummy_first_unparsed;
2416 ExpressionPathScanEndReason dummy_reason_to_stop;
2417 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002418 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002419
2420 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2421 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2422 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2423 final_value_type ? final_value_type : &dummy_final_value_type,
2424 options,
2425 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2426
2427 if (!ret_val.get()) // if there are errors, I add nothing to the list
2428 return 0;
2429
Enrico Granata86ea8d82012-03-29 01:34:34 +00002430 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002431 {
2432 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002433 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002434 {
2435 list->Append(ret_val);
2436 return 1;
2437 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002438 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 +00002439 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002440 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002441 {
2442 Error error;
2443 ValueObjectSP final_value = ret_val->Dereference(error);
2444 if (error.Fail() || !final_value.get())
2445 {
Greg Clayton23f59502012-07-17 03:23:13 +00002446 if (reason_to_stop)
2447 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2448 if (final_value_type)
2449 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002450 return 0;
2451 }
2452 else
2453 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002454 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002455 list->Append(final_value);
2456 return 1;
2457 }
2458 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002459 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002460 {
2461 Error error;
2462 ValueObjectSP final_value = ret_val->AddressOf(error);
2463 if (error.Fail() || !final_value.get())
2464 {
Greg Clayton23f59502012-07-17 03:23:13 +00002465 if (reason_to_stop)
2466 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2467 if (final_value_type)
2468 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002469 return 0;
2470 }
2471 else
2472 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002473 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002474 list->Append(final_value);
2475 return 1;
2476 }
2477 }
2478 }
2479 }
2480 else
2481 {
2482 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2483 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2484 ret_val,
2485 list,
2486 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2487 final_value_type ? final_value_type : &dummy_final_value_type,
2488 options,
2489 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2490 }
2491 // in any non-covered case, just do the obviously right thing
2492 list->Append(ret_val);
2493 return 1;
2494}
2495
Greg Claytonafacd142011-09-02 01:15:17 +00002496ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002497ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2498 const char** first_unparsed,
2499 ExpressionPathScanEndReason* reason_to_stop,
2500 ExpressionPathEndResultType* final_result,
2501 const GetValueForExpressionPathOptions& options,
2502 ExpressionPathAftermath* what_next)
2503{
2504 ValueObjectSP root = GetSP();
2505
2506 if (!root.get())
2507 return ValueObjectSP();
2508
2509 *first_unparsed = expression_cstr;
2510
2511 while (true)
2512 {
2513
2514 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2515
Greg Claytonafacd142011-09-02 01:15:17 +00002516 clang_type_t root_clang_type = root->GetClangType();
2517 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002518 Flags root_clang_type_info,pointee_clang_type_info;
2519
2520 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2521 if (pointee_clang_type)
2522 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002523
2524 if (!expression_cstr || *expression_cstr == '\0')
2525 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002526 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002527 return root;
2528 }
2529
2530 switch (*expression_cstr)
2531 {
2532 case '-':
2533 {
2534 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002535 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 +00002536 {
2537 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002538 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2539 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002540 return ValueObjectSP();
2541 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002542 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2543 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002544 options.m_no_fragile_ivar)
2545 {
2546 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002547 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2548 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002549 return ValueObjectSP();
2550 }
2551 if (expression_cstr[1] != '>')
2552 {
2553 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002554 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2555 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002556 return ValueObjectSP();
2557 }
2558 expression_cstr++; // skip the -
2559 }
2560 case '.': // or fallthrough from ->
2561 {
2562 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002563 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 +00002564 {
2565 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002566 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2567 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002568 return ValueObjectSP();
2569 }
2570 expression_cstr++; // skip .
2571 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2572 ConstString child_name;
2573 if (!next_separator) // if no other separator just expand this last layer
2574 {
2575 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002576 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2577
2578 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002579 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002580 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002581 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2582 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002583 return child_valobj_sp;
2584 }
2585 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2586 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002587 if (root->IsSynthetic())
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002588 {
2589 *first_unparsed = expression_cstr;
2590 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2591 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2592 return ValueObjectSP();
2593 }
2594
2595 child_valobj_sp = root->GetSyntheticValue();
Enrico Granata86cc9822012-03-19 22:58:49 +00002596 if (child_valobj_sp.get())
2597 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002598 }
2599
2600 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2601 // so we hit the "else" branch, and return an error
2602 if(child_valobj_sp.get()) // if it worked, just return
2603 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002604 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002605 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2606 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002607 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002608 }
2609 else
2610 {
2611 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002612 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2613 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002614 return ValueObjectSP();
2615 }
2616 }
2617 else // other layers do expand
2618 {
2619 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002620 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2621 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002622 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002623 root = child_valobj_sp;
2624 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002625 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002626 continue;
2627 }
2628 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2629 {
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002630 if (root->IsSynthetic())
2631 {
2632 *first_unparsed = expression_cstr;
2633 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2634 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2635 return ValueObjectSP();
2636 }
2637
Enrico Granata86cc9822012-03-19 22:58:49 +00002638 child_valobj_sp = root->GetSyntheticValue(true);
2639 if (child_valobj_sp)
2640 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002641 }
2642
2643 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2644 // so we hit the "else" branch, and return an error
2645 if(child_valobj_sp.get()) // if it worked, move on
2646 {
2647 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002648 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002649 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002650 continue;
2651 }
2652 else
2653 {
2654 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002655 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2656 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002657 return ValueObjectSP();
2658 }
2659 }
2660 break;
2661 }
2662 case '[':
2663 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002664 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 +00002665 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002666 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002667 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002668 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2669 {
2670 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002671 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2672 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002673 return ValueObjectSP();
2674 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002675 }
2676 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2677 {
2678 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002679 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2680 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002681 return ValueObjectSP();
2682 }
2683 }
2684 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2685 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002686 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002687 {
2688 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002689 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2690 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002691 return ValueObjectSP();
2692 }
2693 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2694 {
2695 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002696 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2697 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002698 return root;
2699 }
2700 }
2701 const char *separator_position = ::strchr(expression_cstr+1,'-');
2702 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2703 if (!close_bracket_position) // if there is no ], this is a syntax error
2704 {
2705 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002706 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2707 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002708 return ValueObjectSP();
2709 }
2710 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2711 {
2712 char *end = NULL;
2713 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2714 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2715 {
2716 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002717 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2718 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002719 return ValueObjectSP();
2720 }
2721 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2722 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002723 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002724 {
2725 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002726 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2727 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002728 return root;
2729 }
2730 else
2731 {
2732 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002733 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2734 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002735 return ValueObjectSP();
2736 }
2737 }
2738 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002739 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002740 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002741 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2742 if (!child_valobj_sp)
2743 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002744 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002745 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2746 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002747 if (child_valobj_sp)
2748 {
2749 root = child_valobj_sp;
2750 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002751 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002752 continue;
2753 }
2754 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002755 {
2756 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002757 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2758 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002759 return ValueObjectSP();
2760 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002761 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002762 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002763 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002764 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 +00002765 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002766 {
2767 Error error;
2768 root = root->Dereference(error);
2769 if (error.Fail() || !root.get())
2770 {
2771 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002772 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2773 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002774 return ValueObjectSP();
2775 }
2776 else
2777 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002778 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002779 continue;
2780 }
2781 }
2782 else
2783 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002784 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Clayton84db9102012-03-26 23:03:23 +00002785 root->GetClangType()) == eLanguageTypeObjC
2786 && ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2787 && root->HasSyntheticValue()
2788 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002789 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002790 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002791 }
2792 else
2793 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002794 if (!root.get())
2795 {
2796 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002797 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2798 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002799 return ValueObjectSP();
2800 }
2801 else
2802 {
2803 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002804 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002805 continue;
2806 }
2807 }
2808 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002809 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002810 {
2811 root = root->GetSyntheticBitFieldChild(index, index, true);
2812 if (!root.get())
2813 {
2814 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002815 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2816 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002817 return ValueObjectSP();
2818 }
2819 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2820 {
2821 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002822 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2823 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002824 return root;
2825 }
2826 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002827 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002828 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002829 if (root->HasSyntheticValue())
2830 root = root->GetSyntheticValue();
2831 else if (!root->IsSynthetic())
2832 {
2833 *first_unparsed = expression_cstr;
2834 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2835 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2836 return ValueObjectSP();
2837 }
2838 // if we are here, then root itself is a synthetic VO.. should be good to go
2839
Enrico Granata27b625e2011-08-09 01:04:56 +00002840 if (!root.get())
2841 {
2842 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002843 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2844 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2845 return ValueObjectSP();
2846 }
2847 root = root->GetChildAtIndex(index, true);
2848 if (!root.get())
2849 {
2850 *first_unparsed = expression_cstr;
2851 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2852 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002853 return ValueObjectSP();
2854 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002855 else
2856 {
2857 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002858 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002859 continue;
2860 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002861 }
2862 else
2863 {
2864 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002865 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2866 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002867 return ValueObjectSP();
2868 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002869 }
2870 else // we have a low and a high index
2871 {
2872 char *end = NULL;
2873 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2874 if (!end || end != separator_position) // if something weird is in our way return an error
2875 {
2876 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002877 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2878 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002879 return ValueObjectSP();
2880 }
2881 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2882 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2883 {
2884 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002885 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2886 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002887 return ValueObjectSP();
2888 }
2889 if (index_lower > index_higher) // swap indices if required
2890 {
2891 unsigned long temp = index_lower;
2892 index_lower = index_higher;
2893 index_higher = temp;
2894 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002895 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002896 {
2897 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2898 if (!root.get())
2899 {
2900 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002901 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2902 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002903 return ValueObjectSP();
2904 }
2905 else
2906 {
2907 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002908 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2909 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002910 return root;
2911 }
2912 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002913 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 +00002914 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002915 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002916 {
2917 Error error;
2918 root = root->Dereference(error);
2919 if (error.Fail() || !root.get())
2920 {
2921 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002922 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2923 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002924 return ValueObjectSP();
2925 }
2926 else
2927 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002928 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002929 continue;
2930 }
2931 }
2932 else
2933 {
2934 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002935 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2936 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002937 return root;
2938 }
2939 }
2940 break;
2941 }
2942 default: // some non-separator is in the way
2943 {
2944 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002945 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2946 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002947 return ValueObjectSP();
2948 break;
2949 }
2950 }
2951 }
2952}
2953
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002954int
2955ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2956 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002957 ValueObjectSP root,
2958 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002959 ExpressionPathScanEndReason* reason_to_stop,
2960 ExpressionPathEndResultType* final_result,
2961 const GetValueForExpressionPathOptions& options,
2962 ExpressionPathAftermath* what_next)
2963{
2964 if (!root.get())
2965 return 0;
2966
2967 *first_unparsed = expression_cstr;
2968
2969 while (true)
2970 {
2971
2972 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2973
Greg Claytonafacd142011-09-02 01:15:17 +00002974 clang_type_t root_clang_type = root->GetClangType();
2975 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002976 Flags root_clang_type_info,pointee_clang_type_info;
2977
2978 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2979 if (pointee_clang_type)
2980 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2981
2982 if (!expression_cstr || *expression_cstr == '\0')
2983 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002984 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002985 list->Append(root);
2986 return 1;
2987 }
2988
2989 switch (*expression_cstr)
2990 {
2991 case '[':
2992 {
2993 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2994 {
2995 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2996 {
2997 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002998 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2999 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003000 return 0;
3001 }
3002 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3003 {
3004 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003005 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3006 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003007 return 0;
3008 }
3009 }
3010 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3011 {
3012 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3013 {
3014 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003015 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3016 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003017 return 0;
3018 }
3019 else // expand this into list
3020 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003021 const size_t max_index = root->GetNumChildren() - 1;
3022 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003023 {
3024 ValueObjectSP child =
3025 root->GetChildAtIndex(index, true);
3026 list->Append(child);
3027 }
3028 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003029 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3030 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003031 return max_index; // tell me number of items I added to the VOList
3032 }
3033 }
3034 const char *separator_position = ::strchr(expression_cstr+1,'-');
3035 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3036 if (!close_bracket_position) // if there is no ], this is a syntax error
3037 {
3038 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003039 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3040 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003041 return 0;
3042 }
3043 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3044 {
3045 char *end = NULL;
3046 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3047 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3048 {
3049 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003050 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3051 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003052 return 0;
3053 }
3054 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3055 {
3056 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3057 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003058 const size_t max_index = root->GetNumChildren() - 1;
3059 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003060 {
3061 ValueObjectSP child =
3062 root->GetChildAtIndex(index, true);
3063 list->Append(child);
3064 }
3065 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003066 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3067 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003068 return max_index; // tell me number of items I added to the VOList
3069 }
3070 else
3071 {
3072 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003073 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3074 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003075 return 0;
3076 }
3077 }
3078 // from here on we do have a valid index
3079 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3080 {
3081 root = root->GetChildAtIndex(index, true);
3082 if (!root.get())
3083 {
3084 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003085 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3086 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003087 return 0;
3088 }
3089 else
3090 {
3091 list->Append(root);
3092 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003093 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3094 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003095 return 1;
3096 }
3097 }
3098 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
3099 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003100 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 +00003101 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3102 {
3103 Error error;
3104 root = root->Dereference(error);
3105 if (error.Fail() || !root.get())
3106 {
3107 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003108 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3109 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003110 return 0;
3111 }
3112 else
3113 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003114 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003115 continue;
3116 }
3117 }
3118 else
3119 {
3120 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3121 if (!root.get())
3122 {
3123 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003124 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3125 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003126 return 0;
3127 }
3128 else
3129 {
3130 list->Append(root);
3131 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003132 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3133 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003134 return 1;
3135 }
3136 }
3137 }
3138 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3139 {
3140 root = root->GetSyntheticBitFieldChild(index, index, true);
3141 if (!root.get())
3142 {
3143 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003144 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3145 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003146 return 0;
3147 }
3148 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3149 {
3150 list->Append(root);
3151 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003152 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3153 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003154 return 1;
3155 }
3156 }
3157 }
3158 else // we have a low and a high index
3159 {
3160 char *end = NULL;
3161 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3162 if (!end || end != separator_position) // if something weird is in our way return an error
3163 {
3164 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003165 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3166 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003167 return 0;
3168 }
3169 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3170 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3171 {
3172 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003173 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3174 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003175 return 0;
3176 }
3177 if (index_lower > index_higher) // swap indices if required
3178 {
3179 unsigned long temp = index_lower;
3180 index_lower = index_higher;
3181 index_higher = temp;
3182 }
3183 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
3184 {
3185 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3186 if (!root.get())
3187 {
3188 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003189 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3190 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003191 return 0;
3192 }
3193 else
3194 {
3195 list->Append(root);
3196 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003197 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3198 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003199 return 1;
3200 }
3201 }
3202 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 +00003203 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003204 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3205 {
3206 Error error;
3207 root = root->Dereference(error);
3208 if (error.Fail() || !root.get())
3209 {
3210 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003211 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3212 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003213 return 0;
3214 }
3215 else
3216 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003217 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003218 continue;
3219 }
3220 }
3221 else
3222 {
Johnny Chen44805302011-07-19 19:48:13 +00003223 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003224 index <= index_higher; index++)
3225 {
3226 ValueObjectSP child =
3227 root->GetChildAtIndex(index, true);
3228 list->Append(child);
3229 }
3230 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003231 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3232 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003233 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3234 }
3235 }
3236 break;
3237 }
3238 default: // some non-[ separator, or something entirely wrong, is in the way
3239 {
3240 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003241 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3242 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003243 return 0;
3244 break;
3245 }
3246 }
3247 }
3248}
3249
Enrico Granata0c489f52012-03-01 04:24:26 +00003250static void
3251DumpValueObject_Impl (Stream &s,
3252 ValueObject *valobj,
3253 const ValueObject::DumpValueObjectOptions& options,
3254 uint32_t ptr_depth,
3255 uint32_t curr_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003256{
Greg Clayton007d5be2011-05-30 00:49:24 +00003257 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003258 {
Enrico Granata5548cb52013-01-28 23:47:25 +00003259 bool update_success = valobj->UpdateValueIfNeeded (true);
Greg Clayton007d5be2011-05-30 00:49:24 +00003260
Enrico Granata0c489f52012-03-01 04:24:26 +00003261 const char *root_valobj_name =
3262 options.m_root_valobj_name.empty() ?
3263 valobj->GetName().AsCString() :
3264 options.m_root_valobj_name.c_str();
3265
3266 if (update_success && options.m_use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00003267 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003268 ValueObject *dynamic_value = valobj->GetDynamicValue(options.m_use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003269 if (dynamic_value)
3270 valobj = dynamic_value;
3271 }
3272
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003273 clang_type_t clang_type = valobj->GetClangType();
3274
Greg Clayton73b472d2010-10-27 03:32:59 +00003275 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003276 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00003277 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
3278 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003279
Enrico Granata0c489f52012-03-01 04:24:26 +00003280 const bool print_valobj = options.m_flat_output == false || has_value;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003281
3282 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003283 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003284 if (options.m_show_location)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003285 {
Jim Ingham6035b672011-03-31 00:19:25 +00003286 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003287 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003288
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003289 s.Indent();
Enrico Granata2b2631c2012-08-09 16:51:25 +00003290
3291 bool show_type = true;
3292 // if we are at the root-level and been asked to hide the root's type, then hide it
3293 if (curr_depth == 0 && options.m_hide_root_type)
3294 show_type = false;
3295 else
3296 // otherwise decide according to the usual rules (asked to show types - always at the root level)
3297 show_type = options.m_show_types || (curr_depth == 0 && !options.m_flat_output);
3298
3299 if (show_type)
Enrico Granataf7b1a342013-01-23 01:17:27 +00003300 s.Printf("(%s) ", valobj->GetQualifiedTypeName().AsCString("<invalid type>"));
Greg Clayton1d3afba2010-10-05 00:00:42 +00003301
Enrico Granata0c489f52012-03-01 04:24:26 +00003302 if (options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003303 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003304 // If we are showing types, also qualify the C++ base classes
Enrico Granata0c489f52012-03-01 04:24:26 +00003305 const bool qualify_cxx_base_classes = options.m_show_types;
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003306 if (!options.m_hide_name)
3307 {
3308 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
3309 s.PutCString(" =");
3310 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003311 }
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003312 else if (!options.m_hide_name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003313 {
3314 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3315 s.Printf ("%s =", name_cstr);
3316 }
3317
Enrico Granata0c489f52012-03-01 04:24:26 +00003318 if (!options.m_scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003319 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003320 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003321 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003322 }
3323
Enrico Granata0c489f52012-03-01 04:24:26 +00003324 std::string summary_str;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003325 std::string value_str;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003326 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003327 const char *sum_cstr = NULL;
Enrico Granata0c489f52012-03-01 04:24:26 +00003328 TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003329
Enrico Granata0c489f52012-03-01 04:24:26 +00003330 if (options.m_omit_summary_depth > 0)
Enrico Granata0c5ef692011-07-16 01:22:04 +00003331 entry = NULL;
3332
Enrico Granata9e7b3882012-12-13 23:50:33 +00003333 bool is_nil = valobj->IsObjCNil();
3334
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003335 if (err_cstr == NULL)
3336 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003337 if (options.m_format != eFormatDefault && options.m_format != valobj->GetFormat())
Greg Clayton6efba4f2012-01-26 21:08:30 +00003338 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003339 valobj->GetValueAsCString(options.m_format,
3340 value_str);
Greg Clayton6efba4f2012-01-26 21:08:30 +00003341 }
Enrico Granata0c489f52012-03-01 04:24:26 +00003342 else
Greg Clayton6efba4f2012-01-26 21:08:30 +00003343 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003344 val_cstr = valobj->GetValueAsCString();
3345 if (val_cstr)
3346 value_str = val_cstr;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003347 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003348 err_cstr = valobj->GetError().AsCString();
3349 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003350
3351 if (err_cstr)
3352 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003353 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003354 }
3355 else
3356 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003357 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003358 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003359 {
Enrico Granata9e7b3882012-12-13 23:50:33 +00003360 if (is_nil)
3361 sum_cstr = "nil";
3362 else if (options.m_omit_summary_depth == 0)
Enrico Granata0c489f52012-03-01 04:24:26 +00003363 {
3364 if (options.m_summary_sp)
3365 {
3366 valobj->GetSummaryAsCString(entry, summary_str);
3367 sum_cstr = summary_str.c_str();
3368 }
3369 else
3370 sum_cstr = valobj->GetSummaryAsCString();
3371 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003372
Greg Clayton6efba4f2012-01-26 21:08:30 +00003373 // Make sure we have a value and make sure the summary didn't
Enrico Granata9e7b3882012-12-13 23:50:33 +00003374 // specify that the value should not be printed - and do not print
3375 // the value if this thing is nil
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003376 if (!is_nil && !value_str.empty() && (entry == NULL || entry->DoesPrintValue() || sum_cstr == NULL) && !options.m_hide_value)
Greg Clayton6efba4f2012-01-26 21:08:30 +00003377 s.Printf(" %s", value_str.c_str());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003378
Enrico Granata9dd75c82011-07-15 23:30:15 +00003379 if (sum_cstr)
Enrico Granata0c489f52012-03-01 04:24:26 +00003380 s.Printf(" %s", sum_cstr);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003381
Enrico Granata9e7b3882012-12-13 23:50:33 +00003382 // let's avoid the overly verbose no description error for a nil thing
3383 if (options.m_use_objc && !is_nil)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003384 {
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003385 if (!options.m_hide_value || !options.m_hide_name)
3386 s.Printf(" ");
Jim Ingham6035b672011-03-31 00:19:25 +00003387 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003388 if (object_desc)
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003389 s.Printf("%s\n", object_desc);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003390 else
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003391 s.Printf ("[no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003392 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003393 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003394 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003395
Enrico Granata0c489f52012-03-01 04:24:26 +00003396 if (curr_depth < options.m_max_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003397 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003398 // We will show children for all concrete types. We won't show
3399 // pointer contents unless a pointer depth has been specified.
3400 // We won't reference contents unless the reference is the
3401 // root object (depth of zero).
3402 bool print_children = true;
3403
3404 // Use a new temporary pointer depth in case we override the
3405 // current pointer depth below...
3406 uint32_t curr_ptr_depth = ptr_depth;
3407
3408 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3409 if (is_ptr || is_ref)
3410 {
3411 // We have a pointer or reference whose value is an address.
3412 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003413 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003414 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003415 print_children = false;
3416
3417 else if (is_ref && curr_depth == 0)
3418 {
3419 // If this is the root object (depth is zero) that we are showing
3420 // and it is a reference, and no pointer depth has been supplied
3421 // print out what it references. Don't do this at deeper depths
3422 // otherwise we can end up with infinite recursion...
3423 curr_ptr_depth = 1;
3424 }
3425
3426 if (curr_ptr_depth == 0)
3427 print_children = false;
3428 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003429
Enrico Granata0a3958e2011-07-02 00:25:22 +00003430 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003431 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003432 ValueObject* synth_valobj;
3433 ValueObjectSP synth_valobj_sp = valobj->GetSyntheticValue (options.m_use_synthetic);
3434 synth_valobj = (synth_valobj_sp ? synth_valobj_sp.get() : valobj);
Enrico Granatac5bc4122012-03-27 02:35:13 +00003435
Greg Claytonc7bece562013-01-25 18:06:21 +00003436 size_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003437 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003438 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003439 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003440 if (options.m_flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003441 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003442 if (print_valobj)
3443 s.EOL();
3444 }
3445 else
3446 {
3447 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003448 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003449 s.IndentMore();
3450 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003451
Greg Claytonc7bece562013-01-25 18:06:21 +00003452 const size_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00003453
Enrico Granata0c489f52012-03-01 04:24:26 +00003454 if (num_children > max_num_children && !options.m_ignore_cap)
Enrico Granata22c55d12011-08-12 02:00:06 +00003455 {
3456 num_children = max_num_children;
3457 print_dotdotdot = true;
3458 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003459
Enrico Granata0c489f52012-03-01 04:24:26 +00003460 ValueObject::DumpValueObjectOptions child_options(options);
Enrico Granatac953a6a2012-12-11 02:17:22 +00003461 child_options.SetFormat(options.m_format).SetSummary().SetRootValueObjectName();
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003462 child_options.SetScopeChecked(true).SetHideName(options.m_hide_name).SetHideValue(options.m_hide_value)
Enrico Granata0c489f52012-03-01 04:24:26 +00003463 .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0);
Greg Claytonc7bece562013-01-25 18:06:21 +00003464 for (size_t idx=0; idx<num_children; ++idx)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003465 {
Enrico Granatac482a192011-08-17 22:13:59 +00003466 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003467 if (child_sp.get())
3468 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003469 DumpValueObject_Impl (s,
3470 child_sp.get(),
3471 child_options,
3472 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
3473 curr_depth + 1);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003474 }
3475 }
3476
Enrico Granata0c489f52012-03-01 04:24:26 +00003477 if (!options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003478 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003479 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003480 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003481 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3482 Target *target = exe_ctx.GetTargetPtr();
3483 if (target)
3484 target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003485 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003486 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003487 s.IndentLess();
3488 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003489 }
3490 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003491 else if (has_children)
3492 {
3493 // Aggregate, no children...
3494 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003495 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003496 }
3497 else
3498 {
3499 if (print_valobj)
3500 s.EOL();
3501 }
3502
Greg Clayton1d3afba2010-10-05 00:00:42 +00003503 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003504 else
3505 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003506 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003507 }
3508 }
3509 else
3510 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003511 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003512 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003513 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003514 }
3515 }
3516 }
3517 }
3518}
3519
Enrico Granata0c489f52012-03-01 04:24:26 +00003520void
Greg Claytonf830dbb2012-03-22 18:15:37 +00003521ValueObject::LogValueObject (Log *log,
3522 ValueObject *valobj)
3523{
3524 if (log && valobj)
3525 return LogValueObject (log, valobj, DumpValueObjectOptions::DefaultOptions());
3526}
3527
3528void
3529ValueObject::LogValueObject (Log *log,
3530 ValueObject *valobj,
3531 const DumpValueObjectOptions& options)
3532{
3533 if (log && valobj)
3534 {
3535 StreamString s;
3536 ValueObject::DumpValueObject (s, valobj, options);
3537 if (s.GetSize())
3538 log->PutCString(s.GetData());
3539 }
3540}
3541
3542void
Enrico Granata0c489f52012-03-01 04:24:26 +00003543ValueObject::DumpValueObject (Stream &s,
3544 ValueObject *valobj)
3545{
3546
3547 if (!valobj)
3548 return;
3549
3550 DumpValueObject_Impl(s,
3551 valobj,
3552 DumpValueObjectOptions::DefaultOptions(),
3553 0,
3554 0);
3555}
3556
3557void
3558ValueObject::DumpValueObject (Stream &s,
3559 ValueObject *valobj,
3560 const DumpValueObjectOptions& options)
3561{
3562 DumpValueObject_Impl(s,
3563 valobj,
3564 options,
3565 options.m_max_ptr_depth, // max pointer depth allowed, we will go down from here
3566 0 // current object depth is 0 since we are just starting
3567 );
3568}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003569
3570ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003571ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003572{
3573 ValueObjectSP valobj_sp;
3574
Enrico Granatac3e320a2011-08-02 17:27:39 +00003575 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003576 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003577 ExecutionContext exe_ctx (GetExecutionContextRef());
3578 clang::ASTContext *ast = GetClangAST ();
3579
3580 DataExtractor data;
3581 data.SetByteOrder (m_data.GetByteOrder());
3582 data.SetAddressByteSize(m_data.GetAddressByteSize());
3583
Enrico Granata9f1e2042012-04-24 22:15:37 +00003584 if (IsBitfield())
3585 {
3586 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
3587 m_error = v.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
3588 }
3589 else
3590 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003591
3592 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3593 ast,
3594 GetClangType(),
3595 name,
3596 data,
3597 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003598 }
Jim Ingham6035b672011-03-31 00:19:25 +00003599
3600 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003601 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003602 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003603 }
3604 return valobj_sp;
3605}
3606
Greg Claytonafacd142011-09-02 01:15:17 +00003607ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003608ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003609{
Jim Ingham58b59f92011-04-22 23:53:53 +00003610 if (m_deref_valobj)
3611 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003612
Greg Clayton54979cd2010-12-15 05:08:08 +00003613 const bool is_pointer_type = IsPointerType();
3614 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003615 {
3616 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003617 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003618
3619 std::string child_name_str;
3620 uint32_t child_byte_size = 0;
3621 int32_t child_byte_offset = 0;
3622 uint32_t child_bitfield_bit_size = 0;
3623 uint32_t child_bitfield_bit_offset = 0;
3624 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003625 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003626 const bool transparent_pointers = false;
3627 clang::ASTContext *clang_ast = GetClangAST();
3628 clang_type_t clang_type = GetClangType();
3629 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003630
Greg Claytoncc4d0142012-02-17 07:49:44 +00003631 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003632
3633 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3634 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003635 GetName().GetCString(),
3636 clang_type,
3637 0,
3638 transparent_pointers,
3639 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003640 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003641 child_name_str,
3642 child_byte_size,
3643 child_byte_offset,
3644 child_bitfield_bit_size,
3645 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003646 child_is_base_class,
3647 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003648 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003649 {
3650 ConstString child_name;
3651 if (!child_name_str.empty())
3652 child_name.SetCString (child_name_str.c_str());
3653
Jim Ingham58b59f92011-04-22 23:53:53 +00003654 m_deref_valobj = new ValueObjectChild (*this,
3655 clang_ast,
3656 child_clang_type,
3657 child_name,
3658 child_byte_size,
3659 child_byte_offset,
3660 child_bitfield_bit_size,
3661 child_bitfield_bit_offset,
3662 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003663 child_is_deref_of_parent,
3664 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003665 }
3666 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003667
Jim Ingham58b59f92011-04-22 23:53:53 +00003668 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003669 {
3670 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003671 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003672 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003673 else
3674 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003675 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003676 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003677
3678 if (is_pointer_type)
3679 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3680 else
3681 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003682 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003683 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003684}
3685
Greg Claytonafacd142011-09-02 01:15:17 +00003686ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003687ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003688{
Jim Ingham78a685a2011-04-16 00:01:13 +00003689 if (m_addr_of_valobj_sp)
3690 return m_addr_of_valobj_sp;
3691
Greg Claytone0d378b2011-03-24 21:19:54 +00003692 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003693 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003694 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003695 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003696 if (addr != LLDB_INVALID_ADDRESS)
3697 {
3698 switch (address_type)
3699 {
3700 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003701 {
3702 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003703 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003704 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3705 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003706 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003707
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003708 case eAddressTypeFile:
3709 case eAddressTypeLoad:
3710 case eAddressTypeHost:
3711 {
3712 clang::ASTContext *ast = GetClangAST();
3713 clang_type_t clang_type = GetClangType();
3714 if (ast && clang_type)
3715 {
3716 std::string name (1, '&');
3717 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003718 ExecutionContext exe_ctx (GetExecutionContextRef());
3719 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003720 ast,
3721 ClangASTContext::CreatePointerType (ast, clang_type),
3722 ConstString (name.c_str()),
3723 addr,
3724 eAddressTypeInvalid,
3725 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003726 }
3727 }
3728 break;
3729 }
3730 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003731 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003732}
3733
Greg Clayton9a142cf2012-02-03 05:34:10 +00003734ValueObjectSP
3735ValueObject::Cast (const ClangASTType &clang_ast_type)
3736{
Greg Clayton81e871e2012-02-04 02:27:34 +00003737 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003738}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003739
Greg Claytonafacd142011-09-02 01:15:17 +00003740ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003741ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3742{
Greg Claytonafacd142011-09-02 01:15:17 +00003743 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003744 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003745 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003746
3747 if (ptr_value != LLDB_INVALID_ADDRESS)
3748 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003749 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003750 ExecutionContext exe_ctx (GetExecutionContextRef());
3751 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003752 name,
3753 ptr_addr,
3754 clang_ast_type);
3755 }
3756 return valobj_sp;
3757}
3758
Greg Claytonafacd142011-09-02 01:15:17 +00003759ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003760ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3761{
Greg Claytonafacd142011-09-02 01:15:17 +00003762 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003763 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003764 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003765
3766 if (ptr_value != LLDB_INVALID_ADDRESS)
3767 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003768 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003769 ExecutionContext exe_ctx (GetExecutionContextRef());
3770 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003771 name,
3772 ptr_addr,
3773 type_sp);
3774 }
3775 return valobj_sp;
3776}
3777
Jim Ingham6035b672011-03-31 00:19:25 +00003778ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003779 m_mod_id(),
3780 m_exe_ctx_ref(),
3781 m_needs_update (true),
3782 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003783{
3784}
3785
3786ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003787 m_mod_id(),
3788 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003789 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003790 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003791{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003792 ExecutionContext exe_ctx(exe_scope);
3793 TargetSP target_sp (exe_ctx.GetTargetSP());
3794 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003795 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003796 m_exe_ctx_ref.SetTargetSP (target_sp);
3797 ProcessSP process_sp (exe_ctx.GetProcessSP());
3798 if (!process_sp)
3799 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003800
Greg Claytoncc4d0142012-02-17 07:49:44 +00003801 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003802 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003803 m_mod_id = process_sp->GetModID();
3804 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003805
Greg Claytoncc4d0142012-02-17 07:49:44 +00003806 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003807
Greg Claytoncc4d0142012-02-17 07:49:44 +00003808 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003809 {
3810 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003811 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003812 }
Jim Ingham6035b672011-03-31 00:19:25 +00003813
Greg Claytoncc4d0142012-02-17 07:49:44 +00003814 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003815 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003816 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003817
Greg Claytoncc4d0142012-02-17 07:49:44 +00003818 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3819 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003820 {
3821 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003822 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003823 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003824 if (frame_sp)
3825 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003826 }
3827 }
3828 }
Jim Ingham6035b672011-03-31 00:19:25 +00003829}
3830
3831ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003832 m_mod_id(),
3833 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3834 m_needs_update (true),
3835 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003836{
3837}
3838
3839ValueObject::EvaluationPoint::~EvaluationPoint ()
3840{
3841}
3842
Jim Ingham6035b672011-03-31 00:19:25 +00003843// This function checks the EvaluationPoint against the current process state. If the current
3844// state matches the evaluation point, or the evaluation point is already invalid, then we return
3845// false, meaning "no change". If the current state is different, we update our state, and return
3846// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3847// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003848// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003849
3850bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003851ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003852{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003853
3854 // 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 +00003855 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00003856
Greg Claytoncc4d0142012-02-17 07:49:44 +00003857 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003858 return false;
3859
Jim Ingham6035b672011-03-31 00:19:25 +00003860 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003861 Process *process = exe_ctx.GetProcessPtr();
3862 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003863 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003864
Jim Ingham6035b672011-03-31 00:19:25 +00003865 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003866 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003867
Jim Ingham78a685a2011-04-16 00:01:13 +00003868 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3869 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003870 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003871 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003872
Greg Clayton23f59502012-07-17 03:23:13 +00003873 bool changed = false;
3874 const bool was_valid = m_mod_id.IsValid();
3875 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003876 {
3877 if (m_mod_id == current_mod_id)
3878 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003879 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003880 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003881 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003882 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003883 else
3884 {
3885 m_mod_id = current_mod_id;
3886 m_needs_update = true;
3887 changed = true;
3888 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003889 }
Jim Ingham6035b672011-03-31 00:19:25 +00003890
Jim Ingham73ca05a2011-12-17 01:35:57 +00003891 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3892 // That way we'll be sure to return a valid exe_scope.
3893 // 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 +00003894
Greg Claytoncc4d0142012-02-17 07:49:44 +00003895 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003896 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003897 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3898 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003899 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003900 if (m_exe_ctx_ref.HasFrameRef())
3901 {
3902 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3903 if (!frame_sp)
3904 {
3905 // We used to have a frame, but now it is gone
3906 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003907 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00003908 }
3909 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003910 }
Jim Ingham6035b672011-03-31 00:19:25 +00003911 else
3912 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003913 // We used to have a thread, but now it is gone
3914 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003915 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00003916 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003917
Jim Ingham6035b672011-03-31 00:19:25 +00003918 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003919 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003920}
3921
Jim Ingham61be0902011-05-02 18:13:59 +00003922void
3923ValueObject::EvaluationPoint::SetUpdated ()
3924{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003925 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3926 if (process_sp)
3927 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003928 m_first_update = false;
3929 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003930}
3931
3932
Greg Claytoncc4d0142012-02-17 07:49:44 +00003933//bool
3934//ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3935//{
3936// if (!IsValid())
3937// return false;
3938//
3939// bool needs_update = false;
3940//
3941// // The target has to be non-null, and the
3942// Target *target = exe_scope->CalculateTarget();
3943// if (target != NULL)
3944// {
3945// Target *old_target = m_target_sp.get();
3946// assert (target == old_target);
3947// Process *process = exe_scope->CalculateProcess();
3948// if (process != NULL)
3949// {
3950// // FOR NOW - assume you can't update variable objects across process boundaries.
3951// Process *old_process = m_process_sp.get();
3952// assert (process == old_process);
3953// ProcessModID current_mod_id = process->GetModID();
3954// if (m_mod_id != current_mod_id)
3955// {
3956// needs_update = true;
3957// m_mod_id = current_mod_id;
3958// }
3959// // See if we're switching the thread or stack context. If no thread is given, this is
3960// // being evaluated in a global context.
3961// Thread *thread = exe_scope->CalculateThread();
3962// if (thread != NULL)
3963// {
3964// user_id_t new_thread_index = thread->GetIndexID();
3965// if (new_thread_index != m_thread_id)
3966// {
3967// needs_update = true;
3968// m_thread_id = new_thread_index;
3969// m_stack_id.Clear();
3970// }
3971//
3972// StackFrame *new_frame = exe_scope->CalculateStackFrame();
3973// if (new_frame != NULL)
3974// {
3975// if (new_frame->GetStackID() != m_stack_id)
3976// {
3977// needs_update = true;
3978// m_stack_id = new_frame->GetStackID();
3979// }
3980// }
3981// else
3982// {
3983// m_stack_id.Clear();
3984// needs_update = true;
3985// }
3986// }
3987// else
3988// {
3989// // If this had been given a thread, and now there is none, we should update.
3990// // Otherwise we don't have to do anything.
3991// if (m_thread_id != LLDB_INVALID_UID)
3992// {
3993// m_thread_id = LLDB_INVALID_UID;
3994// m_stack_id.Clear();
3995// needs_update = true;
3996// }
3997// }
3998// }
3999// else
4000// {
4001// // If there is no process, then we don't need to update anything.
4002// // But if we're switching from having a process to not, we should try to update.
4003// if (m_process_sp.get() != NULL)
4004// {
4005// needs_update = true;
4006// m_process_sp.reset();
4007// m_thread_id = LLDB_INVALID_UID;
4008// m_stack_id.Clear();
4009// }
4010// }
4011// }
4012// else
4013// {
4014// // If there's no target, nothing can change so we don't need to update anything.
4015// // But if we're switching from having a target to not, we should try to update.
4016// if (m_target_sp.get() != NULL)
4017// {
4018// needs_update = true;
4019// m_target_sp.reset();
4020// m_process_sp.reset();
4021// m_thread_id = LLDB_INVALID_UID;
4022// m_stack_id.Clear();
4023// }
4024// }
4025// if (!m_needs_update)
4026// m_needs_update = needs_update;
4027//
4028// return needs_update;
4029//}
Enrico Granataf2bbf712011-07-15 02:26:42 +00004030
4031void
Enrico Granata86cc9822012-03-19 22:58:49 +00004032ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004033{
Enrico Granata86cc9822012-03-19 22:58:49 +00004034 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4035 m_value_str.clear();
4036
4037 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4038 m_location_str.clear();
4039
4040 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
4041 {
Enrico Granata86cc9822012-03-19 22:58:49 +00004042 m_summary_str.clear();
4043 }
4044
4045 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4046 m_object_desc_str.clear();
4047
4048 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4049 {
4050 if (m_synthetic_value)
4051 m_synthetic_value = NULL;
4052 }
Johnny Chen44805302011-07-19 19:48:13 +00004053}
Enrico Granata9128ee22011-09-06 19:20:51 +00004054
4055SymbolContextScope *
4056ValueObject::GetSymbolContextScope()
4057{
4058 if (m_parent)
4059 {
4060 if (!m_parent->IsPointerOrReferenceType())
4061 return m_parent->GetSymbolContextScope();
4062 }
4063 return NULL;
4064}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004065
4066lldb::ValueObjectSP
4067ValueObject::CreateValueObjectFromExpression (const char* name,
4068 const char* expression,
4069 const ExecutionContext& exe_ctx)
4070{
4071 lldb::ValueObjectSP retval_sp;
4072 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4073 if (!target_sp)
4074 return retval_sp;
4075 if (!expression || !*expression)
4076 return retval_sp;
4077 target_sp->EvaluateExpression (expression,
4078 exe_ctx.GetFrameSP().get(),
4079 retval_sp);
4080 if (retval_sp && name && *name)
4081 retval_sp->SetName(ConstString(name));
4082 return retval_sp;
4083}
4084
4085lldb::ValueObjectSP
4086ValueObject::CreateValueObjectFromAddress (const char* name,
4087 uint64_t address,
4088 const ExecutionContext& exe_ctx,
4089 ClangASTType type)
4090{
4091 ClangASTType pointer_type(type.GetASTContext(),type.GetPointerType());
4092 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4093 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4094 pointer_type.GetASTContext(),
4095 pointer_type.GetOpaqueQualType(),
4096 ConstString(name),
4097 buffer,
4098 lldb::endian::InlHostByteOrder(),
4099 exe_ctx.GetAddressByteSize()));
4100 if (ptr_result_valobj_sp)
4101 {
4102 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4103 Error err;
4104 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4105 if (ptr_result_valobj_sp && name && *name)
4106 ptr_result_valobj_sp->SetName(ConstString(name));
4107 }
4108 return ptr_result_valobj_sp;
4109}
4110
4111lldb::ValueObjectSP
4112ValueObject::CreateValueObjectFromData (const char* name,
4113 DataExtractor& data,
4114 const ExecutionContext& exe_ctx,
4115 ClangASTType type)
4116{
4117 lldb::ValueObjectSP new_value_sp;
4118 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4119 type.GetASTContext() ,
4120 type.GetOpaqueQualType(),
4121 ConstString(name),
4122 data,
4123 LLDB_INVALID_ADDRESS);
4124 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4125 if (new_value_sp && name && *name)
4126 new_value_sp->SetName(ConstString(name));
4127 return new_value_sp;
4128}