blob: d8564b85de8dc8181b77995fed277ba73f257a3b [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 {
423 default:
424 break;
425
426 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +0000427 case Value::eValueTypeVector:
Greg Clayton526e5af2010-11-13 03:52:47 +0000428 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000429 {
430 RegisterInfo *reg_info = m_value.GetRegisterInfo();
431 if (reg_info)
432 {
433 if (reg_info->name)
434 m_location_str = reg_info->name;
435 else if (reg_info->alt_name)
436 m_location_str = reg_info->alt_name;
Greg Clayton0665a0f2012-10-30 18:18:43 +0000437
438 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000439 }
440 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000441 break;
442
443 case Value::eValueTypeLoadAddress:
444 case Value::eValueTypeFileAddress:
445 case Value::eValueTypeHostAddress:
446 {
447 uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2;
448 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
449 m_location_str.swap(sstr.GetString());
450 }
451 break;
452 }
453 }
454 }
455 return m_location_str.c_str();
456}
457
458Value &
459ValueObject::GetValue()
460{
461 return m_value;
462}
463
464const Value &
465ValueObject::GetValue() const
466{
467 return m_value;
468}
469
470bool
Jim Ingham6035b672011-03-31 00:19:25 +0000471ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000472{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000473 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
474 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000475 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000476 Value tmp_value(m_value);
477 scalar = tmp_value.ResolveValue(&exe_ctx, GetClangAST ());
Greg Claytondcad5022011-12-29 01:26:56 +0000478 if (scalar.IsValid())
479 {
480 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
481 if (bitfield_bit_size)
482 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
483 return true;
484 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000485 }
Greg Claytondcad5022011-12-29 01:26:56 +0000486 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000487}
488
489bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000490ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000491{
Greg Clayton288bdf92010-09-02 02:59:18 +0000492 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000493}
494
495
496void
497ValueObject::SetValueIsValid (bool b)
498{
Greg Clayton288bdf92010-09-02 02:59:18 +0000499 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000500}
501
502bool
Jim Ingham6035b672011-03-31 00:19:25 +0000503ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000504{
Jim Ingham6035b672011-03-31 00:19:25 +0000505 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000506 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000507}
508
509void
510ValueObject::SetValueDidChange (bool value_changed)
511{
Greg Clayton288bdf92010-09-02 02:59:18 +0000512 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000513}
514
515ValueObjectSP
516ValueObject::GetChildAtIndex (uint32_t idx, bool can_create)
517{
518 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000519 // We may need to update our value if we are dynamic
520 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000521 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000522 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000523 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000524 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000525 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000526 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000527 // No we haven't created the child at this index, so lets have our
528 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000529 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000530 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000531
Enrico Granata9d60f602012-03-09 03:09:58 +0000532 ValueObject* child = m_children.GetChildAtIndex(idx);
533 if (child != NULL)
534 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000535 }
536 return child_sp;
537}
538
539uint32_t
540ValueObject::GetIndexOfChildWithName (const ConstString &name)
541{
542 bool omit_empty_base_classes = true;
543 return ClangASTContext::GetIndexOfChildWithName (GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +0000544 GetClangType(),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000545 name.GetCString(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000546 omit_empty_base_classes);
547}
548
549ValueObjectSP
550ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
551{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000552 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000553 // classes (which really aren't part of the expression path), so we
554 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000555 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000556
Greg Claytondea8cb42011-06-29 22:09:02 +0000557 // We may need to update our value if we are dynamic
558 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000559 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000560
561 std::vector<uint32_t> child_indexes;
562 clang::ASTContext *clang_ast = GetClangAST();
563 void *clang_type = GetClangType();
564 bool omit_empty_base_classes = true;
565 const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast,
566 clang_type,
567 name.GetCString(),
568 omit_empty_base_classes,
569 child_indexes);
570 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000571 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000572 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
573 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
574
575 child_sp = GetChildAtIndex(*pos, can_create);
576 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000577 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000578 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000579 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000580 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
581 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000582 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000583 else
584 {
585 child_sp.reset();
586 }
587
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000588 }
589 }
590 return child_sp;
591}
592
593
594uint32_t
595ValueObject::GetNumChildren ()
596{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000597 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000598 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000599 {
600 SetNumChildren (CalculateNumChildren());
601 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000602 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000603}
Greg Clayton4a792072012-10-23 01:50:10 +0000604
605bool
606ValueObject::MightHaveChildren()
607{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000608 bool has_children = false;
Greg Clayton4a792072012-10-23 01:50:10 +0000609 clang_type_t clang_type = GetClangType();
610 if (clang_type)
611 {
612 const uint32_t type_info = ClangASTContext::GetTypeInfo (clang_type,
613 GetClangAST(),
614 NULL);
615 if (type_info & (ClangASTContext::eTypeHasChildren |
616 ClangASTContext::eTypeIsPointer |
617 ClangASTContext::eTypeIsReference))
618 has_children = true;
619 }
620 else
621 {
622 has_children = GetNumChildren () > 0;
623 }
624 return has_children;
625}
626
627// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000628void
629ValueObject::SetNumChildren (uint32_t num_children)
630{
Greg Clayton288bdf92010-09-02 02:59:18 +0000631 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000632 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000633}
634
635void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000636ValueObject::SetName (const ConstString &name)
637{
638 m_name = name;
639}
640
Jim Ingham58b59f92011-04-22 23:53:53 +0000641ValueObject *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000642ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index)
643{
Jim Ingham2eec4872011-05-07 00:10:58 +0000644 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000645
Greg Claytondea8cb42011-06-29 22:09:02 +0000646 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000647 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000648 std::string child_name_str;
649 uint32_t child_byte_size = 0;
650 int32_t child_byte_offset = 0;
651 uint32_t child_bitfield_bit_size = 0;
652 uint32_t child_bitfield_bit_offset = 0;
653 bool child_is_base_class = false;
654 bool child_is_deref_of_parent = false;
655
656 const bool transparent_pointers = synthetic_array_member == false;
657 clang::ASTContext *clang_ast = GetClangAST();
658 clang_type_t clang_type = GetClangType();
659 clang_type_t child_clang_type;
660
Greg Claytoncc4d0142012-02-17 07:49:44 +0000661 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000662
663 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
664 clang_ast,
665 GetName().GetCString(),
666 clang_type,
667 idx,
668 transparent_pointers,
669 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +0000670 ignore_array_bounds,
Greg Claytondea8cb42011-06-29 22:09:02 +0000671 child_name_str,
672 child_byte_size,
673 child_byte_offset,
674 child_bitfield_bit_size,
675 child_bitfield_bit_offset,
676 child_is_base_class,
677 child_is_deref_of_parent);
Greg Clayton4ef877f2012-12-06 02:33:54 +0000678 if (child_clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000679 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000680 if (synthetic_index)
681 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000682
Greg Claytondea8cb42011-06-29 22:09:02 +0000683 ConstString child_name;
684 if (!child_name_str.empty())
685 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000686
Greg Claytondea8cb42011-06-29 22:09:02 +0000687 valobj = new ValueObjectChild (*this,
688 clang_ast,
689 child_clang_type,
690 child_name,
691 child_byte_size,
692 child_byte_offset,
693 child_bitfield_bit_size,
694 child_bitfield_bit_offset,
695 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000696 child_is_deref_of_parent,
697 eAddressTypeInvalid);
698 //if (valobj)
699 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
700 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000701
Jim Ingham58b59f92011-04-22 23:53:53 +0000702 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000703}
704
Enrico Granata0c489f52012-03-01 04:24:26 +0000705bool
706ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
707 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000708{
Enrico Granata0c489f52012-03-01 04:24:26 +0000709 destination.clear();
710
711 // ideally we would like to bail out if passing NULL, but if we do so
712 // we end up not providing the summary for function pointers anymore
713 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
714 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000715
716 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000717
718 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
719 // information that we might care to see in a crash log. might be useful in very specific situations though.
720 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
721 GetTypeName().GetCString(),
722 GetName().GetCString(),
723 summary_ptr->GetDescription().c_str());*/
724
Enrico Granata0c489f52012-03-01 04:24:26 +0000725 if (UpdateValueIfNeeded (false))
726 {
727 if (summary_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000728 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000729 if (HasSyntheticValue())
730 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
731 summary_ptr->FormatObject(this, destination);
Enrico Granata0c489f52012-03-01 04:24:26 +0000732 }
733 else
734 {
735 clang_type_t clang_type = GetClangType();
736
737 // Do some default printout for function pointers
738 if (clang_type)
Enrico Granata4becb372011-06-29 22:27:15 +0000739 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000740 StreamString sstr;
741 clang_type_t elem_or_pointee_clang_type;
742 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
743 GetClangAST(),
744 &elem_or_pointee_clang_type));
745
746 if (ClangASTContext::IsFunctionPointerType (clang_type))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000747 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000748 AddressType func_ptr_address_type = eAddressTypeInvalid;
749 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
750 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000751 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000752 switch (func_ptr_address_type)
Jim Ingham6035b672011-03-31 00:19:25 +0000753 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000754 case eAddressTypeInvalid:
755 case eAddressTypeFile:
756 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000757
Greg Claytoncc4d0142012-02-17 07:49:44 +0000758 case eAddressTypeLoad:
Enrico Granata0c489f52012-03-01 04:24:26 +0000759 {
760 ExecutionContext exe_ctx (GetExecutionContextRef());
761
762 Address so_addr;
763 Target *target = exe_ctx.GetTargetPtr();
764 if (target && target->GetSectionLoadList().IsEmpty() == false)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000765 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000766 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000767 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000768 so_addr.Dump (&sstr,
769 exe_ctx.GetBestExecutionContextScope(),
770 Address::DumpStyleResolvedDescription,
771 Address::DumpStyleSectionNameOffset);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000772 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000773 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000774 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000775 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000776
Greg Claytoncc4d0142012-02-17 07:49:44 +0000777 case eAddressTypeHost:
778 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +0000779 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000780 }
781 if (sstr.GetSize() > 0)
782 {
783 destination.assign (1, '(');
784 destination.append (sstr.GetData(), sstr.GetSize());
785 destination.append (1, ')');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000786 }
787 }
788 }
789 }
790 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000791 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000792 return !destination.empty();
793}
794
795const char *
796ValueObject::GetSummaryAsCString ()
797{
798 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
799 {
800 GetSummaryAsCString(GetSummaryFormat().get(),
801 m_summary_str);
802 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000803 if (m_summary_str.empty())
804 return NULL;
805 return m_summary_str.c_str();
806}
807
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000808bool
809ValueObject::IsCStringContainer(bool check_pointer)
810{
811 clang_type_t elem_or_pointee_clang_type;
812 const Flags type_flags (ClangASTContext::GetTypeInfo (GetClangType(),
813 GetClangAST(),
814 &elem_or_pointee_clang_type));
815 bool is_char_arr_ptr (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
816 ClangASTContext::IsCharType (elem_or_pointee_clang_type));
817 if (!is_char_arr_ptr)
818 return false;
819 if (!check_pointer)
820 return true;
821 if (type_flags.Test(ClangASTContext::eTypeIsArray))
822 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000823 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000824 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000825 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000826 return (cstr_address != LLDB_INVALID_ADDRESS);
827}
828
Enrico Granata9128ee22011-09-06 19:20:51 +0000829size_t
830ValueObject::GetPointeeData (DataExtractor& data,
831 uint32_t item_idx,
832 uint32_t item_count)
833{
834 if (!IsPointerType() && !IsArrayType())
835 return 0;
836
837 if (item_count == 0)
838 return 0;
839
840 uint32_t stride = 0;
841
842 ClangASTType type(GetClangAST(),
843 GetClangType());
844
845 const uint64_t item_type_size = (IsPointerType() ? ClangASTType::GetTypeByteSize(GetClangAST(), type.GetPointeeType()) :
846 ClangASTType::GetTypeByteSize(GetClangAST(), type.GetArrayElementType(stride)));
847
848 const uint64_t bytes = item_count * item_type_size;
849
850 const uint64_t offset = item_idx * item_type_size;
851
852 if (item_idx == 0 && item_count == 1) // simply a deref
853 {
854 if (IsPointerType())
855 {
856 Error error;
857 ValueObjectSP pointee_sp = Dereference(error);
858 if (error.Fail() || pointee_sp.get() == NULL)
859 return 0;
860 return pointee_sp->GetDataExtractor().Copy(data);
861 }
862 else
863 {
864 ValueObjectSP child_sp = GetChildAtIndex(0, true);
865 if (child_sp.get() == NULL)
866 return 0;
867 return child_sp->GetDataExtractor().Copy(data);
868 }
869 return true;
870 }
871 else /* (items > 1) */
872 {
873 Error error;
874 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
875 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
876
877 AddressType addr_type;
878 lldb::addr_t addr = IsPointerType() ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
879
Enrico Granata9128ee22011-09-06 19:20:51 +0000880 switch (addr_type)
881 {
882 case eAddressTypeFile:
883 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000884 ModuleSP module_sp (GetModule());
885 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000886 {
Enrico Granata9c2efe32012-08-07 01:49:34 +0000887 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +0000888 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +0000889 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000890 ExecutionContext exe_ctx (GetExecutionContextRef());
891 Target* target = exe_ctx.GetTargetPtr();
892 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +0000893 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000894 heap_buf_ptr->SetByteSize(bytes);
895 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
896 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +0000897 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000898 data.SetData(data_sp);
899 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +0000900 }
901 }
902 }
903 }
904 break;
905 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +0000906 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000907 ExecutionContext exe_ctx (GetExecutionContextRef());
908 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +0000909 if (process)
910 {
911 heap_buf_ptr->SetByteSize(bytes);
912 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
913 if (error.Success())
914 {
915 data.SetData(data_sp);
916 return bytes_read;
917 }
918 }
919 }
920 break;
921 case eAddressTypeHost:
922 {
923 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes);
924 data.SetData(data_sp);
925 return bytes;
926 }
927 break;
928 case eAddressTypeInvalid:
929 default:
930 break;
931 }
932 }
933 return 0;
934}
935
936size_t
937ValueObject::GetData (DataExtractor& data)
938{
939 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000940 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytone72dfb32012-02-24 01:59:29 +0000941 Error error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +0000942 if (error.Fail())
943 return 0;
944 data.SetAddressByteSize(m_data.GetAddressByteSize());
945 data.SetByteOrder(m_data.GetByteOrder());
946 return data.GetByteSize();
947}
948
949// will compute strlen(str), but without consuming more than
950// maxlen bytes out of str (this serves the purpose of reading
951// chunks of a string without having to worry about
952// missing NULL terminators in the chunk)
953// of course, if strlen(str) > maxlen, the function will return
954// maxlen_value (which should be != maxlen, because that allows you
955// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
956static uint32_t
957strlen_or_inf (const char* str,
958 uint32_t maxlen,
959 uint32_t maxlen_value)
960{
961 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +0000962 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +0000963 {
Greg Clayton8dd5c172011-10-05 22:19:51 +0000964 while(*str)
965 {
966 len++;str++;
967 if (len > maxlen)
968 return maxlen_value;
969 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000970 }
971 return len;
972}
973
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000974void
Greg Claytoncc4d0142012-02-17 07:49:44 +0000975ValueObject::ReadPointedString (Stream& s,
976 Error& error,
977 uint32_t max_length,
978 bool honor_array,
979 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000980{
Greg Claytoncc4d0142012-02-17 07:49:44 +0000981 ExecutionContext exe_ctx (GetExecutionContextRef());
982 Target* target = exe_ctx.GetTargetPtr();
983
984 if (target && max_length == 0)
985 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000986
987 clang_type_t clang_type = GetClangType();
988 clang_type_t elem_or_pointee_clang_type;
989 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
990 GetClangAST(),
991 &elem_or_pointee_clang_type));
992 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
993 ClangASTContext::IsCharType (elem_or_pointee_clang_type))
994 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000995 if (target == NULL)
996 {
997 s << "<no target to read from>";
998 }
999 else
1000 {
1001 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1002 AddressType cstr_address_type = eAddressTypeInvalid;
1003
1004 size_t cstr_len = 0;
1005 bool capped_data = false;
1006 if (type_flags.Test (ClangASTContext::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001007 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001008 // We have an array
1009 cstr_len = ClangASTContext::GetArraySize (clang_type);
1010 if (cstr_len > max_length)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001011 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001012 capped_data = true;
1013 cstr_len = max_length;
1014 }
1015 cstr_address = GetAddressOf (true, &cstr_address_type);
1016 }
1017 else
1018 {
1019 // We have a pointer
1020 cstr_address = GetPointerValue (&cstr_address_type);
1021 }
1022 if (cstr_address != 0 && cstr_address != LLDB_INVALID_ADDRESS)
1023 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001024 Address cstr_so_addr (cstr_address);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001025 DataExtractor data;
1026 size_t bytes_read = 0;
1027 if (cstr_len > 0 && honor_array)
1028 {
1029 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1030 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1031 GetPointeeData(data, 0, cstr_len);
1032
1033 if ((bytes_read = data.GetByteSize()) > 0)
1034 {
1035 s << '"';
1036 data.Dump (&s,
1037 0, // Start offset in "data"
1038 item_format,
1039 1, // Size of item (1 byte for a char!)
1040 bytes_read, // How many bytes to print?
1041 UINT32_MAX, // num per line
1042 LLDB_INVALID_ADDRESS,// base address
1043 0, // bitfield bit size
1044 0); // bitfield bit offset
1045 if (capped_data)
1046 s << "...";
1047 s << '"';
1048 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00001049 }
1050 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001051 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001052 cstr_len = max_length;
1053 const size_t k_max_buf_size = 64;
1054
1055 size_t offset = 0;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001056
Greg Claytoncc4d0142012-02-17 07:49:44 +00001057 int cstr_len_displayed = -1;
1058 bool capped_cstr = false;
1059 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1060 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1061 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001062 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001063 const char *cstr = data.PeekCStr(0);
1064 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1065 if (len > k_max_buf_size)
1066 len = k_max_buf_size;
1067 if (cstr && cstr_len_displayed < 0)
1068 s << '"';
1069
1070 if (cstr_len_displayed < 0)
1071 cstr_len_displayed = len;
1072
1073 if (len == 0)
1074 break;
1075 cstr_len_displayed += len;
1076 if (len > bytes_read)
1077 len = bytes_read;
1078 if (len > cstr_len)
1079 len = cstr_len;
1080
1081 data.Dump (&s,
1082 0, // Start offset in "data"
1083 item_format,
1084 1, // Size of item (1 byte for a char!)
1085 len, // How many bytes to print?
1086 UINT32_MAX, // num per line
1087 LLDB_INVALID_ADDRESS,// base address
1088 0, // bitfield bit size
1089 0); // bitfield bit offset
1090
1091 if (len < k_max_buf_size)
1092 break;
1093
1094 if (len >= cstr_len)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001095 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001096 capped_cstr = true;
1097 break;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001098 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001099
1100 cstr_len -= len;
1101 offset += len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001102 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001103
1104 if (cstr_len_displayed >= 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001105 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001106 s << '"';
1107 if (capped_cstr)
1108 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001109 }
1110 }
1111 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001112 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001113 }
1114 else
1115 {
1116 error.SetErrorString("impossible to read a string from this object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001117 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001118 }
1119}
1120
Jim Ingham53c47f12010-09-10 23:12:17 +00001121const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001122ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001123{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001124
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001125 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001126 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001127
1128 if (!m_object_desc_str.empty())
1129 return m_object_desc_str.c_str();
1130
Greg Claytoncc4d0142012-02-17 07:49:44 +00001131 ExecutionContext exe_ctx (GetExecutionContextRef());
1132 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001133 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001134 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001135
Jim Ingham53c47f12010-09-10 23:12:17 +00001136 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001137
Greg Claytonafacd142011-09-02 01:15:17 +00001138 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001139 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1140
Jim Inghama2cf2632010-12-23 02:29:54 +00001141 if (runtime == NULL)
1142 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001143 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Jim Inghama2cf2632010-12-23 02:29:54 +00001144 clang_type_t opaque_qual_type = GetClangType();
1145 if (opaque_qual_type != NULL)
1146 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001147 bool is_signed;
1148 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed)
1149 || ClangASTContext::IsPointerType (opaque_qual_type))
1150 {
Greg Claytonafacd142011-09-02 01:15:17 +00001151 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001152 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001153 }
1154 }
1155
Jim Ingham8d543de2011-03-31 23:01:21 +00001156 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001157 {
1158 m_object_desc_str.append (s.GetData());
1159 }
Sean Callanan672ad942010-10-23 00:18:49 +00001160
1161 if (m_object_desc_str.empty())
1162 return NULL;
1163 else
1164 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001165}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001166
Enrico Granata0c489f52012-03-01 04:24:26 +00001167bool
1168ValueObject::GetValueAsCString (lldb::Format format,
1169 std::string& destination)
1170{
1171 if (ClangASTContext::IsAggregateType (GetClangType()) == false &&
1172 UpdateValueIfNeeded(false))
1173 {
1174 const Value::ContextType context_type = m_value.GetContextType();
1175
1176 switch (context_type)
1177 {
1178 case Value::eContextTypeClangType:
1179 case Value::eContextTypeLLDBType:
1180 case Value::eContextTypeVariable:
1181 {
1182 clang_type_t clang_type = GetClangType ();
1183 if (clang_type)
1184 {
1185 StreamString sstr;
1186 ExecutionContext exe_ctx (GetExecutionContextRef());
1187 ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
1188 clang_type, // The clang type to display
1189 &sstr,
1190 format, // Format to display this type with
1191 m_data, // Data to extract from
1192 0, // Byte offset into "m_data"
1193 GetByteSize(), // Byte size of item in "m_data"
1194 GetBitfieldBitSize(), // Bitfield bit size
1195 GetBitfieldBitOffset(), // Bitfield bit offset
1196 exe_ctx.GetBestExecutionContextScope());
1197 // Don't set the m_error to anything here otherwise
1198 // we won't be able to re-format as anything else. The
1199 // code for ClangASTType::DumpTypeValue() should always
1200 // return something, even if that something contains
1201 // an error messsage. "m_error" is used to detect errors
1202 // when reading the valid object, not for formatting errors.
1203 if (sstr.GetString().empty())
1204 destination.clear();
1205 else
1206 destination.swap(sstr.GetString());
1207 }
1208 }
1209 break;
1210
1211 case Value::eContextTypeRegisterInfo:
1212 {
1213 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1214 if (reg_info)
1215 {
1216 ExecutionContext exe_ctx (GetExecutionContextRef());
1217
1218 StreamString reg_sstr;
1219 m_data.Dump (&reg_sstr,
1220 0,
1221 format,
1222 reg_info->byte_size,
1223 1,
1224 UINT32_MAX,
1225 LLDB_INVALID_ADDRESS,
1226 0,
1227 0,
1228 exe_ctx.GetBestExecutionContextScope());
1229 destination.swap(reg_sstr.GetString());
1230 }
1231 }
1232 break;
1233
1234 default:
1235 break;
1236 }
1237 return !destination.empty();
1238 }
1239 else
1240 return false;
1241}
1242
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001243const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001244ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001245{
Enrico Granata0c489f52012-03-01 04:24:26 +00001246 if (UpdateValueIfNeeded(true) && m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001247 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001248 lldb::Format my_format = GetFormat();
1249 if (m_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001250 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001251 if (m_type_format_sp)
1252 my_format = m_type_format_sp->GetFormat();
1253 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001254 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001255 if (m_is_bitfield_for_scalar)
1256 my_format = eFormatUnsigned;
1257 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001258 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001259 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001260 {
1261 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1262 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001263 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001264 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001265 else
1266 {
1267 clang_type_t clang_type = GetClangType ();
1268 my_format = ClangASTType::GetFormat(clang_type);
1269 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001270 }
1271 }
1272 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001273 if (GetValueAsCString(my_format, m_value_str))
1274 {
1275 if (!m_value_did_change && m_old_value_valid)
1276 {
1277 // The value was gotten successfully, so we consider the
1278 // value as changed if the value string differs
1279 SetValueDidChange (m_old_value_str != m_value_str);
1280 }
1281 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001282 }
1283 if (m_value_str.empty())
1284 return NULL;
1285 return m_value_str.c_str();
1286}
1287
Enrico Granatac3e320a2011-08-02 17:27:39 +00001288// if > 8bytes, 0 is returned. this method should mostly be used
1289// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001290uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001291ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001292{
1293 // If our byte size is zero this is an aggregate type that has children
1294 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
1295 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001296 Scalar scalar;
1297 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001298 {
1299 if (success)
1300 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001301 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001302 }
1303 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001304 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001305
1306 if (success)
1307 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001308 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001309}
1310
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001311// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1312// this call up to date by returning true for your new special cases. We will eventually move
1313// to checking this call result before trying to display special cases
1314bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001315ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1316 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001317{
1318 clang_type_t elem_or_pointee_type;
1319 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
1320
1321 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001322 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001323 {
1324 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001325 (custom_format == eFormatCString ||
1326 custom_format == eFormatCharArray ||
1327 custom_format == eFormatChar ||
1328 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001329 return true;
1330
1331 if (flags.Test(ClangASTContext::eTypeIsArray))
1332 {
Greg Claytonafacd142011-09-02 01:15:17 +00001333 if ((custom_format == eFormatBytes) ||
1334 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001335 return true;
1336
Greg Claytonafacd142011-09-02 01:15:17 +00001337 if ((custom_format == eFormatVectorOfChar) ||
1338 (custom_format == eFormatVectorOfFloat32) ||
1339 (custom_format == eFormatVectorOfFloat64) ||
1340 (custom_format == eFormatVectorOfSInt16) ||
1341 (custom_format == eFormatVectorOfSInt32) ||
1342 (custom_format == eFormatVectorOfSInt64) ||
1343 (custom_format == eFormatVectorOfSInt8) ||
1344 (custom_format == eFormatVectorOfUInt128) ||
1345 (custom_format == eFormatVectorOfUInt16) ||
1346 (custom_format == eFormatVectorOfUInt32) ||
1347 (custom_format == eFormatVectorOfUInt64) ||
1348 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001349 return true;
1350 }
1351 }
1352 return false;
1353}
1354
Enrico Granata9fc19442011-07-06 02:13:41 +00001355bool
1356ValueObject::DumpPrintableRepresentation(Stream& s,
1357 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001358 Format custom_format,
Enrico Granata86cc9822012-03-19 22:58:49 +00001359 PrintableRepresentationSpecialCases special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001360{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001361
1362 clang_type_t elem_or_pointee_type;
1363 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001364
Enrico Granata86cc9822012-03-19 22:58:49 +00001365 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1366 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1367
1368 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001369 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001370 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1371 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001372 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001373 // when being asked to get a printable display an array or pointer type directly,
1374 // try to "do the right thing"
1375
1376 if (IsCStringContainer(true) &&
1377 (custom_format == eFormatCString ||
1378 custom_format == eFormatCharArray ||
1379 custom_format == eFormatChar ||
1380 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001381 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001382 Error error;
1383 ReadPointedString(s,
1384 error,
1385 0,
1386 (custom_format == eFormatVectorOfChar) ||
1387 (custom_format == eFormatCharArray));
1388 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001389 }
1390
Enrico Granata86cc9822012-03-19 22:58:49 +00001391 if (custom_format == eFormatEnum)
1392 return false;
1393
1394 // this only works for arrays, because I have no way to know when
1395 // the pointed memory ends, and no special \0 end of data marker
1396 if (flags.Test(ClangASTContext::eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001397 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001398 if ((custom_format == eFormatBytes) ||
1399 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001400 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001401 uint32_t count = GetNumChildren();
1402
1403 s << '[';
1404 for (uint32_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001405 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001406
1407 if (low)
1408 s << ',';
1409
1410 ValueObjectSP child = GetChildAtIndex(low,true);
1411 if (!child.get())
1412 {
1413 s << "<invalid child>";
1414 continue;
1415 }
1416 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1417 }
1418
1419 s << ']';
1420
1421 return true;
1422 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001423
Enrico Granata86cc9822012-03-19 22:58:49 +00001424 if ((custom_format == eFormatVectorOfChar) ||
1425 (custom_format == eFormatVectorOfFloat32) ||
1426 (custom_format == eFormatVectorOfFloat64) ||
1427 (custom_format == eFormatVectorOfSInt16) ||
1428 (custom_format == eFormatVectorOfSInt32) ||
1429 (custom_format == eFormatVectorOfSInt64) ||
1430 (custom_format == eFormatVectorOfSInt8) ||
1431 (custom_format == eFormatVectorOfUInt128) ||
1432 (custom_format == eFormatVectorOfUInt16) ||
1433 (custom_format == eFormatVectorOfUInt32) ||
1434 (custom_format == eFormatVectorOfUInt64) ||
1435 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1436 {
1437 uint32_t count = GetNumChildren();
1438
1439 Format format = FormatManager::GetSingleItemFormat(custom_format);
1440
1441 s << '[';
1442 for (uint32_t low = 0; low < count; low++)
1443 {
1444
1445 if (low)
1446 s << ',';
1447
1448 ValueObjectSP child = GetChildAtIndex(low,true);
1449 if (!child.get())
1450 {
1451 s << "<invalid child>";
1452 continue;
1453 }
1454 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1455 }
1456
1457 s << ']';
1458
1459 return true;
1460 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001461 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001462
1463 if ((custom_format == eFormatBoolean) ||
1464 (custom_format == eFormatBinary) ||
1465 (custom_format == eFormatChar) ||
1466 (custom_format == eFormatCharPrintable) ||
1467 (custom_format == eFormatComplexFloat) ||
1468 (custom_format == eFormatDecimal) ||
1469 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001470 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001471 (custom_format == eFormatFloat) ||
1472 (custom_format == eFormatOctal) ||
1473 (custom_format == eFormatOSType) ||
1474 (custom_format == eFormatUnicode16) ||
1475 (custom_format == eFormatUnicode32) ||
1476 (custom_format == eFormatUnsigned) ||
1477 (custom_format == eFormatPointer) ||
1478 (custom_format == eFormatComplexInteger) ||
1479 (custom_format == eFormatComplex) ||
1480 (custom_format == eFormatDefault)) // use the [] operator
1481 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001482 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001483 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001484
1485 if (only_special)
1486 return false;
1487
Enrico Granata86cc9822012-03-19 22:58:49 +00001488 bool var_success = false;
1489
1490 {
1491 const char * return_value;
1492 std::string alloc_mem;
1493
1494 if (custom_format != eFormatInvalid)
1495 SetFormat(custom_format);
1496
1497 switch(val_obj_display)
1498 {
1499 case eValueObjectRepresentationStyleValue:
1500 return_value = GetValueAsCString();
1501 break;
1502
1503 case eValueObjectRepresentationStyleSummary:
1504 return_value = GetSummaryAsCString();
1505 break;
1506
1507 case eValueObjectRepresentationStyleLanguageSpecific:
1508 return_value = GetObjectDescription();
1509 break;
1510
1511 case eValueObjectRepresentationStyleLocation:
1512 return_value = GetLocationAsCString();
1513 break;
1514
1515 case eValueObjectRepresentationStyleChildrenCount:
1516 {
1517 alloc_mem.resize(512);
1518 return_value = &alloc_mem[0];
1519 int count = GetNumChildren();
1520 snprintf((char*)return_value, 512, "%d", count);
1521 }
1522 break;
1523
1524 case eValueObjectRepresentationStyleType:
1525 return_value = GetTypeName().AsCString();
1526 break;
1527
1528 default:
1529 break;
1530 }
1531
1532 if (!return_value)
1533 {
1534 if (val_obj_display == eValueObjectRepresentationStyleValue)
1535 return_value = GetSummaryAsCString();
1536 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1537 {
1538 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1539 {
1540 // this thing has no value, and it seems to have no summary
1541 // some combination of unitialized data and other factors can also
1542 // raise this condition, so let's print a nice generic description
1543 {
1544 alloc_mem.resize(684);
1545 return_value = &alloc_mem[0];
1546 snprintf((char*)return_value, 684, "%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1547 }
1548 }
1549 else
1550 return_value = GetValueAsCString();
1551 }
1552 }
1553
1554 if (return_value)
1555 s.PutCString(return_value);
1556 else
1557 {
1558 if (m_error.Fail())
1559 s.Printf("<%s>", m_error.AsCString());
1560 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1561 s.PutCString("<no summary available>");
1562 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1563 s.PutCString("<no value available>");
1564 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1565 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1566 else
1567 s.PutCString("<no printable representation>");
1568 }
1569
1570 // we should only return false here if we could not do *anything*
1571 // even if we have an error message as output, that's a success
1572 // from our callers' perspective, so return true
1573 var_success = true;
1574
1575 if (custom_format != eFormatInvalid)
1576 SetFormat(eFormatDefault);
1577 }
1578
Enrico Granataf4efecd2011-07-12 22:56:10 +00001579 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001580}
1581
Greg Clayton737b9322010-09-13 03:32:57 +00001582addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001583ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001584{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001585 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001586 return LLDB_INVALID_ADDRESS;
1587
Greg Clayton73b472d2010-10-27 03:32:59 +00001588 switch (m_value.GetValueType())
1589 {
1590 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001591 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001592 if (scalar_is_load_address)
1593 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001594 if(address_type)
1595 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001596 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1597 }
1598 break;
1599
1600 case Value::eValueTypeLoadAddress:
1601 case Value::eValueTypeFileAddress:
1602 case Value::eValueTypeHostAddress:
1603 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001604 if(address_type)
1605 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001606 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1607 }
1608 break;
1609 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001610 if (address_type)
1611 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001612 return LLDB_INVALID_ADDRESS;
1613}
1614
1615addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001616ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001617{
Greg Claytonafacd142011-09-02 01:15:17 +00001618 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001619 if(address_type)
1620 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001621
Enrico Granatac3e320a2011-08-02 17:27:39 +00001622 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001623 return address;
1624
Greg Clayton73b472d2010-10-27 03:32:59 +00001625 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001626 {
1627 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001628 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001629 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001630 break;
1631
Enrico Granata9128ee22011-09-06 19:20:51 +00001632 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001633 case Value::eValueTypeLoadAddress:
1634 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001635 {
1636 uint32_t data_offset = 0;
1637 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001638 }
1639 break;
1640 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001641
Enrico Granata9128ee22011-09-06 19:20:51 +00001642 if (address_type)
1643 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001644
Greg Clayton737b9322010-09-13 03:32:57 +00001645 return address;
1646}
1647
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001648bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001649ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001650{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001651 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001652 // Make sure our value is up to date first so that our location and location
1653 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001654 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001655 {
1656 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001657 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001658 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001659
1660 uint32_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001661 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001662
Greg Claytonb1320972010-07-14 00:18:15 +00001663 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001664
Jim Ingham16e0c682011-08-12 23:34:31 +00001665 Value::ValueType value_type = m_value.GetValueType();
1666
1667 if (value_type == Value::eValueTypeScalar)
1668 {
1669 // If the value is already a scalar, then let the scalar change itself:
1670 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1671 }
1672 else if (byte_size <= Scalar::GetMaxByteSize())
1673 {
1674 // If the value fits in a scalar, then make a new scalar and again let the
1675 // scalar code do the conversion, then figure out where to put the new value.
1676 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001677 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1678 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001679 {
Jim Ingham4b536182011-08-09 02:12:22 +00001680 switch (value_type)
1681 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001682 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001683 {
1684 // If it is a load address, then the scalar value is the storage location
1685 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001686 ExecutionContext exe_ctx (GetExecutionContextRef());
1687 Process *process = exe_ctx.GetProcessPtr();
1688 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001689 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001690 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001691 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1692 new_scalar,
1693 byte_size,
1694 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001695 if (!error.Success())
1696 return false;
1697 if (bytes_written != byte_size)
1698 {
1699 error.SetErrorString("unable to write value to memory");
1700 return false;
1701 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001702 }
1703 }
Jim Ingham4b536182011-08-09 02:12:22 +00001704 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001705 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001706 {
1707 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1708 DataExtractor new_data;
1709 new_data.SetByteOrder (m_data.GetByteOrder());
1710
1711 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1712 m_data.SetData(buffer_sp, 0);
1713 bool success = new_scalar.GetData(new_data);
1714 if (success)
1715 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001716 new_data.CopyByteOrderedData (0,
1717 byte_size,
1718 const_cast<uint8_t *>(m_data.GetDataStart()),
1719 byte_size,
1720 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001721 }
1722 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1723
1724 }
Jim Ingham4b536182011-08-09 02:12:22 +00001725 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001726 case Value::eValueTypeFileAddress:
1727 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001728 case Value::eValueTypeVector:
1729 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001730 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001731 }
1732 else
1733 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001734 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001735 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001736 }
1737 else
1738 {
1739 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001740 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001741 return false;
1742 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001743
1744 // If we have reached this point, then we have successfully changed the value.
1745 SetNeedsUpdate();
1746 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001747}
1748
Greg Clayton81e871e2012-02-04 02:27:34 +00001749bool
1750ValueObject::GetDeclaration (Declaration &decl)
1751{
1752 decl.Clear();
1753 return false;
1754}
1755
Greg Clayton84db9102012-03-26 23:03:23 +00001756ConstString
1757ValueObject::GetTypeName()
1758{
1759 return ClangASTType::GetConstTypeName (GetClangAST(), GetClangType());
1760}
1761
1762ConstString
1763ValueObject::GetQualifiedTypeName()
1764{
1765 return ClangASTType::GetConstQualifiedTypeName (GetClangAST(), GetClangType());
1766}
1767
1768
Greg Claytonafacd142011-09-02 01:15:17 +00001769LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001770ValueObject::GetObjectRuntimeLanguage ()
1771{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001772 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1773 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001774}
1775
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001776void
Jim Ingham58b59f92011-04-22 23:53:53 +00001777ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001778{
Jim Ingham58b59f92011-04-22 23:53:53 +00001779 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001780}
1781
1782ValueObjectSP
1783ValueObject::GetSyntheticChild (const ConstString &key) const
1784{
1785 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001786 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001787 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001788 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001789 return synthetic_child_sp;
1790}
1791
1792bool
1793ValueObject::IsPointerType ()
1794{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001795 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001796}
1797
Jim Inghamb7603bb2011-03-18 00:05:18 +00001798bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001799ValueObject::IsArrayType ()
1800{
Greg Clayton4ef877f2012-12-06 02:33:54 +00001801 return ClangASTContext::IsArrayType (GetClangType(), NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00001802}
1803
1804bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001805ValueObject::IsScalarType ()
1806{
1807 return ClangASTContext::IsScalarType (GetClangType());
1808}
1809
1810bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001811ValueObject::IsIntegerType (bool &is_signed)
1812{
1813 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1814}
Greg Clayton73b472d2010-10-27 03:32:59 +00001815
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001816bool
1817ValueObject::IsPointerOrReferenceType ()
1818{
Greg Clayton007d5be2011-05-30 00:49:24 +00001819 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1820}
1821
1822bool
Greg Claytondea8cb42011-06-29 22:09:02 +00001823ValueObject::IsPossibleDynamicType ()
1824{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00001825 ExecutionContext exe_ctx (GetExecutionContextRef());
1826 Process *process = exe_ctx.GetProcessPtr();
1827 if (process)
1828 return process->IsPossibleDynamicValue(*this);
1829 else
Greg Clayton70364252012-08-31 18:56:24 +00001830 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType(), NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00001831}
1832
Greg Claytonafacd142011-09-02 01:15:17 +00001833ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001834ValueObject::GetSyntheticArrayMember (int32_t index, bool can_create)
1835{
1836 if (IsArrayType())
1837 return GetSyntheticArrayMemberFromArray(index, can_create);
1838
1839 if (IsPointerType())
1840 return GetSyntheticArrayMemberFromPointer(index, can_create);
1841
1842 return ValueObjectSP();
1843
1844}
1845
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001846ValueObjectSP
1847ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1848{
1849 ValueObjectSP synthetic_child_sp;
1850 if (IsPointerType ())
1851 {
1852 char index_str[64];
1853 snprintf(index_str, sizeof(index_str), "[%i]", index);
1854 ConstString index_const_str(index_str);
1855 // Check if we have already created a synthetic array member in this
1856 // valid object. If we have we will re-use it.
1857 synthetic_child_sp = GetSyntheticChild (index_const_str);
1858 if (!synthetic_child_sp)
1859 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001860 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001861 // We haven't made a synthetic array member for INDEX yet, so
1862 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001863 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001864
1865 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001866 if (synthetic_child)
1867 {
1868 AddSyntheticChild(index_const_str, synthetic_child);
1869 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001870 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001871 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001872 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001873 }
1874 }
1875 return synthetic_child_sp;
1876}
Jim Ingham22777012010-09-23 02:01:19 +00001877
Greg Claytondaf515f2011-07-09 20:12:33 +00001878// This allows you to create an array member using and index
1879// that doesn't not fall in the normal bounds of the array.
1880// Many times structure can be defined as:
1881// struct Collection
1882// {
1883// uint32_t item_count;
1884// Item item_array[0];
1885// };
1886// The size of the "item_array" is 1, but many times in practice
1887// there are more items in "item_array".
1888
1889ValueObjectSP
1890ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1891{
1892 ValueObjectSP synthetic_child_sp;
1893 if (IsArrayType ())
1894 {
1895 char index_str[64];
1896 snprintf(index_str, sizeof(index_str), "[%i]", index);
1897 ConstString index_const_str(index_str);
1898 // Check if we have already created a synthetic array member in this
1899 // valid object. If we have we will re-use it.
1900 synthetic_child_sp = GetSyntheticChild (index_const_str);
1901 if (!synthetic_child_sp)
1902 {
1903 ValueObject *synthetic_child;
1904 // We haven't made a synthetic array member for INDEX yet, so
1905 // lets make one and cache it for any future reference.
1906 synthetic_child = CreateChildAtIndex(0, true, index);
1907
1908 // Cache the value if we got one back...
1909 if (synthetic_child)
1910 {
1911 AddSyntheticChild(index_const_str, synthetic_child);
1912 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001913 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001914 synthetic_child_sp->m_is_array_item_for_pointer = true;
1915 }
1916 }
1917 }
1918 return synthetic_child_sp;
1919}
1920
Enrico Granata9fc19442011-07-06 02:13:41 +00001921ValueObjectSP
1922ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1923{
1924 ValueObjectSP synthetic_child_sp;
1925 if (IsScalarType ())
1926 {
1927 char index_str[64];
1928 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1929 ConstString index_const_str(index_str);
1930 // Check if we have already created a synthetic array member in this
1931 // valid object. If we have we will re-use it.
1932 synthetic_child_sp = GetSyntheticChild (index_const_str);
1933 if (!synthetic_child_sp)
1934 {
1935 ValueObjectChild *synthetic_child;
1936 // We haven't made a synthetic array member for INDEX yet, so
1937 // lets make one and cache it for any future reference.
1938 synthetic_child = new ValueObjectChild(*this,
1939 GetClangAST(),
1940 GetClangType(),
1941 index_const_str,
1942 GetByteSize(),
1943 0,
1944 to-from+1,
1945 from,
1946 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001947 false,
1948 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00001949
1950 // Cache the value if we got one back...
1951 if (synthetic_child)
1952 {
1953 AddSyntheticChild(index_const_str, synthetic_child);
1954 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001955 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00001956 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1957 }
1958 }
1959 }
1960 return synthetic_child_sp;
1961}
1962
Greg Claytonafacd142011-09-02 01:15:17 +00001963ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001964ValueObject::GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create)
1965{
1966 ValueObjectSP synthetic_child_sp;
1967 if (IsArrayType () || IsPointerType ())
1968 {
1969 char index_str[64];
1970 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1971 ConstString index_const_str(index_str);
1972 // Check if we have already created a synthetic array member in this
1973 // valid object. If we have we will re-use it.
1974 synthetic_child_sp = GetSyntheticChild (index_const_str);
1975 if (!synthetic_child_sp)
1976 {
1977 ValueObjectSynthetic *synthetic_child;
1978
1979 // We haven't made a synthetic array member for INDEX yet, so
1980 // lets make one and cache it for any future reference.
Enrico Granata061858c2012-02-15 02:34:21 +00001981 SyntheticArrayView *view = new SyntheticArrayView(SyntheticChildren::Flags());
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001982 view->AddRange(from,to);
1983 SyntheticChildrenSP view_sp(view);
1984 synthetic_child = new ValueObjectSynthetic(*this, view_sp);
1985
1986 // Cache the value if we got one back...
1987 if (synthetic_child)
1988 {
1989 AddSyntheticChild(index_const_str, synthetic_child);
1990 synthetic_child_sp = synthetic_child->GetSP();
1991 synthetic_child_sp->SetName(ConstString(index_str));
1992 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1993 }
1994 }
1995 }
1996 return synthetic_child_sp;
1997}
1998
Greg Claytonafacd142011-09-02 01:15:17 +00001999ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00002000ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
2001{
2002
2003 ValueObjectSP synthetic_child_sp;
2004
2005 char name_str[64];
2006 snprintf(name_str, sizeof(name_str), "@%i", offset);
2007 ConstString name_const_str(name_str);
2008
2009 // Check if we have already created a synthetic array member in this
2010 // valid object. If we have we will re-use it.
2011 synthetic_child_sp = GetSyntheticChild (name_const_str);
2012
2013 if (synthetic_child_sp.get())
2014 return synthetic_child_sp;
2015
2016 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002017 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002018
2019 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2020 type.GetASTContext(),
2021 type.GetOpaqueQualType(),
2022 name_const_str,
2023 type.GetTypeByteSize(),
2024 offset,
2025 0,
2026 0,
2027 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002028 false,
2029 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002030 if (synthetic_child)
2031 {
2032 AddSyntheticChild(name_const_str, synthetic_child);
2033 synthetic_child_sp = synthetic_child->GetSP();
2034 synthetic_child_sp->SetName(name_const_str);
2035 synthetic_child_sp->m_is_child_at_offset = true;
2036 }
2037 return synthetic_child_sp;
2038}
2039
Enrico Granatad55546b2011-07-22 00:16:08 +00002040// your expression path needs to have a leading . or ->
2041// (unless it somehow "looks like" an array, in which case it has
2042// a leading [ symbol). while the [ is meaningful and should be shown
2043// to the user, . and -> are just parser design, but by no means
2044// added information for the user.. strip them off
2045static const char*
2046SkipLeadingExpressionPathSeparators(const char* expression)
2047{
2048 if (!expression || !expression[0])
2049 return expression;
2050 if (expression[0] == '.')
2051 return expression+1;
2052 if (expression[0] == '-' && expression[1] == '>')
2053 return expression+2;
2054 return expression;
2055}
2056
Greg Claytonafacd142011-09-02 01:15:17 +00002057ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002058ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2059{
2060 ValueObjectSP synthetic_child_sp;
2061 ConstString name_const_string(expression);
2062 // Check if we have already created a synthetic array member in this
2063 // valid object. If we have we will re-use it.
2064 synthetic_child_sp = GetSyntheticChild (name_const_string);
2065 if (!synthetic_child_sp)
2066 {
2067 // We haven't made a synthetic array member for expression yet, so
2068 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002069 synthetic_child_sp = GetValueForExpressionPath(expression,
2070 NULL, NULL, NULL,
2071 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
Enrico Granatad55546b2011-07-22 00:16:08 +00002072
2073 // Cache the value if we got one back...
2074 if (synthetic_child_sp.get())
2075 {
2076 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002077 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002078 synthetic_child_sp->m_is_expression_path_child = true;
2079 }
2080 }
2081 return synthetic_child_sp;
2082}
2083
2084void
Enrico Granata86cc9822012-03-19 22:58:49 +00002085ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002086{
Enrico Granata86cc9822012-03-19 22:58:49 +00002087 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002088 return;
2089
Enrico Granatac5bc4122012-03-27 02:35:13 +00002090 TargetSP target_sp(GetTargetSP());
2091 if (target_sp && (target_sp->GetEnableSyntheticValue() == false || target_sp->GetSuppressSyntheticValue() == true))
2092 {
2093 m_synthetic_value = NULL;
2094 return;
2095 }
2096
Enrico Granatae3e91512012-10-22 18:18:36 +00002097 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2098
Enrico Granata86cc9822012-03-19 22:58:49 +00002099 if (!UpdateFormatsIfNeeded(m_last_format_mgr_dynamic) && m_synthetic_value)
2100 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002101
Enrico Granata0c489f52012-03-01 04:24:26 +00002102 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002103 return;
2104
Enrico Granatae3e91512012-10-22 18:18:36 +00002105 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2106 return;
2107
Enrico Granata86cc9822012-03-19 22:58:49 +00002108 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002109}
2110
Jim Ingham78a685a2011-04-16 00:01:13 +00002111void
Greg Claytonafacd142011-09-02 01:15:17 +00002112ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002113{
Greg Claytonafacd142011-09-02 01:15:17 +00002114 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002115 return;
2116
Jim Ingham58b59f92011-04-22 23:53:53 +00002117 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002118 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002119 ExecutionContext exe_ctx (GetExecutionContextRef());
2120 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002121 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002122 {
2123 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002124 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002125 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002126 }
2127}
2128
Jim Ingham58b59f92011-04-22 23:53:53 +00002129ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002130ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002131{
Greg Claytonafacd142011-09-02 01:15:17 +00002132 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002133 return ValueObjectSP();
2134
2135 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002136 {
Jim Ingham2837b762011-05-04 03:43:18 +00002137 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002138 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002139 if (m_dynamic_value)
2140 return m_dynamic_value->GetSP();
2141 else
2142 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002143}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002144
Jim Ingham60dbabb2011-12-08 19:44:08 +00002145ValueObjectSP
2146ValueObject::GetStaticValue()
2147{
2148 return GetSP();
2149}
2150
Enrico Granata886147f2012-05-08 18:47:08 +00002151lldb::ValueObjectSP
2152ValueObject::GetNonSyntheticValue ()
2153{
2154 return GetSP();
2155}
2156
Enrico Granatad55546b2011-07-22 00:16:08 +00002157ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002158ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002159{
Enrico Granata86cc9822012-03-19 22:58:49 +00002160 if (use_synthetic == false)
2161 return ValueObjectSP();
2162
Enrico Granatad55546b2011-07-22 00:16:08 +00002163 CalculateSyntheticValue(use_synthetic);
2164
2165 if (m_synthetic_value)
2166 return m_synthetic_value->GetSP();
2167 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002168 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002169}
2170
Greg Claytone221f822011-01-21 01:59:00 +00002171bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002172ValueObject::HasSyntheticValue()
2173{
2174 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
2175
Enrico Granata0c489f52012-03-01 04:24:26 +00002176 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002177 return false;
2178
Enrico Granata86cc9822012-03-19 22:58:49 +00002179 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002180
2181 if (m_synthetic_value)
2182 return true;
2183 else
2184 return false;
2185}
2186
2187bool
Greg Claytone221f822011-01-21 01:59:00 +00002188ValueObject::GetBaseClassPath (Stream &s)
2189{
2190 if (IsBaseClass())
2191 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002192 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00002193 clang_type_t clang_type = GetClangType();
2194 std::string cxx_class_name;
2195 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
2196 if (this_had_base_class)
2197 {
2198 if (parent_had_base_class)
2199 s.PutCString("::");
2200 s.PutCString(cxx_class_name.c_str());
2201 }
2202 return parent_had_base_class || this_had_base_class;
2203 }
2204 return false;
2205}
2206
2207
2208ValueObject *
2209ValueObject::GetNonBaseClassParent()
2210{
Jim Ingham78a685a2011-04-16 00:01:13 +00002211 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002212 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002213 if (GetParent()->IsBaseClass())
2214 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002215 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002216 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002217 }
2218 return NULL;
2219}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002220
2221void
Enrico Granata4becb372011-06-29 22:27:15 +00002222ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002223{
Greg Claytone221f822011-01-21 01:59:00 +00002224 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002225
Enrico Granata86cc9822012-03-19 22:58:49 +00002226 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002227 {
Enrico Granata4becb372011-06-29 22:27:15 +00002228 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2229 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2230 // the eHonorPointers mode is meant to produce strings in this latter format
2231 s.PutCString("*(");
2232 }
Greg Claytone221f822011-01-21 01:59:00 +00002233
Enrico Granata4becb372011-06-29 22:27:15 +00002234 ValueObject* parent = GetParent();
2235
2236 if (parent)
2237 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002238
2239 // if we are a deref_of_parent just because we are synthetic array
2240 // members made up to allow ptr[%d] syntax to work in variable
2241 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002242 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002243 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002244
Greg Claytone221f822011-01-21 01:59:00 +00002245 if (!IsBaseClass())
2246 {
2247 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002248 {
Greg Claytone221f822011-01-21 01:59:00 +00002249 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2250 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002251 {
Greg Claytone221f822011-01-21 01:59:00 +00002252 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2253 if (non_base_class_parent_clang_type)
2254 {
2255 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2256
Enrico Granata86cc9822012-03-19 22:58:49 +00002257 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002258 {
2259 s.PutCString("->");
2260 }
Enrico Granata4becb372011-06-29 22:27:15 +00002261 else
2262 {
2263 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2264 {
2265 s.PutCString("->");
2266 }
2267 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2268 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2269 {
2270 s.PutChar('.');
2271 }
Greg Claytone221f822011-01-21 01:59:00 +00002272 }
2273 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002274 }
Greg Claytone221f822011-01-21 01:59:00 +00002275
2276 const char *name = GetName().GetCString();
2277 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002278 {
Greg Claytone221f822011-01-21 01:59:00 +00002279 if (qualify_cxx_base_classes)
2280 {
2281 if (GetBaseClassPath (s))
2282 s.PutCString("::");
2283 }
2284 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002285 }
2286 }
2287 }
2288
Enrico Granata86cc9822012-03-19 22:58:49 +00002289 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002290 {
Greg Claytone221f822011-01-21 01:59:00 +00002291 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002292 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002293}
2294
Greg Claytonafacd142011-09-02 01:15:17 +00002295ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002296ValueObject::GetValueForExpressionPath(const char* expression,
2297 const char** first_unparsed,
2298 ExpressionPathScanEndReason* reason_to_stop,
2299 ExpressionPathEndResultType* final_value_type,
2300 const GetValueForExpressionPathOptions& options,
2301 ExpressionPathAftermath* final_task_on_target)
2302{
2303
2304 const char* dummy_first_unparsed;
2305 ExpressionPathScanEndReason dummy_reason_to_stop;
2306 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002307 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002308
2309 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2310 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2311 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2312 final_value_type ? final_value_type : &dummy_final_value_type,
2313 options,
2314 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2315
Enrico Granata86cc9822012-03-19 22:58:49 +00002316 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002317 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002318
Enrico Granata86cc9822012-03-19 22:58:49 +00002319 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 +00002320 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002321 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002322 {
2323 Error error;
2324 ValueObjectSP final_value = ret_val->Dereference(error);
2325 if (error.Fail() || !final_value.get())
2326 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002327 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002328 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002329 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002330 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002331 return ValueObjectSP();
2332 }
2333 else
2334 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002335 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002336 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002337 return final_value;
2338 }
2339 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002340 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002341 {
2342 Error error;
2343 ValueObjectSP final_value = ret_val->AddressOf(error);
2344 if (error.Fail() || !final_value.get())
2345 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002346 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002347 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002348 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002349 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002350 return ValueObjectSP();
2351 }
2352 else
2353 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002354 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002355 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002356 return final_value;
2357 }
2358 }
2359 }
2360 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2361}
2362
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002363int
2364ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002365 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002366 const char** first_unparsed,
2367 ExpressionPathScanEndReason* reason_to_stop,
2368 ExpressionPathEndResultType* final_value_type,
2369 const GetValueForExpressionPathOptions& options,
2370 ExpressionPathAftermath* final_task_on_target)
2371{
2372 const char* dummy_first_unparsed;
2373 ExpressionPathScanEndReason dummy_reason_to_stop;
2374 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002375 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002376
2377 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2378 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2379 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2380 final_value_type ? final_value_type : &dummy_final_value_type,
2381 options,
2382 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2383
2384 if (!ret_val.get()) // if there are errors, I add nothing to the list
2385 return 0;
2386
Enrico Granata86ea8d82012-03-29 01:34:34 +00002387 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002388 {
2389 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002390 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002391 {
2392 list->Append(ret_val);
2393 return 1;
2394 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002395 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 +00002396 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002397 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002398 {
2399 Error error;
2400 ValueObjectSP final_value = ret_val->Dereference(error);
2401 if (error.Fail() || !final_value.get())
2402 {
Greg Clayton23f59502012-07-17 03:23:13 +00002403 if (reason_to_stop)
2404 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2405 if (final_value_type)
2406 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002407 return 0;
2408 }
2409 else
2410 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002411 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002412 list->Append(final_value);
2413 return 1;
2414 }
2415 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002416 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002417 {
2418 Error error;
2419 ValueObjectSP final_value = ret_val->AddressOf(error);
2420 if (error.Fail() || !final_value.get())
2421 {
Greg Clayton23f59502012-07-17 03:23:13 +00002422 if (reason_to_stop)
2423 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2424 if (final_value_type)
2425 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002426 return 0;
2427 }
2428 else
2429 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002430 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002431 list->Append(final_value);
2432 return 1;
2433 }
2434 }
2435 }
2436 }
2437 else
2438 {
2439 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2440 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2441 ret_val,
2442 list,
2443 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2444 final_value_type ? final_value_type : &dummy_final_value_type,
2445 options,
2446 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2447 }
2448 // in any non-covered case, just do the obviously right thing
2449 list->Append(ret_val);
2450 return 1;
2451}
2452
Greg Claytonafacd142011-09-02 01:15:17 +00002453ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002454ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2455 const char** first_unparsed,
2456 ExpressionPathScanEndReason* reason_to_stop,
2457 ExpressionPathEndResultType* final_result,
2458 const GetValueForExpressionPathOptions& options,
2459 ExpressionPathAftermath* what_next)
2460{
2461 ValueObjectSP root = GetSP();
2462
2463 if (!root.get())
2464 return ValueObjectSP();
2465
2466 *first_unparsed = expression_cstr;
2467
2468 while (true)
2469 {
2470
2471 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2472
Greg Claytonafacd142011-09-02 01:15:17 +00002473 clang_type_t root_clang_type = root->GetClangType();
2474 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002475 Flags root_clang_type_info,pointee_clang_type_info;
2476
2477 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2478 if (pointee_clang_type)
2479 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002480
2481 if (!expression_cstr || *expression_cstr == '\0')
2482 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002483 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002484 return root;
2485 }
2486
2487 switch (*expression_cstr)
2488 {
2489 case '-':
2490 {
2491 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002492 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 +00002493 {
2494 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002495 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2496 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002497 return ValueObjectSP();
2498 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002499 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2500 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002501 options.m_no_fragile_ivar)
2502 {
2503 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002504 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2505 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002506 return ValueObjectSP();
2507 }
2508 if (expression_cstr[1] != '>')
2509 {
2510 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002511 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2512 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002513 return ValueObjectSP();
2514 }
2515 expression_cstr++; // skip the -
2516 }
2517 case '.': // or fallthrough from ->
2518 {
2519 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002520 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 +00002521 {
2522 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002523 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2524 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002525 return ValueObjectSP();
2526 }
2527 expression_cstr++; // skip .
2528 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2529 ConstString child_name;
2530 if (!next_separator) // if no other separator just expand this last layer
2531 {
2532 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002533 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2534
2535 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002536 {
2537 *first_unparsed = '\0';
Enrico Granata86cc9822012-03-19 22:58:49 +00002538 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2539 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002540 return child_valobj_sp;
2541 }
2542 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2543 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002544 if (root->IsSynthetic())
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002545 {
2546 *first_unparsed = expression_cstr;
2547 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2548 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2549 return ValueObjectSP();
2550 }
2551
2552 child_valobj_sp = root->GetSyntheticValue();
Enrico Granata86cc9822012-03-19 22:58:49 +00002553 if (child_valobj_sp.get())
2554 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002555 }
2556
2557 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2558 // so we hit the "else" branch, and return an error
2559 if(child_valobj_sp.get()) // if it worked, just return
2560 {
2561 *first_unparsed = '\0';
Enrico Granata86cc9822012-03-19 22:58:49 +00002562 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2563 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002564 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002565 }
2566 else
2567 {
2568 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002569 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2570 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002571 return ValueObjectSP();
2572 }
2573 }
2574 else // other layers do expand
2575 {
2576 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002577 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2578 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002579 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002580 root = child_valobj_sp;
2581 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002582 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002583 continue;
2584 }
2585 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2586 {
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002587 if (root->IsSynthetic())
2588 {
2589 *first_unparsed = expression_cstr;
2590 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2591 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2592 return ValueObjectSP();
2593 }
2594
Enrico Granata86cc9822012-03-19 22:58:49 +00002595 child_valobj_sp = root->GetSyntheticValue(true);
2596 if (child_valobj_sp)
2597 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002598 }
2599
2600 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2601 // so we hit the "else" branch, and return an error
2602 if(child_valobj_sp.get()) // if it worked, move on
2603 {
2604 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002605 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002606 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002607 continue;
2608 }
2609 else
2610 {
2611 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002612 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2613 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002614 return ValueObjectSP();
2615 }
2616 }
2617 break;
2618 }
2619 case '[':
2620 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002621 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 +00002622 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002623 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002624 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002625 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2626 {
2627 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002628 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2629 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002630 return ValueObjectSP();
2631 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002632 }
2633 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2634 {
2635 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002636 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2637 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002638 return ValueObjectSP();
2639 }
2640 }
2641 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2642 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002643 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002644 {
2645 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002646 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2647 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002648 return ValueObjectSP();
2649 }
2650 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2651 {
2652 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002653 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2654 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002655 return root;
2656 }
2657 }
2658 const char *separator_position = ::strchr(expression_cstr+1,'-');
2659 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2660 if (!close_bracket_position) // if there is no ], this is a syntax error
2661 {
2662 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002663 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2664 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002665 return ValueObjectSP();
2666 }
2667 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2668 {
2669 char *end = NULL;
2670 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2671 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2672 {
2673 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002674 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2675 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002676 return ValueObjectSP();
2677 }
2678 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2679 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002680 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002681 {
2682 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002683 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2684 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002685 return root;
2686 }
2687 else
2688 {
2689 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002690 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2691 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002692 return ValueObjectSP();
2693 }
2694 }
2695 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002696 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002697 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002698 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2699 if (!child_valobj_sp)
2700 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002701 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002702 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2703 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002704 if (child_valobj_sp)
2705 {
2706 root = child_valobj_sp;
2707 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002708 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002709 continue;
2710 }
2711 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002712 {
2713 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002714 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2715 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002716 return ValueObjectSP();
2717 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002718 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002719 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002720 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002721 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 +00002722 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002723 {
2724 Error error;
2725 root = root->Dereference(error);
2726 if (error.Fail() || !root.get())
2727 {
2728 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002729 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2730 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002731 return ValueObjectSP();
2732 }
2733 else
2734 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002735 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002736 continue;
2737 }
2738 }
2739 else
2740 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002741 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Clayton84db9102012-03-26 23:03:23 +00002742 root->GetClangType()) == eLanguageTypeObjC
2743 && ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2744 && root->HasSyntheticValue()
2745 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002746 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002747 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002748 }
2749 else
2750 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002751 if (!root.get())
2752 {
2753 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002754 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2755 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002756 return ValueObjectSP();
2757 }
2758 else
2759 {
2760 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002761 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002762 continue;
2763 }
2764 }
2765 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002766 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002767 {
2768 root = root->GetSyntheticBitFieldChild(index, index, true);
2769 if (!root.get())
2770 {
2771 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002772 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2773 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002774 return ValueObjectSP();
2775 }
2776 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2777 {
2778 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002779 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2780 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002781 return root;
2782 }
2783 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002784 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002785 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002786 if (root->HasSyntheticValue())
2787 root = root->GetSyntheticValue();
2788 else if (!root->IsSynthetic())
2789 {
2790 *first_unparsed = expression_cstr;
2791 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2792 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2793 return ValueObjectSP();
2794 }
2795 // if we are here, then root itself is a synthetic VO.. should be good to go
2796
Enrico Granata27b625e2011-08-09 01:04:56 +00002797 if (!root.get())
2798 {
2799 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002800 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2801 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2802 return ValueObjectSP();
2803 }
2804 root = root->GetChildAtIndex(index, true);
2805 if (!root.get())
2806 {
2807 *first_unparsed = expression_cstr;
2808 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2809 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002810 return ValueObjectSP();
2811 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002812 else
2813 {
2814 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002815 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002816 continue;
2817 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002818 }
2819 else
2820 {
2821 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002822 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2823 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002824 return ValueObjectSP();
2825 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002826 }
2827 else // we have a low and a high index
2828 {
2829 char *end = NULL;
2830 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2831 if (!end || end != separator_position) // if something weird is in our way return an error
2832 {
2833 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002834 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2835 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002836 return ValueObjectSP();
2837 }
2838 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2839 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2840 {
2841 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002842 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2843 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002844 return ValueObjectSP();
2845 }
2846 if (index_lower > index_higher) // swap indices if required
2847 {
2848 unsigned long temp = index_lower;
2849 index_lower = index_higher;
2850 index_higher = temp;
2851 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002852 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002853 {
2854 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2855 if (!root.get())
2856 {
2857 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002858 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2859 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002860 return ValueObjectSP();
2861 }
2862 else
2863 {
2864 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002865 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2866 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002867 return root;
2868 }
2869 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002870 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 +00002871 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002872 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002873 {
2874 Error error;
2875 root = root->Dereference(error);
2876 if (error.Fail() || !root.get())
2877 {
2878 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002879 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2880 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002881 return ValueObjectSP();
2882 }
2883 else
2884 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002885 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002886 continue;
2887 }
2888 }
2889 else
2890 {
2891 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002892 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2893 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002894 return root;
2895 }
2896 }
2897 break;
2898 }
2899 default: // some non-separator is in the way
2900 {
2901 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002902 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2903 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002904 return ValueObjectSP();
2905 break;
2906 }
2907 }
2908 }
2909}
2910
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002911int
2912ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2913 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002914 ValueObjectSP root,
2915 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002916 ExpressionPathScanEndReason* reason_to_stop,
2917 ExpressionPathEndResultType* final_result,
2918 const GetValueForExpressionPathOptions& options,
2919 ExpressionPathAftermath* what_next)
2920{
2921 if (!root.get())
2922 return 0;
2923
2924 *first_unparsed = expression_cstr;
2925
2926 while (true)
2927 {
2928
2929 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2930
Greg Claytonafacd142011-09-02 01:15:17 +00002931 clang_type_t root_clang_type = root->GetClangType();
2932 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002933 Flags root_clang_type_info,pointee_clang_type_info;
2934
2935 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2936 if (pointee_clang_type)
2937 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2938
2939 if (!expression_cstr || *expression_cstr == '\0')
2940 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002941 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002942 list->Append(root);
2943 return 1;
2944 }
2945
2946 switch (*expression_cstr)
2947 {
2948 case '[':
2949 {
2950 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2951 {
2952 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2953 {
2954 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002955 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2956 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002957 return 0;
2958 }
2959 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2960 {
2961 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002962 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2963 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002964 return 0;
2965 }
2966 }
2967 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2968 {
2969 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2970 {
2971 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002972 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2973 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002974 return 0;
2975 }
2976 else // expand this into list
2977 {
2978 int max_index = root->GetNumChildren() - 1;
2979 for (int index = 0; index < max_index; index++)
2980 {
2981 ValueObjectSP child =
2982 root->GetChildAtIndex(index, true);
2983 list->Append(child);
2984 }
2985 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002986 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
2987 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002988 return max_index; // tell me number of items I added to the VOList
2989 }
2990 }
2991 const char *separator_position = ::strchr(expression_cstr+1,'-');
2992 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2993 if (!close_bracket_position) // if there is no ], this is a syntax error
2994 {
2995 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002996 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2997 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002998 return 0;
2999 }
3000 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3001 {
3002 char *end = NULL;
3003 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3004 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3005 {
3006 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003007 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3008 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003009 return 0;
3010 }
3011 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3012 {
3013 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3014 {
3015 int max_index = root->GetNumChildren() - 1;
3016 for (int index = 0; index < max_index; index++)
3017 {
3018 ValueObjectSP child =
3019 root->GetChildAtIndex(index, true);
3020 list->Append(child);
3021 }
3022 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003023 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3024 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003025 return max_index; // tell me number of items I added to the VOList
3026 }
3027 else
3028 {
3029 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003030 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3031 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003032 return 0;
3033 }
3034 }
3035 // from here on we do have a valid index
3036 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3037 {
3038 root = root->GetChildAtIndex(index, true);
3039 if (!root.get())
3040 {
3041 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003042 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3043 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003044 return 0;
3045 }
3046 else
3047 {
3048 list->Append(root);
3049 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003050 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3051 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003052 return 1;
3053 }
3054 }
3055 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
3056 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003057 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 +00003058 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3059 {
3060 Error error;
3061 root = root->Dereference(error);
3062 if (error.Fail() || !root.get())
3063 {
3064 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003065 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3066 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003067 return 0;
3068 }
3069 else
3070 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003071 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003072 continue;
3073 }
3074 }
3075 else
3076 {
3077 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3078 if (!root.get())
3079 {
3080 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003081 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3082 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003083 return 0;
3084 }
3085 else
3086 {
3087 list->Append(root);
3088 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003089 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3090 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003091 return 1;
3092 }
3093 }
3094 }
3095 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3096 {
3097 root = root->GetSyntheticBitFieldChild(index, index, true);
3098 if (!root.get())
3099 {
3100 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003101 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3102 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003103 return 0;
3104 }
3105 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3106 {
3107 list->Append(root);
3108 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003109 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3110 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003111 return 1;
3112 }
3113 }
3114 }
3115 else // we have a low and a high index
3116 {
3117 char *end = NULL;
3118 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3119 if (!end || end != separator_position) // if something weird is in our way return an error
3120 {
3121 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003122 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3123 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003124 return 0;
3125 }
3126 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3127 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3128 {
3129 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003130 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3131 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003132 return 0;
3133 }
3134 if (index_lower > index_higher) // swap indices if required
3135 {
3136 unsigned long temp = index_lower;
3137 index_lower = index_higher;
3138 index_higher = temp;
3139 }
3140 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
3141 {
3142 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3143 if (!root.get())
3144 {
3145 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003146 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3147 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003148 return 0;
3149 }
3150 else
3151 {
3152 list->Append(root);
3153 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003154 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3155 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003156 return 1;
3157 }
3158 }
3159 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 +00003160 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003161 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3162 {
3163 Error error;
3164 root = root->Dereference(error);
3165 if (error.Fail() || !root.get())
3166 {
3167 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003168 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3169 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003170 return 0;
3171 }
3172 else
3173 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003174 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003175 continue;
3176 }
3177 }
3178 else
3179 {
Johnny Chen44805302011-07-19 19:48:13 +00003180 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003181 index <= index_higher; index++)
3182 {
3183 ValueObjectSP child =
3184 root->GetChildAtIndex(index, true);
3185 list->Append(child);
3186 }
3187 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003188 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3189 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003190 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3191 }
3192 }
3193 break;
3194 }
3195 default: // some non-[ separator, or something entirely wrong, is in the way
3196 {
3197 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003198 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3199 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003200 return 0;
3201 break;
3202 }
3203 }
3204 }
3205}
3206
Enrico Granata0c489f52012-03-01 04:24:26 +00003207static void
3208DumpValueObject_Impl (Stream &s,
3209 ValueObject *valobj,
3210 const ValueObject::DumpValueObjectOptions& options,
3211 uint32_t ptr_depth,
3212 uint32_t curr_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003213{
Greg Clayton007d5be2011-05-30 00:49:24 +00003214 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003215 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003216 bool update_success = valobj->UpdateValueIfNeeded (options.m_use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00003217
Enrico Granata0c489f52012-03-01 04:24:26 +00003218 const char *root_valobj_name =
3219 options.m_root_valobj_name.empty() ?
3220 valobj->GetName().AsCString() :
3221 options.m_root_valobj_name.c_str();
3222
3223 if (update_success && options.m_use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00003224 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003225 ValueObject *dynamic_value = valobj->GetDynamicValue(options.m_use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003226 if (dynamic_value)
3227 valobj = dynamic_value;
3228 }
3229
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003230 clang_type_t clang_type = valobj->GetClangType();
3231
Greg Clayton73b472d2010-10-27 03:32:59 +00003232 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003233 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00003234 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
3235 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003236
Enrico Granata0c489f52012-03-01 04:24:26 +00003237 const bool print_valobj = options.m_flat_output == false || has_value;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003238
3239 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003240 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003241 if (options.m_show_location)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003242 {
Jim Ingham6035b672011-03-31 00:19:25 +00003243 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003244 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003245
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003246 s.Indent();
Enrico Granata2b2631c2012-08-09 16:51:25 +00003247
3248 bool show_type = true;
3249 // if we are at the root-level and been asked to hide the root's type, then hide it
3250 if (curr_depth == 0 && options.m_hide_root_type)
3251 show_type = false;
3252 else
3253 // otherwise decide according to the usual rules (asked to show types - always at the root level)
3254 show_type = options.m_show_types || (curr_depth == 0 && !options.m_flat_output);
3255
3256 if (show_type)
Enrico Granatac3e320a2011-08-02 17:27:39 +00003257 {
Greg Clayton84db9102012-03-26 23:03:23 +00003258 const char* typeName = valobj->GetQualifiedTypeName().AsCString("<invalid type>");
3259 //const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
Enrico Granata9910bc82011-08-03 02:18:51 +00003260 s.Printf("(%s", typeName);
3261 // only show dynamic types if the user really wants to see types
Enrico Granata0c489f52012-03-01 04:24:26 +00003262 if (options.m_show_types && options.m_use_dynamic != eNoDynamicValues &&
Enrico Granata9910bc82011-08-03 02:18:51 +00003263 (/*strstr(typeName, "id") == typeName ||*/
Greg Claytonafacd142011-09-02 01:15:17 +00003264 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003265 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003266 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3267 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatac3e320a2011-08-02 17:27:39 +00003268 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003269 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003270 else
3271 {
3272 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
3273 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003274 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003275 else
3276 {
Greg Claytonf0246d12012-10-11 18:07:21 +00003277 ObjCLanguageRuntime::ClassDescriptorSP objc_class_sp (runtime->GetNonKVOClassDescriptor(*valobj));
3278 if (objc_class_sp)
3279 s.Printf(", dynamic type: %s) ", objc_class_sp->GetClassName().GetCString());
Enrico Granatac3e320a2011-08-02 17:27:39 +00003280 else
Greg Claytonf0246d12012-10-11 18:07:21 +00003281 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003282 }
3283 }
3284 }
3285 else
3286 s.Printf(") ");
3287 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003288
Greg Clayton1d3afba2010-10-05 00:00:42 +00003289
Enrico Granata0c489f52012-03-01 04:24:26 +00003290 if (options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003291 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003292 // If we are showing types, also qualify the C++ base classes
Enrico Granata0c489f52012-03-01 04:24:26 +00003293 const bool qualify_cxx_base_classes = options.m_show_types;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003294 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003295 s.PutCString(" =");
3296 }
3297 else
3298 {
3299 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3300 s.Printf ("%s =", name_cstr);
3301 }
3302
Enrico Granata0c489f52012-03-01 04:24:26 +00003303 if (!options.m_scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003304 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003305 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003306 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003307 }
3308
Enrico Granata0c489f52012-03-01 04:24:26 +00003309 std::string summary_str;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003310 std::string value_str;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003311 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003312 const char *sum_cstr = NULL;
Enrico Granata0c489f52012-03-01 04:24:26 +00003313 TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003314
Enrico Granata0c489f52012-03-01 04:24:26 +00003315 if (options.m_omit_summary_depth > 0)
Enrico Granata0c5ef692011-07-16 01:22:04 +00003316 entry = NULL;
3317
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003318 if (err_cstr == NULL)
3319 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003320 if (options.m_format != eFormatDefault && options.m_format != valobj->GetFormat())
Greg Clayton6efba4f2012-01-26 21:08:30 +00003321 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003322 valobj->GetValueAsCString(options.m_format,
3323 value_str);
Greg Clayton6efba4f2012-01-26 21:08:30 +00003324 }
Enrico Granata0c489f52012-03-01 04:24:26 +00003325 else
Greg Clayton6efba4f2012-01-26 21:08:30 +00003326 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003327 val_cstr = valobj->GetValueAsCString();
3328 if (val_cstr)
3329 value_str = val_cstr;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003330 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003331 err_cstr = valobj->GetError().AsCString();
3332 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003333
3334 if (err_cstr)
3335 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003336 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003337 }
3338 else
3339 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003340 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003341 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003342 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003343 if (options.m_omit_summary_depth == 0)
3344 {
3345 if (options.m_summary_sp)
3346 {
3347 valobj->GetSummaryAsCString(entry, summary_str);
3348 sum_cstr = summary_str.c_str();
3349 }
3350 else
3351 sum_cstr = valobj->GetSummaryAsCString();
3352 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003353
Greg Clayton6efba4f2012-01-26 21:08:30 +00003354 // Make sure we have a value and make sure the summary didn't
3355 // specify that the value should not be printed
3356 if (!value_str.empty() && (entry == NULL || entry->DoesPrintValue() || sum_cstr == NULL))
3357 s.Printf(" %s", value_str.c_str());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003358
Enrico Granata9dd75c82011-07-15 23:30:15 +00003359 if (sum_cstr)
Enrico Granata0c489f52012-03-01 04:24:26 +00003360 s.Printf(" %s", sum_cstr);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003361
Enrico Granata0c489f52012-03-01 04:24:26 +00003362 if (options.m_use_objc)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003363 {
Jim Ingham6035b672011-03-31 00:19:25 +00003364 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003365 if (object_desc)
3366 s.Printf(" %s\n", object_desc);
3367 else
Sean Callanan672ad942010-10-23 00:18:49 +00003368 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003369 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003370 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003371 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003372
Enrico Granata0c489f52012-03-01 04:24:26 +00003373 if (curr_depth < options.m_max_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003374 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003375 // We will show children for all concrete types. We won't show
3376 // pointer contents unless a pointer depth has been specified.
3377 // We won't reference contents unless the reference is the
3378 // root object (depth of zero).
3379 bool print_children = true;
3380
3381 // Use a new temporary pointer depth in case we override the
3382 // current pointer depth below...
3383 uint32_t curr_ptr_depth = ptr_depth;
3384
3385 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3386 if (is_ptr || is_ref)
3387 {
3388 // We have a pointer or reference whose value is an address.
3389 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003390 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003391 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003392 print_children = false;
3393
3394 else if (is_ref && curr_depth == 0)
3395 {
3396 // If this is the root object (depth is zero) that we are showing
3397 // and it is a reference, and no pointer depth has been supplied
3398 // print out what it references. Don't do this at deeper depths
3399 // otherwise we can end up with infinite recursion...
3400 curr_ptr_depth = 1;
3401 }
3402
3403 if (curr_ptr_depth == 0)
3404 print_children = false;
3405 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003406
Enrico Granata0a3958e2011-07-02 00:25:22 +00003407 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003408 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003409 ValueObject* synth_valobj;
3410 ValueObjectSP synth_valobj_sp = valobj->GetSyntheticValue (options.m_use_synthetic);
3411 synth_valobj = (synth_valobj_sp ? synth_valobj_sp.get() : valobj);
Enrico Granatac5bc4122012-03-27 02:35:13 +00003412
Enrico Granatac482a192011-08-17 22:13:59 +00003413 uint32_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003414 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003415 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003416 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003417 if (options.m_flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003418 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003419 if (print_valobj)
3420 s.EOL();
3421 }
3422 else
3423 {
3424 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003425 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003426 s.IndentMore();
3427 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003428
Greg Claytoncc4d0142012-02-17 07:49:44 +00003429 uint32_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00003430
Enrico Granata0c489f52012-03-01 04:24:26 +00003431 if (num_children > max_num_children && !options.m_ignore_cap)
Enrico Granata22c55d12011-08-12 02:00:06 +00003432 {
3433 num_children = max_num_children;
3434 print_dotdotdot = true;
3435 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003436
Enrico Granata0c489f52012-03-01 04:24:26 +00003437 ValueObject::DumpValueObjectOptions child_options(options);
3438 child_options.SetFormat().SetSummary().SetRootValueObjectName();
3439 child_options.SetScopeChecked(true)
3440 .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003441 for (uint32_t idx=0; idx<num_children; ++idx)
3442 {
Enrico Granatac482a192011-08-17 22:13:59 +00003443 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003444 if (child_sp.get())
3445 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003446 DumpValueObject_Impl (s,
3447 child_sp.get(),
3448 child_options,
3449 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
3450 curr_depth + 1);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003451 }
3452 }
3453
Enrico Granata0c489f52012-03-01 04:24:26 +00003454 if (!options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003455 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003456 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003457 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003458 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3459 Target *target = exe_ctx.GetTargetPtr();
3460 if (target)
3461 target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003462 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003463 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003464 s.IndentLess();
3465 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003466 }
3467 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003468 else if (has_children)
3469 {
3470 // Aggregate, no children...
3471 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003472 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003473 }
3474 else
3475 {
3476 if (print_valobj)
3477 s.EOL();
3478 }
3479
Greg Clayton1d3afba2010-10-05 00:00:42 +00003480 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003481 else
3482 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003483 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003484 }
3485 }
3486 else
3487 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003488 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003489 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003490 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003491 }
3492 }
3493 }
3494 }
3495}
3496
Enrico Granata0c489f52012-03-01 04:24:26 +00003497void
Greg Claytonf830dbb2012-03-22 18:15:37 +00003498ValueObject::LogValueObject (Log *log,
3499 ValueObject *valobj)
3500{
3501 if (log && valobj)
3502 return LogValueObject (log, valobj, DumpValueObjectOptions::DefaultOptions());
3503}
3504
3505void
3506ValueObject::LogValueObject (Log *log,
3507 ValueObject *valobj,
3508 const DumpValueObjectOptions& options)
3509{
3510 if (log && valobj)
3511 {
3512 StreamString s;
3513 ValueObject::DumpValueObject (s, valobj, options);
3514 if (s.GetSize())
3515 log->PutCString(s.GetData());
3516 }
3517}
3518
3519void
Enrico Granata0c489f52012-03-01 04:24:26 +00003520ValueObject::DumpValueObject (Stream &s,
3521 ValueObject *valobj)
3522{
3523
3524 if (!valobj)
3525 return;
3526
3527 DumpValueObject_Impl(s,
3528 valobj,
3529 DumpValueObjectOptions::DefaultOptions(),
3530 0,
3531 0);
3532}
3533
3534void
3535ValueObject::DumpValueObject (Stream &s,
3536 ValueObject *valobj,
3537 const DumpValueObjectOptions& options)
3538{
3539 DumpValueObject_Impl(s,
3540 valobj,
3541 options,
3542 options.m_max_ptr_depth, // max pointer depth allowed, we will go down from here
3543 0 // current object depth is 0 since we are just starting
3544 );
3545}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003546
3547ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003548ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003549{
3550 ValueObjectSP valobj_sp;
3551
Enrico Granatac3e320a2011-08-02 17:27:39 +00003552 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003553 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003554 ExecutionContext exe_ctx (GetExecutionContextRef());
3555 clang::ASTContext *ast = GetClangAST ();
3556
3557 DataExtractor data;
3558 data.SetByteOrder (m_data.GetByteOrder());
3559 data.SetAddressByteSize(m_data.GetAddressByteSize());
3560
Enrico Granata9f1e2042012-04-24 22:15:37 +00003561 if (IsBitfield())
3562 {
3563 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
3564 m_error = v.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
3565 }
3566 else
3567 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003568
3569 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3570 ast,
3571 GetClangType(),
3572 name,
3573 data,
3574 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003575 }
Jim Ingham6035b672011-03-31 00:19:25 +00003576
3577 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003578 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003579 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003580 }
3581 return valobj_sp;
3582}
3583
Greg Claytonafacd142011-09-02 01:15:17 +00003584ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003585ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003586{
Jim Ingham58b59f92011-04-22 23:53:53 +00003587 if (m_deref_valobj)
3588 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003589
Greg Clayton54979cd2010-12-15 05:08:08 +00003590 const bool is_pointer_type = IsPointerType();
3591 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003592 {
3593 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003594 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003595
3596 std::string child_name_str;
3597 uint32_t child_byte_size = 0;
3598 int32_t child_byte_offset = 0;
3599 uint32_t child_bitfield_bit_size = 0;
3600 uint32_t child_bitfield_bit_offset = 0;
3601 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003602 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003603 const bool transparent_pointers = false;
3604 clang::ASTContext *clang_ast = GetClangAST();
3605 clang_type_t clang_type = GetClangType();
3606 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003607
Greg Claytoncc4d0142012-02-17 07:49:44 +00003608 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003609
3610 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3611 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003612 GetName().GetCString(),
3613 clang_type,
3614 0,
3615 transparent_pointers,
3616 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003617 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003618 child_name_str,
3619 child_byte_size,
3620 child_byte_offset,
3621 child_bitfield_bit_size,
3622 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003623 child_is_base_class,
3624 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003625 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003626 {
3627 ConstString child_name;
3628 if (!child_name_str.empty())
3629 child_name.SetCString (child_name_str.c_str());
3630
Jim Ingham58b59f92011-04-22 23:53:53 +00003631 m_deref_valobj = new ValueObjectChild (*this,
3632 clang_ast,
3633 child_clang_type,
3634 child_name,
3635 child_byte_size,
3636 child_byte_offset,
3637 child_bitfield_bit_size,
3638 child_bitfield_bit_offset,
3639 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003640 child_is_deref_of_parent,
3641 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003642 }
3643 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003644
Jim Ingham58b59f92011-04-22 23:53:53 +00003645 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003646 {
3647 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003648 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003649 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003650 else
3651 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003652 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003653 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003654
3655 if (is_pointer_type)
3656 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3657 else
3658 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003659 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003660 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003661}
3662
Greg Claytonafacd142011-09-02 01:15:17 +00003663ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003664ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003665{
Jim Ingham78a685a2011-04-16 00:01:13 +00003666 if (m_addr_of_valobj_sp)
3667 return m_addr_of_valobj_sp;
3668
Greg Claytone0d378b2011-03-24 21:19:54 +00003669 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003670 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003671 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003672 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003673 if (addr != LLDB_INVALID_ADDRESS)
3674 {
3675 switch (address_type)
3676 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003677 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003678 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003679 {
3680 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003681 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003682 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3683 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003684 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003685
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003686 case eAddressTypeFile:
3687 case eAddressTypeLoad:
3688 case eAddressTypeHost:
3689 {
3690 clang::ASTContext *ast = GetClangAST();
3691 clang_type_t clang_type = GetClangType();
3692 if (ast && clang_type)
3693 {
3694 std::string name (1, '&');
3695 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003696 ExecutionContext exe_ctx (GetExecutionContextRef());
3697 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003698 ast,
3699 ClangASTContext::CreatePointerType (ast, clang_type),
3700 ConstString (name.c_str()),
3701 addr,
3702 eAddressTypeInvalid,
3703 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003704 }
3705 }
3706 break;
3707 }
3708 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003709 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003710}
3711
Greg Clayton9a142cf2012-02-03 05:34:10 +00003712ValueObjectSP
3713ValueObject::Cast (const ClangASTType &clang_ast_type)
3714{
Greg Clayton81e871e2012-02-04 02:27:34 +00003715 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003716}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003717
Greg Claytonafacd142011-09-02 01:15:17 +00003718ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003719ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3720{
Greg Claytonafacd142011-09-02 01:15:17 +00003721 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003722 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003723 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003724
3725 if (ptr_value != LLDB_INVALID_ADDRESS)
3726 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003727 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003728 ExecutionContext exe_ctx (GetExecutionContextRef());
3729 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003730 name,
3731 ptr_addr,
3732 clang_ast_type);
3733 }
3734 return valobj_sp;
3735}
3736
Greg Claytonafacd142011-09-02 01:15:17 +00003737ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003738ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3739{
Greg Claytonafacd142011-09-02 01:15:17 +00003740 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003741 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003742 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003743
3744 if (ptr_value != LLDB_INVALID_ADDRESS)
3745 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003746 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003747 ExecutionContext exe_ctx (GetExecutionContextRef());
3748 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003749 name,
3750 ptr_addr,
3751 type_sp);
3752 }
3753 return valobj_sp;
3754}
3755
Jim Ingham6035b672011-03-31 00:19:25 +00003756ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003757 m_mod_id(),
3758 m_exe_ctx_ref(),
3759 m_needs_update (true),
3760 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003761{
3762}
3763
3764ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003765 m_mod_id(),
3766 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003767 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003768 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003769{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003770 ExecutionContext exe_ctx(exe_scope);
3771 TargetSP target_sp (exe_ctx.GetTargetSP());
3772 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003773 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003774 m_exe_ctx_ref.SetTargetSP (target_sp);
3775 ProcessSP process_sp (exe_ctx.GetProcessSP());
3776 if (!process_sp)
3777 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003778
Greg Claytoncc4d0142012-02-17 07:49:44 +00003779 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003780 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003781 m_mod_id = process_sp->GetModID();
3782 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003783
Greg Claytoncc4d0142012-02-17 07:49:44 +00003784 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003785
Greg Claytoncc4d0142012-02-17 07:49:44 +00003786 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003787 {
3788 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003789 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003790 }
Jim Ingham6035b672011-03-31 00:19:25 +00003791
Greg Claytoncc4d0142012-02-17 07:49:44 +00003792 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003793 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003794 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003795
Greg Claytoncc4d0142012-02-17 07:49:44 +00003796 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3797 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003798 {
3799 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003800 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003801 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003802 if (frame_sp)
3803 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003804 }
3805 }
3806 }
Jim Ingham6035b672011-03-31 00:19:25 +00003807}
3808
3809ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003810 m_mod_id(),
3811 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3812 m_needs_update (true),
3813 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003814{
3815}
3816
3817ValueObject::EvaluationPoint::~EvaluationPoint ()
3818{
3819}
3820
Jim Ingham6035b672011-03-31 00:19:25 +00003821// This function checks the EvaluationPoint against the current process state. If the current
3822// state matches the evaluation point, or the evaluation point is already invalid, then we return
3823// false, meaning "no change". If the current state is different, we update our state, and return
3824// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3825// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003826// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003827
3828bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003829ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003830{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003831
3832 // 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 +00003833 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00003834
Greg Claytoncc4d0142012-02-17 07:49:44 +00003835 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003836 return false;
3837
Jim Ingham6035b672011-03-31 00:19:25 +00003838 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003839 Process *process = exe_ctx.GetProcessPtr();
3840 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003841 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003842
Jim Ingham6035b672011-03-31 00:19:25 +00003843 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003844 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003845
Jim Ingham78a685a2011-04-16 00:01:13 +00003846 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3847 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003848 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003849 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003850
Greg Clayton23f59502012-07-17 03:23:13 +00003851 bool changed = false;
3852 const bool was_valid = m_mod_id.IsValid();
3853 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003854 {
3855 if (m_mod_id == current_mod_id)
3856 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003857 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003858 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003859 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003860 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003861 else
3862 {
3863 m_mod_id = current_mod_id;
3864 m_needs_update = true;
3865 changed = true;
3866 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003867 }
Jim Ingham6035b672011-03-31 00:19:25 +00003868
Jim Ingham73ca05a2011-12-17 01:35:57 +00003869 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3870 // That way we'll be sure to return a valid exe_scope.
3871 // 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 +00003872
Greg Claytoncc4d0142012-02-17 07:49:44 +00003873 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003874 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003875 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3876 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003877 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003878 if (m_exe_ctx_ref.HasFrameRef())
3879 {
3880 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3881 if (!frame_sp)
3882 {
3883 // We used to have a frame, but now it is gone
3884 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003885 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00003886 }
3887 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003888 }
Jim Ingham6035b672011-03-31 00:19:25 +00003889 else
3890 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003891 // We used to have a thread, but now it is gone
3892 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003893 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00003894 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003895
Jim Ingham6035b672011-03-31 00:19:25 +00003896 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003897 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003898}
3899
Jim Ingham61be0902011-05-02 18:13:59 +00003900void
3901ValueObject::EvaluationPoint::SetUpdated ()
3902{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003903 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3904 if (process_sp)
3905 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003906 m_first_update = false;
3907 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003908}
3909
3910
Greg Claytoncc4d0142012-02-17 07:49:44 +00003911//bool
3912//ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3913//{
3914// if (!IsValid())
3915// return false;
3916//
3917// bool needs_update = false;
3918//
3919// // The target has to be non-null, and the
3920// Target *target = exe_scope->CalculateTarget();
3921// if (target != NULL)
3922// {
3923// Target *old_target = m_target_sp.get();
3924// assert (target == old_target);
3925// Process *process = exe_scope->CalculateProcess();
3926// if (process != NULL)
3927// {
3928// // FOR NOW - assume you can't update variable objects across process boundaries.
3929// Process *old_process = m_process_sp.get();
3930// assert (process == old_process);
3931// ProcessModID current_mod_id = process->GetModID();
3932// if (m_mod_id != current_mod_id)
3933// {
3934// needs_update = true;
3935// m_mod_id = current_mod_id;
3936// }
3937// // See if we're switching the thread or stack context. If no thread is given, this is
3938// // being evaluated in a global context.
3939// Thread *thread = exe_scope->CalculateThread();
3940// if (thread != NULL)
3941// {
3942// user_id_t new_thread_index = thread->GetIndexID();
3943// if (new_thread_index != m_thread_id)
3944// {
3945// needs_update = true;
3946// m_thread_id = new_thread_index;
3947// m_stack_id.Clear();
3948// }
3949//
3950// StackFrame *new_frame = exe_scope->CalculateStackFrame();
3951// if (new_frame != NULL)
3952// {
3953// if (new_frame->GetStackID() != m_stack_id)
3954// {
3955// needs_update = true;
3956// m_stack_id = new_frame->GetStackID();
3957// }
3958// }
3959// else
3960// {
3961// m_stack_id.Clear();
3962// needs_update = true;
3963// }
3964// }
3965// else
3966// {
3967// // If this had been given a thread, and now there is none, we should update.
3968// // Otherwise we don't have to do anything.
3969// if (m_thread_id != LLDB_INVALID_UID)
3970// {
3971// m_thread_id = LLDB_INVALID_UID;
3972// m_stack_id.Clear();
3973// needs_update = true;
3974// }
3975// }
3976// }
3977// else
3978// {
3979// // If there is no process, then we don't need to update anything.
3980// // But if we're switching from having a process to not, we should try to update.
3981// if (m_process_sp.get() != NULL)
3982// {
3983// needs_update = true;
3984// m_process_sp.reset();
3985// m_thread_id = LLDB_INVALID_UID;
3986// m_stack_id.Clear();
3987// }
3988// }
3989// }
3990// else
3991// {
3992// // If there's no target, nothing can change so we don't need to update anything.
3993// // But if we're switching from having a target to not, we should try to update.
3994// if (m_target_sp.get() != NULL)
3995// {
3996// needs_update = true;
3997// m_target_sp.reset();
3998// m_process_sp.reset();
3999// m_thread_id = LLDB_INVALID_UID;
4000// m_stack_id.Clear();
4001// }
4002// }
4003// if (!m_needs_update)
4004// m_needs_update = needs_update;
4005//
4006// return needs_update;
4007//}
Enrico Granataf2bbf712011-07-15 02:26:42 +00004008
4009void
Enrico Granata86cc9822012-03-19 22:58:49 +00004010ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004011{
Enrico Granata86cc9822012-03-19 22:58:49 +00004012 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4013 m_value_str.clear();
4014
4015 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4016 m_location_str.clear();
4017
4018 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
4019 {
Enrico Granata86cc9822012-03-19 22:58:49 +00004020 m_summary_str.clear();
4021 }
4022
4023 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4024 m_object_desc_str.clear();
4025
4026 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4027 {
4028 if (m_synthetic_value)
4029 m_synthetic_value = NULL;
4030 }
Johnny Chen44805302011-07-19 19:48:13 +00004031}
Enrico Granata9128ee22011-09-06 19:20:51 +00004032
4033SymbolContextScope *
4034ValueObject::GetSymbolContextScope()
4035{
4036 if (m_parent)
4037 {
4038 if (!m_parent->IsPointerOrReferenceType())
4039 return m_parent->GetSymbolContextScope();
4040 }
4041 return NULL;
4042}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004043
4044lldb::ValueObjectSP
4045ValueObject::CreateValueObjectFromExpression (const char* name,
4046 const char* expression,
4047 const ExecutionContext& exe_ctx)
4048{
4049 lldb::ValueObjectSP retval_sp;
4050 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4051 if (!target_sp)
4052 return retval_sp;
4053 if (!expression || !*expression)
4054 return retval_sp;
4055 target_sp->EvaluateExpression (expression,
4056 exe_ctx.GetFrameSP().get(),
4057 retval_sp);
4058 if (retval_sp && name && *name)
4059 retval_sp->SetName(ConstString(name));
4060 return retval_sp;
4061}
4062
4063lldb::ValueObjectSP
4064ValueObject::CreateValueObjectFromAddress (const char* name,
4065 uint64_t address,
4066 const ExecutionContext& exe_ctx,
4067 ClangASTType type)
4068{
4069 ClangASTType pointer_type(type.GetASTContext(),type.GetPointerType());
4070 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4071 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4072 pointer_type.GetASTContext(),
4073 pointer_type.GetOpaqueQualType(),
4074 ConstString(name),
4075 buffer,
4076 lldb::endian::InlHostByteOrder(),
4077 exe_ctx.GetAddressByteSize()));
4078 if (ptr_result_valobj_sp)
4079 {
4080 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4081 Error err;
4082 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4083 if (ptr_result_valobj_sp && name && *name)
4084 ptr_result_valobj_sp->SetName(ConstString(name));
4085 }
4086 return ptr_result_valobj_sp;
4087}
4088
4089lldb::ValueObjectSP
4090ValueObject::CreateValueObjectFromData (const char* name,
4091 DataExtractor& data,
4092 const ExecutionContext& exe_ctx,
4093 ClangASTType type)
4094{
4095 lldb::ValueObjectSP new_value_sp;
4096 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4097 type.GetASTContext() ,
4098 type.GetOpaqueQualType(),
4099 ConstString(name),
4100 data,
4101 LLDB_INVALID_ADDRESS);
4102 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4103 if (new_value_sp && name && *name)
4104 new_value_sp->SetName(ConstString(name));
4105 return new_value_sp;
4106}