blob: 449e49c0720a357fff331032208f7c234dd6342e [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 Granata0a976142011-08-22 22:03:47 +000024#include "lldb/Core/DataVisualization.h"
Enrico Granata4becb372011-06-29 22:27:15 +000025#include "lldb/Core/Debugger.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000026#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000027#include "lldb/Core/Module.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028#include "lldb/Core/StreamString.h"
Enrico Granata21fd13f2012-10-27 02:05:48 +000029#include "lldb/Core/ValueObjectCast.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030#include "lldb/Core/ValueObjectChild.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000031#include "lldb/Core/ValueObjectConstResult.h"
Jim Ingham78a685a2011-04-16 00:01:13 +000032#include "lldb/Core/ValueObjectDynamicValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033#include "lldb/Core/ValueObjectList.h"
Greg Claytonb2dcc362011-05-05 23:32:56 +000034#include "lldb/Core/ValueObjectMemory.h"
Enrico Granatad55546b2011-07-22 00:16:08 +000035#include "lldb/Core/ValueObjectSyntheticFilter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000036
Greg Clayton7fb56d02011-02-01 01:31:41 +000037#include "lldb/Host/Endian.h"
38
Enrico Granata61a80ba2011-08-12 16:42:31 +000039#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granataf2bbf712011-07-15 02:26:42 +000040#include "lldb/Interpreter/ScriptInterpreterPython.h"
41
Greg Claytone1a916a2010-07-21 22:12:05 +000042#include "lldb/Symbol/ClangASTType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043#include "lldb/Symbol/ClangASTContext.h"
44#include "lldb/Symbol/Type.h"
45
Jim Ingham53c47f12010-09-10 23:12:17 +000046#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000047#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000048#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049#include "lldb/Target/Process.h"
50#include "lldb/Target/RegisterContext.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000051#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053
Enrico Granataf4efecd2011-07-12 22:56:10 +000054#include "lldb/Utility/RefCounter.h"
55
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056using namespace lldb;
57using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000058using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000059
Greg Claytonafacd142011-09-02 01:15:17 +000060static user_id_t g_value_obj_uid = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061
62//----------------------------------------------------------------------
63// ValueObject constructor
64//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000065ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000067 m_parent (&parent),
Stephen Wilson71c21d12011-04-11 19:41:40 +000068 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000069 m_name (),
70 m_data (),
71 m_value (),
72 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000073 m_value_str (),
74 m_old_value_str (),
75 m_location_str (),
76 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000077 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +000078 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000079 m_children (),
80 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000081 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000082 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000083 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000084 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000085 m_last_format_mgr_revision(0),
Enrico Granatad8b5fce2011-08-02 23:12:24 +000086 m_last_format_mgr_dynamic(parent.m_last_format_mgr_dynamic),
Enrico Granata0c489f52012-03-01 04:24:26 +000087 m_type_summary_sp(),
88 m_type_format_sp(),
89 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +000090 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +000091 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
Greg Clayton288bdf92010-09-02 02:59:18 +000092 m_value_is_valid (false),
93 m_value_did_change (false),
94 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000095 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +000096 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +000097 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +000098 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +000099 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000100 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000101 m_is_getting_summary(false),
102 m_did_calculate_complete_objc_class_type(false)
Jim Ingham6035b672011-03-31 00:19:25 +0000103{
Jim Ingham58b59f92011-04-22 23:53:53 +0000104 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000105}
106
107//----------------------------------------------------------------------
108// ValueObject constructor
109//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000110ValueObject::ValueObject (ExecutionContextScope *exe_scope,
111 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000112 UserID (++g_value_obj_uid), // Unique identifier for every value object
113 m_parent (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000114 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000115 m_name (),
116 m_data (),
117 m_value (),
118 m_error (),
119 m_value_str (),
120 m_old_value_str (),
121 m_location_str (),
122 m_summary_str (),
123 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000124 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000125 m_children (),
126 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000127 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000128 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000129 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000130 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000131 m_last_format_mgr_revision(0),
Greg Claytonafacd142011-09-02 01:15:17 +0000132 m_last_format_mgr_dynamic(eNoDynamicValues),
Enrico Granata0c489f52012-03-01 04:24:26 +0000133 m_type_summary_sp(),
134 m_type_format_sp(),
135 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000136 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000137 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Jim Ingham6035b672011-03-31 00:19:25 +0000138 m_value_is_valid (false),
139 m_value_did_change (false),
140 m_children_count_valid (false),
141 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000142 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000143 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000144 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +0000145 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000146 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000147 m_is_getting_summary(false),
148 m_did_calculate_complete_objc_class_type(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000149{
Jim Ingham58b59f92011-04-22 23:53:53 +0000150 m_manager = new ValueObjectManager();
151 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000152}
153
154//----------------------------------------------------------------------
155// Destructor
156//----------------------------------------------------------------------
157ValueObject::~ValueObject ()
158{
159}
160
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000161bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000162ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000163{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000164 return UpdateValueIfNeeded(m_last_format_mgr_dynamic, update_format);
165}
166
167bool
Greg Claytonafacd142011-09-02 01:15:17 +0000168ValueObject::UpdateValueIfNeeded (DynamicValueType use_dynamic, bool update_format)
Enrico Granatac3e320a2011-08-02 17:27:39 +0000169{
Enrico Granata4becb372011-06-29 22:27:15 +0000170
Enrico Granata9128ee22011-09-06 19:20:51 +0000171 bool did_change_formats = false;
172
Enrico Granata0a3958e2011-07-02 00:25:22 +0000173 if (update_format)
Enrico Granata9128ee22011-09-06 19:20:51 +0000174 did_change_formats = UpdateFormatsIfNeeded(use_dynamic);
Enrico Granata4becb372011-06-29 22:27:15 +0000175
Greg Claytonb71f3842010-10-05 03:13:51 +0000176 // If this is a constant value, then our success is predicated on whether
177 // we have an error or not
178 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000179 {
180 // if you were asked to update your formatters, but did not get a chance to do it
181 // clear your own values (this serves the purpose of faking a stop-id for frozen
182 // objects (which are regarded as constant, but could have changes behind their backs
183 // because of the frozen-pointer depth limit)
184 // TODO: decouple summary from value and then remove this code and only force-clear the summary
185 if (update_format && !did_change_formats)
Enrico Granata86cc9822012-03-19 22:58:49 +0000186 ClearUserVisibleData(eClearUserVisibleDataItemsSummary);
Greg Claytonb71f3842010-10-05 03:13:51 +0000187 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000188 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000189
Jim Ingham6035b672011-03-31 00:19:25 +0000190 bool first_update = m_update_point.IsFirstEvaluation();
191
192 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000193 {
Jim Ingham6035b672011-03-31 00:19:25 +0000194 m_update_point.SetUpdated();
195
196 // Save the old value using swap to avoid a string copy which
197 // also will clear our m_value_str
198 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000199 {
Jim Ingham6035b672011-03-31 00:19:25 +0000200 m_old_value_valid = false;
201 }
202 else
203 {
204 m_old_value_valid = true;
205 m_old_value_str.swap (m_value_str);
Enrico Granata86cc9822012-03-19 22:58:49 +0000206 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham6035b672011-03-31 00:19:25 +0000207 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000208
Enrico Granataf2bbf712011-07-15 02:26:42 +0000209 ClearUserVisibleData();
210
Greg Claytonefbc7d22012-03-09 04:23:44 +0000211 if (IsInScope())
Jim Ingham6035b672011-03-31 00:19:25 +0000212 {
Greg Claytonefbc7d22012-03-09 04:23:44 +0000213 const bool value_was_valid = GetValueIsValid();
214 SetValueDidChange (false);
215
216 m_error.Clear();
217
218 // Call the pure virtual function to update the value
219 bool success = UpdateValue ();
220
221 SetValueIsValid (success);
222
223 if (first_update)
224 SetValueDidChange (false);
225 else if (!m_value_did_change && success == false)
226 {
227 // The value wasn't gotten successfully, so we mark this
228 // as changed if the value used to be valid and now isn't
229 SetValueDidChange (value_was_valid);
230 }
231 }
232 else
233 {
234 m_error.SetErrorString("out of scope");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000235 }
236 }
237 return m_error.Success();
238}
239
Enrico Granata9128ee22011-09-06 19:20:51 +0000240bool
Greg Claytonafacd142011-09-02 01:15:17 +0000241ValueObject::UpdateFormatsIfNeeded(DynamicValueType use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000242{
Enrico Granata6f3533f2011-07-29 19:53:35 +0000243 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
244 if (log)
Enrico Granatad2284832012-10-17 22:23:56 +0000245 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
Enrico Granata6f3533f2011-07-29 19:53:35 +0000246 GetName().GetCString(),
Enrico Granatad2284832012-10-17 22:23:56 +0000247 this,
Enrico Granata4becb372011-06-29 22:27:15 +0000248 m_last_format_mgr_revision,
Enrico Granata85933ed2011-08-18 16:38:26 +0000249 DataVisualization::GetCurrentRevision());
Enrico Granata9128ee22011-09-06 19:20:51 +0000250
251 bool any_change = false;
252
Enrico Granata85933ed2011-08-18 16:38:26 +0000253 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()) ||
Enrico Granatac3e320a2011-08-02 17:27:39 +0000254 m_last_format_mgr_dynamic != use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000255 {
Enrico Granata78d06382011-09-09 23:33:14 +0000256 SetValueFormat(DataVisualization::ValueFormats::GetFormat (*this, eNoDynamicValues));
257 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, use_dynamic));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000258#ifndef LLDB_DISABLE_PYTHON
Enrico Granata78d06382011-09-09 23:33:14 +0000259 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, use_dynamic));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000260#endif
Enrico Granata1490c6f2011-07-19 02:34:21 +0000261
Enrico Granata85933ed2011-08-18 16:38:26 +0000262 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
Enrico Granatac3e320a2011-08-02 17:27:39 +0000263 m_last_format_mgr_dynamic = use_dynamic;
Enrico Granata855cd902011-09-06 22:59:55 +0000264
265 any_change = true;
Enrico Granata4becb372011-06-29 22:27:15 +0000266 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000267
268 return any_change;
269
Enrico Granata4becb372011-06-29 22:27:15 +0000270}
271
Jim Ingham16e0c682011-08-12 23:34:31 +0000272void
273ValueObject::SetNeedsUpdate ()
274{
275 m_update_point.SetNeedsUpdate();
276 // We have to clear the value string here so ConstResult children will notice if their values are
277 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000278 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000279}
280
Enrico Granata13ac0e22012-10-17 19:03:34 +0000281void
Enrico Granatae3e91512012-10-22 18:18:36 +0000282ValueObject::ClearDynamicTypeInformation ()
Enrico Granata13ac0e22012-10-17 19:03:34 +0000283{
284 m_did_calculate_complete_objc_class_type = false;
Enrico Granatae3e91512012-10-22 18:18:36 +0000285 m_last_format_mgr_revision = 0;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000286 m_override_type = ClangASTType();
Enrico Granatae3e91512012-10-22 18:18:36 +0000287 SetValueFormat(lldb::TypeFormatImplSP());
288 SetSummaryFormat(lldb::TypeSummaryImplSP());
289 SetSyntheticChildren(lldb::SyntheticChildrenSP());
Enrico Granata13ac0e22012-10-17 19:03:34 +0000290}
291
Sean Callanan72772842012-02-22 23:57:45 +0000292ClangASTType
293ValueObject::MaybeCalculateCompleteType ()
294{
295 ClangASTType ret(GetClangASTImpl(), GetClangTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000296
Sean Callanan72772842012-02-22 23:57:45 +0000297 if (m_did_calculate_complete_objc_class_type)
298 {
299 if (m_override_type.IsValid())
300 return m_override_type;
301 else
302 return ret;
303 }
304
305 clang_type_t ast_type(GetClangTypeImpl());
306 clang_type_t class_type;
307 bool is_pointer_type;
308
309 if (ClangASTContext::IsObjCObjectPointerType(ast_type, &class_type))
310 {
311 is_pointer_type = true;
312 }
313 else if (ClangASTContext::IsObjCClassType(ast_type))
314 {
315 is_pointer_type = false;
316 class_type = ast_type;
317 }
318 else
319 {
320 return ret;
321 }
322
323 m_did_calculate_complete_objc_class_type = true;
324
325 if (!class_type)
326 return ret;
327
328 std::string class_name;
329
330 if (!ClangASTContext::GetObjCClassName(class_type, class_name))
331 return ret;
332
333 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
334
335 if (!process_sp)
336 return ret;
337
338 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
339
340 if (!objc_language_runtime)
341 return ret;
342
343 ConstString class_name_cs(class_name.c_str());
344
345 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name_cs);
346
347 if (!complete_objc_class_type_sp)
348 return ret;
349
350 ClangASTType complete_class(complete_objc_class_type_sp->GetClangAST(),
351 complete_objc_class_type_sp->GetClangFullType());
352
353 if (!ClangASTContext::GetCompleteType(complete_class.GetASTContext(),
354 complete_class.GetOpaqueQualType()))
355 return ret;
356
357 if (is_pointer_type)
358 {
359 clang_type_t pointer_type = ClangASTContext::CreatePointerType(complete_class.GetASTContext(),
360 complete_class.GetOpaqueQualType());
361
362 m_override_type = ClangASTType(complete_class.GetASTContext(),
363 pointer_type);
364 }
365 else
366 {
367 m_override_type = complete_class;
368 }
369
Sean Callanan356e17c2012-03-30 02:04:38 +0000370 if (m_override_type.IsValid())
371 return m_override_type;
372 else
373 return ret;
Sean Callanan72772842012-02-22 23:57:45 +0000374}
375
376clang::ASTContext *
377ValueObject::GetClangAST ()
378{
379 ClangASTType type = MaybeCalculateCompleteType();
380
381 return type.GetASTContext();
382}
383
384lldb::clang_type_t
385ValueObject::GetClangType ()
386{
387 ClangASTType type = MaybeCalculateCompleteType();
388
389 return type.GetOpaqueQualType();
390}
391
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000392DataExtractor &
393ValueObject::GetDataExtractor ()
394{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000395 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000396 return m_data;
397}
398
399const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000400ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000401{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000402 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000403 return m_error;
404}
405
406const ConstString &
407ValueObject::GetName() const
408{
409 return m_name;
410}
411
412const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000413ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000414{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000415 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000416 {
417 if (m_location_str.empty())
418 {
419 StreamString sstr;
420
421 switch (m_value.GetValueType())
422 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000423 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +0000424 case Value::eValueTypeVector:
Greg Clayton526e5af2010-11-13 03:52:47 +0000425 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000426 {
427 RegisterInfo *reg_info = m_value.GetRegisterInfo();
428 if (reg_info)
429 {
430 if (reg_info->name)
431 m_location_str = reg_info->name;
432 else if (reg_info->alt_name)
433 m_location_str = reg_info->alt_name;
Greg Clayton0665a0f2012-10-30 18:18:43 +0000434
435 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000436 }
437 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000438 break;
439
440 case Value::eValueTypeLoadAddress:
441 case Value::eValueTypeFileAddress:
442 case Value::eValueTypeHostAddress:
443 {
444 uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2;
445 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
446 m_location_str.swap(sstr.GetString());
447 }
448 break;
449 }
450 }
451 }
452 return m_location_str.c_str();
453}
454
455Value &
456ValueObject::GetValue()
457{
458 return m_value;
459}
460
461const Value &
462ValueObject::GetValue() const
463{
464 return m_value;
465}
466
467bool
Jim Ingham6035b672011-03-31 00:19:25 +0000468ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000469{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000470 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
471 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000472 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000473 Value tmp_value(m_value);
474 scalar = tmp_value.ResolveValue(&exe_ctx, GetClangAST ());
Greg Claytondcad5022011-12-29 01:26:56 +0000475 if (scalar.IsValid())
476 {
477 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
478 if (bitfield_bit_size)
479 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
480 return true;
481 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000482 }
Greg Claytondcad5022011-12-29 01:26:56 +0000483 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000484}
485
486bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000487ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000488{
Greg Clayton288bdf92010-09-02 02:59:18 +0000489 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000490}
491
492
493void
494ValueObject::SetValueIsValid (bool b)
495{
Greg Clayton288bdf92010-09-02 02:59:18 +0000496 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000497}
498
499bool
Jim Ingham6035b672011-03-31 00:19:25 +0000500ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000501{
Jim Ingham6035b672011-03-31 00:19:25 +0000502 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000503 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000504}
505
506void
507ValueObject::SetValueDidChange (bool value_changed)
508{
Greg Clayton288bdf92010-09-02 02:59:18 +0000509 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000510}
511
512ValueObjectSP
513ValueObject::GetChildAtIndex (uint32_t idx, bool can_create)
514{
515 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000516 // We may need to update our value if we are dynamic
517 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000518 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000519 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000520 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000521 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000522 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000523 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000524 // No we haven't created the child at this index, so lets have our
525 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000526 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000527 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000528
Enrico Granata9d60f602012-03-09 03:09:58 +0000529 ValueObject* child = m_children.GetChildAtIndex(idx);
530 if (child != NULL)
531 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000532 }
533 return child_sp;
534}
535
Enrico Granata3309d882013-01-12 01:00:22 +0000536ValueObjectSP
537ValueObject::GetChildAtIndexPath (const std::initializer_list<uint32_t>& idxs,
538 uint32_t* index_of_error)
539{
540 if (idxs.size() == 0)
541 return GetSP();
542 ValueObjectSP root(GetSP());
543 for (uint32_t idx : idxs)
544 {
545 root = root->GetChildAtIndex(idx, true);
546 if (!root)
547 {
548 if (index_of_error)
549 *index_of_error = idx;
550 return root;
551 }
552 }
553 return root;
554}
555
556ValueObjectSP
557ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<uint32_t, bool> >& idxs,
558 uint32_t* index_of_error)
559{
560 if (idxs.size() == 0)
561 return GetSP();
562 ValueObjectSP root(GetSP());
563 for (std::pair<uint32_t, bool> idx : idxs)
564 {
565 root = root->GetChildAtIndex(idx.first, idx.second);
566 if (!root)
567 {
568 if (index_of_error)
569 *index_of_error = idx.first;
570 return root;
571 }
572 }
573 return root;
574}
575
576lldb::ValueObjectSP
577ValueObject::GetChildAtIndexPath (const std::vector<uint32_t> &idxs,
578 uint32_t* index_of_error)
579{
580 if (idxs.size() == 0)
581 return GetSP();
582 ValueObjectSP root(GetSP());
583 for (uint32_t idx : idxs)
584 {
585 root = root->GetChildAtIndex(idx, true);
586 if (!root)
587 {
588 if (index_of_error)
589 *index_of_error = idx;
590 return root;
591 }
592 }
593 return root;
594}
595
596lldb::ValueObjectSP
597ValueObject::GetChildAtIndexPath (const std::vector< std::pair<uint32_t, bool> > &idxs,
598 uint32_t* index_of_error)
599{
600 if (idxs.size() == 0)
601 return GetSP();
602 ValueObjectSP root(GetSP());
603 for (std::pair<uint32_t, bool> idx : idxs)
604 {
605 root = root->GetChildAtIndex(idx.first, idx.second);
606 if (!root)
607 {
608 if (index_of_error)
609 *index_of_error = idx.first;
610 return root;
611 }
612 }
613 return root;
614}
615
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000616uint32_t
617ValueObject::GetIndexOfChildWithName (const ConstString &name)
618{
619 bool omit_empty_base_classes = true;
620 return ClangASTContext::GetIndexOfChildWithName (GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +0000621 GetClangType(),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000622 name.GetCString(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000623 omit_empty_base_classes);
624}
625
626ValueObjectSP
627ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
628{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000629 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000630 // classes (which really aren't part of the expression path), so we
631 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000632 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000633
Greg Claytondea8cb42011-06-29 22:09:02 +0000634 // We may need to update our value if we are dynamic
635 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000636 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000637
638 std::vector<uint32_t> child_indexes;
639 clang::ASTContext *clang_ast = GetClangAST();
640 void *clang_type = GetClangType();
641 bool omit_empty_base_classes = true;
642 const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast,
643 clang_type,
644 name.GetCString(),
645 omit_empty_base_classes,
646 child_indexes);
647 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000648 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000649 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
650 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
651
652 child_sp = GetChildAtIndex(*pos, can_create);
653 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000654 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000655 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000656 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000657 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
658 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000659 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000660 else
661 {
662 child_sp.reset();
663 }
664
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000665 }
666 }
667 return child_sp;
668}
669
670
671uint32_t
672ValueObject::GetNumChildren ()
673{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000674 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000675 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000676 {
677 SetNumChildren (CalculateNumChildren());
678 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000679 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000680}
Greg Clayton4a792072012-10-23 01:50:10 +0000681
682bool
683ValueObject::MightHaveChildren()
684{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000685 bool has_children = false;
Greg Clayton4a792072012-10-23 01:50:10 +0000686 clang_type_t clang_type = GetClangType();
687 if (clang_type)
688 {
689 const uint32_t type_info = ClangASTContext::GetTypeInfo (clang_type,
690 GetClangAST(),
691 NULL);
692 if (type_info & (ClangASTContext::eTypeHasChildren |
693 ClangASTContext::eTypeIsPointer |
694 ClangASTContext::eTypeIsReference))
695 has_children = true;
696 }
697 else
698 {
699 has_children = GetNumChildren () > 0;
700 }
701 return has_children;
702}
703
704// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000705void
706ValueObject::SetNumChildren (uint32_t num_children)
707{
Greg Clayton288bdf92010-09-02 02:59:18 +0000708 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000709 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000710}
711
712void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000713ValueObject::SetName (const ConstString &name)
714{
715 m_name = name;
716}
717
Jim Ingham58b59f92011-04-22 23:53:53 +0000718ValueObject *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000719ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index)
720{
Jim Ingham2eec4872011-05-07 00:10:58 +0000721 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000722
Greg Claytondea8cb42011-06-29 22:09:02 +0000723 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000724 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000725 std::string child_name_str;
726 uint32_t child_byte_size = 0;
727 int32_t child_byte_offset = 0;
728 uint32_t child_bitfield_bit_size = 0;
729 uint32_t child_bitfield_bit_offset = 0;
730 bool child_is_base_class = false;
731 bool child_is_deref_of_parent = false;
732
733 const bool transparent_pointers = synthetic_array_member == false;
734 clang::ASTContext *clang_ast = GetClangAST();
735 clang_type_t clang_type = GetClangType();
736 clang_type_t child_clang_type;
737
Greg Claytoncc4d0142012-02-17 07:49:44 +0000738 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000739
740 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
741 clang_ast,
742 GetName().GetCString(),
743 clang_type,
744 idx,
745 transparent_pointers,
746 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +0000747 ignore_array_bounds,
Greg Claytondea8cb42011-06-29 22:09:02 +0000748 child_name_str,
749 child_byte_size,
750 child_byte_offset,
751 child_bitfield_bit_size,
752 child_bitfield_bit_offset,
753 child_is_base_class,
754 child_is_deref_of_parent);
Greg Clayton4ef877f2012-12-06 02:33:54 +0000755 if (child_clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000756 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000757 if (synthetic_index)
758 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000759
Greg Claytondea8cb42011-06-29 22:09:02 +0000760 ConstString child_name;
761 if (!child_name_str.empty())
762 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000763
Greg Claytondea8cb42011-06-29 22:09:02 +0000764 valobj = new ValueObjectChild (*this,
765 clang_ast,
766 child_clang_type,
767 child_name,
768 child_byte_size,
769 child_byte_offset,
770 child_bitfield_bit_size,
771 child_bitfield_bit_offset,
772 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000773 child_is_deref_of_parent,
774 eAddressTypeInvalid);
775 //if (valobj)
776 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
777 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000778
Jim Ingham58b59f92011-04-22 23:53:53 +0000779 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000780}
781
Enrico Granata0c489f52012-03-01 04:24:26 +0000782bool
783ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
784 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000785{
Enrico Granata0c489f52012-03-01 04:24:26 +0000786 destination.clear();
787
788 // ideally we would like to bail out if passing NULL, but if we do so
789 // we end up not providing the summary for function pointers anymore
790 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
791 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000792
793 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000794
795 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
796 // information that we might care to see in a crash log. might be useful in very specific situations though.
797 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
798 GetTypeName().GetCString(),
799 GetName().GetCString(),
800 summary_ptr->GetDescription().c_str());*/
801
Enrico Granata0c489f52012-03-01 04:24:26 +0000802 if (UpdateValueIfNeeded (false))
803 {
804 if (summary_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000805 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000806 if (HasSyntheticValue())
807 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
808 summary_ptr->FormatObject(this, destination);
Enrico Granata0c489f52012-03-01 04:24:26 +0000809 }
810 else
811 {
812 clang_type_t clang_type = GetClangType();
813
814 // Do some default printout for function pointers
815 if (clang_type)
Enrico Granata4becb372011-06-29 22:27:15 +0000816 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000817 StreamString sstr;
818 clang_type_t elem_or_pointee_clang_type;
819 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
820 GetClangAST(),
821 &elem_or_pointee_clang_type));
822
823 if (ClangASTContext::IsFunctionPointerType (clang_type))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000824 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000825 AddressType func_ptr_address_type = eAddressTypeInvalid;
826 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
827 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000828 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000829 switch (func_ptr_address_type)
Jim Ingham6035b672011-03-31 00:19:25 +0000830 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000831 case eAddressTypeInvalid:
832 case eAddressTypeFile:
833 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000834
Greg Claytoncc4d0142012-02-17 07:49:44 +0000835 case eAddressTypeLoad:
Enrico Granata0c489f52012-03-01 04:24:26 +0000836 {
837 ExecutionContext exe_ctx (GetExecutionContextRef());
838
839 Address so_addr;
840 Target *target = exe_ctx.GetTargetPtr();
841 if (target && target->GetSectionLoadList().IsEmpty() == false)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000842 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000843 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000844 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000845 so_addr.Dump (&sstr,
846 exe_ctx.GetBestExecutionContextScope(),
847 Address::DumpStyleResolvedDescription,
848 Address::DumpStyleSectionNameOffset);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000849 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000850 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000851 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000852 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000853
Greg Claytoncc4d0142012-02-17 07:49:44 +0000854 case eAddressTypeHost:
855 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +0000856 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000857 }
858 if (sstr.GetSize() > 0)
859 {
860 destination.assign (1, '(');
861 destination.append (sstr.GetData(), sstr.GetSize());
862 destination.append (1, ')');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000863 }
864 }
865 }
866 }
867 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000868 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000869 return !destination.empty();
870}
871
872const char *
873ValueObject::GetSummaryAsCString ()
874{
875 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
876 {
877 GetSummaryAsCString(GetSummaryFormat().get(),
878 m_summary_str);
879 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000880 if (m_summary_str.empty())
881 return NULL;
882 return m_summary_str.c_str();
883}
884
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000885bool
886ValueObject::IsCStringContainer(bool check_pointer)
887{
888 clang_type_t elem_or_pointee_clang_type;
889 const Flags type_flags (ClangASTContext::GetTypeInfo (GetClangType(),
890 GetClangAST(),
891 &elem_or_pointee_clang_type));
892 bool is_char_arr_ptr (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
893 ClangASTContext::IsCharType (elem_or_pointee_clang_type));
894 if (!is_char_arr_ptr)
895 return false;
896 if (!check_pointer)
897 return true;
898 if (type_flags.Test(ClangASTContext::eTypeIsArray))
899 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000900 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000901 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000902 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000903 return (cstr_address != LLDB_INVALID_ADDRESS);
904}
905
Enrico Granata9128ee22011-09-06 19:20:51 +0000906size_t
907ValueObject::GetPointeeData (DataExtractor& data,
908 uint32_t item_idx,
909 uint32_t item_count)
910{
911 if (!IsPointerType() && !IsArrayType())
912 return 0;
913
914 if (item_count == 0)
915 return 0;
916
917 uint32_t stride = 0;
918
919 ClangASTType type(GetClangAST(),
920 GetClangType());
921
922 const uint64_t item_type_size = (IsPointerType() ? ClangASTType::GetTypeByteSize(GetClangAST(), type.GetPointeeType()) :
923 ClangASTType::GetTypeByteSize(GetClangAST(), type.GetArrayElementType(stride)));
924
925 const uint64_t bytes = item_count * item_type_size;
926
927 const uint64_t offset = item_idx * item_type_size;
928
929 if (item_idx == 0 && item_count == 1) // simply a deref
930 {
931 if (IsPointerType())
932 {
933 Error error;
934 ValueObjectSP pointee_sp = Dereference(error);
935 if (error.Fail() || pointee_sp.get() == NULL)
936 return 0;
937 return pointee_sp->GetDataExtractor().Copy(data);
938 }
939 else
940 {
941 ValueObjectSP child_sp = GetChildAtIndex(0, true);
942 if (child_sp.get() == NULL)
943 return 0;
944 return child_sp->GetDataExtractor().Copy(data);
945 }
946 return true;
947 }
948 else /* (items > 1) */
949 {
950 Error error;
951 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
952 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
953
954 AddressType addr_type;
955 lldb::addr_t addr = IsPointerType() ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
956
Enrico Granata9128ee22011-09-06 19:20:51 +0000957 switch (addr_type)
958 {
959 case eAddressTypeFile:
960 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000961 ModuleSP module_sp (GetModule());
962 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000963 {
Enrico Granata9c2efe32012-08-07 01:49:34 +0000964 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +0000965 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +0000966 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000967 ExecutionContext exe_ctx (GetExecutionContextRef());
968 Target* target = exe_ctx.GetTargetPtr();
969 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +0000970 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000971 heap_buf_ptr->SetByteSize(bytes);
972 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
973 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +0000974 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000975 data.SetData(data_sp);
976 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +0000977 }
978 }
979 }
980 }
981 break;
982 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +0000983 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000984 ExecutionContext exe_ctx (GetExecutionContextRef());
985 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +0000986 if (process)
987 {
988 heap_buf_ptr->SetByteSize(bytes);
989 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
990 if (error.Success())
991 {
992 data.SetData(data_sp);
993 return bytes_read;
994 }
995 }
996 }
997 break;
998 case eAddressTypeHost:
999 {
1000 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes);
1001 data.SetData(data_sp);
1002 return bytes;
1003 }
1004 break;
1005 case eAddressTypeInvalid:
Enrico Granata9128ee22011-09-06 19:20:51 +00001006 break;
1007 }
1008 }
1009 return 0;
1010}
1011
1012size_t
1013ValueObject::GetData (DataExtractor& data)
1014{
1015 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001016 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytone72dfb32012-02-24 01:59:29 +00001017 Error error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001018 if (error.Fail())
1019 return 0;
1020 data.SetAddressByteSize(m_data.GetAddressByteSize());
1021 data.SetByteOrder(m_data.GetByteOrder());
1022 return data.GetByteSize();
1023}
1024
1025// will compute strlen(str), but without consuming more than
1026// maxlen bytes out of str (this serves the purpose of reading
1027// chunks of a string without having to worry about
1028// missing NULL terminators in the chunk)
1029// of course, if strlen(str) > maxlen, the function will return
1030// maxlen_value (which should be != maxlen, because that allows you
1031// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1032static uint32_t
1033strlen_or_inf (const char* str,
1034 uint32_t maxlen,
1035 uint32_t maxlen_value)
1036{
1037 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +00001038 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +00001039 {
Greg Clayton8dd5c172011-10-05 22:19:51 +00001040 while(*str)
1041 {
1042 len++;str++;
1043 if (len > maxlen)
1044 return maxlen_value;
1045 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001046 }
1047 return len;
1048}
1049
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001050void
Greg Claytoncc4d0142012-02-17 07:49:44 +00001051ValueObject::ReadPointedString (Stream& s,
1052 Error& error,
1053 uint32_t max_length,
1054 bool honor_array,
1055 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001056{
Greg Claytoncc4d0142012-02-17 07:49:44 +00001057 ExecutionContext exe_ctx (GetExecutionContextRef());
1058 Target* target = exe_ctx.GetTargetPtr();
1059
1060 if (target && max_length == 0)
1061 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001062
1063 clang_type_t clang_type = GetClangType();
1064 clang_type_t elem_or_pointee_clang_type;
1065 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
1066 GetClangAST(),
1067 &elem_or_pointee_clang_type));
1068 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
1069 ClangASTContext::IsCharType (elem_or_pointee_clang_type))
1070 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001071 if (target == NULL)
1072 {
1073 s << "<no target to read from>";
1074 }
1075 else
1076 {
1077 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1078 AddressType cstr_address_type = eAddressTypeInvalid;
1079
1080 size_t cstr_len = 0;
1081 bool capped_data = false;
1082 if (type_flags.Test (ClangASTContext::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001083 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001084 // We have an array
1085 cstr_len = ClangASTContext::GetArraySize (clang_type);
1086 if (cstr_len > max_length)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001087 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001088 capped_data = true;
1089 cstr_len = max_length;
1090 }
1091 cstr_address = GetAddressOf (true, &cstr_address_type);
1092 }
1093 else
1094 {
1095 // We have a pointer
1096 cstr_address = GetPointerValue (&cstr_address_type);
1097 }
1098 if (cstr_address != 0 && cstr_address != LLDB_INVALID_ADDRESS)
1099 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001100 Address cstr_so_addr (cstr_address);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001101 DataExtractor data;
1102 size_t bytes_read = 0;
1103 if (cstr_len > 0 && honor_array)
1104 {
1105 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1106 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1107 GetPointeeData(data, 0, cstr_len);
1108
1109 if ((bytes_read = data.GetByteSize()) > 0)
1110 {
1111 s << '"';
1112 data.Dump (&s,
1113 0, // Start offset in "data"
1114 item_format,
1115 1, // Size of item (1 byte for a char!)
1116 bytes_read, // How many bytes to print?
1117 UINT32_MAX, // num per line
1118 LLDB_INVALID_ADDRESS,// base address
1119 0, // bitfield bit size
1120 0); // bitfield bit offset
1121 if (capped_data)
1122 s << "...";
1123 s << '"';
1124 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00001125 }
1126 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001127 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001128 cstr_len = max_length;
1129 const size_t k_max_buf_size = 64;
1130
1131 size_t offset = 0;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001132
Greg Claytoncc4d0142012-02-17 07:49:44 +00001133 int cstr_len_displayed = -1;
1134 bool capped_cstr = false;
1135 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1136 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1137 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001138 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001139 const char *cstr = data.PeekCStr(0);
1140 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1141 if (len > k_max_buf_size)
1142 len = k_max_buf_size;
1143 if (cstr && cstr_len_displayed < 0)
1144 s << '"';
1145
1146 if (cstr_len_displayed < 0)
1147 cstr_len_displayed = len;
1148
1149 if (len == 0)
1150 break;
1151 cstr_len_displayed += len;
1152 if (len > bytes_read)
1153 len = bytes_read;
1154 if (len > cstr_len)
1155 len = cstr_len;
1156
1157 data.Dump (&s,
1158 0, // Start offset in "data"
1159 item_format,
1160 1, // Size of item (1 byte for a char!)
1161 len, // How many bytes to print?
1162 UINT32_MAX, // num per line
1163 LLDB_INVALID_ADDRESS,// base address
1164 0, // bitfield bit size
1165 0); // bitfield bit offset
1166
1167 if (len < k_max_buf_size)
1168 break;
1169
1170 if (len >= cstr_len)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001171 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001172 capped_cstr = true;
1173 break;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001174 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001175
1176 cstr_len -= len;
1177 offset += len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001178 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001179
1180 if (cstr_len_displayed >= 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001181 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001182 s << '"';
1183 if (capped_cstr)
1184 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001185 }
1186 }
1187 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001188 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001189 }
1190 else
1191 {
1192 error.SetErrorString("impossible to read a string from this object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001193 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001194 }
1195}
1196
Jim Ingham53c47f12010-09-10 23:12:17 +00001197const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001198ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001199{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001200
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001201 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001202 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001203
1204 if (!m_object_desc_str.empty())
1205 return m_object_desc_str.c_str();
1206
Greg Claytoncc4d0142012-02-17 07:49:44 +00001207 ExecutionContext exe_ctx (GetExecutionContextRef());
1208 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001209 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001210 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001211
Jim Ingham53c47f12010-09-10 23:12:17 +00001212 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001213
Greg Claytonafacd142011-09-02 01:15:17 +00001214 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001215 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1216
Jim Inghama2cf2632010-12-23 02:29:54 +00001217 if (runtime == NULL)
1218 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001219 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Jim Inghama2cf2632010-12-23 02:29:54 +00001220 clang_type_t opaque_qual_type = GetClangType();
1221 if (opaque_qual_type != NULL)
1222 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001223 bool is_signed;
1224 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed)
1225 || ClangASTContext::IsPointerType (opaque_qual_type))
1226 {
Greg Claytonafacd142011-09-02 01:15:17 +00001227 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001228 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001229 }
1230 }
1231
Jim Ingham8d543de2011-03-31 23:01:21 +00001232 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001233 {
1234 m_object_desc_str.append (s.GetData());
1235 }
Sean Callanan672ad942010-10-23 00:18:49 +00001236
1237 if (m_object_desc_str.empty())
1238 return NULL;
1239 else
1240 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001241}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001242
Enrico Granata0c489f52012-03-01 04:24:26 +00001243bool
1244ValueObject::GetValueAsCString (lldb::Format format,
1245 std::string& destination)
1246{
1247 if (ClangASTContext::IsAggregateType (GetClangType()) == false &&
1248 UpdateValueIfNeeded(false))
1249 {
1250 const Value::ContextType context_type = m_value.GetContextType();
1251
1252 switch (context_type)
1253 {
1254 case Value::eContextTypeClangType:
1255 case Value::eContextTypeLLDBType:
1256 case Value::eContextTypeVariable:
1257 {
1258 clang_type_t clang_type = GetClangType ();
1259 if (clang_type)
1260 {
1261 StreamString sstr;
1262 ExecutionContext exe_ctx (GetExecutionContextRef());
1263 ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
1264 clang_type, // The clang type to display
1265 &sstr,
1266 format, // Format to display this type with
1267 m_data, // Data to extract from
1268 0, // Byte offset into "m_data"
1269 GetByteSize(), // Byte size of item in "m_data"
1270 GetBitfieldBitSize(), // Bitfield bit size
1271 GetBitfieldBitOffset(), // Bitfield bit offset
1272 exe_ctx.GetBestExecutionContextScope());
1273 // Don't set the m_error to anything here otherwise
1274 // we won't be able to re-format as anything else. The
1275 // code for ClangASTType::DumpTypeValue() should always
1276 // return something, even if that something contains
1277 // an error messsage. "m_error" is used to detect errors
1278 // when reading the valid object, not for formatting errors.
1279 if (sstr.GetString().empty())
1280 destination.clear();
1281 else
1282 destination.swap(sstr.GetString());
1283 }
1284 }
1285 break;
1286
1287 case Value::eContextTypeRegisterInfo:
1288 {
1289 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1290 if (reg_info)
1291 {
1292 ExecutionContext exe_ctx (GetExecutionContextRef());
1293
1294 StreamString reg_sstr;
1295 m_data.Dump (&reg_sstr,
1296 0,
1297 format,
1298 reg_info->byte_size,
1299 1,
1300 UINT32_MAX,
1301 LLDB_INVALID_ADDRESS,
1302 0,
1303 0,
1304 exe_ctx.GetBestExecutionContextScope());
1305 destination.swap(reg_sstr.GetString());
1306 }
1307 }
1308 break;
1309
1310 default:
1311 break;
1312 }
1313 return !destination.empty();
1314 }
1315 else
1316 return false;
1317}
1318
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001319const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001320ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001321{
Enrico Granata0c489f52012-03-01 04:24:26 +00001322 if (UpdateValueIfNeeded(true) && m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001323 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001324 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001325 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001326 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001327 if (m_type_format_sp)
1328 my_format = m_type_format_sp->GetFormat();
1329 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001330 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001331 if (m_is_bitfield_for_scalar)
1332 my_format = eFormatUnsigned;
1333 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001334 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001335 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001336 {
1337 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1338 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001339 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001340 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001341 else
1342 {
1343 clang_type_t clang_type = GetClangType ();
1344 my_format = ClangASTType::GetFormat(clang_type);
1345 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001346 }
1347 }
1348 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001349 if (GetValueAsCString(my_format, m_value_str))
1350 {
1351 if (!m_value_did_change && m_old_value_valid)
1352 {
1353 // The value was gotten successfully, so we consider the
1354 // value as changed if the value string differs
1355 SetValueDidChange (m_old_value_str != m_value_str);
1356 }
1357 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001358 }
1359 if (m_value_str.empty())
1360 return NULL;
1361 return m_value_str.c_str();
1362}
1363
Enrico Granatac3e320a2011-08-02 17:27:39 +00001364// if > 8bytes, 0 is returned. this method should mostly be used
1365// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001366uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001367ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001368{
1369 // If our byte size is zero this is an aggregate type that has children
1370 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
1371 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001372 Scalar scalar;
1373 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001374 {
1375 if (success)
1376 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001377 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001378 }
1379 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001380 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001381
1382 if (success)
1383 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001384 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001385}
1386
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001387// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1388// this call up to date by returning true for your new special cases. We will eventually move
1389// to checking this call result before trying to display special cases
1390bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001391ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1392 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001393{
1394 clang_type_t elem_or_pointee_type;
1395 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
1396
1397 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001398 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001399 {
1400 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001401 (custom_format == eFormatCString ||
1402 custom_format == eFormatCharArray ||
1403 custom_format == eFormatChar ||
1404 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001405 return true;
1406
1407 if (flags.Test(ClangASTContext::eTypeIsArray))
1408 {
Greg Claytonafacd142011-09-02 01:15:17 +00001409 if ((custom_format == eFormatBytes) ||
1410 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001411 return true;
1412
Greg Claytonafacd142011-09-02 01:15:17 +00001413 if ((custom_format == eFormatVectorOfChar) ||
1414 (custom_format == eFormatVectorOfFloat32) ||
1415 (custom_format == eFormatVectorOfFloat64) ||
1416 (custom_format == eFormatVectorOfSInt16) ||
1417 (custom_format == eFormatVectorOfSInt32) ||
1418 (custom_format == eFormatVectorOfSInt64) ||
1419 (custom_format == eFormatVectorOfSInt8) ||
1420 (custom_format == eFormatVectorOfUInt128) ||
1421 (custom_format == eFormatVectorOfUInt16) ||
1422 (custom_format == eFormatVectorOfUInt32) ||
1423 (custom_format == eFormatVectorOfUInt64) ||
1424 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001425 return true;
1426 }
1427 }
1428 return false;
1429}
1430
Enrico Granata9fc19442011-07-06 02:13:41 +00001431bool
1432ValueObject::DumpPrintableRepresentation(Stream& s,
1433 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001434 Format custom_format,
Enrico Granata86cc9822012-03-19 22:58:49 +00001435 PrintableRepresentationSpecialCases special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001436{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001437
1438 clang_type_t elem_or_pointee_type;
1439 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001440
Enrico Granata86cc9822012-03-19 22:58:49 +00001441 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1442 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1443
1444 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001445 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001446 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1447 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001448 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001449 // when being asked to get a printable display an array or pointer type directly,
1450 // try to "do the right thing"
1451
1452 if (IsCStringContainer(true) &&
1453 (custom_format == eFormatCString ||
1454 custom_format == eFormatCharArray ||
1455 custom_format == eFormatChar ||
1456 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001457 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001458 Error error;
1459 ReadPointedString(s,
1460 error,
1461 0,
1462 (custom_format == eFormatVectorOfChar) ||
1463 (custom_format == eFormatCharArray));
1464 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001465 }
1466
Enrico Granata86cc9822012-03-19 22:58:49 +00001467 if (custom_format == eFormatEnum)
1468 return false;
1469
1470 // this only works for arrays, because I have no way to know when
1471 // the pointed memory ends, and no special \0 end of data marker
1472 if (flags.Test(ClangASTContext::eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001473 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001474 if ((custom_format == eFormatBytes) ||
1475 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001476 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001477 uint32_t count = GetNumChildren();
1478
1479 s << '[';
1480 for (uint32_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001481 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001482
1483 if (low)
1484 s << ',';
1485
1486 ValueObjectSP child = GetChildAtIndex(low,true);
1487 if (!child.get())
1488 {
1489 s << "<invalid child>";
1490 continue;
1491 }
1492 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1493 }
1494
1495 s << ']';
1496
1497 return true;
1498 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001499
Enrico Granata86cc9822012-03-19 22:58:49 +00001500 if ((custom_format == eFormatVectorOfChar) ||
1501 (custom_format == eFormatVectorOfFloat32) ||
1502 (custom_format == eFormatVectorOfFloat64) ||
1503 (custom_format == eFormatVectorOfSInt16) ||
1504 (custom_format == eFormatVectorOfSInt32) ||
1505 (custom_format == eFormatVectorOfSInt64) ||
1506 (custom_format == eFormatVectorOfSInt8) ||
1507 (custom_format == eFormatVectorOfUInt128) ||
1508 (custom_format == eFormatVectorOfUInt16) ||
1509 (custom_format == eFormatVectorOfUInt32) ||
1510 (custom_format == eFormatVectorOfUInt64) ||
1511 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1512 {
1513 uint32_t count = GetNumChildren();
1514
1515 Format format = FormatManager::GetSingleItemFormat(custom_format);
1516
1517 s << '[';
1518 for (uint32_t low = 0; low < count; low++)
1519 {
1520
1521 if (low)
1522 s << ',';
1523
1524 ValueObjectSP child = GetChildAtIndex(low,true);
1525 if (!child.get())
1526 {
1527 s << "<invalid child>";
1528 continue;
1529 }
1530 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1531 }
1532
1533 s << ']';
1534
1535 return true;
1536 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001537 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001538
1539 if ((custom_format == eFormatBoolean) ||
1540 (custom_format == eFormatBinary) ||
1541 (custom_format == eFormatChar) ||
1542 (custom_format == eFormatCharPrintable) ||
1543 (custom_format == eFormatComplexFloat) ||
1544 (custom_format == eFormatDecimal) ||
1545 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001546 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001547 (custom_format == eFormatFloat) ||
1548 (custom_format == eFormatOctal) ||
1549 (custom_format == eFormatOSType) ||
1550 (custom_format == eFormatUnicode16) ||
1551 (custom_format == eFormatUnicode32) ||
1552 (custom_format == eFormatUnsigned) ||
1553 (custom_format == eFormatPointer) ||
1554 (custom_format == eFormatComplexInteger) ||
1555 (custom_format == eFormatComplex) ||
1556 (custom_format == eFormatDefault)) // use the [] operator
1557 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001558 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001559 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001560
1561 if (only_special)
1562 return false;
1563
Enrico Granata86cc9822012-03-19 22:58:49 +00001564 bool var_success = false;
1565
1566 {
1567 const char * return_value;
1568 std::string alloc_mem;
1569
1570 if (custom_format != eFormatInvalid)
1571 SetFormat(custom_format);
1572
1573 switch(val_obj_display)
1574 {
1575 case eValueObjectRepresentationStyleValue:
1576 return_value = GetValueAsCString();
1577 break;
1578
1579 case eValueObjectRepresentationStyleSummary:
1580 return_value = GetSummaryAsCString();
1581 break;
1582
1583 case eValueObjectRepresentationStyleLanguageSpecific:
1584 return_value = GetObjectDescription();
1585 break;
1586
1587 case eValueObjectRepresentationStyleLocation:
1588 return_value = GetLocationAsCString();
1589 break;
1590
1591 case eValueObjectRepresentationStyleChildrenCount:
1592 {
1593 alloc_mem.resize(512);
1594 return_value = &alloc_mem[0];
1595 int count = GetNumChildren();
1596 snprintf((char*)return_value, 512, "%d", count);
1597 }
1598 break;
1599
1600 case eValueObjectRepresentationStyleType:
1601 return_value = GetTypeName().AsCString();
1602 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001603 }
1604
1605 if (!return_value)
1606 {
1607 if (val_obj_display == eValueObjectRepresentationStyleValue)
1608 return_value = GetSummaryAsCString();
1609 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1610 {
1611 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1612 {
1613 // this thing has no value, and it seems to have no summary
1614 // some combination of unitialized data and other factors can also
1615 // raise this condition, so let's print a nice generic description
1616 {
1617 alloc_mem.resize(684);
1618 return_value = &alloc_mem[0];
1619 snprintf((char*)return_value, 684, "%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1620 }
1621 }
1622 else
1623 return_value = GetValueAsCString();
1624 }
1625 }
1626
1627 if (return_value)
1628 s.PutCString(return_value);
1629 else
1630 {
1631 if (m_error.Fail())
1632 s.Printf("<%s>", m_error.AsCString());
1633 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1634 s.PutCString("<no summary available>");
1635 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1636 s.PutCString("<no value available>");
1637 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1638 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1639 else
1640 s.PutCString("<no printable representation>");
1641 }
1642
1643 // we should only return false here if we could not do *anything*
1644 // even if we have an error message as output, that's a success
1645 // from our callers' perspective, so return true
1646 var_success = true;
1647
1648 if (custom_format != eFormatInvalid)
1649 SetFormat(eFormatDefault);
1650 }
1651
Enrico Granataf4efecd2011-07-12 22:56:10 +00001652 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001653}
1654
Greg Clayton737b9322010-09-13 03:32:57 +00001655addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001656ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001657{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001658 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001659 return LLDB_INVALID_ADDRESS;
1660
Greg Clayton73b472d2010-10-27 03:32:59 +00001661 switch (m_value.GetValueType())
1662 {
1663 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001664 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001665 if (scalar_is_load_address)
1666 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001667 if(address_type)
1668 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001669 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1670 }
1671 break;
1672
1673 case Value::eValueTypeLoadAddress:
1674 case Value::eValueTypeFileAddress:
1675 case Value::eValueTypeHostAddress:
1676 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001677 if(address_type)
1678 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001679 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1680 }
1681 break;
1682 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001683 if (address_type)
1684 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001685 return LLDB_INVALID_ADDRESS;
1686}
1687
1688addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001689ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001690{
Greg Claytonafacd142011-09-02 01:15:17 +00001691 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001692 if(address_type)
1693 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001694
Enrico Granatac3e320a2011-08-02 17:27:39 +00001695 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001696 return address;
1697
Greg Clayton73b472d2010-10-27 03:32:59 +00001698 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001699 {
1700 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001701 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001702 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001703 break;
1704
Enrico Granata9128ee22011-09-06 19:20:51 +00001705 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001706 case Value::eValueTypeLoadAddress:
1707 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001708 {
1709 uint32_t data_offset = 0;
1710 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001711 }
1712 break;
1713 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001714
Enrico Granata9128ee22011-09-06 19:20:51 +00001715 if (address_type)
1716 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001717
Greg Clayton737b9322010-09-13 03:32:57 +00001718 return address;
1719}
1720
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001721bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001722ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001723{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001724 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001725 // Make sure our value is up to date first so that our location and location
1726 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001727 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001728 {
1729 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001730 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001731 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001732
1733 uint32_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001734 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001735
Greg Claytonb1320972010-07-14 00:18:15 +00001736 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001737
Jim Ingham16e0c682011-08-12 23:34:31 +00001738 Value::ValueType value_type = m_value.GetValueType();
1739
1740 if (value_type == Value::eValueTypeScalar)
1741 {
1742 // If the value is already a scalar, then let the scalar change itself:
1743 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1744 }
1745 else if (byte_size <= Scalar::GetMaxByteSize())
1746 {
1747 // If the value fits in a scalar, then make a new scalar and again let the
1748 // scalar code do the conversion, then figure out where to put the new value.
1749 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001750 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1751 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001752 {
Jim Ingham4b536182011-08-09 02:12:22 +00001753 switch (value_type)
1754 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001755 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001756 {
1757 // If it is a load address, then the scalar value is the storage location
1758 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001759 ExecutionContext exe_ctx (GetExecutionContextRef());
1760 Process *process = exe_ctx.GetProcessPtr();
1761 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001762 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001763 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001764 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1765 new_scalar,
1766 byte_size,
1767 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001768 if (!error.Success())
1769 return false;
1770 if (bytes_written != byte_size)
1771 {
1772 error.SetErrorString("unable to write value to memory");
1773 return false;
1774 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001775 }
1776 }
Jim Ingham4b536182011-08-09 02:12:22 +00001777 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001778 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001779 {
1780 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1781 DataExtractor new_data;
1782 new_data.SetByteOrder (m_data.GetByteOrder());
1783
1784 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1785 m_data.SetData(buffer_sp, 0);
1786 bool success = new_scalar.GetData(new_data);
1787 if (success)
1788 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001789 new_data.CopyByteOrderedData (0,
1790 byte_size,
1791 const_cast<uint8_t *>(m_data.GetDataStart()),
1792 byte_size,
1793 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001794 }
1795 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1796
1797 }
Jim Ingham4b536182011-08-09 02:12:22 +00001798 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001799 case Value::eValueTypeFileAddress:
1800 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001801 case Value::eValueTypeVector:
1802 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001803 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001804 }
1805 else
1806 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001807 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001808 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001809 }
1810 else
1811 {
1812 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001813 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001814 return false;
1815 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001816
1817 // If we have reached this point, then we have successfully changed the value.
1818 SetNeedsUpdate();
1819 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001820}
1821
Greg Clayton81e871e2012-02-04 02:27:34 +00001822bool
1823ValueObject::GetDeclaration (Declaration &decl)
1824{
1825 decl.Clear();
1826 return false;
1827}
1828
Greg Clayton84db9102012-03-26 23:03:23 +00001829ConstString
1830ValueObject::GetTypeName()
1831{
1832 return ClangASTType::GetConstTypeName (GetClangAST(), GetClangType());
1833}
1834
1835ConstString
1836ValueObject::GetQualifiedTypeName()
1837{
1838 return ClangASTType::GetConstQualifiedTypeName (GetClangAST(), GetClangType());
1839}
1840
1841
Greg Claytonafacd142011-09-02 01:15:17 +00001842LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001843ValueObject::GetObjectRuntimeLanguage ()
1844{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001845 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1846 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001847}
1848
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001849void
Jim Ingham58b59f92011-04-22 23:53:53 +00001850ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001851{
Jim Ingham58b59f92011-04-22 23:53:53 +00001852 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001853}
1854
1855ValueObjectSP
1856ValueObject::GetSyntheticChild (const ConstString &key) const
1857{
1858 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001859 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001860 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001861 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001862 return synthetic_child_sp;
1863}
1864
1865bool
1866ValueObject::IsPointerType ()
1867{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001868 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001869}
1870
Jim Inghamb7603bb2011-03-18 00:05:18 +00001871bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001872ValueObject::IsArrayType ()
1873{
Greg Clayton4ef877f2012-12-06 02:33:54 +00001874 return ClangASTContext::IsArrayType (GetClangType(), NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00001875}
1876
1877bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001878ValueObject::IsScalarType ()
1879{
1880 return ClangASTContext::IsScalarType (GetClangType());
1881}
1882
1883bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001884ValueObject::IsIntegerType (bool &is_signed)
1885{
1886 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1887}
Greg Clayton73b472d2010-10-27 03:32:59 +00001888
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001889bool
1890ValueObject::IsPointerOrReferenceType ()
1891{
Greg Clayton007d5be2011-05-30 00:49:24 +00001892 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1893}
1894
1895bool
Greg Claytondea8cb42011-06-29 22:09:02 +00001896ValueObject::IsPossibleDynamicType ()
1897{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00001898 ExecutionContext exe_ctx (GetExecutionContextRef());
1899 Process *process = exe_ctx.GetProcessPtr();
1900 if (process)
1901 return process->IsPossibleDynamicValue(*this);
1902 else
Greg Clayton70364252012-08-31 18:56:24 +00001903 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType(), NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00001904}
1905
Enrico Granata9e7b3882012-12-13 23:50:33 +00001906bool
1907ValueObject::IsObjCNil ()
1908{
1909 bool isObjCpointer = ClangASTContext::IsObjCObjectPointerType(GetClangType(), NULL);
1910 bool canReadValue = true;
1911 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
1912 return canReadValue && isZero && isObjCpointer;
1913}
1914
Greg Claytonafacd142011-09-02 01:15:17 +00001915ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001916ValueObject::GetSyntheticArrayMember (int32_t index, bool can_create)
1917{
1918 if (IsArrayType())
1919 return GetSyntheticArrayMemberFromArray(index, can_create);
1920
1921 if (IsPointerType())
1922 return GetSyntheticArrayMemberFromPointer(index, can_create);
1923
1924 return ValueObjectSP();
1925
1926}
1927
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001928ValueObjectSP
1929ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1930{
1931 ValueObjectSP synthetic_child_sp;
1932 if (IsPointerType ())
1933 {
1934 char index_str[64];
1935 snprintf(index_str, sizeof(index_str), "[%i]", index);
1936 ConstString index_const_str(index_str);
1937 // Check if we have already created a synthetic array member in this
1938 // valid object. If we have we will re-use it.
1939 synthetic_child_sp = GetSyntheticChild (index_const_str);
1940 if (!synthetic_child_sp)
1941 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001942 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001943 // We haven't made a synthetic array member for INDEX yet, so
1944 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001945 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001946
1947 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001948 if (synthetic_child)
1949 {
1950 AddSyntheticChild(index_const_str, synthetic_child);
1951 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001952 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001953 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001954 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001955 }
1956 }
1957 return synthetic_child_sp;
1958}
Jim Ingham22777012010-09-23 02:01:19 +00001959
Greg Claytondaf515f2011-07-09 20:12:33 +00001960// This allows you to create an array member using and index
1961// that doesn't not fall in the normal bounds of the array.
1962// Many times structure can be defined as:
1963// struct Collection
1964// {
1965// uint32_t item_count;
1966// Item item_array[0];
1967// };
1968// The size of the "item_array" is 1, but many times in practice
1969// there are more items in "item_array".
1970
1971ValueObjectSP
1972ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1973{
1974 ValueObjectSP synthetic_child_sp;
1975 if (IsArrayType ())
1976 {
1977 char index_str[64];
1978 snprintf(index_str, sizeof(index_str), "[%i]", index);
1979 ConstString index_const_str(index_str);
1980 // Check if we have already created a synthetic array member in this
1981 // valid object. If we have we will re-use it.
1982 synthetic_child_sp = GetSyntheticChild (index_const_str);
1983 if (!synthetic_child_sp)
1984 {
1985 ValueObject *synthetic_child;
1986 // We haven't made a synthetic array member for INDEX yet, so
1987 // lets make one and cache it for any future reference.
1988 synthetic_child = CreateChildAtIndex(0, true, index);
1989
1990 // Cache the value if we got one back...
1991 if (synthetic_child)
1992 {
1993 AddSyntheticChild(index_const_str, synthetic_child);
1994 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001995 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001996 synthetic_child_sp->m_is_array_item_for_pointer = true;
1997 }
1998 }
1999 }
2000 return synthetic_child_sp;
2001}
2002
Enrico Granata9fc19442011-07-06 02:13:41 +00002003ValueObjectSP
2004ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2005{
2006 ValueObjectSP synthetic_child_sp;
2007 if (IsScalarType ())
2008 {
2009 char index_str[64];
2010 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2011 ConstString index_const_str(index_str);
2012 // Check if we have already created a synthetic array member in this
2013 // valid object. If we have we will re-use it.
2014 synthetic_child_sp = GetSyntheticChild (index_const_str);
2015 if (!synthetic_child_sp)
2016 {
2017 ValueObjectChild *synthetic_child;
2018 // We haven't made a synthetic array member for INDEX yet, so
2019 // lets make one and cache it for any future reference.
2020 synthetic_child = new ValueObjectChild(*this,
2021 GetClangAST(),
2022 GetClangType(),
2023 index_const_str,
2024 GetByteSize(),
2025 0,
2026 to-from+1,
2027 from,
2028 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002029 false,
2030 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002031
2032 // Cache the value if we got one back...
2033 if (synthetic_child)
2034 {
2035 AddSyntheticChild(index_const_str, synthetic_child);
2036 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002037 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002038 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2039 }
2040 }
2041 }
2042 return synthetic_child_sp;
2043}
2044
Greg Claytonafacd142011-09-02 01:15:17 +00002045ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002046ValueObject::GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create)
2047{
2048 ValueObjectSP synthetic_child_sp;
2049 if (IsArrayType () || IsPointerType ())
2050 {
2051 char index_str[64];
2052 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2053 ConstString index_const_str(index_str);
2054 // Check if we have already created a synthetic array member in this
2055 // valid object. If we have we will re-use it.
2056 synthetic_child_sp = GetSyntheticChild (index_const_str);
2057 if (!synthetic_child_sp)
2058 {
2059 ValueObjectSynthetic *synthetic_child;
2060
2061 // We haven't made a synthetic array member for INDEX yet, so
2062 // lets make one and cache it for any future reference.
Enrico Granata061858c2012-02-15 02:34:21 +00002063 SyntheticArrayView *view = new SyntheticArrayView(SyntheticChildren::Flags());
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002064 view->AddRange(from,to);
2065 SyntheticChildrenSP view_sp(view);
2066 synthetic_child = new ValueObjectSynthetic(*this, view_sp);
2067
2068 // Cache the value if we got one back...
2069 if (synthetic_child)
2070 {
2071 AddSyntheticChild(index_const_str, synthetic_child);
2072 synthetic_child_sp = synthetic_child->GetSP();
2073 synthetic_child_sp->SetName(ConstString(index_str));
2074 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2075 }
2076 }
2077 }
2078 return synthetic_child_sp;
2079}
2080
Greg Claytonafacd142011-09-02 01:15:17 +00002081ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00002082ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
2083{
2084
2085 ValueObjectSP synthetic_child_sp;
2086
2087 char name_str[64];
2088 snprintf(name_str, sizeof(name_str), "@%i", offset);
2089 ConstString name_const_str(name_str);
2090
2091 // Check if we have already created a synthetic array member in this
2092 // valid object. If we have we will re-use it.
2093 synthetic_child_sp = GetSyntheticChild (name_const_str);
2094
2095 if (synthetic_child_sp.get())
2096 return synthetic_child_sp;
2097
2098 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002099 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002100
2101 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2102 type.GetASTContext(),
2103 type.GetOpaqueQualType(),
2104 name_const_str,
2105 type.GetTypeByteSize(),
2106 offset,
2107 0,
2108 0,
2109 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002110 false,
2111 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002112 if (synthetic_child)
2113 {
2114 AddSyntheticChild(name_const_str, synthetic_child);
2115 synthetic_child_sp = synthetic_child->GetSP();
2116 synthetic_child_sp->SetName(name_const_str);
2117 synthetic_child_sp->m_is_child_at_offset = true;
2118 }
2119 return synthetic_child_sp;
2120}
2121
Enrico Granatad55546b2011-07-22 00:16:08 +00002122// your expression path needs to have a leading . or ->
2123// (unless it somehow "looks like" an array, in which case it has
2124// a leading [ symbol). while the [ is meaningful and should be shown
2125// to the user, . and -> are just parser design, but by no means
2126// added information for the user.. strip them off
2127static const char*
2128SkipLeadingExpressionPathSeparators(const char* expression)
2129{
2130 if (!expression || !expression[0])
2131 return expression;
2132 if (expression[0] == '.')
2133 return expression+1;
2134 if (expression[0] == '-' && expression[1] == '>')
2135 return expression+2;
2136 return expression;
2137}
2138
Greg Claytonafacd142011-09-02 01:15:17 +00002139ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002140ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2141{
2142 ValueObjectSP synthetic_child_sp;
2143 ConstString name_const_string(expression);
2144 // Check if we have already created a synthetic array member in this
2145 // valid object. If we have we will re-use it.
2146 synthetic_child_sp = GetSyntheticChild (name_const_string);
2147 if (!synthetic_child_sp)
2148 {
2149 // We haven't made a synthetic array member for expression yet, so
2150 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002151 synthetic_child_sp = GetValueForExpressionPath(expression,
2152 NULL, NULL, NULL,
2153 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
Enrico Granatad55546b2011-07-22 00:16:08 +00002154
2155 // Cache the value if we got one back...
2156 if (synthetic_child_sp.get())
2157 {
2158 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002159 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002160 synthetic_child_sp->m_is_expression_path_child = true;
2161 }
2162 }
2163 return synthetic_child_sp;
2164}
2165
2166void
Enrico Granata86cc9822012-03-19 22:58:49 +00002167ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002168{
Enrico Granata86cc9822012-03-19 22:58:49 +00002169 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002170 return;
2171
Enrico Granatac5bc4122012-03-27 02:35:13 +00002172 TargetSP target_sp(GetTargetSP());
2173 if (target_sp && (target_sp->GetEnableSyntheticValue() == false || target_sp->GetSuppressSyntheticValue() == true))
2174 {
2175 m_synthetic_value = NULL;
2176 return;
2177 }
2178
Enrico Granatae3e91512012-10-22 18:18:36 +00002179 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2180
Enrico Granata86cc9822012-03-19 22:58:49 +00002181 if (!UpdateFormatsIfNeeded(m_last_format_mgr_dynamic) && m_synthetic_value)
2182 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002183
Enrico Granata0c489f52012-03-01 04:24:26 +00002184 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002185 return;
2186
Enrico Granatae3e91512012-10-22 18:18:36 +00002187 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2188 return;
2189
Enrico Granata86cc9822012-03-19 22:58:49 +00002190 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002191}
2192
Jim Ingham78a685a2011-04-16 00:01:13 +00002193void
Greg Claytonafacd142011-09-02 01:15:17 +00002194ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002195{
Greg Claytonafacd142011-09-02 01:15:17 +00002196 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002197 return;
2198
Jim Ingham58b59f92011-04-22 23:53:53 +00002199 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002200 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002201 ExecutionContext exe_ctx (GetExecutionContextRef());
2202 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002203 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002204 {
2205 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002206 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002207 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002208 }
2209}
2210
Jim Ingham58b59f92011-04-22 23:53:53 +00002211ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002212ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002213{
Greg Claytonafacd142011-09-02 01:15:17 +00002214 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002215 return ValueObjectSP();
2216
2217 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002218 {
Jim Ingham2837b762011-05-04 03:43:18 +00002219 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002220 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002221 if (m_dynamic_value)
2222 return m_dynamic_value->GetSP();
2223 else
2224 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002225}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002226
Jim Ingham60dbabb2011-12-08 19:44:08 +00002227ValueObjectSP
2228ValueObject::GetStaticValue()
2229{
2230 return GetSP();
2231}
2232
Enrico Granata886147f2012-05-08 18:47:08 +00002233lldb::ValueObjectSP
2234ValueObject::GetNonSyntheticValue ()
2235{
2236 return GetSP();
2237}
2238
Enrico Granatad55546b2011-07-22 00:16:08 +00002239ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002240ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002241{
Enrico Granata86cc9822012-03-19 22:58:49 +00002242 if (use_synthetic == false)
2243 return ValueObjectSP();
2244
Enrico Granatad55546b2011-07-22 00:16:08 +00002245 CalculateSyntheticValue(use_synthetic);
2246
2247 if (m_synthetic_value)
2248 return m_synthetic_value->GetSP();
2249 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002250 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002251}
2252
Greg Claytone221f822011-01-21 01:59:00 +00002253bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002254ValueObject::HasSyntheticValue()
2255{
2256 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
2257
Enrico Granata0c489f52012-03-01 04:24:26 +00002258 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002259 return false;
2260
Enrico Granata86cc9822012-03-19 22:58:49 +00002261 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002262
2263 if (m_synthetic_value)
2264 return true;
2265 else
2266 return false;
2267}
2268
2269bool
Greg Claytone221f822011-01-21 01:59:00 +00002270ValueObject::GetBaseClassPath (Stream &s)
2271{
2272 if (IsBaseClass())
2273 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002274 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00002275 clang_type_t clang_type = GetClangType();
2276 std::string cxx_class_name;
2277 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
2278 if (this_had_base_class)
2279 {
2280 if (parent_had_base_class)
2281 s.PutCString("::");
2282 s.PutCString(cxx_class_name.c_str());
2283 }
2284 return parent_had_base_class || this_had_base_class;
2285 }
2286 return false;
2287}
2288
2289
2290ValueObject *
2291ValueObject::GetNonBaseClassParent()
2292{
Jim Ingham78a685a2011-04-16 00:01:13 +00002293 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002294 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002295 if (GetParent()->IsBaseClass())
2296 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002297 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002298 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002299 }
2300 return NULL;
2301}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002302
2303void
Enrico Granata4becb372011-06-29 22:27:15 +00002304ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002305{
Greg Claytone221f822011-01-21 01:59:00 +00002306 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002307
Enrico Granata86cc9822012-03-19 22:58:49 +00002308 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002309 {
Enrico Granata4becb372011-06-29 22:27:15 +00002310 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2311 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2312 // the eHonorPointers mode is meant to produce strings in this latter format
2313 s.PutCString("*(");
2314 }
Greg Claytone221f822011-01-21 01:59:00 +00002315
Enrico Granata4becb372011-06-29 22:27:15 +00002316 ValueObject* parent = GetParent();
2317
2318 if (parent)
2319 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002320
2321 // if we are a deref_of_parent just because we are synthetic array
2322 // members made up to allow ptr[%d] syntax to work in variable
2323 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002324 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002325 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002326
Greg Claytone221f822011-01-21 01:59:00 +00002327 if (!IsBaseClass())
2328 {
2329 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002330 {
Greg Claytone221f822011-01-21 01:59:00 +00002331 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2332 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002333 {
Greg Claytone221f822011-01-21 01:59:00 +00002334 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2335 if (non_base_class_parent_clang_type)
2336 {
2337 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2338
Enrico Granata86cc9822012-03-19 22:58:49 +00002339 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002340 {
2341 s.PutCString("->");
2342 }
Enrico Granata4becb372011-06-29 22:27:15 +00002343 else
2344 {
2345 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2346 {
2347 s.PutCString("->");
2348 }
2349 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2350 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2351 {
2352 s.PutChar('.');
2353 }
Greg Claytone221f822011-01-21 01:59:00 +00002354 }
2355 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002356 }
Greg Claytone221f822011-01-21 01:59:00 +00002357
2358 const char *name = GetName().GetCString();
2359 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002360 {
Greg Claytone221f822011-01-21 01:59:00 +00002361 if (qualify_cxx_base_classes)
2362 {
2363 if (GetBaseClassPath (s))
2364 s.PutCString("::");
2365 }
2366 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002367 }
2368 }
2369 }
2370
Enrico Granata86cc9822012-03-19 22:58:49 +00002371 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002372 {
Greg Claytone221f822011-01-21 01:59:00 +00002373 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002374 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002375}
2376
Greg Claytonafacd142011-09-02 01:15:17 +00002377ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002378ValueObject::GetValueForExpressionPath(const char* expression,
2379 const char** first_unparsed,
2380 ExpressionPathScanEndReason* reason_to_stop,
2381 ExpressionPathEndResultType* final_value_type,
2382 const GetValueForExpressionPathOptions& options,
2383 ExpressionPathAftermath* final_task_on_target)
2384{
2385
2386 const char* dummy_first_unparsed;
2387 ExpressionPathScanEndReason dummy_reason_to_stop;
2388 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002389 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002390
2391 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2392 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2393 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2394 final_value_type ? final_value_type : &dummy_final_value_type,
2395 options,
2396 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2397
Enrico Granata86cc9822012-03-19 22:58:49 +00002398 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002399 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002400
Enrico Granata86cc9822012-03-19 22:58:49 +00002401 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 +00002402 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002403 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002404 {
2405 Error error;
2406 ValueObjectSP final_value = ret_val->Dereference(error);
2407 if (error.Fail() || !final_value.get())
2408 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002409 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002410 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002411 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002412 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002413 return ValueObjectSP();
2414 }
2415 else
2416 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002417 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002418 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002419 return final_value;
2420 }
2421 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002422 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002423 {
2424 Error error;
2425 ValueObjectSP final_value = ret_val->AddressOf(error);
2426 if (error.Fail() || !final_value.get())
2427 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002428 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002429 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002430 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002431 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002432 return ValueObjectSP();
2433 }
2434 else
2435 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002436 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002437 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002438 return final_value;
2439 }
2440 }
2441 }
2442 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2443}
2444
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002445int
2446ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002447 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002448 const char** first_unparsed,
2449 ExpressionPathScanEndReason* reason_to_stop,
2450 ExpressionPathEndResultType* final_value_type,
2451 const GetValueForExpressionPathOptions& options,
2452 ExpressionPathAftermath* final_task_on_target)
2453{
2454 const char* dummy_first_unparsed;
2455 ExpressionPathScanEndReason dummy_reason_to_stop;
2456 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002457 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002458
2459 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2460 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2461 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2462 final_value_type ? final_value_type : &dummy_final_value_type,
2463 options,
2464 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2465
2466 if (!ret_val.get()) // if there are errors, I add nothing to the list
2467 return 0;
2468
Enrico Granata86ea8d82012-03-29 01:34:34 +00002469 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002470 {
2471 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002472 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002473 {
2474 list->Append(ret_val);
2475 return 1;
2476 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002477 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 +00002478 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002479 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002480 {
2481 Error error;
2482 ValueObjectSP final_value = ret_val->Dereference(error);
2483 if (error.Fail() || !final_value.get())
2484 {
Greg Clayton23f59502012-07-17 03:23:13 +00002485 if (reason_to_stop)
2486 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2487 if (final_value_type)
2488 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002489 return 0;
2490 }
2491 else
2492 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002493 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002494 list->Append(final_value);
2495 return 1;
2496 }
2497 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002498 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002499 {
2500 Error error;
2501 ValueObjectSP final_value = ret_val->AddressOf(error);
2502 if (error.Fail() || !final_value.get())
2503 {
Greg Clayton23f59502012-07-17 03:23:13 +00002504 if (reason_to_stop)
2505 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2506 if (final_value_type)
2507 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002508 return 0;
2509 }
2510 else
2511 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002512 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002513 list->Append(final_value);
2514 return 1;
2515 }
2516 }
2517 }
2518 }
2519 else
2520 {
2521 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2522 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2523 ret_val,
2524 list,
2525 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2526 final_value_type ? final_value_type : &dummy_final_value_type,
2527 options,
2528 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2529 }
2530 // in any non-covered case, just do the obviously right thing
2531 list->Append(ret_val);
2532 return 1;
2533}
2534
Greg Claytonafacd142011-09-02 01:15:17 +00002535ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002536ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2537 const char** first_unparsed,
2538 ExpressionPathScanEndReason* reason_to_stop,
2539 ExpressionPathEndResultType* final_result,
2540 const GetValueForExpressionPathOptions& options,
2541 ExpressionPathAftermath* what_next)
2542{
2543 ValueObjectSP root = GetSP();
2544
2545 if (!root.get())
2546 return ValueObjectSP();
2547
2548 *first_unparsed = expression_cstr;
2549
2550 while (true)
2551 {
2552
2553 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2554
Greg Claytonafacd142011-09-02 01:15:17 +00002555 clang_type_t root_clang_type = root->GetClangType();
2556 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002557 Flags root_clang_type_info,pointee_clang_type_info;
2558
2559 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2560 if (pointee_clang_type)
2561 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002562
2563 if (!expression_cstr || *expression_cstr == '\0')
2564 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002565 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002566 return root;
2567 }
2568
2569 switch (*expression_cstr)
2570 {
2571 case '-':
2572 {
2573 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002574 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 +00002575 {
2576 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002577 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2578 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002579 return ValueObjectSP();
2580 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002581 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2582 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002583 options.m_no_fragile_ivar)
2584 {
2585 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002586 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2587 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002588 return ValueObjectSP();
2589 }
2590 if (expression_cstr[1] != '>')
2591 {
2592 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002593 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2594 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002595 return ValueObjectSP();
2596 }
2597 expression_cstr++; // skip the -
2598 }
2599 case '.': // or fallthrough from ->
2600 {
2601 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002602 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 +00002603 {
2604 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002605 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2606 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002607 return ValueObjectSP();
2608 }
2609 expression_cstr++; // skip .
2610 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2611 ConstString child_name;
2612 if (!next_separator) // if no other separator just expand this last layer
2613 {
2614 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002615 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2616
2617 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002618 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002619 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002620 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2621 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002622 return child_valobj_sp;
2623 }
2624 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2625 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002626 if (root->IsSynthetic())
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002627 {
2628 *first_unparsed = expression_cstr;
2629 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2630 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2631 return ValueObjectSP();
2632 }
2633
2634 child_valobj_sp = root->GetSyntheticValue();
Enrico Granata86cc9822012-03-19 22:58:49 +00002635 if (child_valobj_sp.get())
2636 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002637 }
2638
2639 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2640 // so we hit the "else" branch, and return an error
2641 if(child_valobj_sp.get()) // if it worked, just return
2642 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002643 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002644 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2645 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002646 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002647 }
2648 else
2649 {
2650 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002651 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2652 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002653 return ValueObjectSP();
2654 }
2655 }
2656 else // other layers do expand
2657 {
2658 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002659 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2660 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002661 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002662 root = child_valobj_sp;
2663 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002664 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002665 continue;
2666 }
2667 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2668 {
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002669 if (root->IsSynthetic())
2670 {
2671 *first_unparsed = expression_cstr;
2672 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2673 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2674 return ValueObjectSP();
2675 }
2676
Enrico Granata86cc9822012-03-19 22:58:49 +00002677 child_valobj_sp = root->GetSyntheticValue(true);
2678 if (child_valobj_sp)
2679 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002680 }
2681
2682 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2683 // so we hit the "else" branch, and return an error
2684 if(child_valobj_sp.get()) // if it worked, move on
2685 {
2686 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002687 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002688 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002689 continue;
2690 }
2691 else
2692 {
2693 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002694 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2695 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002696 return ValueObjectSP();
2697 }
2698 }
2699 break;
2700 }
2701 case '[':
2702 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002703 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 +00002704 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002705 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002706 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002707 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2708 {
2709 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002710 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2711 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002712 return ValueObjectSP();
2713 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002714 }
2715 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2716 {
2717 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002718 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2719 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002720 return ValueObjectSP();
2721 }
2722 }
2723 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2724 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002725 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002726 {
2727 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002728 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2729 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002730 return ValueObjectSP();
2731 }
2732 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2733 {
2734 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002735 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2736 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002737 return root;
2738 }
2739 }
2740 const char *separator_position = ::strchr(expression_cstr+1,'-');
2741 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2742 if (!close_bracket_position) // if there is no ], this is a syntax error
2743 {
2744 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002745 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2746 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002747 return ValueObjectSP();
2748 }
2749 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2750 {
2751 char *end = NULL;
2752 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2753 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2754 {
2755 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002756 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2757 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002758 return ValueObjectSP();
2759 }
2760 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2761 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002762 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002763 {
2764 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002765 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2766 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002767 return root;
2768 }
2769 else
2770 {
2771 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002772 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2773 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002774 return ValueObjectSP();
2775 }
2776 }
2777 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002778 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002779 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002780 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2781 if (!child_valobj_sp)
2782 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002783 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002784 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2785 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002786 if (child_valobj_sp)
2787 {
2788 root = child_valobj_sp;
2789 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002790 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002791 continue;
2792 }
2793 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002794 {
2795 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002796 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2797 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002798 return ValueObjectSP();
2799 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002800 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002801 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002802 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002803 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 +00002804 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002805 {
2806 Error error;
2807 root = root->Dereference(error);
2808 if (error.Fail() || !root.get())
2809 {
2810 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002811 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2812 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002813 return ValueObjectSP();
2814 }
2815 else
2816 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002817 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002818 continue;
2819 }
2820 }
2821 else
2822 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002823 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Clayton84db9102012-03-26 23:03:23 +00002824 root->GetClangType()) == eLanguageTypeObjC
2825 && ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2826 && root->HasSyntheticValue()
2827 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002828 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002829 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002830 }
2831 else
2832 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002833 if (!root.get())
2834 {
2835 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002836 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2837 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002838 return ValueObjectSP();
2839 }
2840 else
2841 {
2842 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002843 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002844 continue;
2845 }
2846 }
2847 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002848 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002849 {
2850 root = root->GetSyntheticBitFieldChild(index, index, true);
2851 if (!root.get())
2852 {
2853 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002854 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2855 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002856 return ValueObjectSP();
2857 }
2858 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2859 {
2860 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002861 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2862 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002863 return root;
2864 }
2865 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002866 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002867 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002868 if (root->HasSyntheticValue())
2869 root = root->GetSyntheticValue();
2870 else if (!root->IsSynthetic())
2871 {
2872 *first_unparsed = expression_cstr;
2873 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2874 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2875 return ValueObjectSP();
2876 }
2877 // if we are here, then root itself is a synthetic VO.. should be good to go
2878
Enrico Granata27b625e2011-08-09 01:04:56 +00002879 if (!root.get())
2880 {
2881 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002882 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2883 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2884 return ValueObjectSP();
2885 }
2886 root = root->GetChildAtIndex(index, true);
2887 if (!root.get())
2888 {
2889 *first_unparsed = expression_cstr;
2890 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2891 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002892 return ValueObjectSP();
2893 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002894 else
2895 {
2896 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002897 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002898 continue;
2899 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002900 }
2901 else
2902 {
2903 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002904 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2905 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002906 return ValueObjectSP();
2907 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002908 }
2909 else // we have a low and a high index
2910 {
2911 char *end = NULL;
2912 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2913 if (!end || end != separator_position) // if something weird is in our way return an error
2914 {
2915 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002916 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2917 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002918 return ValueObjectSP();
2919 }
2920 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2921 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2922 {
2923 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002924 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2925 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002926 return ValueObjectSP();
2927 }
2928 if (index_lower > index_higher) // swap indices if required
2929 {
2930 unsigned long temp = index_lower;
2931 index_lower = index_higher;
2932 index_higher = temp;
2933 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002934 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002935 {
2936 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2937 if (!root.get())
2938 {
2939 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002940 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2941 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002942 return ValueObjectSP();
2943 }
2944 else
2945 {
2946 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002947 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2948 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002949 return root;
2950 }
2951 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002952 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 +00002953 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002954 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002955 {
2956 Error error;
2957 root = root->Dereference(error);
2958 if (error.Fail() || !root.get())
2959 {
2960 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002961 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2962 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002963 return ValueObjectSP();
2964 }
2965 else
2966 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002967 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002968 continue;
2969 }
2970 }
2971 else
2972 {
2973 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002974 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2975 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002976 return root;
2977 }
2978 }
2979 break;
2980 }
2981 default: // some non-separator is in the way
2982 {
2983 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002984 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2985 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002986 return ValueObjectSP();
2987 break;
2988 }
2989 }
2990 }
2991}
2992
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002993int
2994ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2995 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002996 ValueObjectSP root,
2997 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002998 ExpressionPathScanEndReason* reason_to_stop,
2999 ExpressionPathEndResultType* final_result,
3000 const GetValueForExpressionPathOptions& options,
3001 ExpressionPathAftermath* what_next)
3002{
3003 if (!root.get())
3004 return 0;
3005
3006 *first_unparsed = expression_cstr;
3007
3008 while (true)
3009 {
3010
3011 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3012
Greg Claytonafacd142011-09-02 01:15:17 +00003013 clang_type_t root_clang_type = root->GetClangType();
3014 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003015 Flags root_clang_type_info,pointee_clang_type_info;
3016
3017 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
3018 if (pointee_clang_type)
3019 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
3020
3021 if (!expression_cstr || *expression_cstr == '\0')
3022 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003023 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003024 list->Append(root);
3025 return 1;
3026 }
3027
3028 switch (*expression_cstr)
3029 {
3030 case '[':
3031 {
3032 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
3033 {
3034 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
3035 {
3036 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003037 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3038 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003039 return 0;
3040 }
3041 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3042 {
3043 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003044 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3045 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003046 return 0;
3047 }
3048 }
3049 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3050 {
3051 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3052 {
3053 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003054 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3055 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003056 return 0;
3057 }
3058 else // expand this into list
3059 {
3060 int max_index = root->GetNumChildren() - 1;
3061 for (int index = 0; index < max_index; index++)
3062 {
3063 ValueObjectSP child =
3064 root->GetChildAtIndex(index, true);
3065 list->Append(child);
3066 }
3067 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003068 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3069 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003070 return max_index; // tell me number of items I added to the VOList
3071 }
3072 }
3073 const char *separator_position = ::strchr(expression_cstr+1,'-');
3074 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3075 if (!close_bracket_position) // if there is no ], this is a syntax error
3076 {
3077 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003078 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3079 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003080 return 0;
3081 }
3082 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3083 {
3084 char *end = NULL;
3085 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3086 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3087 {
3088 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003089 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3090 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003091 return 0;
3092 }
3093 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3094 {
3095 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3096 {
3097 int max_index = root->GetNumChildren() - 1;
3098 for (int index = 0; index < max_index; index++)
3099 {
3100 ValueObjectSP child =
3101 root->GetChildAtIndex(index, true);
3102 list->Append(child);
3103 }
3104 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003105 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3106 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003107 return max_index; // tell me number of items I added to the VOList
3108 }
3109 else
3110 {
3111 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003112 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3113 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003114 return 0;
3115 }
3116 }
3117 // from here on we do have a valid index
3118 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3119 {
3120 root = root->GetChildAtIndex(index, true);
3121 if (!root.get())
3122 {
3123 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003124 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3125 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003126 return 0;
3127 }
3128 else
3129 {
3130 list->Append(root);
3131 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003132 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3133 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003134 return 1;
3135 }
3136 }
3137 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
3138 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003139 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 +00003140 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3141 {
3142 Error error;
3143 root = root->Dereference(error);
3144 if (error.Fail() || !root.get())
3145 {
3146 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003147 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3148 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003149 return 0;
3150 }
3151 else
3152 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003153 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003154 continue;
3155 }
3156 }
3157 else
3158 {
3159 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3160 if (!root.get())
3161 {
3162 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003163 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3164 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003165 return 0;
3166 }
3167 else
3168 {
3169 list->Append(root);
3170 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003171 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3172 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003173 return 1;
3174 }
3175 }
3176 }
3177 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3178 {
3179 root = root->GetSyntheticBitFieldChild(index, index, true);
3180 if (!root.get())
3181 {
3182 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003183 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3184 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003185 return 0;
3186 }
3187 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3188 {
3189 list->Append(root);
3190 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003191 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3192 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003193 return 1;
3194 }
3195 }
3196 }
3197 else // we have a low and a high index
3198 {
3199 char *end = NULL;
3200 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3201 if (!end || end != separator_position) // if something weird is in our way return an error
3202 {
3203 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003204 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3205 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003206 return 0;
3207 }
3208 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3209 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3210 {
3211 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003212 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3213 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003214 return 0;
3215 }
3216 if (index_lower > index_higher) // swap indices if required
3217 {
3218 unsigned long temp = index_lower;
3219 index_lower = index_higher;
3220 index_higher = temp;
3221 }
3222 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
3223 {
3224 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3225 if (!root.get())
3226 {
3227 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003228 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3229 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003230 return 0;
3231 }
3232 else
3233 {
3234 list->Append(root);
3235 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003236 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3237 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003238 return 1;
3239 }
3240 }
3241 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 +00003242 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003243 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3244 {
3245 Error error;
3246 root = root->Dereference(error);
3247 if (error.Fail() || !root.get())
3248 {
3249 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003250 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3251 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003252 return 0;
3253 }
3254 else
3255 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003256 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003257 continue;
3258 }
3259 }
3260 else
3261 {
Johnny Chen44805302011-07-19 19:48:13 +00003262 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003263 index <= index_higher; index++)
3264 {
3265 ValueObjectSP child =
3266 root->GetChildAtIndex(index, true);
3267 list->Append(child);
3268 }
3269 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003270 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3271 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003272 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3273 }
3274 }
3275 break;
3276 }
3277 default: // some non-[ separator, or something entirely wrong, is in the way
3278 {
3279 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003280 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3281 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003282 return 0;
3283 break;
3284 }
3285 }
3286 }
3287}
3288
Enrico Granata0c489f52012-03-01 04:24:26 +00003289static void
3290DumpValueObject_Impl (Stream &s,
3291 ValueObject *valobj,
3292 const ValueObject::DumpValueObjectOptions& options,
3293 uint32_t ptr_depth,
3294 uint32_t curr_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003295{
Greg Clayton007d5be2011-05-30 00:49:24 +00003296 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003297 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003298 bool update_success = valobj->UpdateValueIfNeeded (options.m_use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00003299
Enrico Granata0c489f52012-03-01 04:24:26 +00003300 const char *root_valobj_name =
3301 options.m_root_valobj_name.empty() ?
3302 valobj->GetName().AsCString() :
3303 options.m_root_valobj_name.c_str();
3304
3305 if (update_success && options.m_use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00003306 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003307 ValueObject *dynamic_value = valobj->GetDynamicValue(options.m_use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003308 if (dynamic_value)
3309 valobj = dynamic_value;
3310 }
3311
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003312 clang_type_t clang_type = valobj->GetClangType();
3313
Greg Clayton73b472d2010-10-27 03:32:59 +00003314 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003315 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00003316 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
3317 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003318
Enrico Granata0c489f52012-03-01 04:24:26 +00003319 const bool print_valobj = options.m_flat_output == false || has_value;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003320
3321 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003322 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003323 if (options.m_show_location)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003324 {
Jim Ingham6035b672011-03-31 00:19:25 +00003325 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003326 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003327
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003328 s.Indent();
Enrico Granata2b2631c2012-08-09 16:51:25 +00003329
3330 bool show_type = true;
3331 // if we are at the root-level and been asked to hide the root's type, then hide it
3332 if (curr_depth == 0 && options.m_hide_root_type)
3333 show_type = false;
3334 else
3335 // otherwise decide according to the usual rules (asked to show types - always at the root level)
3336 show_type = options.m_show_types || (curr_depth == 0 && !options.m_flat_output);
3337
3338 if (show_type)
Enrico Granatac3e320a2011-08-02 17:27:39 +00003339 {
Greg Clayton84db9102012-03-26 23:03:23 +00003340 const char* typeName = valobj->GetQualifiedTypeName().AsCString("<invalid type>");
3341 //const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
Enrico Granata9910bc82011-08-03 02:18:51 +00003342 s.Printf("(%s", typeName);
3343 // only show dynamic types if the user really wants to see types
Enrico Granata0c489f52012-03-01 04:24:26 +00003344 if (options.m_show_types && options.m_use_dynamic != eNoDynamicValues &&
Enrico Granata9910bc82011-08-03 02:18:51 +00003345 (/*strstr(typeName, "id") == typeName ||*/
Greg Claytonafacd142011-09-02 01:15:17 +00003346 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003347 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003348 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3349 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatac3e320a2011-08-02 17:27:39 +00003350 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003351 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003352 else
3353 {
3354 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
3355 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003356 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003357 else
3358 {
Greg Claytonf0246d12012-10-11 18:07:21 +00003359 ObjCLanguageRuntime::ClassDescriptorSP objc_class_sp (runtime->GetNonKVOClassDescriptor(*valobj));
3360 if (objc_class_sp)
3361 s.Printf(", dynamic type: %s) ", objc_class_sp->GetClassName().GetCString());
Enrico Granatac3e320a2011-08-02 17:27:39 +00003362 else
Greg Claytonf0246d12012-10-11 18:07:21 +00003363 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003364 }
3365 }
3366 }
3367 else
3368 s.Printf(") ");
3369 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003370
Greg Clayton1d3afba2010-10-05 00:00:42 +00003371
Enrico Granata0c489f52012-03-01 04:24:26 +00003372 if (options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003373 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003374 // If we are showing types, also qualify the C++ base classes
Enrico Granata0c489f52012-03-01 04:24:26 +00003375 const bool qualify_cxx_base_classes = options.m_show_types;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003376 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003377 s.PutCString(" =");
3378 }
3379 else
3380 {
3381 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3382 s.Printf ("%s =", name_cstr);
3383 }
3384
Enrico Granata0c489f52012-03-01 04:24:26 +00003385 if (!options.m_scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003386 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003387 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003388 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003389 }
3390
Enrico Granata0c489f52012-03-01 04:24:26 +00003391 std::string summary_str;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003392 std::string value_str;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003393 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003394 const char *sum_cstr = NULL;
Enrico Granata0c489f52012-03-01 04:24:26 +00003395 TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003396
Enrico Granata0c489f52012-03-01 04:24:26 +00003397 if (options.m_omit_summary_depth > 0)
Enrico Granata0c5ef692011-07-16 01:22:04 +00003398 entry = NULL;
3399
Enrico Granata9e7b3882012-12-13 23:50:33 +00003400 bool is_nil = valobj->IsObjCNil();
3401
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003402 if (err_cstr == NULL)
3403 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003404 if (options.m_format != eFormatDefault && options.m_format != valobj->GetFormat())
Greg Clayton6efba4f2012-01-26 21:08:30 +00003405 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003406 valobj->GetValueAsCString(options.m_format,
3407 value_str);
Greg Clayton6efba4f2012-01-26 21:08:30 +00003408 }
Enrico Granata0c489f52012-03-01 04:24:26 +00003409 else
Greg Clayton6efba4f2012-01-26 21:08:30 +00003410 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003411 val_cstr = valobj->GetValueAsCString();
3412 if (val_cstr)
3413 value_str = val_cstr;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003414 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003415 err_cstr = valobj->GetError().AsCString();
3416 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003417
3418 if (err_cstr)
3419 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003420 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003421 }
3422 else
3423 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003424 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003425 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003426 {
Enrico Granata9e7b3882012-12-13 23:50:33 +00003427 if (is_nil)
3428 sum_cstr = "nil";
3429 else if (options.m_omit_summary_depth == 0)
Enrico Granata0c489f52012-03-01 04:24:26 +00003430 {
3431 if (options.m_summary_sp)
3432 {
3433 valobj->GetSummaryAsCString(entry, summary_str);
3434 sum_cstr = summary_str.c_str();
3435 }
3436 else
3437 sum_cstr = valobj->GetSummaryAsCString();
3438 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003439
Greg Clayton6efba4f2012-01-26 21:08:30 +00003440 // Make sure we have a value and make sure the summary didn't
Enrico Granata9e7b3882012-12-13 23:50:33 +00003441 // specify that the value should not be printed - and do not print
3442 // the value if this thing is nil
3443 if (!is_nil && !value_str.empty() && (entry == NULL || entry->DoesPrintValue() || sum_cstr == NULL))
Greg Clayton6efba4f2012-01-26 21:08:30 +00003444 s.Printf(" %s", value_str.c_str());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003445
Enrico Granata9dd75c82011-07-15 23:30:15 +00003446 if (sum_cstr)
Enrico Granata0c489f52012-03-01 04:24:26 +00003447 s.Printf(" %s", sum_cstr);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003448
Enrico Granata9e7b3882012-12-13 23:50:33 +00003449 // let's avoid the overly verbose no description error for a nil thing
3450 if (options.m_use_objc && !is_nil)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003451 {
Jim Ingham6035b672011-03-31 00:19:25 +00003452 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003453 if (object_desc)
3454 s.Printf(" %s\n", object_desc);
3455 else
Sean Callanan672ad942010-10-23 00:18:49 +00003456 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003457 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003458 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003459 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003460
Enrico Granata0c489f52012-03-01 04:24:26 +00003461 if (curr_depth < options.m_max_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003462 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003463 // We will show children for all concrete types. We won't show
3464 // pointer contents unless a pointer depth has been specified.
3465 // We won't reference contents unless the reference is the
3466 // root object (depth of zero).
3467 bool print_children = true;
3468
3469 // Use a new temporary pointer depth in case we override the
3470 // current pointer depth below...
3471 uint32_t curr_ptr_depth = ptr_depth;
3472
3473 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3474 if (is_ptr || is_ref)
3475 {
3476 // We have a pointer or reference whose value is an address.
3477 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003478 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003479 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003480 print_children = false;
3481
3482 else if (is_ref && curr_depth == 0)
3483 {
3484 // If this is the root object (depth is zero) that we are showing
3485 // and it is a reference, and no pointer depth has been supplied
3486 // print out what it references. Don't do this at deeper depths
3487 // otherwise we can end up with infinite recursion...
3488 curr_ptr_depth = 1;
3489 }
3490
3491 if (curr_ptr_depth == 0)
3492 print_children = false;
3493 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003494
Enrico Granata0a3958e2011-07-02 00:25:22 +00003495 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003496 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003497 ValueObject* synth_valobj;
3498 ValueObjectSP synth_valobj_sp = valobj->GetSyntheticValue (options.m_use_synthetic);
3499 synth_valobj = (synth_valobj_sp ? synth_valobj_sp.get() : valobj);
Enrico Granatac5bc4122012-03-27 02:35:13 +00003500
Enrico Granatac482a192011-08-17 22:13:59 +00003501 uint32_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003502 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003503 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003504 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003505 if (options.m_flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003506 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003507 if (print_valobj)
3508 s.EOL();
3509 }
3510 else
3511 {
3512 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003513 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003514 s.IndentMore();
3515 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003516
Greg Claytoncc4d0142012-02-17 07:49:44 +00003517 uint32_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00003518
Enrico Granata0c489f52012-03-01 04:24:26 +00003519 if (num_children > max_num_children && !options.m_ignore_cap)
Enrico Granata22c55d12011-08-12 02:00:06 +00003520 {
3521 num_children = max_num_children;
3522 print_dotdotdot = true;
3523 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003524
Enrico Granata0c489f52012-03-01 04:24:26 +00003525 ValueObject::DumpValueObjectOptions child_options(options);
Enrico Granatac953a6a2012-12-11 02:17:22 +00003526 child_options.SetFormat(options.m_format).SetSummary().SetRootValueObjectName();
Enrico Granata0c489f52012-03-01 04:24:26 +00003527 child_options.SetScopeChecked(true)
3528 .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003529 for (uint32_t idx=0; idx<num_children; ++idx)
3530 {
Enrico Granatac482a192011-08-17 22:13:59 +00003531 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003532 if (child_sp.get())
3533 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003534 DumpValueObject_Impl (s,
3535 child_sp.get(),
3536 child_options,
3537 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
3538 curr_depth + 1);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003539 }
3540 }
3541
Enrico Granata0c489f52012-03-01 04:24:26 +00003542 if (!options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003543 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003544 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003545 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003546 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3547 Target *target = exe_ctx.GetTargetPtr();
3548 if (target)
3549 target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003550 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003551 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003552 s.IndentLess();
3553 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003554 }
3555 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003556 else if (has_children)
3557 {
3558 // Aggregate, no children...
3559 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003560 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003561 }
3562 else
3563 {
3564 if (print_valobj)
3565 s.EOL();
3566 }
3567
Greg Clayton1d3afba2010-10-05 00:00:42 +00003568 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003569 else
3570 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003571 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003572 }
3573 }
3574 else
3575 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003576 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003577 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003578 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003579 }
3580 }
3581 }
3582 }
3583}
3584
Enrico Granata0c489f52012-03-01 04:24:26 +00003585void
Greg Claytonf830dbb2012-03-22 18:15:37 +00003586ValueObject::LogValueObject (Log *log,
3587 ValueObject *valobj)
3588{
3589 if (log && valobj)
3590 return LogValueObject (log, valobj, DumpValueObjectOptions::DefaultOptions());
3591}
3592
3593void
3594ValueObject::LogValueObject (Log *log,
3595 ValueObject *valobj,
3596 const DumpValueObjectOptions& options)
3597{
3598 if (log && valobj)
3599 {
3600 StreamString s;
3601 ValueObject::DumpValueObject (s, valobj, options);
3602 if (s.GetSize())
3603 log->PutCString(s.GetData());
3604 }
3605}
3606
3607void
Enrico Granata0c489f52012-03-01 04:24:26 +00003608ValueObject::DumpValueObject (Stream &s,
3609 ValueObject *valobj)
3610{
3611
3612 if (!valobj)
3613 return;
3614
3615 DumpValueObject_Impl(s,
3616 valobj,
3617 DumpValueObjectOptions::DefaultOptions(),
3618 0,
3619 0);
3620}
3621
3622void
3623ValueObject::DumpValueObject (Stream &s,
3624 ValueObject *valobj,
3625 const DumpValueObjectOptions& options)
3626{
3627 DumpValueObject_Impl(s,
3628 valobj,
3629 options,
3630 options.m_max_ptr_depth, // max pointer depth allowed, we will go down from here
3631 0 // current object depth is 0 since we are just starting
3632 );
3633}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003634
3635ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003636ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003637{
3638 ValueObjectSP valobj_sp;
3639
Enrico Granatac3e320a2011-08-02 17:27:39 +00003640 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003641 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003642 ExecutionContext exe_ctx (GetExecutionContextRef());
3643 clang::ASTContext *ast = GetClangAST ();
3644
3645 DataExtractor data;
3646 data.SetByteOrder (m_data.GetByteOrder());
3647 data.SetAddressByteSize(m_data.GetAddressByteSize());
3648
Enrico Granata9f1e2042012-04-24 22:15:37 +00003649 if (IsBitfield())
3650 {
3651 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
3652 m_error = v.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
3653 }
3654 else
3655 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003656
3657 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3658 ast,
3659 GetClangType(),
3660 name,
3661 data,
3662 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003663 }
Jim Ingham6035b672011-03-31 00:19:25 +00003664
3665 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003666 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003667 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003668 }
3669 return valobj_sp;
3670}
3671
Greg Claytonafacd142011-09-02 01:15:17 +00003672ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003673ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003674{
Jim Ingham58b59f92011-04-22 23:53:53 +00003675 if (m_deref_valobj)
3676 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003677
Greg Clayton54979cd2010-12-15 05:08:08 +00003678 const bool is_pointer_type = IsPointerType();
3679 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003680 {
3681 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003682 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003683
3684 std::string child_name_str;
3685 uint32_t child_byte_size = 0;
3686 int32_t child_byte_offset = 0;
3687 uint32_t child_bitfield_bit_size = 0;
3688 uint32_t child_bitfield_bit_offset = 0;
3689 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003690 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003691 const bool transparent_pointers = false;
3692 clang::ASTContext *clang_ast = GetClangAST();
3693 clang_type_t clang_type = GetClangType();
3694 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003695
Greg Claytoncc4d0142012-02-17 07:49:44 +00003696 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003697
3698 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3699 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003700 GetName().GetCString(),
3701 clang_type,
3702 0,
3703 transparent_pointers,
3704 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003705 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003706 child_name_str,
3707 child_byte_size,
3708 child_byte_offset,
3709 child_bitfield_bit_size,
3710 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003711 child_is_base_class,
3712 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003713 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003714 {
3715 ConstString child_name;
3716 if (!child_name_str.empty())
3717 child_name.SetCString (child_name_str.c_str());
3718
Jim Ingham58b59f92011-04-22 23:53:53 +00003719 m_deref_valobj = new ValueObjectChild (*this,
3720 clang_ast,
3721 child_clang_type,
3722 child_name,
3723 child_byte_size,
3724 child_byte_offset,
3725 child_bitfield_bit_size,
3726 child_bitfield_bit_offset,
3727 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003728 child_is_deref_of_parent,
3729 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003730 }
3731 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003732
Jim Ingham58b59f92011-04-22 23:53:53 +00003733 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003734 {
3735 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003736 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003737 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003738 else
3739 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003740 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003741 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003742
3743 if (is_pointer_type)
3744 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3745 else
3746 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003747 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003748 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003749}
3750
Greg Claytonafacd142011-09-02 01:15:17 +00003751ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003752ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003753{
Jim Ingham78a685a2011-04-16 00:01:13 +00003754 if (m_addr_of_valobj_sp)
3755 return m_addr_of_valobj_sp;
3756
Greg Claytone0d378b2011-03-24 21:19:54 +00003757 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003758 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003759 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003760 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003761 if (addr != LLDB_INVALID_ADDRESS)
3762 {
3763 switch (address_type)
3764 {
3765 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003766 {
3767 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003768 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003769 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3770 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003771 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003772
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003773 case eAddressTypeFile:
3774 case eAddressTypeLoad:
3775 case eAddressTypeHost:
3776 {
3777 clang::ASTContext *ast = GetClangAST();
3778 clang_type_t clang_type = GetClangType();
3779 if (ast && clang_type)
3780 {
3781 std::string name (1, '&');
3782 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003783 ExecutionContext exe_ctx (GetExecutionContextRef());
3784 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003785 ast,
3786 ClangASTContext::CreatePointerType (ast, clang_type),
3787 ConstString (name.c_str()),
3788 addr,
3789 eAddressTypeInvalid,
3790 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003791 }
3792 }
3793 break;
3794 }
3795 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003796 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003797}
3798
Greg Clayton9a142cf2012-02-03 05:34:10 +00003799ValueObjectSP
3800ValueObject::Cast (const ClangASTType &clang_ast_type)
3801{
Greg Clayton81e871e2012-02-04 02:27:34 +00003802 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003803}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003804
Greg Claytonafacd142011-09-02 01:15:17 +00003805ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003806ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3807{
Greg Claytonafacd142011-09-02 01:15:17 +00003808 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003809 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003810 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003811
3812 if (ptr_value != LLDB_INVALID_ADDRESS)
3813 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003814 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003815 ExecutionContext exe_ctx (GetExecutionContextRef());
3816 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003817 name,
3818 ptr_addr,
3819 clang_ast_type);
3820 }
3821 return valobj_sp;
3822}
3823
Greg Claytonafacd142011-09-02 01:15:17 +00003824ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003825ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3826{
Greg Claytonafacd142011-09-02 01:15:17 +00003827 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003828 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003829 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003830
3831 if (ptr_value != LLDB_INVALID_ADDRESS)
3832 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003833 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003834 ExecutionContext exe_ctx (GetExecutionContextRef());
3835 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003836 name,
3837 ptr_addr,
3838 type_sp);
3839 }
3840 return valobj_sp;
3841}
3842
Jim Ingham6035b672011-03-31 00:19:25 +00003843ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003844 m_mod_id(),
3845 m_exe_ctx_ref(),
3846 m_needs_update (true),
3847 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003848{
3849}
3850
3851ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003852 m_mod_id(),
3853 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003854 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003855 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003856{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003857 ExecutionContext exe_ctx(exe_scope);
3858 TargetSP target_sp (exe_ctx.GetTargetSP());
3859 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003860 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003861 m_exe_ctx_ref.SetTargetSP (target_sp);
3862 ProcessSP process_sp (exe_ctx.GetProcessSP());
3863 if (!process_sp)
3864 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003865
Greg Claytoncc4d0142012-02-17 07:49:44 +00003866 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003867 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003868 m_mod_id = process_sp->GetModID();
3869 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003870
Greg Claytoncc4d0142012-02-17 07:49:44 +00003871 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003872
Greg Claytoncc4d0142012-02-17 07:49:44 +00003873 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003874 {
3875 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003876 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003877 }
Jim Ingham6035b672011-03-31 00:19:25 +00003878
Greg Claytoncc4d0142012-02-17 07:49:44 +00003879 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003880 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003881 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003882
Greg Claytoncc4d0142012-02-17 07:49:44 +00003883 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3884 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003885 {
3886 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003887 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003888 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003889 if (frame_sp)
3890 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003891 }
3892 }
3893 }
Jim Ingham6035b672011-03-31 00:19:25 +00003894}
3895
3896ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003897 m_mod_id(),
3898 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3899 m_needs_update (true),
3900 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003901{
3902}
3903
3904ValueObject::EvaluationPoint::~EvaluationPoint ()
3905{
3906}
3907
Jim Ingham6035b672011-03-31 00:19:25 +00003908// This function checks the EvaluationPoint against the current process state. If the current
3909// state matches the evaluation point, or the evaluation point is already invalid, then we return
3910// false, meaning "no change". If the current state is different, we update our state, and return
3911// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3912// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003913// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003914
3915bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003916ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003917{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003918
3919 // 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 +00003920 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00003921
Greg Claytoncc4d0142012-02-17 07:49:44 +00003922 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003923 return false;
3924
Jim Ingham6035b672011-03-31 00:19:25 +00003925 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003926 Process *process = exe_ctx.GetProcessPtr();
3927 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003928 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003929
Jim Ingham6035b672011-03-31 00:19:25 +00003930 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003931 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003932
Jim Ingham78a685a2011-04-16 00:01:13 +00003933 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3934 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003935 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003936 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003937
Greg Clayton23f59502012-07-17 03:23:13 +00003938 bool changed = false;
3939 const bool was_valid = m_mod_id.IsValid();
3940 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003941 {
3942 if (m_mod_id == current_mod_id)
3943 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003944 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003945 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003946 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003947 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003948 else
3949 {
3950 m_mod_id = current_mod_id;
3951 m_needs_update = true;
3952 changed = true;
3953 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003954 }
Jim Ingham6035b672011-03-31 00:19:25 +00003955
Jim Ingham73ca05a2011-12-17 01:35:57 +00003956 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3957 // That way we'll be sure to return a valid exe_scope.
3958 // 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 +00003959
Greg Claytoncc4d0142012-02-17 07:49:44 +00003960 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003961 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003962 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3963 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003964 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003965 if (m_exe_ctx_ref.HasFrameRef())
3966 {
3967 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3968 if (!frame_sp)
3969 {
3970 // We used to have a frame, but now it is gone
3971 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003972 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00003973 }
3974 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003975 }
Jim Ingham6035b672011-03-31 00:19:25 +00003976 else
3977 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003978 // We used to have a thread, but now it is gone
3979 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003980 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00003981 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003982
Jim Ingham6035b672011-03-31 00:19:25 +00003983 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003984 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003985}
3986
Jim Ingham61be0902011-05-02 18:13:59 +00003987void
3988ValueObject::EvaluationPoint::SetUpdated ()
3989{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003990 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3991 if (process_sp)
3992 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003993 m_first_update = false;
3994 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003995}
3996
3997
Greg Claytoncc4d0142012-02-17 07:49:44 +00003998//bool
3999//ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
4000//{
4001// if (!IsValid())
4002// return false;
4003//
4004// bool needs_update = false;
4005//
4006// // The target has to be non-null, and the
4007// Target *target = exe_scope->CalculateTarget();
4008// if (target != NULL)
4009// {
4010// Target *old_target = m_target_sp.get();
4011// assert (target == old_target);
4012// Process *process = exe_scope->CalculateProcess();
4013// if (process != NULL)
4014// {
4015// // FOR NOW - assume you can't update variable objects across process boundaries.
4016// Process *old_process = m_process_sp.get();
4017// assert (process == old_process);
4018// ProcessModID current_mod_id = process->GetModID();
4019// if (m_mod_id != current_mod_id)
4020// {
4021// needs_update = true;
4022// m_mod_id = current_mod_id;
4023// }
4024// // See if we're switching the thread or stack context. If no thread is given, this is
4025// // being evaluated in a global context.
4026// Thread *thread = exe_scope->CalculateThread();
4027// if (thread != NULL)
4028// {
4029// user_id_t new_thread_index = thread->GetIndexID();
4030// if (new_thread_index != m_thread_id)
4031// {
4032// needs_update = true;
4033// m_thread_id = new_thread_index;
4034// m_stack_id.Clear();
4035// }
4036//
4037// StackFrame *new_frame = exe_scope->CalculateStackFrame();
4038// if (new_frame != NULL)
4039// {
4040// if (new_frame->GetStackID() != m_stack_id)
4041// {
4042// needs_update = true;
4043// m_stack_id = new_frame->GetStackID();
4044// }
4045// }
4046// else
4047// {
4048// m_stack_id.Clear();
4049// needs_update = true;
4050// }
4051// }
4052// else
4053// {
4054// // If this had been given a thread, and now there is none, we should update.
4055// // Otherwise we don't have to do anything.
4056// if (m_thread_id != LLDB_INVALID_UID)
4057// {
4058// m_thread_id = LLDB_INVALID_UID;
4059// m_stack_id.Clear();
4060// needs_update = true;
4061// }
4062// }
4063// }
4064// else
4065// {
4066// // If there is no process, then we don't need to update anything.
4067// // But if we're switching from having a process to not, we should try to update.
4068// if (m_process_sp.get() != NULL)
4069// {
4070// needs_update = true;
4071// m_process_sp.reset();
4072// m_thread_id = LLDB_INVALID_UID;
4073// m_stack_id.Clear();
4074// }
4075// }
4076// }
4077// else
4078// {
4079// // If there's no target, nothing can change so we don't need to update anything.
4080// // But if we're switching from having a target to not, we should try to update.
4081// if (m_target_sp.get() != NULL)
4082// {
4083// needs_update = true;
4084// m_target_sp.reset();
4085// m_process_sp.reset();
4086// m_thread_id = LLDB_INVALID_UID;
4087// m_stack_id.Clear();
4088// }
4089// }
4090// if (!m_needs_update)
4091// m_needs_update = needs_update;
4092//
4093// return needs_update;
4094//}
Enrico Granataf2bbf712011-07-15 02:26:42 +00004095
4096void
Enrico Granata86cc9822012-03-19 22:58:49 +00004097ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004098{
Enrico Granata86cc9822012-03-19 22:58:49 +00004099 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4100 m_value_str.clear();
4101
4102 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4103 m_location_str.clear();
4104
4105 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
4106 {
Enrico Granata86cc9822012-03-19 22:58:49 +00004107 m_summary_str.clear();
4108 }
4109
4110 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4111 m_object_desc_str.clear();
4112
4113 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4114 {
4115 if (m_synthetic_value)
4116 m_synthetic_value = NULL;
4117 }
Johnny Chen44805302011-07-19 19:48:13 +00004118}
Enrico Granata9128ee22011-09-06 19:20:51 +00004119
4120SymbolContextScope *
4121ValueObject::GetSymbolContextScope()
4122{
4123 if (m_parent)
4124 {
4125 if (!m_parent->IsPointerOrReferenceType())
4126 return m_parent->GetSymbolContextScope();
4127 }
4128 return NULL;
4129}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004130
4131lldb::ValueObjectSP
4132ValueObject::CreateValueObjectFromExpression (const char* name,
4133 const char* expression,
4134 const ExecutionContext& exe_ctx)
4135{
4136 lldb::ValueObjectSP retval_sp;
4137 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4138 if (!target_sp)
4139 return retval_sp;
4140 if (!expression || !*expression)
4141 return retval_sp;
4142 target_sp->EvaluateExpression (expression,
4143 exe_ctx.GetFrameSP().get(),
4144 retval_sp);
4145 if (retval_sp && name && *name)
4146 retval_sp->SetName(ConstString(name));
4147 return retval_sp;
4148}
4149
4150lldb::ValueObjectSP
4151ValueObject::CreateValueObjectFromAddress (const char* name,
4152 uint64_t address,
4153 const ExecutionContext& exe_ctx,
4154 ClangASTType type)
4155{
4156 ClangASTType pointer_type(type.GetASTContext(),type.GetPointerType());
4157 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4158 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4159 pointer_type.GetASTContext(),
4160 pointer_type.GetOpaqueQualType(),
4161 ConstString(name),
4162 buffer,
4163 lldb::endian::InlHostByteOrder(),
4164 exe_ctx.GetAddressByteSize()));
4165 if (ptr_result_valobj_sp)
4166 {
4167 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4168 Error err;
4169 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4170 if (ptr_result_valobj_sp && name && *name)
4171 ptr_result_valobj_sp->SetName(ConstString(name));
4172 }
4173 return ptr_result_valobj_sp;
4174}
4175
4176lldb::ValueObjectSP
4177ValueObject::CreateValueObjectFromData (const char* name,
4178 DataExtractor& data,
4179 const ExecutionContext& exe_ctx,
4180 ClangASTType type)
4181{
4182 lldb::ValueObjectSP new_value_sp;
4183 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4184 type.GetASTContext() ,
4185 type.GetOpaqueQualType(),
4186 ConstString(name),
4187 data,
4188 LLDB_INVALID_ADDRESS);
4189 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4190 if (new_value_sp && name && *name)
4191 new_value_sp->SetName(ConstString(name));
4192 return new_value_sp;
4193}