blob: 140c4b48b5ee37e70c2e3b4a495fb641a928f9f6 [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{
Greg Clayton5160ce52013-03-27 23:08:40 +0000232 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000233 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 {
Enrico Granata852cce72013-03-23 01:12:38 +00001258 // put custom bytes to display in this DataExtractor to override the default value logic
1259 lldb_private::DataExtractor special_format_data;
1260 clang::ASTContext* ast = GetClangAST();
Enrico Granata123c39c2013-03-23 01:44:23 +00001261 if (format == eFormatCString)
Enrico Granata852cce72013-03-23 01:12:38 +00001262 {
Enrico Granata9d71afe2013-03-23 01:44:59 +00001263 Flags type_flags(ClangASTContext::GetTypeInfo(clang_type, ast, NULL));
Enrico Granata123c39c2013-03-23 01:44:23 +00001264 if (type_flags.Test(ClangASTContext::eTypeIsPointer) && !type_flags.Test(ClangASTContext::eTypeIsObjC))
Enrico Granata852cce72013-03-23 01:12:38 +00001265 {
1266 // if we are dumping a pointer as a c-string, get the pointee data as a string
1267 TargetSP target_sp(GetTargetSP());
1268 if (target_sp)
1269 {
1270 size_t max_len = target_sp->GetMaximumSizeOfStringSummary();
1271 Error error;
1272 DataBufferSP buffer_sp(new DataBufferHeap(max_len+1,0));
1273 Address address(GetPointerValue());
1274 if (target_sp->ReadCStringFromMemory(address, (char*)buffer_sp->GetBytes(), max_len, error) && error.Success())
1275 special_format_data.SetData(buffer_sp);
1276 }
1277 }
1278 }
1279
Enrico Granata0c489f52012-03-01 04:24:26 +00001280 StreamString sstr;
1281 ExecutionContext exe_ctx (GetExecutionContextRef());
Enrico Granata852cce72013-03-23 01:12:38 +00001282 ClangASTType::DumpTypeValue (ast, // The clang AST
1283 clang_type, // The clang type to display
1284 &sstr, // The stream to use for display
1285 format, // Format to display this type with
1286 special_format_data.GetByteSize() ?
1287 special_format_data: m_data, // Data to extract from
1288 0, // Byte offset into "m_data"
1289 GetByteSize(), // Byte size of item in "m_data"
1290 GetBitfieldBitSize(), // Bitfield bit size
1291 GetBitfieldBitOffset(), // Bitfield bit offset
Enrico Granata0c489f52012-03-01 04:24:26 +00001292 exe_ctx.GetBestExecutionContextScope());
1293 // Don't set the m_error to anything here otherwise
1294 // we won't be able to re-format as anything else. The
1295 // code for ClangASTType::DumpTypeValue() should always
1296 // return something, even if that something contains
1297 // an error messsage. "m_error" is used to detect errors
1298 // when reading the valid object, not for formatting errors.
1299 if (sstr.GetString().empty())
1300 destination.clear();
1301 else
1302 destination.swap(sstr.GetString());
1303 }
1304 }
1305 break;
1306
1307 case Value::eContextTypeRegisterInfo:
1308 {
1309 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1310 if (reg_info)
1311 {
1312 ExecutionContext exe_ctx (GetExecutionContextRef());
1313
1314 StreamString reg_sstr;
1315 m_data.Dump (&reg_sstr,
1316 0,
1317 format,
1318 reg_info->byte_size,
1319 1,
1320 UINT32_MAX,
1321 LLDB_INVALID_ADDRESS,
1322 0,
1323 0,
1324 exe_ctx.GetBestExecutionContextScope());
1325 destination.swap(reg_sstr.GetString());
1326 }
1327 }
1328 break;
1329
1330 default:
1331 break;
1332 }
1333 return !destination.empty();
1334 }
1335 else
1336 return false;
1337}
1338
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001339const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001340ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001341{
Enrico Granata0c489f52012-03-01 04:24:26 +00001342 if (UpdateValueIfNeeded(true) && m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001343 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001344 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001345 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001346 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001347 if (m_type_format_sp)
1348 my_format = m_type_format_sp->GetFormat();
1349 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001350 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001351 if (m_is_bitfield_for_scalar)
1352 my_format = eFormatUnsigned;
1353 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001354 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001355 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001356 {
1357 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1358 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001359 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001360 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001361 else
1362 {
1363 clang_type_t clang_type = GetClangType ();
1364 my_format = ClangASTType::GetFormat(clang_type);
1365 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001366 }
1367 }
1368 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001369 if (GetValueAsCString(my_format, m_value_str))
1370 {
1371 if (!m_value_did_change && m_old_value_valid)
1372 {
1373 // The value was gotten successfully, so we consider the
1374 // value as changed if the value string differs
1375 SetValueDidChange (m_old_value_str != m_value_str);
1376 }
1377 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001378 }
1379 if (m_value_str.empty())
1380 return NULL;
1381 return m_value_str.c_str();
1382}
1383
Enrico Granatac3e320a2011-08-02 17:27:39 +00001384// if > 8bytes, 0 is returned. this method should mostly be used
1385// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001386uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001387ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001388{
1389 // If our byte size is zero this is an aggregate type that has children
1390 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
1391 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001392 Scalar scalar;
1393 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001394 {
1395 if (success)
1396 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001397 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001398 }
1399 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001400 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001401
1402 if (success)
1403 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001404 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001405}
1406
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001407// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1408// this call up to date by returning true for your new special cases. We will eventually move
1409// to checking this call result before trying to display special cases
1410bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001411ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1412 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001413{
1414 clang_type_t elem_or_pointee_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001415 Flags flags(GetTypeInfo(&elem_or_pointee_type));
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001416
1417 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001418 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001419 {
1420 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001421 (custom_format == eFormatCString ||
1422 custom_format == eFormatCharArray ||
1423 custom_format == eFormatChar ||
1424 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001425 return true;
1426
1427 if (flags.Test(ClangASTContext::eTypeIsArray))
1428 {
Greg Claytonafacd142011-09-02 01:15:17 +00001429 if ((custom_format == eFormatBytes) ||
1430 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001431 return true;
1432
Greg Claytonafacd142011-09-02 01:15:17 +00001433 if ((custom_format == eFormatVectorOfChar) ||
1434 (custom_format == eFormatVectorOfFloat32) ||
1435 (custom_format == eFormatVectorOfFloat64) ||
1436 (custom_format == eFormatVectorOfSInt16) ||
1437 (custom_format == eFormatVectorOfSInt32) ||
1438 (custom_format == eFormatVectorOfSInt64) ||
1439 (custom_format == eFormatVectorOfSInt8) ||
1440 (custom_format == eFormatVectorOfUInt128) ||
1441 (custom_format == eFormatVectorOfUInt16) ||
1442 (custom_format == eFormatVectorOfUInt32) ||
1443 (custom_format == eFormatVectorOfUInt64) ||
1444 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001445 return true;
1446 }
1447 }
1448 return false;
1449}
1450
Enrico Granata9fc19442011-07-06 02:13:41 +00001451bool
1452ValueObject::DumpPrintableRepresentation(Stream& s,
1453 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001454 Format custom_format,
Enrico Granata86cc9822012-03-19 22:58:49 +00001455 PrintableRepresentationSpecialCases special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001456{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001457
1458 clang_type_t elem_or_pointee_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001459 Flags flags(GetTypeInfo(&elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001460
Enrico Granata86cc9822012-03-19 22:58:49 +00001461 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1462 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1463
1464 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001465 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001466 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1467 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001468 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001469 // when being asked to get a printable display an array or pointer type directly,
1470 // try to "do the right thing"
1471
1472 if (IsCStringContainer(true) &&
1473 (custom_format == eFormatCString ||
1474 custom_format == eFormatCharArray ||
1475 custom_format == eFormatChar ||
1476 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001477 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001478 Error error;
1479 ReadPointedString(s,
1480 error,
1481 0,
1482 (custom_format == eFormatVectorOfChar) ||
1483 (custom_format == eFormatCharArray));
1484 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001485 }
1486
Enrico Granata86cc9822012-03-19 22:58:49 +00001487 if (custom_format == eFormatEnum)
1488 return false;
1489
1490 // this only works for arrays, because I have no way to know when
1491 // the pointed memory ends, and no special \0 end of data marker
1492 if (flags.Test(ClangASTContext::eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001493 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001494 if ((custom_format == eFormatBytes) ||
1495 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001496 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001497 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001498
1499 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001500 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001501 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001502
1503 if (low)
1504 s << ',';
1505
1506 ValueObjectSP child = GetChildAtIndex(low,true);
1507 if (!child.get())
1508 {
1509 s << "<invalid child>";
1510 continue;
1511 }
1512 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1513 }
1514
1515 s << ']';
1516
1517 return true;
1518 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001519
Enrico Granata86cc9822012-03-19 22:58:49 +00001520 if ((custom_format == eFormatVectorOfChar) ||
1521 (custom_format == eFormatVectorOfFloat32) ||
1522 (custom_format == eFormatVectorOfFloat64) ||
1523 (custom_format == eFormatVectorOfSInt16) ||
1524 (custom_format == eFormatVectorOfSInt32) ||
1525 (custom_format == eFormatVectorOfSInt64) ||
1526 (custom_format == eFormatVectorOfSInt8) ||
1527 (custom_format == eFormatVectorOfUInt128) ||
1528 (custom_format == eFormatVectorOfUInt16) ||
1529 (custom_format == eFormatVectorOfUInt32) ||
1530 (custom_format == eFormatVectorOfUInt64) ||
1531 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1532 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001533 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001534
1535 Format format = FormatManager::GetSingleItemFormat(custom_format);
1536
1537 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001538 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001539 {
1540
1541 if (low)
1542 s << ',';
1543
1544 ValueObjectSP child = GetChildAtIndex(low,true);
1545 if (!child.get())
1546 {
1547 s << "<invalid child>";
1548 continue;
1549 }
1550 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1551 }
1552
1553 s << ']';
1554
1555 return true;
1556 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001557 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001558
1559 if ((custom_format == eFormatBoolean) ||
1560 (custom_format == eFormatBinary) ||
1561 (custom_format == eFormatChar) ||
1562 (custom_format == eFormatCharPrintable) ||
1563 (custom_format == eFormatComplexFloat) ||
1564 (custom_format == eFormatDecimal) ||
1565 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001566 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001567 (custom_format == eFormatFloat) ||
1568 (custom_format == eFormatOctal) ||
1569 (custom_format == eFormatOSType) ||
1570 (custom_format == eFormatUnicode16) ||
1571 (custom_format == eFormatUnicode32) ||
1572 (custom_format == eFormatUnsigned) ||
1573 (custom_format == eFormatPointer) ||
1574 (custom_format == eFormatComplexInteger) ||
1575 (custom_format == eFormatComplex) ||
1576 (custom_format == eFormatDefault)) // use the [] operator
1577 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001578 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001579 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001580
1581 if (only_special)
1582 return false;
1583
Enrico Granata86cc9822012-03-19 22:58:49 +00001584 bool var_success = false;
1585
1586 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001587 const char *cstr = NULL;
1588 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001589
1590 if (custom_format != eFormatInvalid)
1591 SetFormat(custom_format);
1592
1593 switch(val_obj_display)
1594 {
1595 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001596 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001597 break;
1598
1599 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001600 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001601 break;
1602
1603 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001604 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001605 break;
1606
1607 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001608 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001609 break;
1610
1611 case eValueObjectRepresentationStyleChildrenCount:
Greg Claytonc7bece562013-01-25 18:06:21 +00001612 strm.Printf("%zu", GetNumChildren());
1613 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001614 break;
1615
1616 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001617 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001618 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001619 }
1620
Greg Claytonc7bece562013-01-25 18:06:21 +00001621 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001622 {
1623 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001624 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001625 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1626 {
1627 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1628 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001629 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1630 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001631 }
1632 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001633 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001634 }
1635 }
1636
Greg Claytonc7bece562013-01-25 18:06:21 +00001637 if (cstr)
1638 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001639 else
1640 {
1641 if (m_error.Fail())
1642 s.Printf("<%s>", m_error.AsCString());
1643 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1644 s.PutCString("<no summary available>");
1645 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1646 s.PutCString("<no value available>");
1647 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1648 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1649 else
1650 s.PutCString("<no printable representation>");
1651 }
1652
1653 // we should only return false here if we could not do *anything*
1654 // even if we have an error message as output, that's a success
1655 // from our callers' perspective, so return true
1656 var_success = true;
1657
1658 if (custom_format != eFormatInvalid)
1659 SetFormat(eFormatDefault);
1660 }
1661
Enrico Granataf4efecd2011-07-12 22:56:10 +00001662 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001663}
1664
Greg Clayton737b9322010-09-13 03:32:57 +00001665addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001666ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001667{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001668 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001669 return LLDB_INVALID_ADDRESS;
1670
Greg Clayton73b472d2010-10-27 03:32:59 +00001671 switch (m_value.GetValueType())
1672 {
1673 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001674 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001675 if (scalar_is_load_address)
1676 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001677 if(address_type)
1678 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001679 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1680 }
1681 break;
1682
1683 case Value::eValueTypeLoadAddress:
1684 case Value::eValueTypeFileAddress:
1685 case Value::eValueTypeHostAddress:
1686 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001687 if(address_type)
1688 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001689 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1690 }
1691 break;
1692 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001693 if (address_type)
1694 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001695 return LLDB_INVALID_ADDRESS;
1696}
1697
1698addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001699ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001700{
Greg Claytonafacd142011-09-02 01:15:17 +00001701 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001702 if(address_type)
1703 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001704
Enrico Granatac3e320a2011-08-02 17:27:39 +00001705 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001706 return address;
1707
Greg Clayton73b472d2010-10-27 03:32:59 +00001708 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001709 {
1710 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001711 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001712 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001713 break;
1714
Enrico Granata9128ee22011-09-06 19:20:51 +00001715 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001716 case Value::eValueTypeLoadAddress:
1717 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001718 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001719 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001720 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001721 }
1722 break;
1723 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001724
Enrico Granata9128ee22011-09-06 19:20:51 +00001725 if (address_type)
1726 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001727
Greg Clayton737b9322010-09-13 03:32:57 +00001728 return address;
1729}
1730
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001731bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001732ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001733{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001734 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001735 // Make sure our value is up to date first so that our location and location
1736 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001737 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001738 {
1739 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001740 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001741 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001742
Greg Claytonfaac1112013-03-14 18:31:44 +00001743 uint64_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001744 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001745
Greg Claytonb1320972010-07-14 00:18:15 +00001746 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001747
Jim Ingham16e0c682011-08-12 23:34:31 +00001748 Value::ValueType value_type = m_value.GetValueType();
1749
1750 if (value_type == Value::eValueTypeScalar)
1751 {
1752 // If the value is already a scalar, then let the scalar change itself:
1753 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1754 }
1755 else if (byte_size <= Scalar::GetMaxByteSize())
1756 {
1757 // If the value fits in a scalar, then make a new scalar and again let the
1758 // scalar code do the conversion, then figure out where to put the new value.
1759 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001760 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1761 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001762 {
Jim Ingham4b536182011-08-09 02:12:22 +00001763 switch (value_type)
1764 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001765 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001766 {
1767 // If it is a load address, then the scalar value is the storage location
1768 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001769 ExecutionContext exe_ctx (GetExecutionContextRef());
1770 Process *process = exe_ctx.GetProcessPtr();
1771 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001772 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001773 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001774 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1775 new_scalar,
1776 byte_size,
1777 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001778 if (!error.Success())
1779 return false;
1780 if (bytes_written != byte_size)
1781 {
1782 error.SetErrorString("unable to write value to memory");
1783 return false;
1784 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001785 }
1786 }
Jim Ingham4b536182011-08-09 02:12:22 +00001787 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001788 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001789 {
1790 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1791 DataExtractor new_data;
1792 new_data.SetByteOrder (m_data.GetByteOrder());
1793
1794 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1795 m_data.SetData(buffer_sp, 0);
1796 bool success = new_scalar.GetData(new_data);
1797 if (success)
1798 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001799 new_data.CopyByteOrderedData (0,
1800 byte_size,
1801 const_cast<uint8_t *>(m_data.GetDataStart()),
1802 byte_size,
1803 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001804 }
1805 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1806
1807 }
Jim Ingham4b536182011-08-09 02:12:22 +00001808 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001809 case Value::eValueTypeFileAddress:
1810 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001811 case Value::eValueTypeVector:
1812 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001813 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001814 }
1815 else
1816 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001817 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001818 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001819 }
1820 else
1821 {
1822 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001823 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001824 return false;
1825 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001826
1827 // If we have reached this point, then we have successfully changed the value.
1828 SetNeedsUpdate();
1829 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001830}
1831
Greg Clayton81e871e2012-02-04 02:27:34 +00001832bool
1833ValueObject::GetDeclaration (Declaration &decl)
1834{
1835 decl.Clear();
1836 return false;
1837}
1838
Greg Clayton84db9102012-03-26 23:03:23 +00001839ConstString
1840ValueObject::GetTypeName()
1841{
1842 return ClangASTType::GetConstTypeName (GetClangAST(), GetClangType());
1843}
1844
1845ConstString
1846ValueObject::GetQualifiedTypeName()
1847{
1848 return ClangASTType::GetConstQualifiedTypeName (GetClangAST(), GetClangType());
1849}
1850
1851
Greg Claytonafacd142011-09-02 01:15:17 +00001852LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001853ValueObject::GetObjectRuntimeLanguage ()
1854{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001855 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1856 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001857}
1858
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001859void
Jim Ingham58b59f92011-04-22 23:53:53 +00001860ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001861{
Jim Ingham58b59f92011-04-22 23:53:53 +00001862 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001863}
1864
1865ValueObjectSP
1866ValueObject::GetSyntheticChild (const ConstString &key) const
1867{
1868 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001869 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001870 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001871 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001872 return synthetic_child_sp;
1873}
1874
Greg Clayton2452ab72013-02-08 22:02:02 +00001875uint32_t
1876ValueObject::GetTypeInfo (clang_type_t *pointee_or_element_clang_type)
1877{
1878 return ClangASTContext::GetTypeInfo (GetClangType(), GetClangAST(), pointee_or_element_clang_type);
1879}
1880
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001881bool
1882ValueObject::IsPointerType ()
1883{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001884 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001885}
1886
Jim Inghamb7603bb2011-03-18 00:05:18 +00001887bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001888ValueObject::IsArrayType ()
1889{
Greg Clayton4ef877f2012-12-06 02:33:54 +00001890 return ClangASTContext::IsArrayType (GetClangType(), NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00001891}
1892
1893bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001894ValueObject::IsScalarType ()
1895{
1896 return ClangASTContext::IsScalarType (GetClangType());
1897}
1898
1899bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001900ValueObject::IsIntegerType (bool &is_signed)
1901{
1902 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1903}
Greg Clayton73b472d2010-10-27 03:32:59 +00001904
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001905bool
1906ValueObject::IsPointerOrReferenceType ()
1907{
Greg Clayton007d5be2011-05-30 00:49:24 +00001908 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1909}
1910
1911bool
Greg Claytondea8cb42011-06-29 22:09:02 +00001912ValueObject::IsPossibleDynamicType ()
1913{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00001914 ExecutionContext exe_ctx (GetExecutionContextRef());
1915 Process *process = exe_ctx.GetProcessPtr();
1916 if (process)
1917 return process->IsPossibleDynamicValue(*this);
1918 else
Greg Clayton70364252012-08-31 18:56:24 +00001919 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType(), NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00001920}
1921
Enrico Granata9e7b3882012-12-13 23:50:33 +00001922bool
1923ValueObject::IsObjCNil ()
1924{
Enrico Granata7277d202013-03-15 23:33:15 +00001925 const uint32_t mask = ClangASTContext::eTypeIsObjC | ClangASTContext::eTypeIsPointer;
1926 bool isObjCpointer = ( ((ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), NULL)) & mask) == mask);
1927 if (!isObjCpointer)
1928 return false;
Enrico Granata9e7b3882012-12-13 23:50:33 +00001929 bool canReadValue = true;
1930 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
Enrico Granata7277d202013-03-15 23:33:15 +00001931 return canReadValue && isZero;
Enrico Granata9e7b3882012-12-13 23:50:33 +00001932}
1933
Greg Claytonafacd142011-09-02 01:15:17 +00001934ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00001935ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001936{
Greg Clayton2452ab72013-02-08 22:02:02 +00001937 const uint32_t type_info = GetTypeInfo ();
1938 if (type_info & ClangASTContext::eTypeIsArray)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001939 return GetSyntheticArrayMemberFromArray(index, can_create);
1940
Greg Clayton2452ab72013-02-08 22:02:02 +00001941 if (type_info & ClangASTContext::eTypeIsPointer)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001942 return GetSyntheticArrayMemberFromPointer(index, can_create);
1943
1944 return ValueObjectSP();
1945
1946}
1947
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001948ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00001949ValueObject::GetSyntheticArrayMemberFromPointer (size_t index, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001950{
1951 ValueObjectSP synthetic_child_sp;
1952 if (IsPointerType ())
1953 {
1954 char index_str[64];
Greg Claytonc7bece562013-01-25 18:06:21 +00001955 snprintf(index_str, sizeof(index_str), "[%zu]", index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001956 ConstString index_const_str(index_str);
1957 // Check if we have already created a synthetic array member in this
1958 // valid object. If we have we will re-use it.
1959 synthetic_child_sp = GetSyntheticChild (index_const_str);
1960 if (!synthetic_child_sp)
1961 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001962 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001963 // We haven't made a synthetic array member for INDEX yet, so
1964 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001965 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001966
1967 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001968 if (synthetic_child)
1969 {
1970 AddSyntheticChild(index_const_str, synthetic_child);
1971 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001972 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001973 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001974 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001975 }
1976 }
1977 return synthetic_child_sp;
1978}
Jim Ingham22777012010-09-23 02:01:19 +00001979
Greg Claytondaf515f2011-07-09 20:12:33 +00001980// This allows you to create an array member using and index
1981// that doesn't not fall in the normal bounds of the array.
1982// Many times structure can be defined as:
1983// struct Collection
1984// {
1985// uint32_t item_count;
1986// Item item_array[0];
1987// };
1988// The size of the "item_array" is 1, but many times in practice
1989// there are more items in "item_array".
1990
1991ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00001992ValueObject::GetSyntheticArrayMemberFromArray (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00001993{
1994 ValueObjectSP synthetic_child_sp;
1995 if (IsArrayType ())
1996 {
1997 char index_str[64];
Greg Claytonc7bece562013-01-25 18:06:21 +00001998 snprintf(index_str, sizeof(index_str), "[%zu]", index);
Greg Claytondaf515f2011-07-09 20:12:33 +00001999 ConstString index_const_str(index_str);
2000 // Check if we have already created a synthetic array member in this
2001 // valid object. If we have we will re-use it.
2002 synthetic_child_sp = GetSyntheticChild (index_const_str);
2003 if (!synthetic_child_sp)
2004 {
2005 ValueObject *synthetic_child;
2006 // We haven't made a synthetic array member for INDEX yet, so
2007 // lets make one and cache it for any future reference.
2008 synthetic_child = CreateChildAtIndex(0, true, index);
2009
2010 // Cache the value if we got one back...
2011 if (synthetic_child)
2012 {
2013 AddSyntheticChild(index_const_str, synthetic_child);
2014 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002015 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00002016 synthetic_child_sp->m_is_array_item_for_pointer = true;
2017 }
2018 }
2019 }
2020 return synthetic_child_sp;
2021}
2022
Enrico Granata9fc19442011-07-06 02:13:41 +00002023ValueObjectSP
2024ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2025{
2026 ValueObjectSP synthetic_child_sp;
2027 if (IsScalarType ())
2028 {
2029 char index_str[64];
2030 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2031 ConstString index_const_str(index_str);
2032 // Check if we have already created a synthetic array member in this
2033 // valid object. If we have we will re-use it.
2034 synthetic_child_sp = GetSyntheticChild (index_const_str);
2035 if (!synthetic_child_sp)
2036 {
2037 ValueObjectChild *synthetic_child;
2038 // We haven't made a synthetic array member for INDEX yet, so
2039 // lets make one and cache it for any future reference.
2040 synthetic_child = new ValueObjectChild(*this,
2041 GetClangAST(),
2042 GetClangType(),
2043 index_const_str,
2044 GetByteSize(),
2045 0,
2046 to-from+1,
2047 from,
2048 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002049 false,
2050 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002051
2052 // Cache the value if we got one back...
2053 if (synthetic_child)
2054 {
2055 AddSyntheticChild(index_const_str, synthetic_child);
2056 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002057 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002058 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2059 }
2060 }
2061 }
2062 return synthetic_child_sp;
2063}
2064
Greg Claytonafacd142011-09-02 01:15:17 +00002065ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00002066ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
2067{
2068
2069 ValueObjectSP synthetic_child_sp;
2070
2071 char name_str[64];
2072 snprintf(name_str, sizeof(name_str), "@%i", offset);
2073 ConstString name_const_str(name_str);
2074
2075 // Check if we have already created a synthetic array member in this
2076 // valid object. If we have we will re-use it.
2077 synthetic_child_sp = GetSyntheticChild (name_const_str);
2078
2079 if (synthetic_child_sp.get())
2080 return synthetic_child_sp;
2081
2082 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002083 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002084
2085 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2086 type.GetASTContext(),
2087 type.GetOpaqueQualType(),
2088 name_const_str,
2089 type.GetTypeByteSize(),
2090 offset,
2091 0,
2092 0,
2093 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002094 false,
2095 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002096 if (synthetic_child)
2097 {
2098 AddSyntheticChild(name_const_str, synthetic_child);
2099 synthetic_child_sp = synthetic_child->GetSP();
2100 synthetic_child_sp->SetName(name_const_str);
2101 synthetic_child_sp->m_is_child_at_offset = true;
2102 }
2103 return synthetic_child_sp;
2104}
2105
Enrico Granatad55546b2011-07-22 00:16:08 +00002106// your expression path needs to have a leading . or ->
2107// (unless it somehow "looks like" an array, in which case it has
2108// a leading [ symbol). while the [ is meaningful and should be shown
2109// to the user, . and -> are just parser design, but by no means
2110// added information for the user.. strip them off
2111static const char*
2112SkipLeadingExpressionPathSeparators(const char* expression)
2113{
2114 if (!expression || !expression[0])
2115 return expression;
2116 if (expression[0] == '.')
2117 return expression+1;
2118 if (expression[0] == '-' && expression[1] == '>')
2119 return expression+2;
2120 return expression;
2121}
2122
Greg Claytonafacd142011-09-02 01:15:17 +00002123ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002124ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2125{
2126 ValueObjectSP synthetic_child_sp;
2127 ConstString name_const_string(expression);
2128 // Check if we have already created a synthetic array member in this
2129 // valid object. If we have we will re-use it.
2130 synthetic_child_sp = GetSyntheticChild (name_const_string);
2131 if (!synthetic_child_sp)
2132 {
2133 // We haven't made a synthetic array member for expression yet, so
2134 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002135 synthetic_child_sp = GetValueForExpressionPath(expression,
2136 NULL, NULL, NULL,
2137 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
Enrico Granatad55546b2011-07-22 00:16:08 +00002138
2139 // Cache the value if we got one back...
2140 if (synthetic_child_sp.get())
2141 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002142 // 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 +00002143 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002144 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002145 }
2146 }
2147 return synthetic_child_sp;
2148}
2149
2150void
Enrico Granata86cc9822012-03-19 22:58:49 +00002151ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002152{
Enrico Granata86cc9822012-03-19 22:58:49 +00002153 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002154 return;
2155
Enrico Granatac5bc4122012-03-27 02:35:13 +00002156 TargetSP target_sp(GetTargetSP());
2157 if (target_sp && (target_sp->GetEnableSyntheticValue() == false || target_sp->GetSuppressSyntheticValue() == true))
2158 {
2159 m_synthetic_value = NULL;
2160 return;
2161 }
2162
Enrico Granatae3e91512012-10-22 18:18:36 +00002163 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2164
Enrico Granata5548cb52013-01-28 23:47:25 +00002165 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002166 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002167
Enrico Granata0c489f52012-03-01 04:24:26 +00002168 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002169 return;
2170
Enrico Granatae3e91512012-10-22 18:18:36 +00002171 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2172 return;
2173
Enrico Granata86cc9822012-03-19 22:58:49 +00002174 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002175}
2176
Jim Ingham78a685a2011-04-16 00:01:13 +00002177void
Greg Claytonafacd142011-09-02 01:15:17 +00002178ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002179{
Greg Claytonafacd142011-09-02 01:15:17 +00002180 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002181 return;
2182
Jim Ingham58b59f92011-04-22 23:53:53 +00002183 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002184 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002185 ExecutionContext exe_ctx (GetExecutionContextRef());
2186 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002187 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002188 {
2189 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002190 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002191 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002192 }
2193}
2194
Jim Ingham58b59f92011-04-22 23:53:53 +00002195ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002196ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002197{
Greg Claytonafacd142011-09-02 01:15:17 +00002198 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002199 return ValueObjectSP();
2200
2201 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002202 {
Jim Ingham2837b762011-05-04 03:43:18 +00002203 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002204 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002205 if (m_dynamic_value)
2206 return m_dynamic_value->GetSP();
2207 else
2208 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002209}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002210
Jim Ingham60dbabb2011-12-08 19:44:08 +00002211ValueObjectSP
2212ValueObject::GetStaticValue()
2213{
2214 return GetSP();
2215}
2216
Enrico Granata886147f2012-05-08 18:47:08 +00002217lldb::ValueObjectSP
2218ValueObject::GetNonSyntheticValue ()
2219{
2220 return GetSP();
2221}
2222
Enrico Granatad55546b2011-07-22 00:16:08 +00002223ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002224ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002225{
Enrico Granata86cc9822012-03-19 22:58:49 +00002226 if (use_synthetic == false)
2227 return ValueObjectSP();
2228
Enrico Granatad55546b2011-07-22 00:16:08 +00002229 CalculateSyntheticValue(use_synthetic);
2230
2231 if (m_synthetic_value)
2232 return m_synthetic_value->GetSP();
2233 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002234 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002235}
2236
Greg Claytone221f822011-01-21 01:59:00 +00002237bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002238ValueObject::HasSyntheticValue()
2239{
Enrico Granata5548cb52013-01-28 23:47:25 +00002240 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002241
Enrico Granata0c489f52012-03-01 04:24:26 +00002242 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002243 return false;
2244
Enrico Granata86cc9822012-03-19 22:58:49 +00002245 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002246
2247 if (m_synthetic_value)
2248 return true;
2249 else
2250 return false;
2251}
2252
2253bool
Greg Claytone221f822011-01-21 01:59:00 +00002254ValueObject::GetBaseClassPath (Stream &s)
2255{
2256 if (IsBaseClass())
2257 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002258 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00002259 clang_type_t clang_type = GetClangType();
2260 std::string cxx_class_name;
2261 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
2262 if (this_had_base_class)
2263 {
2264 if (parent_had_base_class)
2265 s.PutCString("::");
2266 s.PutCString(cxx_class_name.c_str());
2267 }
2268 return parent_had_base_class || this_had_base_class;
2269 }
2270 return false;
2271}
2272
2273
2274ValueObject *
2275ValueObject::GetNonBaseClassParent()
2276{
Jim Ingham78a685a2011-04-16 00:01:13 +00002277 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002278 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002279 if (GetParent()->IsBaseClass())
2280 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002281 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002282 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002283 }
2284 return NULL;
2285}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002286
2287void
Enrico Granata4becb372011-06-29 22:27:15 +00002288ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002289{
Greg Claytone221f822011-01-21 01:59:00 +00002290 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002291
Enrico Granata86cc9822012-03-19 22:58:49 +00002292 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002293 {
Enrico Granata4becb372011-06-29 22:27:15 +00002294 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2295 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2296 // the eHonorPointers mode is meant to produce strings in this latter format
2297 s.PutCString("*(");
2298 }
Greg Claytone221f822011-01-21 01:59:00 +00002299
Enrico Granata4becb372011-06-29 22:27:15 +00002300 ValueObject* parent = GetParent();
2301
2302 if (parent)
2303 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002304
2305 // if we are a deref_of_parent just because we are synthetic array
2306 // members made up to allow ptr[%d] syntax to work in variable
2307 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002308 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002309 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002310
Greg Claytone221f822011-01-21 01:59:00 +00002311 if (!IsBaseClass())
2312 {
2313 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002314 {
Greg Claytone221f822011-01-21 01:59:00 +00002315 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2316 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002317 {
Greg Claytone221f822011-01-21 01:59:00 +00002318 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2319 if (non_base_class_parent_clang_type)
2320 {
2321 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2322
Enrico Granata86cc9822012-03-19 22:58:49 +00002323 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002324 {
2325 s.PutCString("->");
2326 }
Enrico Granata4becb372011-06-29 22:27:15 +00002327 else
2328 {
2329 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2330 {
2331 s.PutCString("->");
2332 }
2333 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2334 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2335 {
2336 s.PutChar('.');
2337 }
Greg Claytone221f822011-01-21 01:59:00 +00002338 }
2339 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002340 }
Greg Claytone221f822011-01-21 01:59:00 +00002341
2342 const char *name = GetName().GetCString();
2343 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002344 {
Greg Claytone221f822011-01-21 01:59:00 +00002345 if (qualify_cxx_base_classes)
2346 {
2347 if (GetBaseClassPath (s))
2348 s.PutCString("::");
2349 }
2350 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002351 }
2352 }
2353 }
2354
Enrico Granata86cc9822012-03-19 22:58:49 +00002355 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002356 {
Greg Claytone221f822011-01-21 01:59:00 +00002357 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002358 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002359}
2360
Greg Claytonafacd142011-09-02 01:15:17 +00002361ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002362ValueObject::GetValueForExpressionPath(const char* expression,
2363 const char** first_unparsed,
2364 ExpressionPathScanEndReason* reason_to_stop,
2365 ExpressionPathEndResultType* final_value_type,
2366 const GetValueForExpressionPathOptions& options,
2367 ExpressionPathAftermath* final_task_on_target)
2368{
2369
2370 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002371 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2372 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002373 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002374
2375 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2376 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2377 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2378 final_value_type ? final_value_type : &dummy_final_value_type,
2379 options,
2380 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2381
Enrico Granata86cc9822012-03-19 22:58:49 +00002382 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002383 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002384
Enrico Granata86cc9822012-03-19 22:58:49 +00002385 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 +00002386 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002387 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002388 {
2389 Error error;
2390 ValueObjectSP final_value = ret_val->Dereference(error);
2391 if (error.Fail() || !final_value.get())
2392 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002393 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002394 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002395 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002396 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002397 return ValueObjectSP();
2398 }
2399 else
2400 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002401 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002402 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002403 return final_value;
2404 }
2405 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002406 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002407 {
2408 Error error;
2409 ValueObjectSP final_value = ret_val->AddressOf(error);
2410 if (error.Fail() || !final_value.get())
2411 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002412 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002413 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002414 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002415 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002416 return ValueObjectSP();
2417 }
2418 else
2419 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002420 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002421 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002422 return final_value;
2423 }
2424 }
2425 }
2426 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2427}
2428
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002429int
2430ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002431 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002432 const char** first_unparsed,
2433 ExpressionPathScanEndReason* reason_to_stop,
2434 ExpressionPathEndResultType* final_value_type,
2435 const GetValueForExpressionPathOptions& options,
2436 ExpressionPathAftermath* final_task_on_target)
2437{
2438 const char* dummy_first_unparsed;
2439 ExpressionPathScanEndReason dummy_reason_to_stop;
2440 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002441 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002442
2443 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2444 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2445 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2446 final_value_type ? final_value_type : &dummy_final_value_type,
2447 options,
2448 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2449
2450 if (!ret_val.get()) // if there are errors, I add nothing to the list
2451 return 0;
2452
Enrico Granata86ea8d82012-03-29 01:34:34 +00002453 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002454 {
2455 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002456 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002457 {
2458 list->Append(ret_val);
2459 return 1;
2460 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002461 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 +00002462 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002463 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002464 {
2465 Error error;
2466 ValueObjectSP final_value = ret_val->Dereference(error);
2467 if (error.Fail() || !final_value.get())
2468 {
Greg Clayton23f59502012-07-17 03:23:13 +00002469 if (reason_to_stop)
2470 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2471 if (final_value_type)
2472 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002473 return 0;
2474 }
2475 else
2476 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002477 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002478 list->Append(final_value);
2479 return 1;
2480 }
2481 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002482 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002483 {
2484 Error error;
2485 ValueObjectSP final_value = ret_val->AddressOf(error);
2486 if (error.Fail() || !final_value.get())
2487 {
Greg Clayton23f59502012-07-17 03:23:13 +00002488 if (reason_to_stop)
2489 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2490 if (final_value_type)
2491 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002492 return 0;
2493 }
2494 else
2495 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002496 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002497 list->Append(final_value);
2498 return 1;
2499 }
2500 }
2501 }
2502 }
2503 else
2504 {
2505 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2506 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2507 ret_val,
2508 list,
2509 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2510 final_value_type ? final_value_type : &dummy_final_value_type,
2511 options,
2512 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2513 }
2514 // in any non-covered case, just do the obviously right thing
2515 list->Append(ret_val);
2516 return 1;
2517}
2518
Greg Claytonafacd142011-09-02 01:15:17 +00002519ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002520ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2521 const char** first_unparsed,
2522 ExpressionPathScanEndReason* reason_to_stop,
2523 ExpressionPathEndResultType* final_result,
2524 const GetValueForExpressionPathOptions& options,
2525 ExpressionPathAftermath* what_next)
2526{
2527 ValueObjectSP root = GetSP();
2528
2529 if (!root.get())
2530 return ValueObjectSP();
2531
2532 *first_unparsed = expression_cstr;
2533
2534 while (true)
2535 {
2536
2537 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2538
Greg Claytonafacd142011-09-02 01:15:17 +00002539 clang_type_t root_clang_type = root->GetClangType();
2540 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002541 Flags root_clang_type_info,pointee_clang_type_info;
2542
2543 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2544 if (pointee_clang_type)
2545 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002546
2547 if (!expression_cstr || *expression_cstr == '\0')
2548 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002549 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002550 return root;
2551 }
2552
2553 switch (*expression_cstr)
2554 {
2555 case '-':
2556 {
2557 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002558 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 +00002559 {
2560 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002561 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2562 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002563 return ValueObjectSP();
2564 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002565 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2566 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002567 options.m_no_fragile_ivar)
2568 {
2569 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002570 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2571 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002572 return ValueObjectSP();
2573 }
2574 if (expression_cstr[1] != '>')
2575 {
2576 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002577 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2578 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002579 return ValueObjectSP();
2580 }
2581 expression_cstr++; // skip the -
2582 }
2583 case '.': // or fallthrough from ->
2584 {
2585 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002586 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 +00002587 {
2588 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002589 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2590 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002591 return ValueObjectSP();
2592 }
2593 expression_cstr++; // skip .
2594 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2595 ConstString child_name;
2596 if (!next_separator) // if no other separator just expand this last layer
2597 {
2598 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002599 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2600
2601 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002602 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002603 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002604 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2605 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002606 return child_valobj_sp;
2607 }
2608 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2609 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002610 if (root->IsSynthetic())
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002611 {
2612 *first_unparsed = expression_cstr;
2613 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2614 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2615 return ValueObjectSP();
2616 }
2617
2618 child_valobj_sp = root->GetSyntheticValue();
Enrico Granata86cc9822012-03-19 22:58:49 +00002619 if (child_valobj_sp.get())
2620 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002621 }
2622
2623 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2624 // so we hit the "else" branch, and return an error
2625 if(child_valobj_sp.get()) // if it worked, just return
2626 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002627 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002628 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2629 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002630 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002631 }
2632 else
2633 {
2634 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002635 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2636 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002637 return ValueObjectSP();
2638 }
2639 }
2640 else // other layers do expand
2641 {
2642 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002643 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2644 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002645 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002646 root = child_valobj_sp;
2647 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002648 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002649 continue;
2650 }
2651 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2652 {
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002653 if (root->IsSynthetic())
2654 {
2655 *first_unparsed = expression_cstr;
2656 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2657 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2658 return ValueObjectSP();
2659 }
2660
Enrico Granata86cc9822012-03-19 22:58:49 +00002661 child_valobj_sp = root->GetSyntheticValue(true);
2662 if (child_valobj_sp)
2663 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002664 }
2665
2666 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2667 // so we hit the "else" branch, and return an error
2668 if(child_valobj_sp.get()) // if it worked, move on
2669 {
2670 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002671 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002672 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002673 continue;
2674 }
2675 else
2676 {
2677 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002678 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2679 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002680 return ValueObjectSP();
2681 }
2682 }
2683 break;
2684 }
2685 case '[':
2686 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002687 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 +00002688 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002689 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002690 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002691 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2692 {
2693 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002694 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2695 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002696 return ValueObjectSP();
2697 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002698 }
2699 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2700 {
2701 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002702 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2703 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002704 return ValueObjectSP();
2705 }
2706 }
2707 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2708 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002709 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002710 {
2711 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002712 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2713 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002714 return ValueObjectSP();
2715 }
2716 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2717 {
2718 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002719 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2720 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002721 return root;
2722 }
2723 }
2724 const char *separator_position = ::strchr(expression_cstr+1,'-');
2725 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2726 if (!close_bracket_position) // if there is no ], this is a syntax error
2727 {
2728 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002729 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2730 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002731 return ValueObjectSP();
2732 }
2733 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2734 {
2735 char *end = NULL;
2736 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2737 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2738 {
2739 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002740 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2741 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002742 return ValueObjectSP();
2743 }
2744 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2745 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002746 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002747 {
2748 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002749 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2750 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002751 return root;
2752 }
2753 else
2754 {
2755 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002756 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2757 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002758 return ValueObjectSP();
2759 }
2760 }
2761 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002762 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002763 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002764 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2765 if (!child_valobj_sp)
2766 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002767 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002768 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2769 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002770 if (child_valobj_sp)
2771 {
2772 root = child_valobj_sp;
2773 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002774 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002775 continue;
2776 }
2777 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002778 {
2779 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002780 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2781 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002782 return ValueObjectSP();
2783 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002784 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002785 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002786 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002787 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 +00002788 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002789 {
2790 Error error;
2791 root = root->Dereference(error);
2792 if (error.Fail() || !root.get())
2793 {
2794 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002795 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2796 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002797 return ValueObjectSP();
2798 }
2799 else
2800 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002801 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002802 continue;
2803 }
2804 }
2805 else
2806 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002807 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Clayton84db9102012-03-26 23:03:23 +00002808 root->GetClangType()) == eLanguageTypeObjC
2809 && ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2810 && root->HasSyntheticValue()
2811 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002812 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002813 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002814 }
2815 else
2816 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002817 if (!root.get())
2818 {
2819 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002820 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2821 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002822 return ValueObjectSP();
2823 }
2824 else
2825 {
2826 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002827 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002828 continue;
2829 }
2830 }
2831 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002832 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002833 {
2834 root = root->GetSyntheticBitFieldChild(index, index, true);
2835 if (!root.get())
2836 {
2837 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002838 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2839 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002840 return ValueObjectSP();
2841 }
2842 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2843 {
2844 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002845 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2846 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002847 return root;
2848 }
2849 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002850 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002851 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002852 if (root->HasSyntheticValue())
2853 root = root->GetSyntheticValue();
2854 else if (!root->IsSynthetic())
2855 {
2856 *first_unparsed = expression_cstr;
2857 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2858 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2859 return ValueObjectSP();
2860 }
2861 // if we are here, then root itself is a synthetic VO.. should be good to go
2862
Enrico Granata27b625e2011-08-09 01:04:56 +00002863 if (!root.get())
2864 {
2865 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002866 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2867 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2868 return ValueObjectSP();
2869 }
2870 root = root->GetChildAtIndex(index, true);
2871 if (!root.get())
2872 {
2873 *first_unparsed = expression_cstr;
2874 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2875 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002876 return ValueObjectSP();
2877 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002878 else
2879 {
2880 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002881 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002882 continue;
2883 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002884 }
2885 else
2886 {
2887 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002888 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2889 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002890 return ValueObjectSP();
2891 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002892 }
2893 else // we have a low and a high index
2894 {
2895 char *end = NULL;
2896 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2897 if (!end || end != separator_position) // if something weird is in our way return an error
2898 {
2899 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002900 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2901 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002902 return ValueObjectSP();
2903 }
2904 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2905 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2906 {
2907 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002908 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2909 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002910 return ValueObjectSP();
2911 }
2912 if (index_lower > index_higher) // swap indices if required
2913 {
2914 unsigned long temp = index_lower;
2915 index_lower = index_higher;
2916 index_higher = temp;
2917 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002918 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002919 {
2920 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2921 if (!root.get())
2922 {
2923 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002924 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2925 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002926 return ValueObjectSP();
2927 }
2928 else
2929 {
2930 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002931 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2932 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002933 return root;
2934 }
2935 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002936 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 +00002937 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002938 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002939 {
2940 Error error;
2941 root = root->Dereference(error);
2942 if (error.Fail() || !root.get())
2943 {
2944 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002945 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2946 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002947 return ValueObjectSP();
2948 }
2949 else
2950 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002951 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002952 continue;
2953 }
2954 }
2955 else
2956 {
2957 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002958 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2959 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002960 return root;
2961 }
2962 }
2963 break;
2964 }
2965 default: // some non-separator is in the way
2966 {
2967 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002968 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2969 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002970 return ValueObjectSP();
2971 break;
2972 }
2973 }
2974 }
2975}
2976
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002977int
2978ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2979 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002980 ValueObjectSP root,
2981 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002982 ExpressionPathScanEndReason* reason_to_stop,
2983 ExpressionPathEndResultType* final_result,
2984 const GetValueForExpressionPathOptions& options,
2985 ExpressionPathAftermath* what_next)
2986{
2987 if (!root.get())
2988 return 0;
2989
2990 *first_unparsed = expression_cstr;
2991
2992 while (true)
2993 {
2994
2995 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2996
Greg Claytonafacd142011-09-02 01:15:17 +00002997 clang_type_t root_clang_type = root->GetClangType();
2998 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002999 Flags root_clang_type_info,pointee_clang_type_info;
3000
3001 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
3002 if (pointee_clang_type)
3003 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
3004
3005 if (!expression_cstr || *expression_cstr == '\0')
3006 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003007 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003008 list->Append(root);
3009 return 1;
3010 }
3011
3012 switch (*expression_cstr)
3013 {
3014 case '[':
3015 {
3016 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
3017 {
3018 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
3019 {
3020 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003021 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3022 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003023 return 0;
3024 }
3025 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3026 {
3027 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003028 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3029 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003030 return 0;
3031 }
3032 }
3033 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3034 {
3035 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3036 {
3037 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003038 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3039 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003040 return 0;
3041 }
3042 else // expand this into list
3043 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003044 const size_t max_index = root->GetNumChildren() - 1;
3045 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003046 {
3047 ValueObjectSP child =
3048 root->GetChildAtIndex(index, true);
3049 list->Append(child);
3050 }
3051 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003052 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3053 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003054 return max_index; // tell me number of items I added to the VOList
3055 }
3056 }
3057 const char *separator_position = ::strchr(expression_cstr+1,'-');
3058 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3059 if (!close_bracket_position) // if there is no ], this is a syntax error
3060 {
3061 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003062 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3063 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003064 return 0;
3065 }
3066 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3067 {
3068 char *end = NULL;
3069 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3070 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3071 {
3072 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003073 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3074 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003075 return 0;
3076 }
3077 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3078 {
3079 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3080 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003081 const size_t max_index = root->GetNumChildren() - 1;
3082 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003083 {
3084 ValueObjectSP child =
3085 root->GetChildAtIndex(index, true);
3086 list->Append(child);
3087 }
3088 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003089 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3090 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003091 return max_index; // tell me number of items I added to the VOList
3092 }
3093 else
3094 {
3095 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003096 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3097 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003098 return 0;
3099 }
3100 }
3101 // from here on we do have a valid index
3102 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3103 {
3104 root = root->GetChildAtIndex(index, true);
3105 if (!root.get())
3106 {
3107 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003108 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3109 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003110 return 0;
3111 }
3112 else
3113 {
3114 list->Append(root);
3115 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003116 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3117 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003118 return 1;
3119 }
3120 }
3121 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
3122 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003123 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 +00003124 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3125 {
3126 Error error;
3127 root = root->Dereference(error);
3128 if (error.Fail() || !root.get())
3129 {
3130 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003131 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3132 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003133 return 0;
3134 }
3135 else
3136 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003137 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003138 continue;
3139 }
3140 }
3141 else
3142 {
3143 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3144 if (!root.get())
3145 {
3146 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003147 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3148 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003149 return 0;
3150 }
3151 else
3152 {
3153 list->Append(root);
3154 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003155 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3156 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003157 return 1;
3158 }
3159 }
3160 }
3161 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3162 {
3163 root = root->GetSyntheticBitFieldChild(index, index, true);
3164 if (!root.get())
3165 {
3166 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003167 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3168 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003169 return 0;
3170 }
3171 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3172 {
3173 list->Append(root);
3174 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003175 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3176 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003177 return 1;
3178 }
3179 }
3180 }
3181 else // we have a low and a high index
3182 {
3183 char *end = NULL;
3184 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3185 if (!end || end != separator_position) // if something weird is in our way return an error
3186 {
3187 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003188 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3189 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003190 return 0;
3191 }
3192 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3193 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3194 {
3195 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003196 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3197 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003198 return 0;
3199 }
3200 if (index_lower > index_higher) // swap indices if required
3201 {
3202 unsigned long temp = index_lower;
3203 index_lower = index_higher;
3204 index_higher = temp;
3205 }
3206 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
3207 {
3208 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3209 if (!root.get())
3210 {
3211 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003212 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3213 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003214 return 0;
3215 }
3216 else
3217 {
3218 list->Append(root);
3219 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003220 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3221 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003222 return 1;
3223 }
3224 }
3225 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 +00003226 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003227 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3228 {
3229 Error error;
3230 root = root->Dereference(error);
3231 if (error.Fail() || !root.get())
3232 {
3233 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003234 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3235 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003236 return 0;
3237 }
3238 else
3239 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003240 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003241 continue;
3242 }
3243 }
3244 else
3245 {
Johnny Chen44805302011-07-19 19:48:13 +00003246 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003247 index <= index_higher; index++)
3248 {
3249 ValueObjectSP child =
3250 root->GetChildAtIndex(index, true);
3251 list->Append(child);
3252 }
3253 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003254 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3255 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003256 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3257 }
3258 }
3259 break;
3260 }
3261 default: // some non-[ separator, or something entirely wrong, is in the way
3262 {
3263 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003264 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3265 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003266 return 0;
3267 break;
3268 }
3269 }
3270 }
3271}
3272
Enrico Granata0c489f52012-03-01 04:24:26 +00003273static void
3274DumpValueObject_Impl (Stream &s,
3275 ValueObject *valobj,
3276 const ValueObject::DumpValueObjectOptions& options,
3277 uint32_t ptr_depth,
3278 uint32_t curr_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003279{
Greg Clayton007d5be2011-05-30 00:49:24 +00003280 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003281 {
Enrico Granata5548cb52013-01-28 23:47:25 +00003282 bool update_success = valobj->UpdateValueIfNeeded (true);
Greg Clayton007d5be2011-05-30 00:49:24 +00003283
Enrico Granata0c489f52012-03-01 04:24:26 +00003284 const char *root_valobj_name =
3285 options.m_root_valobj_name.empty() ?
3286 valobj->GetName().AsCString() :
3287 options.m_root_valobj_name.c_str();
3288
3289 if (update_success && options.m_use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00003290 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003291 ValueObject *dynamic_value = valobj->GetDynamicValue(options.m_use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003292 if (dynamic_value)
3293 valobj = dynamic_value;
3294 }
3295
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003296 clang_type_t clang_type = valobj->GetClangType();
3297
Greg Clayton73b472d2010-10-27 03:32:59 +00003298 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003299 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00003300 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
3301 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003302
Enrico Granata0c489f52012-03-01 04:24:26 +00003303 const bool print_valobj = options.m_flat_output == false || has_value;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003304
3305 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003306 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003307 if (options.m_show_location)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003308 {
Jim Ingham6035b672011-03-31 00:19:25 +00003309 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003310 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003311
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003312 s.Indent();
Enrico Granata2b2631c2012-08-09 16:51:25 +00003313
3314 bool show_type = true;
3315 // if we are at the root-level and been asked to hide the root's type, then hide it
3316 if (curr_depth == 0 && options.m_hide_root_type)
3317 show_type = false;
3318 else
3319 // otherwise decide according to the usual rules (asked to show types - always at the root level)
3320 show_type = options.m_show_types || (curr_depth == 0 && !options.m_flat_output);
3321
3322 if (show_type)
Enrico Granataf7b1a342013-01-23 01:17:27 +00003323 s.Printf("(%s) ", valobj->GetQualifiedTypeName().AsCString("<invalid type>"));
Greg Clayton1d3afba2010-10-05 00:00:42 +00003324
Enrico Granata0c489f52012-03-01 04:24:26 +00003325 if (options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003326 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003327 // If we are showing types, also qualify the C++ base classes
Enrico Granata0c489f52012-03-01 04:24:26 +00003328 const bool qualify_cxx_base_classes = options.m_show_types;
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003329 if (!options.m_hide_name)
3330 {
3331 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
3332 s.PutCString(" =");
3333 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003334 }
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003335 else if (!options.m_hide_name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003336 {
3337 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3338 s.Printf ("%s =", name_cstr);
3339 }
3340
Enrico Granata0c489f52012-03-01 04:24:26 +00003341 if (!options.m_scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003342 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003343 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003344 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003345 }
3346
Enrico Granata0c489f52012-03-01 04:24:26 +00003347 std::string summary_str;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003348 std::string value_str;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003349 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003350 const char *sum_cstr = NULL;
Enrico Granata0c489f52012-03-01 04:24:26 +00003351 TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003352
Enrico Granata0c489f52012-03-01 04:24:26 +00003353 if (options.m_omit_summary_depth > 0)
Enrico Granata0c5ef692011-07-16 01:22:04 +00003354 entry = NULL;
3355
Enrico Granata9e7b3882012-12-13 23:50:33 +00003356 bool is_nil = valobj->IsObjCNil();
3357
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003358 if (err_cstr == NULL)
3359 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003360 if (options.m_format != eFormatDefault && options.m_format != valobj->GetFormat())
Greg Clayton6efba4f2012-01-26 21:08:30 +00003361 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003362 valobj->GetValueAsCString(options.m_format,
3363 value_str);
Greg Clayton6efba4f2012-01-26 21:08:30 +00003364 }
Enrico Granata0c489f52012-03-01 04:24:26 +00003365 else
Greg Clayton6efba4f2012-01-26 21:08:30 +00003366 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003367 val_cstr = valobj->GetValueAsCString();
3368 if (val_cstr)
3369 value_str = val_cstr;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003370 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003371 err_cstr = valobj->GetError().AsCString();
3372 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003373
3374 if (err_cstr)
3375 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003376 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003377 }
3378 else
3379 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003380 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003381 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003382 {
Enrico Granata9e7b3882012-12-13 23:50:33 +00003383 if (is_nil)
3384 sum_cstr = "nil";
3385 else if (options.m_omit_summary_depth == 0)
Enrico Granata0c489f52012-03-01 04:24:26 +00003386 {
3387 if (options.m_summary_sp)
3388 {
3389 valobj->GetSummaryAsCString(entry, summary_str);
3390 sum_cstr = summary_str.c_str();
3391 }
3392 else
3393 sum_cstr = valobj->GetSummaryAsCString();
3394 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003395
Greg Clayton6efba4f2012-01-26 21:08:30 +00003396 // Make sure we have a value and make sure the summary didn't
Enrico Granata9e7b3882012-12-13 23:50:33 +00003397 // specify that the value should not be printed - and do not print
3398 // the value if this thing is nil
Enrico Granatac2a58d72013-03-25 19:46:48 +00003399 // (but show the value if the user passes a format explicitly)
3400 if (!is_nil && !value_str.empty() && (entry == NULL || (entry->DoesPrintValue() || options.m_format != eFormatDefault) || sum_cstr == NULL) && !options.m_hide_value)
Greg Clayton6efba4f2012-01-26 21:08:30 +00003401 s.Printf(" %s", value_str.c_str());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003402
Enrico Granata9dd75c82011-07-15 23:30:15 +00003403 if (sum_cstr)
Enrico Granata0c489f52012-03-01 04:24:26 +00003404 s.Printf(" %s", sum_cstr);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003405
Enrico Granata9e7b3882012-12-13 23:50:33 +00003406 // let's avoid the overly verbose no description error for a nil thing
3407 if (options.m_use_objc && !is_nil)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003408 {
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003409 if (!options.m_hide_value || !options.m_hide_name)
3410 s.Printf(" ");
Jim Ingham6035b672011-03-31 00:19:25 +00003411 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003412 if (object_desc)
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003413 s.Printf("%s\n", object_desc);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003414 else
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003415 s.Printf ("[no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003416 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003417 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003418 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003419
Enrico Granata0c489f52012-03-01 04:24:26 +00003420 if (curr_depth < options.m_max_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003421 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003422 // We will show children for all concrete types. We won't show
3423 // pointer contents unless a pointer depth has been specified.
3424 // We won't reference contents unless the reference is the
3425 // root object (depth of zero).
3426 bool print_children = true;
3427
3428 // Use a new temporary pointer depth in case we override the
3429 // current pointer depth below...
3430 uint32_t curr_ptr_depth = ptr_depth;
3431
3432 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3433 if (is_ptr || is_ref)
3434 {
3435 // We have a pointer or reference whose value is an address.
3436 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003437 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003438 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003439 print_children = false;
3440
3441 else if (is_ref && curr_depth == 0)
3442 {
3443 // If this is the root object (depth is zero) that we are showing
3444 // and it is a reference, and no pointer depth has been supplied
3445 // print out what it references. Don't do this at deeper depths
3446 // otherwise we can end up with infinite recursion...
3447 curr_ptr_depth = 1;
3448 }
3449
3450 if (curr_ptr_depth == 0)
3451 print_children = false;
3452 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003453
Enrico Granata0a3958e2011-07-02 00:25:22 +00003454 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003455 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003456 ValueObject* synth_valobj;
3457 ValueObjectSP synth_valobj_sp = valobj->GetSyntheticValue (options.m_use_synthetic);
3458 synth_valobj = (synth_valobj_sp ? synth_valobj_sp.get() : valobj);
Enrico Granatac5bc4122012-03-27 02:35:13 +00003459
Greg Claytonc7bece562013-01-25 18:06:21 +00003460 size_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003461 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003462 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003463 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003464 if (options.m_flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003465 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003466 if (print_valobj)
3467 s.EOL();
3468 }
3469 else
3470 {
3471 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003472 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003473 s.IndentMore();
3474 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003475
Greg Claytonc7bece562013-01-25 18:06:21 +00003476 const size_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00003477
Enrico Granata0c489f52012-03-01 04:24:26 +00003478 if (num_children > max_num_children && !options.m_ignore_cap)
Enrico Granata22c55d12011-08-12 02:00:06 +00003479 {
3480 num_children = max_num_children;
3481 print_dotdotdot = true;
3482 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003483
Enrico Granata0c489f52012-03-01 04:24:26 +00003484 ValueObject::DumpValueObjectOptions child_options(options);
Enrico Granatac953a6a2012-12-11 02:17:22 +00003485 child_options.SetFormat(options.m_format).SetSummary().SetRootValueObjectName();
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003486 child_options.SetScopeChecked(true).SetHideName(options.m_hide_name).SetHideValue(options.m_hide_value)
Enrico Granata0c489f52012-03-01 04:24:26 +00003487 .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0);
Greg Claytonc7bece562013-01-25 18:06:21 +00003488 for (size_t idx=0; idx<num_children; ++idx)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003489 {
Enrico Granatac482a192011-08-17 22:13:59 +00003490 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003491 if (child_sp.get())
3492 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003493 DumpValueObject_Impl (s,
3494 child_sp.get(),
3495 child_options,
3496 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
3497 curr_depth + 1);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003498 }
3499 }
3500
Enrico Granata0c489f52012-03-01 04:24:26 +00003501 if (!options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003502 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003503 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003504 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003505 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3506 Target *target = exe_ctx.GetTargetPtr();
3507 if (target)
3508 target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003509 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003510 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003511 s.IndentLess();
3512 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003513 }
3514 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003515 else if (has_children)
3516 {
3517 // Aggregate, no children...
3518 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003519 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003520 }
3521 else
3522 {
3523 if (print_valobj)
3524 s.EOL();
3525 }
3526
Greg Clayton1d3afba2010-10-05 00:00:42 +00003527 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003528 else
3529 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003530 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003531 }
3532 }
3533 else
3534 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003535 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003536 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003537 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003538 }
3539 }
3540 }
3541 }
3542}
3543
Enrico Granata0c489f52012-03-01 04:24:26 +00003544void
Greg Claytonf830dbb2012-03-22 18:15:37 +00003545ValueObject::LogValueObject (Log *log,
3546 ValueObject *valobj)
3547{
3548 if (log && valobj)
3549 return LogValueObject (log, valobj, DumpValueObjectOptions::DefaultOptions());
3550}
3551
3552void
3553ValueObject::LogValueObject (Log *log,
3554 ValueObject *valobj,
3555 const DumpValueObjectOptions& options)
3556{
3557 if (log && valobj)
3558 {
3559 StreamString s;
3560 ValueObject::DumpValueObject (s, valobj, options);
3561 if (s.GetSize())
3562 log->PutCString(s.GetData());
3563 }
3564}
3565
3566void
Enrico Granata0c489f52012-03-01 04:24:26 +00003567ValueObject::DumpValueObject (Stream &s,
3568 ValueObject *valobj)
3569{
3570
3571 if (!valobj)
3572 return;
3573
3574 DumpValueObject_Impl(s,
3575 valobj,
3576 DumpValueObjectOptions::DefaultOptions(),
3577 0,
3578 0);
3579}
3580
3581void
3582ValueObject::DumpValueObject (Stream &s,
3583 ValueObject *valobj,
3584 const DumpValueObjectOptions& options)
3585{
3586 DumpValueObject_Impl(s,
3587 valobj,
3588 options,
3589 options.m_max_ptr_depth, // max pointer depth allowed, we will go down from here
3590 0 // current object depth is 0 since we are just starting
3591 );
3592}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003593
3594ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003595ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003596{
3597 ValueObjectSP valobj_sp;
3598
Enrico Granatac3e320a2011-08-02 17:27:39 +00003599 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003600 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003601 ExecutionContext exe_ctx (GetExecutionContextRef());
3602 clang::ASTContext *ast = GetClangAST ();
3603
3604 DataExtractor data;
3605 data.SetByteOrder (m_data.GetByteOrder());
3606 data.SetAddressByteSize(m_data.GetAddressByteSize());
3607
Enrico Granata9f1e2042012-04-24 22:15:37 +00003608 if (IsBitfield())
3609 {
3610 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
3611 m_error = v.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
3612 }
3613 else
3614 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003615
3616 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3617 ast,
3618 GetClangType(),
3619 name,
3620 data,
3621 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003622 }
Jim Ingham6035b672011-03-31 00:19:25 +00003623
3624 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003625 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003626 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003627 }
3628 return valobj_sp;
3629}
3630
Greg Claytonafacd142011-09-02 01:15:17 +00003631ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003632ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003633{
Jim Ingham58b59f92011-04-22 23:53:53 +00003634 if (m_deref_valobj)
3635 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003636
Greg Clayton54979cd2010-12-15 05:08:08 +00003637 const bool is_pointer_type = IsPointerType();
3638 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003639 {
3640 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003641 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003642
3643 std::string child_name_str;
3644 uint32_t child_byte_size = 0;
3645 int32_t child_byte_offset = 0;
3646 uint32_t child_bitfield_bit_size = 0;
3647 uint32_t child_bitfield_bit_offset = 0;
3648 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003649 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003650 const bool transparent_pointers = false;
3651 clang::ASTContext *clang_ast = GetClangAST();
3652 clang_type_t clang_type = GetClangType();
3653 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003654
Greg Claytoncc4d0142012-02-17 07:49:44 +00003655 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003656
3657 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3658 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003659 GetName().GetCString(),
3660 clang_type,
3661 0,
3662 transparent_pointers,
3663 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003664 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003665 child_name_str,
3666 child_byte_size,
3667 child_byte_offset,
3668 child_bitfield_bit_size,
3669 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003670 child_is_base_class,
3671 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003672 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003673 {
3674 ConstString child_name;
3675 if (!child_name_str.empty())
3676 child_name.SetCString (child_name_str.c_str());
3677
Jim Ingham58b59f92011-04-22 23:53:53 +00003678 m_deref_valobj = new ValueObjectChild (*this,
3679 clang_ast,
3680 child_clang_type,
3681 child_name,
3682 child_byte_size,
3683 child_byte_offset,
3684 child_bitfield_bit_size,
3685 child_bitfield_bit_offset,
3686 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003687 child_is_deref_of_parent,
3688 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003689 }
3690 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003691
Jim Ingham58b59f92011-04-22 23:53:53 +00003692 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003693 {
3694 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003695 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003696 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003697 else
3698 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003699 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003700 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003701
3702 if (is_pointer_type)
3703 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3704 else
3705 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003706 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003707 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003708}
3709
Greg Claytonafacd142011-09-02 01:15:17 +00003710ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003711ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003712{
Jim Ingham78a685a2011-04-16 00:01:13 +00003713 if (m_addr_of_valobj_sp)
3714 return m_addr_of_valobj_sp;
3715
Greg Claytone0d378b2011-03-24 21:19:54 +00003716 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003717 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003718 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003719 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003720 if (addr != LLDB_INVALID_ADDRESS)
3721 {
3722 switch (address_type)
3723 {
3724 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003725 {
3726 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003727 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003728 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3729 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003730 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003731
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003732 case eAddressTypeFile:
3733 case eAddressTypeLoad:
3734 case eAddressTypeHost:
3735 {
3736 clang::ASTContext *ast = GetClangAST();
3737 clang_type_t clang_type = GetClangType();
3738 if (ast && clang_type)
3739 {
3740 std::string name (1, '&');
3741 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003742 ExecutionContext exe_ctx (GetExecutionContextRef());
3743 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003744 ast,
3745 ClangASTContext::CreatePointerType (ast, clang_type),
3746 ConstString (name.c_str()),
3747 addr,
3748 eAddressTypeInvalid,
3749 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003750 }
3751 }
3752 break;
3753 }
3754 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003755 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003756}
3757
Greg Clayton9a142cf2012-02-03 05:34:10 +00003758ValueObjectSP
3759ValueObject::Cast (const ClangASTType &clang_ast_type)
3760{
Greg Clayton81e871e2012-02-04 02:27:34 +00003761 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003762}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003763
Greg Claytonafacd142011-09-02 01:15:17 +00003764ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003765ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3766{
Greg Claytonafacd142011-09-02 01:15:17 +00003767 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003768 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003769 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003770
3771 if (ptr_value != LLDB_INVALID_ADDRESS)
3772 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003773 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003774 ExecutionContext exe_ctx (GetExecutionContextRef());
3775 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003776 name,
3777 ptr_addr,
3778 clang_ast_type);
3779 }
3780 return valobj_sp;
3781}
3782
Greg Claytonafacd142011-09-02 01:15:17 +00003783ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003784ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3785{
Greg Claytonafacd142011-09-02 01:15:17 +00003786 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003787 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003788 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003789
3790 if (ptr_value != LLDB_INVALID_ADDRESS)
3791 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003792 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003793 ExecutionContext exe_ctx (GetExecutionContextRef());
3794 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003795 name,
3796 ptr_addr,
3797 type_sp);
3798 }
3799 return valobj_sp;
3800}
3801
Jim Ingham6035b672011-03-31 00:19:25 +00003802ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003803 m_mod_id(),
3804 m_exe_ctx_ref(),
3805 m_needs_update (true),
3806 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003807{
3808}
3809
3810ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003811 m_mod_id(),
3812 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003813 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003814 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003815{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003816 ExecutionContext exe_ctx(exe_scope);
3817 TargetSP target_sp (exe_ctx.GetTargetSP());
3818 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003819 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003820 m_exe_ctx_ref.SetTargetSP (target_sp);
3821 ProcessSP process_sp (exe_ctx.GetProcessSP());
3822 if (!process_sp)
3823 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003824
Greg Claytoncc4d0142012-02-17 07:49:44 +00003825 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003826 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003827 m_mod_id = process_sp->GetModID();
3828 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003829
Greg Claytoncc4d0142012-02-17 07:49:44 +00003830 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003831
Greg Claytoncc4d0142012-02-17 07:49:44 +00003832 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003833 {
3834 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003835 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003836 }
Jim Ingham6035b672011-03-31 00:19:25 +00003837
Greg Claytoncc4d0142012-02-17 07:49:44 +00003838 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003839 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003840 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003841
Greg Claytoncc4d0142012-02-17 07:49:44 +00003842 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3843 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003844 {
3845 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003846 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003847 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003848 if (frame_sp)
3849 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003850 }
3851 }
3852 }
Jim Ingham6035b672011-03-31 00:19:25 +00003853}
3854
3855ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003856 m_mod_id(),
3857 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3858 m_needs_update (true),
3859 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003860{
3861}
3862
3863ValueObject::EvaluationPoint::~EvaluationPoint ()
3864{
3865}
3866
Jim Ingham6035b672011-03-31 00:19:25 +00003867// This function checks the EvaluationPoint against the current process state. If the current
3868// state matches the evaluation point, or the evaluation point is already invalid, then we return
3869// false, meaning "no change". If the current state is different, we update our state, and return
3870// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3871// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003872// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003873
3874bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003875ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003876{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003877
3878 // 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 +00003879 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00003880
Greg Claytoncc4d0142012-02-17 07:49:44 +00003881 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003882 return false;
3883
Jim Ingham6035b672011-03-31 00:19:25 +00003884 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003885 Process *process = exe_ctx.GetProcessPtr();
3886 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003887 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003888
Jim Ingham6035b672011-03-31 00:19:25 +00003889 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003890 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003891
Jim Ingham78a685a2011-04-16 00:01:13 +00003892 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3893 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003894 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003895 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003896
Greg Clayton23f59502012-07-17 03:23:13 +00003897 bool changed = false;
3898 const bool was_valid = m_mod_id.IsValid();
3899 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003900 {
3901 if (m_mod_id == current_mod_id)
3902 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003903 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003904 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003905 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003906 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003907 else
3908 {
3909 m_mod_id = current_mod_id;
3910 m_needs_update = true;
3911 changed = true;
3912 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003913 }
Jim Ingham6035b672011-03-31 00:19:25 +00003914
Jim Ingham73ca05a2011-12-17 01:35:57 +00003915 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3916 // That way we'll be sure to return a valid exe_scope.
3917 // 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 +00003918
Greg Claytoncc4d0142012-02-17 07:49:44 +00003919 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003920 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003921 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3922 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003923 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003924 if (m_exe_ctx_ref.HasFrameRef())
3925 {
3926 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3927 if (!frame_sp)
3928 {
3929 // We used to have a frame, but now it is gone
3930 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003931 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00003932 }
3933 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003934 }
Jim Ingham6035b672011-03-31 00:19:25 +00003935 else
3936 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003937 // We used to have a thread, but now it is gone
3938 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003939 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00003940 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003941
Jim Ingham6035b672011-03-31 00:19:25 +00003942 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003943 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003944}
3945
Jim Ingham61be0902011-05-02 18:13:59 +00003946void
3947ValueObject::EvaluationPoint::SetUpdated ()
3948{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003949 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3950 if (process_sp)
3951 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003952 m_first_update = false;
3953 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003954}
3955
3956
Greg Claytoncc4d0142012-02-17 07:49:44 +00003957//bool
3958//ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3959//{
3960// if (!IsValid())
3961// return false;
3962//
3963// bool needs_update = false;
3964//
3965// // The target has to be non-null, and the
3966// Target *target = exe_scope->CalculateTarget();
3967// if (target != NULL)
3968// {
3969// Target *old_target = m_target_sp.get();
3970// assert (target == old_target);
3971// Process *process = exe_scope->CalculateProcess();
3972// if (process != NULL)
3973// {
3974// // FOR NOW - assume you can't update variable objects across process boundaries.
3975// Process *old_process = m_process_sp.get();
3976// assert (process == old_process);
3977// ProcessModID current_mod_id = process->GetModID();
3978// if (m_mod_id != current_mod_id)
3979// {
3980// needs_update = true;
3981// m_mod_id = current_mod_id;
3982// }
3983// // See if we're switching the thread or stack context. If no thread is given, this is
3984// // being evaluated in a global context.
3985// Thread *thread = exe_scope->CalculateThread();
3986// if (thread != NULL)
3987// {
3988// user_id_t new_thread_index = thread->GetIndexID();
3989// if (new_thread_index != m_thread_id)
3990// {
3991// needs_update = true;
3992// m_thread_id = new_thread_index;
3993// m_stack_id.Clear();
3994// }
3995//
3996// StackFrame *new_frame = exe_scope->CalculateStackFrame();
3997// if (new_frame != NULL)
3998// {
3999// if (new_frame->GetStackID() != m_stack_id)
4000// {
4001// needs_update = true;
4002// m_stack_id = new_frame->GetStackID();
4003// }
4004// }
4005// else
4006// {
4007// m_stack_id.Clear();
4008// needs_update = true;
4009// }
4010// }
4011// else
4012// {
4013// // If this had been given a thread, and now there is none, we should update.
4014// // Otherwise we don't have to do anything.
4015// if (m_thread_id != LLDB_INVALID_UID)
4016// {
4017// m_thread_id = LLDB_INVALID_UID;
4018// m_stack_id.Clear();
4019// needs_update = true;
4020// }
4021// }
4022// }
4023// else
4024// {
4025// // If there is no process, then we don't need to update anything.
4026// // But if we're switching from having a process to not, we should try to update.
4027// if (m_process_sp.get() != NULL)
4028// {
4029// needs_update = true;
4030// m_process_sp.reset();
4031// m_thread_id = LLDB_INVALID_UID;
4032// m_stack_id.Clear();
4033// }
4034// }
4035// }
4036// else
4037// {
4038// // If there's no target, nothing can change so we don't need to update anything.
4039// // But if we're switching from having a target to not, we should try to update.
4040// if (m_target_sp.get() != NULL)
4041// {
4042// needs_update = true;
4043// m_target_sp.reset();
4044// m_process_sp.reset();
4045// m_thread_id = LLDB_INVALID_UID;
4046// m_stack_id.Clear();
4047// }
4048// }
4049// if (!m_needs_update)
4050// m_needs_update = needs_update;
4051//
4052// return needs_update;
4053//}
Enrico Granataf2bbf712011-07-15 02:26:42 +00004054
4055void
Enrico Granata86cc9822012-03-19 22:58:49 +00004056ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004057{
Enrico Granata86cc9822012-03-19 22:58:49 +00004058 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4059 m_value_str.clear();
4060
4061 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4062 m_location_str.clear();
4063
4064 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
4065 {
Enrico Granata86cc9822012-03-19 22:58:49 +00004066 m_summary_str.clear();
4067 }
4068
4069 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4070 m_object_desc_str.clear();
4071
4072 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4073 {
4074 if (m_synthetic_value)
4075 m_synthetic_value = NULL;
4076 }
Johnny Chen44805302011-07-19 19:48:13 +00004077}
Enrico Granata9128ee22011-09-06 19:20:51 +00004078
4079SymbolContextScope *
4080ValueObject::GetSymbolContextScope()
4081{
4082 if (m_parent)
4083 {
4084 if (!m_parent->IsPointerOrReferenceType())
4085 return m_parent->GetSymbolContextScope();
4086 }
4087 return NULL;
4088}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004089
4090lldb::ValueObjectSP
4091ValueObject::CreateValueObjectFromExpression (const char* name,
4092 const char* expression,
4093 const ExecutionContext& exe_ctx)
4094{
4095 lldb::ValueObjectSP retval_sp;
4096 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4097 if (!target_sp)
4098 return retval_sp;
4099 if (!expression || !*expression)
4100 return retval_sp;
4101 target_sp->EvaluateExpression (expression,
4102 exe_ctx.GetFrameSP().get(),
4103 retval_sp);
4104 if (retval_sp && name && *name)
4105 retval_sp->SetName(ConstString(name));
4106 return retval_sp;
4107}
4108
4109lldb::ValueObjectSP
4110ValueObject::CreateValueObjectFromAddress (const char* name,
4111 uint64_t address,
4112 const ExecutionContext& exe_ctx,
4113 ClangASTType type)
4114{
4115 ClangASTType pointer_type(type.GetASTContext(),type.GetPointerType());
4116 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4117 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4118 pointer_type.GetASTContext(),
4119 pointer_type.GetOpaqueQualType(),
4120 ConstString(name),
4121 buffer,
4122 lldb::endian::InlHostByteOrder(),
4123 exe_ctx.GetAddressByteSize()));
4124 if (ptr_result_valobj_sp)
4125 {
4126 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4127 Error err;
4128 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4129 if (ptr_result_valobj_sp && name && *name)
4130 ptr_result_valobj_sp->SetName(ConstString(name));
4131 }
4132 return ptr_result_valobj_sp;
4133}
4134
4135lldb::ValueObjectSP
4136ValueObject::CreateValueObjectFromData (const char* name,
4137 DataExtractor& data,
4138 const ExecutionContext& exe_ctx,
4139 ClangASTType type)
4140{
4141 lldb::ValueObjectSP new_value_sp;
4142 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4143 type.GetASTContext() ,
4144 type.GetOpaqueQualType(),
4145 ConstString(name),
4146 data,
4147 LLDB_INVALID_ADDRESS);
4148 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4149 if (new_value_sp && name && *name)
4150 new_value_sp->SetName(ConstString(name));
4151 return new_value_sp;
4152}