blob: b9a0a13b90484554e6bce2f4972b240ceb52684a [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- ValueObject.cpp -----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "lldb/Core/ValueObject.h"
13
14// C Includes
Greg Claytonf5e56de2010-09-14 23:36:40 +000015#include <stdlib.h>
16
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017// C++ Includes
18// Other libraries and framework includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "llvm/Support/raw_ostream.h"
Jim Ingham5a369122010-09-28 01:25:32 +000020#include "clang/AST/Type.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021
22// Project includes
23#include "lldb/Core/DataBufferHeap.h"
Enrico Granata4becb372011-06-29 22:27:15 +000024#include "lldb/Core/Debugger.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000025#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000026#include "lldb/Core/Module.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Core/StreamString.h"
Enrico Granata21fd13f2012-10-27 02:05:48 +000028#include "lldb/Core/ValueObjectCast.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Core/ValueObjectChild.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000030#include "lldb/Core/ValueObjectConstResult.h"
Jim Ingham78a685a2011-04-16 00:01:13 +000031#include "lldb/Core/ValueObjectDynamicValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032#include "lldb/Core/ValueObjectList.h"
Greg Claytonb2dcc362011-05-05 23:32:56 +000033#include "lldb/Core/ValueObjectMemory.h"
Enrico Granatad55546b2011-07-22 00:16:08 +000034#include "lldb/Core/ValueObjectSyntheticFilter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035
Enrico Granata5548cb52013-01-28 23:47:25 +000036#include "lldb/DataFormatters/DataVisualization.h"
37
Greg Clayton7fb56d02011-02-01 01:31:41 +000038#include "lldb/Host/Endian.h"
39
Enrico Granata61a80ba2011-08-12 16:42:31 +000040#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granataf2bbf712011-07-15 02:26:42 +000041#include "lldb/Interpreter/ScriptInterpreterPython.h"
42
Greg Claytone1a916a2010-07-21 22:12:05 +000043#include "lldb/Symbol/ClangASTType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000044#include "lldb/Symbol/ClangASTContext.h"
45#include "lldb/Symbol/Type.h"
46
Jim Ingham53c47f12010-09-10 23:12:17 +000047#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000048#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000049#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000050#include "lldb/Target/Process.h"
51#include "lldb/Target/RegisterContext.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000052#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054
Enrico Granataf4efecd2011-07-12 22:56:10 +000055#include "lldb/Utility/RefCounter.h"
56
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057using namespace lldb;
58using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000059using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060
Greg Claytonafacd142011-09-02 01:15:17 +000061static user_id_t g_value_obj_uid = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062
63//----------------------------------------------------------------------
64// ValueObject constructor
65//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000066ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000067 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000068 m_parent (&parent),
Stephen Wilson71c21d12011-04-11 19:41:40 +000069 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000070 m_name (),
71 m_data (),
72 m_value (),
73 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000074 m_value_str (),
75 m_old_value_str (),
76 m_location_str (),
77 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000078 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +000079 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000080 m_children (),
81 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000082 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000083 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000084 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000085 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000086 m_last_format_mgr_revision(0),
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),
Enrico Granata0c489f52012-03-01 04:24:26 +0000132 m_type_summary_sp(),
133 m_type_format_sp(),
134 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000135 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000136 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Jim Ingham6035b672011-03-31 00:19:25 +0000137 m_value_is_valid (false),
138 m_value_did_change (false),
139 m_children_count_valid (false),
140 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000141 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000142 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000143 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +0000144 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000145 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000146 m_is_getting_summary(false),
147 m_did_calculate_complete_objc_class_type(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000148{
Jim Ingham58b59f92011-04-22 23:53:53 +0000149 m_manager = new ValueObjectManager();
150 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000151}
152
153//----------------------------------------------------------------------
154// Destructor
155//----------------------------------------------------------------------
156ValueObject::~ValueObject ()
157{
158}
159
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000160bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000161ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000162{
Enrico Granata4becb372011-06-29 22:27:15 +0000163
Enrico Granata9128ee22011-09-06 19:20:51 +0000164 bool did_change_formats = false;
165
Enrico Granata0a3958e2011-07-02 00:25:22 +0000166 if (update_format)
Enrico Granata5548cb52013-01-28 23:47:25 +0000167 did_change_formats = UpdateFormatsIfNeeded();
Enrico Granata4becb372011-06-29 22:27:15 +0000168
Greg Claytonb71f3842010-10-05 03:13:51 +0000169 // If this is a constant value, then our success is predicated on whether
170 // we have an error or not
171 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000172 {
173 // if you were asked to update your formatters, but did not get a chance to do it
174 // clear your own values (this serves the purpose of faking a stop-id for frozen
175 // objects (which are regarded as constant, but could have changes behind their backs
176 // because of the frozen-pointer depth limit)
177 // TODO: decouple summary from value and then remove this code and only force-clear the summary
178 if (update_format && !did_change_formats)
Enrico Granata86cc9822012-03-19 22:58:49 +0000179 ClearUserVisibleData(eClearUserVisibleDataItemsSummary);
Greg Claytonb71f3842010-10-05 03:13:51 +0000180 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000181 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000182
Jim Ingham6035b672011-03-31 00:19:25 +0000183 bool first_update = m_update_point.IsFirstEvaluation();
184
185 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000186 {
Jim Ingham6035b672011-03-31 00:19:25 +0000187 m_update_point.SetUpdated();
188
189 // Save the old value using swap to avoid a string copy which
190 // also will clear our m_value_str
191 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000192 {
Jim Ingham6035b672011-03-31 00:19:25 +0000193 m_old_value_valid = false;
194 }
195 else
196 {
197 m_old_value_valid = true;
198 m_old_value_str.swap (m_value_str);
Enrico Granata86cc9822012-03-19 22:58:49 +0000199 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham6035b672011-03-31 00:19:25 +0000200 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000201
Enrico Granataf2bbf712011-07-15 02:26:42 +0000202 ClearUserVisibleData();
203
Greg Claytonefbc7d22012-03-09 04:23:44 +0000204 if (IsInScope())
Jim Ingham6035b672011-03-31 00:19:25 +0000205 {
Greg Claytonefbc7d22012-03-09 04:23:44 +0000206 const bool value_was_valid = GetValueIsValid();
207 SetValueDidChange (false);
208
209 m_error.Clear();
210
211 // Call the pure virtual function to update the value
212 bool success = UpdateValue ();
213
214 SetValueIsValid (success);
215
216 if (first_update)
217 SetValueDidChange (false);
218 else if (!m_value_did_change && success == false)
219 {
220 // The value wasn't gotten successfully, so we mark this
221 // as changed if the value used to be valid and now isn't
222 SetValueDidChange (value_was_valid);
223 }
224 }
225 else
226 {
227 m_error.SetErrorString("out of scope");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000228 }
229 }
230 return m_error.Success();
231}
232
Enrico Granata9128ee22011-09-06 19:20:51 +0000233bool
Enrico Granata5548cb52013-01-28 23:47:25 +0000234ValueObject::UpdateFormatsIfNeeded()
Enrico Granata4becb372011-06-29 22:27:15 +0000235{
Enrico Granata6f3533f2011-07-29 19:53:35 +0000236 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
237 if (log)
Enrico Granatad2284832012-10-17 22:23:56 +0000238 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
Enrico Granata6f3533f2011-07-29 19:53:35 +0000239 GetName().GetCString(),
Enrico Granatad2284832012-10-17 22:23:56 +0000240 this,
Enrico Granata4becb372011-06-29 22:27:15 +0000241 m_last_format_mgr_revision,
Enrico Granata85933ed2011-08-18 16:38:26 +0000242 DataVisualization::GetCurrentRevision());
Enrico Granata9128ee22011-09-06 19:20:51 +0000243
244 bool any_change = false;
245
Enrico Granata5548cb52013-01-28 23:47:25 +0000246 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()))
Enrico Granata4becb372011-06-29 22:27:15 +0000247 {
Enrico Granata78d06382011-09-09 23:33:14 +0000248 SetValueFormat(DataVisualization::ValueFormats::GetFormat (*this, eNoDynamicValues));
Enrico Granata5548cb52013-01-28 23:47:25 +0000249 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000250#ifndef LLDB_DISABLE_PYTHON
Enrico Granata5548cb52013-01-28 23:47:25 +0000251 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000252#endif
Enrico Granata1490c6f2011-07-19 02:34:21 +0000253
Enrico Granata85933ed2011-08-18 16:38:26 +0000254 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
Enrico Granata855cd902011-09-06 22:59:55 +0000255
256 any_change = true;
Enrico Granata4becb372011-06-29 22:27:15 +0000257 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000258
259 return any_change;
260
Enrico Granata4becb372011-06-29 22:27:15 +0000261}
262
Jim Ingham16e0c682011-08-12 23:34:31 +0000263void
264ValueObject::SetNeedsUpdate ()
265{
266 m_update_point.SetNeedsUpdate();
267 // We have to clear the value string here so ConstResult children will notice if their values are
268 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000269 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000270}
271
Enrico Granata13ac0e22012-10-17 19:03:34 +0000272void
Enrico Granatae3e91512012-10-22 18:18:36 +0000273ValueObject::ClearDynamicTypeInformation ()
Enrico Granata13ac0e22012-10-17 19:03:34 +0000274{
275 m_did_calculate_complete_objc_class_type = false;
Enrico Granatae3e91512012-10-22 18:18:36 +0000276 m_last_format_mgr_revision = 0;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000277 m_override_type = ClangASTType();
Enrico Granatae3e91512012-10-22 18:18:36 +0000278 SetValueFormat(lldb::TypeFormatImplSP());
279 SetSummaryFormat(lldb::TypeSummaryImplSP());
280 SetSyntheticChildren(lldb::SyntheticChildrenSP());
Enrico Granata13ac0e22012-10-17 19:03:34 +0000281}
282
Sean Callanan72772842012-02-22 23:57:45 +0000283ClangASTType
284ValueObject::MaybeCalculateCompleteType ()
285{
286 ClangASTType ret(GetClangASTImpl(), GetClangTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000287
Sean Callanan72772842012-02-22 23:57:45 +0000288 if (m_did_calculate_complete_objc_class_type)
289 {
290 if (m_override_type.IsValid())
291 return m_override_type;
292 else
293 return ret;
294 }
295
296 clang_type_t ast_type(GetClangTypeImpl());
297 clang_type_t class_type;
298 bool is_pointer_type;
299
300 if (ClangASTContext::IsObjCObjectPointerType(ast_type, &class_type))
301 {
302 is_pointer_type = true;
303 }
304 else if (ClangASTContext::IsObjCClassType(ast_type))
305 {
306 is_pointer_type = false;
307 class_type = ast_type;
308 }
309 else
310 {
311 return ret;
312 }
313
314 m_did_calculate_complete_objc_class_type = true;
315
316 if (!class_type)
317 return ret;
318
319 std::string class_name;
320
321 if (!ClangASTContext::GetObjCClassName(class_type, class_name))
322 return ret;
323
324 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
325
326 if (!process_sp)
327 return ret;
328
329 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
330
331 if (!objc_language_runtime)
332 return ret;
333
334 ConstString class_name_cs(class_name.c_str());
335
336 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name_cs);
337
338 if (!complete_objc_class_type_sp)
339 return ret;
340
341 ClangASTType complete_class(complete_objc_class_type_sp->GetClangAST(),
342 complete_objc_class_type_sp->GetClangFullType());
343
344 if (!ClangASTContext::GetCompleteType(complete_class.GetASTContext(),
345 complete_class.GetOpaqueQualType()))
346 return ret;
347
348 if (is_pointer_type)
349 {
350 clang_type_t pointer_type = ClangASTContext::CreatePointerType(complete_class.GetASTContext(),
351 complete_class.GetOpaqueQualType());
352
353 m_override_type = ClangASTType(complete_class.GetASTContext(),
354 pointer_type);
355 }
356 else
357 {
358 m_override_type = complete_class;
359 }
360
Sean Callanan356e17c2012-03-30 02:04:38 +0000361 if (m_override_type.IsValid())
362 return m_override_type;
363 else
364 return ret;
Sean Callanan72772842012-02-22 23:57:45 +0000365}
366
367clang::ASTContext *
368ValueObject::GetClangAST ()
369{
370 ClangASTType type = MaybeCalculateCompleteType();
371
372 return type.GetASTContext();
373}
374
375lldb::clang_type_t
376ValueObject::GetClangType ()
377{
378 ClangASTType type = MaybeCalculateCompleteType();
379
380 return type.GetOpaqueQualType();
381}
382
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000383DataExtractor &
384ValueObject::GetDataExtractor ()
385{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000386 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000387 return m_data;
388}
389
390const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000391ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000392{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000393 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000394 return m_error;
395}
396
397const ConstString &
398ValueObject::GetName() const
399{
400 return m_name;
401}
402
403const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000404ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000405{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000406 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000407 {
408 if (m_location_str.empty())
409 {
410 StreamString sstr;
411
412 switch (m_value.GetValueType())
413 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000414 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +0000415 case Value::eValueTypeVector:
Greg Clayton526e5af2010-11-13 03:52:47 +0000416 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000417 {
418 RegisterInfo *reg_info = m_value.GetRegisterInfo();
419 if (reg_info)
420 {
421 if (reg_info->name)
422 m_location_str = reg_info->name;
423 else if (reg_info->alt_name)
424 m_location_str = reg_info->alt_name;
Greg Clayton0665a0f2012-10-30 18:18:43 +0000425
426 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000427 }
428 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000429 break;
430
431 case Value::eValueTypeLoadAddress:
432 case Value::eValueTypeFileAddress:
433 case Value::eValueTypeHostAddress:
434 {
435 uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2;
436 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
437 m_location_str.swap(sstr.GetString());
438 }
439 break;
440 }
441 }
442 }
443 return m_location_str.c_str();
444}
445
446Value &
447ValueObject::GetValue()
448{
449 return m_value;
450}
451
452const Value &
453ValueObject::GetValue() const
454{
455 return m_value;
456}
457
458bool
Jim Ingham6035b672011-03-31 00:19:25 +0000459ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000460{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000461 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
462 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000463 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000464 Value tmp_value(m_value);
465 scalar = tmp_value.ResolveValue(&exe_ctx, GetClangAST ());
Greg Claytondcad5022011-12-29 01:26:56 +0000466 if (scalar.IsValid())
467 {
468 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
469 if (bitfield_bit_size)
470 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
471 return true;
472 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000473 }
Greg Claytondcad5022011-12-29 01:26:56 +0000474 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000475}
476
477bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000478ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000479{
Greg Clayton288bdf92010-09-02 02:59:18 +0000480 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000481}
482
483
484void
485ValueObject::SetValueIsValid (bool b)
486{
Greg Clayton288bdf92010-09-02 02:59:18 +0000487 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000488}
489
490bool
Jim Ingham6035b672011-03-31 00:19:25 +0000491ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000492{
Jim Ingham6035b672011-03-31 00:19:25 +0000493 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000494 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000495}
496
497void
498ValueObject::SetValueDidChange (bool value_changed)
499{
Greg Clayton288bdf92010-09-02 02:59:18 +0000500 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000501}
502
503ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000504ValueObject::GetChildAtIndex (size_t idx, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000505{
506 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000507 // We may need to update our value if we are dynamic
508 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000509 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000510 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000511 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000512 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000513 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000514 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000515 // No we haven't created the child at this index, so lets have our
516 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000517 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000518 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000519
Enrico Granata9d60f602012-03-09 03:09:58 +0000520 ValueObject* child = m_children.GetChildAtIndex(idx);
521 if (child != NULL)
522 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000523 }
524 return child_sp;
525}
526
Enrico Granata3309d882013-01-12 01:00:22 +0000527ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000528ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
529 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000530{
531 if (idxs.size() == 0)
532 return GetSP();
533 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000534 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000535 {
536 root = root->GetChildAtIndex(idx, true);
537 if (!root)
538 {
539 if (index_of_error)
540 *index_of_error = idx;
541 return root;
542 }
543 }
544 return root;
545}
546
547ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000548ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
549 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000550{
551 if (idxs.size() == 0)
552 return GetSP();
553 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000554 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000555 {
556 root = root->GetChildAtIndex(idx.first, idx.second);
557 if (!root)
558 {
559 if (index_of_error)
560 *index_of_error = idx.first;
561 return root;
562 }
563 }
564 return root;
565}
566
567lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000568ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
569 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000570{
571 if (idxs.size() == 0)
572 return GetSP();
573 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000574 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000575 {
576 root = root->GetChildAtIndex(idx, true);
577 if (!root)
578 {
579 if (index_of_error)
580 *index_of_error = idx;
581 return root;
582 }
583 }
584 return root;
585}
586
587lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000588ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
589 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000590{
591 if (idxs.size() == 0)
592 return GetSP();
593 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000594 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000595 {
596 root = root->GetChildAtIndex(idx.first, idx.second);
597 if (!root)
598 {
599 if (index_of_error)
600 *index_of_error = idx.first;
601 return root;
602 }
603 }
604 return root;
605}
606
Greg Claytonc7bece562013-01-25 18:06:21 +0000607size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000608ValueObject::GetIndexOfChildWithName (const ConstString &name)
609{
610 bool omit_empty_base_classes = true;
611 return ClangASTContext::GetIndexOfChildWithName (GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +0000612 GetClangType(),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000613 name.GetCString(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000614 omit_empty_base_classes);
615}
616
617ValueObjectSP
618ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
619{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000620 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000621 // classes (which really aren't part of the expression path), so we
622 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000623 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000624
Greg Claytondea8cb42011-06-29 22:09:02 +0000625 // We may need to update our value if we are dynamic
626 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000627 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000628
629 std::vector<uint32_t> child_indexes;
630 clang::ASTContext *clang_ast = GetClangAST();
631 void *clang_type = GetClangType();
632 bool omit_empty_base_classes = true;
633 const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast,
634 clang_type,
635 name.GetCString(),
636 omit_empty_base_classes,
637 child_indexes);
638 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000639 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000640 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
641 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
642
643 child_sp = GetChildAtIndex(*pos, can_create);
644 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000645 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000646 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000647 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000648 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
649 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000650 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000651 else
652 {
653 child_sp.reset();
654 }
655
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000656 }
657 }
658 return child_sp;
659}
660
661
Greg Claytonc7bece562013-01-25 18:06:21 +0000662size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000663ValueObject::GetNumChildren ()
664{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000665 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000666 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000667 {
668 SetNumChildren (CalculateNumChildren());
669 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000670 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000671}
Greg Clayton4a792072012-10-23 01:50:10 +0000672
673bool
674ValueObject::MightHaveChildren()
675{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000676 bool has_children = false;
Greg Clayton4a792072012-10-23 01:50:10 +0000677 clang_type_t clang_type = GetClangType();
678 if (clang_type)
679 {
680 const uint32_t type_info = ClangASTContext::GetTypeInfo (clang_type,
681 GetClangAST(),
682 NULL);
683 if (type_info & (ClangASTContext::eTypeHasChildren |
684 ClangASTContext::eTypeIsPointer |
685 ClangASTContext::eTypeIsReference))
686 has_children = true;
687 }
688 else
689 {
690 has_children = GetNumChildren () > 0;
691 }
692 return has_children;
693}
694
695// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000696void
Greg Claytonc7bece562013-01-25 18:06:21 +0000697ValueObject::SetNumChildren (size_t num_children)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000698{
Greg Clayton288bdf92010-09-02 02:59:18 +0000699 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000700 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000701}
702
703void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000704ValueObject::SetName (const ConstString &name)
705{
706 m_name = name;
707}
708
Jim Ingham58b59f92011-04-22 23:53:53 +0000709ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000710ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000711{
Jim Ingham2eec4872011-05-07 00:10:58 +0000712 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000713
Greg Claytondea8cb42011-06-29 22:09:02 +0000714 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000715 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000716 std::string child_name_str;
717 uint32_t child_byte_size = 0;
718 int32_t child_byte_offset = 0;
719 uint32_t child_bitfield_bit_size = 0;
720 uint32_t child_bitfield_bit_offset = 0;
721 bool child_is_base_class = false;
722 bool child_is_deref_of_parent = false;
723
724 const bool transparent_pointers = synthetic_array_member == false;
725 clang::ASTContext *clang_ast = GetClangAST();
726 clang_type_t clang_type = GetClangType();
727 clang_type_t child_clang_type;
728
Greg Claytoncc4d0142012-02-17 07:49:44 +0000729 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000730
731 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
732 clang_ast,
733 GetName().GetCString(),
734 clang_type,
735 idx,
736 transparent_pointers,
737 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +0000738 ignore_array_bounds,
Greg Claytondea8cb42011-06-29 22:09:02 +0000739 child_name_str,
740 child_byte_size,
741 child_byte_offset,
742 child_bitfield_bit_size,
743 child_bitfield_bit_offset,
744 child_is_base_class,
745 child_is_deref_of_parent);
Greg Clayton4ef877f2012-12-06 02:33:54 +0000746 if (child_clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000747 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000748 if (synthetic_index)
749 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000750
Greg Claytondea8cb42011-06-29 22:09:02 +0000751 ConstString child_name;
752 if (!child_name_str.empty())
753 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000754
Greg Claytondea8cb42011-06-29 22:09:02 +0000755 valobj = new ValueObjectChild (*this,
756 clang_ast,
757 child_clang_type,
758 child_name,
759 child_byte_size,
760 child_byte_offset,
761 child_bitfield_bit_size,
762 child_bitfield_bit_offset,
763 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000764 child_is_deref_of_parent,
765 eAddressTypeInvalid);
766 //if (valobj)
767 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
768 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000769
Jim Ingham58b59f92011-04-22 23:53:53 +0000770 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000771}
772
Enrico Granata0c489f52012-03-01 04:24:26 +0000773bool
774ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
775 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000776{
Enrico Granata0c489f52012-03-01 04:24:26 +0000777 destination.clear();
778
779 // ideally we would like to bail out if passing NULL, but if we do so
780 // we end up not providing the summary for function pointers anymore
781 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
782 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000783
784 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000785
786 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
787 // information that we might care to see in a crash log. might be useful in very specific situations though.
788 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
789 GetTypeName().GetCString(),
790 GetName().GetCString(),
791 summary_ptr->GetDescription().c_str());*/
792
Enrico Granata0c489f52012-03-01 04:24:26 +0000793 if (UpdateValueIfNeeded (false))
794 {
795 if (summary_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000796 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000797 if (HasSyntheticValue())
798 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
799 summary_ptr->FormatObject(this, destination);
Enrico Granata0c489f52012-03-01 04:24:26 +0000800 }
801 else
802 {
803 clang_type_t clang_type = GetClangType();
804
805 // Do some default printout for function pointers
806 if (clang_type)
Enrico Granata4becb372011-06-29 22:27:15 +0000807 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000808 StreamString sstr;
809 clang_type_t elem_or_pointee_clang_type;
810 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
811 GetClangAST(),
812 &elem_or_pointee_clang_type));
813
814 if (ClangASTContext::IsFunctionPointerType (clang_type))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000815 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000816 AddressType func_ptr_address_type = eAddressTypeInvalid;
817 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
818 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000819 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000820 switch (func_ptr_address_type)
Jim Ingham6035b672011-03-31 00:19:25 +0000821 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000822 case eAddressTypeInvalid:
823 case eAddressTypeFile:
824 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000825
Greg Claytoncc4d0142012-02-17 07:49:44 +0000826 case eAddressTypeLoad:
Enrico Granata0c489f52012-03-01 04:24:26 +0000827 {
828 ExecutionContext exe_ctx (GetExecutionContextRef());
829
830 Address so_addr;
831 Target *target = exe_ctx.GetTargetPtr();
832 if (target && target->GetSectionLoadList().IsEmpty() == false)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000833 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000834 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000835 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000836 so_addr.Dump (&sstr,
837 exe_ctx.GetBestExecutionContextScope(),
838 Address::DumpStyleResolvedDescription,
839 Address::DumpStyleSectionNameOffset);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000840 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000841 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000842 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000843 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000844
Greg Claytoncc4d0142012-02-17 07:49:44 +0000845 case eAddressTypeHost:
846 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +0000847 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000848 }
849 if (sstr.GetSize() > 0)
850 {
851 destination.assign (1, '(');
852 destination.append (sstr.GetData(), sstr.GetSize());
853 destination.append (1, ')');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000854 }
855 }
856 }
857 }
858 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000859 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000860 return !destination.empty();
861}
862
863const char *
864ValueObject::GetSummaryAsCString ()
865{
866 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
867 {
868 GetSummaryAsCString(GetSummaryFormat().get(),
869 m_summary_str);
870 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000871 if (m_summary_str.empty())
872 return NULL;
873 return m_summary_str.c_str();
874}
875
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000876bool
877ValueObject::IsCStringContainer(bool check_pointer)
878{
879 clang_type_t elem_or_pointee_clang_type;
880 const Flags type_flags (ClangASTContext::GetTypeInfo (GetClangType(),
881 GetClangAST(),
882 &elem_or_pointee_clang_type));
883 bool is_char_arr_ptr (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
884 ClangASTContext::IsCharType (elem_or_pointee_clang_type));
885 if (!is_char_arr_ptr)
886 return false;
887 if (!check_pointer)
888 return true;
889 if (type_flags.Test(ClangASTContext::eTypeIsArray))
890 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000891 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000892 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000893 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000894 return (cstr_address != LLDB_INVALID_ADDRESS);
895}
896
Enrico Granata9128ee22011-09-06 19:20:51 +0000897size_t
898ValueObject::GetPointeeData (DataExtractor& data,
899 uint32_t item_idx,
900 uint32_t item_count)
901{
902 if (!IsPointerType() && !IsArrayType())
903 return 0;
904
905 if (item_count == 0)
906 return 0;
907
908 uint32_t stride = 0;
909
910 ClangASTType type(GetClangAST(),
911 GetClangType());
912
913 const uint64_t item_type_size = (IsPointerType() ? ClangASTType::GetTypeByteSize(GetClangAST(), type.GetPointeeType()) :
914 ClangASTType::GetTypeByteSize(GetClangAST(), type.GetArrayElementType(stride)));
915
916 const uint64_t bytes = item_count * item_type_size;
917
918 const uint64_t offset = item_idx * item_type_size;
919
920 if (item_idx == 0 && item_count == 1) // simply a deref
921 {
922 if (IsPointerType())
923 {
924 Error error;
925 ValueObjectSP pointee_sp = Dereference(error);
926 if (error.Fail() || pointee_sp.get() == NULL)
927 return 0;
928 return pointee_sp->GetDataExtractor().Copy(data);
929 }
930 else
931 {
932 ValueObjectSP child_sp = GetChildAtIndex(0, true);
933 if (child_sp.get() == NULL)
934 return 0;
935 return child_sp->GetDataExtractor().Copy(data);
936 }
937 return true;
938 }
939 else /* (items > 1) */
940 {
941 Error error;
942 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
943 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
944
945 AddressType addr_type;
946 lldb::addr_t addr = IsPointerType() ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
947
Enrico Granata9128ee22011-09-06 19:20:51 +0000948 switch (addr_type)
949 {
950 case eAddressTypeFile:
951 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000952 ModuleSP module_sp (GetModule());
953 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000954 {
Enrico Granata9c2efe32012-08-07 01:49:34 +0000955 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +0000956 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +0000957 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000958 ExecutionContext exe_ctx (GetExecutionContextRef());
959 Target* target = exe_ctx.GetTargetPtr();
960 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +0000961 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000962 heap_buf_ptr->SetByteSize(bytes);
963 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
964 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +0000965 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000966 data.SetData(data_sp);
967 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +0000968 }
969 }
970 }
971 }
972 break;
973 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +0000974 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000975 ExecutionContext exe_ctx (GetExecutionContextRef());
976 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +0000977 if (process)
978 {
979 heap_buf_ptr->SetByteSize(bytes);
980 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
981 if (error.Success())
982 {
983 data.SetData(data_sp);
984 return bytes_read;
985 }
986 }
987 }
988 break;
989 case eAddressTypeHost:
990 {
991 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes);
992 data.SetData(data_sp);
993 return bytes;
994 }
995 break;
996 case eAddressTypeInvalid:
Enrico Granata9128ee22011-09-06 19:20:51 +0000997 break;
998 }
999 }
1000 return 0;
1001}
1002
1003size_t
1004ValueObject::GetData (DataExtractor& data)
1005{
1006 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001007 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytone72dfb32012-02-24 01:59:29 +00001008 Error error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001009 if (error.Fail())
1010 return 0;
1011 data.SetAddressByteSize(m_data.GetAddressByteSize());
1012 data.SetByteOrder(m_data.GetByteOrder());
1013 return data.GetByteSize();
1014}
1015
1016// will compute strlen(str), but without consuming more than
1017// maxlen bytes out of str (this serves the purpose of reading
1018// chunks of a string without having to worry about
1019// missing NULL terminators in the chunk)
1020// of course, if strlen(str) > maxlen, the function will return
1021// maxlen_value (which should be != maxlen, because that allows you
1022// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1023static uint32_t
1024strlen_or_inf (const char* str,
1025 uint32_t maxlen,
1026 uint32_t maxlen_value)
1027{
1028 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +00001029 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +00001030 {
Greg Clayton8dd5c172011-10-05 22:19:51 +00001031 while(*str)
1032 {
1033 len++;str++;
1034 if (len > maxlen)
1035 return maxlen_value;
1036 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001037 }
1038 return len;
1039}
1040
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001041void
Greg Claytoncc4d0142012-02-17 07:49:44 +00001042ValueObject::ReadPointedString (Stream& s,
1043 Error& error,
1044 uint32_t max_length,
1045 bool honor_array,
1046 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001047{
Greg Claytoncc4d0142012-02-17 07:49:44 +00001048 ExecutionContext exe_ctx (GetExecutionContextRef());
1049 Target* target = exe_ctx.GetTargetPtr();
1050
1051 if (target && max_length == 0)
1052 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001053
1054 clang_type_t clang_type = GetClangType();
1055 clang_type_t elem_or_pointee_clang_type;
1056 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
1057 GetClangAST(),
1058 &elem_or_pointee_clang_type));
1059 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
1060 ClangASTContext::IsCharType (elem_or_pointee_clang_type))
1061 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001062 if (target == NULL)
1063 {
1064 s << "<no target to read from>";
1065 }
1066 else
1067 {
1068 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1069 AddressType cstr_address_type = eAddressTypeInvalid;
1070
1071 size_t cstr_len = 0;
1072 bool capped_data = false;
1073 if (type_flags.Test (ClangASTContext::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001074 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001075 // We have an array
1076 cstr_len = ClangASTContext::GetArraySize (clang_type);
1077 if (cstr_len > max_length)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001078 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001079 capped_data = true;
1080 cstr_len = max_length;
1081 }
1082 cstr_address = GetAddressOf (true, &cstr_address_type);
1083 }
1084 else
1085 {
1086 // We have a pointer
1087 cstr_address = GetPointerValue (&cstr_address_type);
1088 }
1089 if (cstr_address != 0 && cstr_address != LLDB_INVALID_ADDRESS)
1090 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001091 Address cstr_so_addr (cstr_address);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001092 DataExtractor data;
1093 size_t bytes_read = 0;
1094 if (cstr_len > 0 && honor_array)
1095 {
1096 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1097 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1098 GetPointeeData(data, 0, cstr_len);
1099
1100 if ((bytes_read = data.GetByteSize()) > 0)
1101 {
1102 s << '"';
1103 data.Dump (&s,
1104 0, // Start offset in "data"
1105 item_format,
1106 1, // Size of item (1 byte for a char!)
1107 bytes_read, // How many bytes to print?
1108 UINT32_MAX, // num per line
1109 LLDB_INVALID_ADDRESS,// base address
1110 0, // bitfield bit size
1111 0); // bitfield bit offset
1112 if (capped_data)
1113 s << "...";
1114 s << '"';
1115 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00001116 }
1117 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001118 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001119 cstr_len = max_length;
1120 const size_t k_max_buf_size = 64;
1121
1122 size_t offset = 0;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001123
Greg Claytoncc4d0142012-02-17 07:49:44 +00001124 int cstr_len_displayed = -1;
1125 bool capped_cstr = false;
1126 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1127 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1128 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001129 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001130 const char *cstr = data.PeekCStr(0);
1131 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1132 if (len > k_max_buf_size)
1133 len = k_max_buf_size;
1134 if (cstr && cstr_len_displayed < 0)
1135 s << '"';
1136
1137 if (cstr_len_displayed < 0)
1138 cstr_len_displayed = len;
1139
1140 if (len == 0)
1141 break;
1142 cstr_len_displayed += len;
1143 if (len > bytes_read)
1144 len = bytes_read;
1145 if (len > cstr_len)
1146 len = cstr_len;
1147
1148 data.Dump (&s,
1149 0, // Start offset in "data"
1150 item_format,
1151 1, // Size of item (1 byte for a char!)
1152 len, // How many bytes to print?
1153 UINT32_MAX, // num per line
1154 LLDB_INVALID_ADDRESS,// base address
1155 0, // bitfield bit size
1156 0); // bitfield bit offset
1157
1158 if (len < k_max_buf_size)
1159 break;
1160
1161 if (len >= cstr_len)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001162 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001163 capped_cstr = true;
1164 break;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001165 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001166
1167 cstr_len -= len;
1168 offset += len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001169 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001170
1171 if (cstr_len_displayed >= 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001172 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001173 s << '"';
1174 if (capped_cstr)
1175 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001176 }
1177 }
1178 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001179 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001180 }
1181 else
1182 {
1183 error.SetErrorString("impossible to read a string from this object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001184 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001185 }
1186}
1187
Jim Ingham53c47f12010-09-10 23:12:17 +00001188const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001189ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001190{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001191
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001192 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001193 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001194
1195 if (!m_object_desc_str.empty())
1196 return m_object_desc_str.c_str();
1197
Greg Claytoncc4d0142012-02-17 07:49:44 +00001198 ExecutionContext exe_ctx (GetExecutionContextRef());
1199 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001200 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001201 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001202
Jim Ingham53c47f12010-09-10 23:12:17 +00001203 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001204
Greg Claytonafacd142011-09-02 01:15:17 +00001205 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001206 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1207
Jim Inghama2cf2632010-12-23 02:29:54 +00001208 if (runtime == NULL)
1209 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001210 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Jim Inghama2cf2632010-12-23 02:29:54 +00001211 clang_type_t opaque_qual_type = GetClangType();
1212 if (opaque_qual_type != NULL)
1213 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001214 bool is_signed;
1215 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed)
1216 || ClangASTContext::IsPointerType (opaque_qual_type))
1217 {
Greg Claytonafacd142011-09-02 01:15:17 +00001218 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001219 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001220 }
1221 }
1222
Jim Ingham8d543de2011-03-31 23:01:21 +00001223 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001224 {
1225 m_object_desc_str.append (s.GetData());
1226 }
Sean Callanan672ad942010-10-23 00:18:49 +00001227
1228 if (m_object_desc_str.empty())
1229 return NULL;
1230 else
1231 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001232}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001233
Enrico Granata0c489f52012-03-01 04:24:26 +00001234bool
1235ValueObject::GetValueAsCString (lldb::Format format,
1236 std::string& destination)
1237{
1238 if (ClangASTContext::IsAggregateType (GetClangType()) == false &&
1239 UpdateValueIfNeeded(false))
1240 {
1241 const Value::ContextType context_type = m_value.GetContextType();
1242
1243 switch (context_type)
1244 {
1245 case Value::eContextTypeClangType:
1246 case Value::eContextTypeLLDBType:
1247 case Value::eContextTypeVariable:
1248 {
1249 clang_type_t clang_type = GetClangType ();
1250 if (clang_type)
1251 {
1252 StreamString sstr;
1253 ExecutionContext exe_ctx (GetExecutionContextRef());
1254 ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
1255 clang_type, // The clang type to display
1256 &sstr,
1257 format, // Format to display this type with
1258 m_data, // Data to extract from
1259 0, // Byte offset into "m_data"
1260 GetByteSize(), // Byte size of item in "m_data"
1261 GetBitfieldBitSize(), // Bitfield bit size
1262 GetBitfieldBitOffset(), // Bitfield bit offset
1263 exe_ctx.GetBestExecutionContextScope());
1264 // Don't set the m_error to anything here otherwise
1265 // we won't be able to re-format as anything else. The
1266 // code for ClangASTType::DumpTypeValue() should always
1267 // return something, even if that something contains
1268 // an error messsage. "m_error" is used to detect errors
1269 // when reading the valid object, not for formatting errors.
1270 if (sstr.GetString().empty())
1271 destination.clear();
1272 else
1273 destination.swap(sstr.GetString());
1274 }
1275 }
1276 break;
1277
1278 case Value::eContextTypeRegisterInfo:
1279 {
1280 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1281 if (reg_info)
1282 {
1283 ExecutionContext exe_ctx (GetExecutionContextRef());
1284
1285 StreamString reg_sstr;
1286 m_data.Dump (&reg_sstr,
1287 0,
1288 format,
1289 reg_info->byte_size,
1290 1,
1291 UINT32_MAX,
1292 LLDB_INVALID_ADDRESS,
1293 0,
1294 0,
1295 exe_ctx.GetBestExecutionContextScope());
1296 destination.swap(reg_sstr.GetString());
1297 }
1298 }
1299 break;
1300
1301 default:
1302 break;
1303 }
1304 return !destination.empty();
1305 }
1306 else
1307 return false;
1308}
1309
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001310const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001311ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001312{
Enrico Granata0c489f52012-03-01 04:24:26 +00001313 if (UpdateValueIfNeeded(true) && m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001314 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001315 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001316 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001317 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001318 if (m_type_format_sp)
1319 my_format = m_type_format_sp->GetFormat();
1320 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001321 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001322 if (m_is_bitfield_for_scalar)
1323 my_format = eFormatUnsigned;
1324 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001325 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001326 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001327 {
1328 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1329 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001330 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001331 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001332 else
1333 {
1334 clang_type_t clang_type = GetClangType ();
1335 my_format = ClangASTType::GetFormat(clang_type);
1336 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001337 }
1338 }
1339 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001340 if (GetValueAsCString(my_format, m_value_str))
1341 {
1342 if (!m_value_did_change && m_old_value_valid)
1343 {
1344 // The value was gotten successfully, so we consider the
1345 // value as changed if the value string differs
1346 SetValueDidChange (m_old_value_str != m_value_str);
1347 }
1348 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001349 }
1350 if (m_value_str.empty())
1351 return NULL;
1352 return m_value_str.c_str();
1353}
1354
Enrico Granatac3e320a2011-08-02 17:27:39 +00001355// if > 8bytes, 0 is returned. this method should mostly be used
1356// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001357uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001358ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001359{
1360 // If our byte size is zero this is an aggregate type that has children
1361 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
1362 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001363 Scalar scalar;
1364 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001365 {
1366 if (success)
1367 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001368 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001369 }
1370 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001371 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001372
1373 if (success)
1374 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001375 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001376}
1377
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001378// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1379// this call up to date by returning true for your new special cases. We will eventually move
1380// to checking this call result before trying to display special cases
1381bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001382ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1383 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001384{
1385 clang_type_t elem_or_pointee_type;
1386 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
1387
1388 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001389 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001390 {
1391 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001392 (custom_format == eFormatCString ||
1393 custom_format == eFormatCharArray ||
1394 custom_format == eFormatChar ||
1395 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001396 return true;
1397
1398 if (flags.Test(ClangASTContext::eTypeIsArray))
1399 {
Greg Claytonafacd142011-09-02 01:15:17 +00001400 if ((custom_format == eFormatBytes) ||
1401 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001402 return true;
1403
Greg Claytonafacd142011-09-02 01:15:17 +00001404 if ((custom_format == eFormatVectorOfChar) ||
1405 (custom_format == eFormatVectorOfFloat32) ||
1406 (custom_format == eFormatVectorOfFloat64) ||
1407 (custom_format == eFormatVectorOfSInt16) ||
1408 (custom_format == eFormatVectorOfSInt32) ||
1409 (custom_format == eFormatVectorOfSInt64) ||
1410 (custom_format == eFormatVectorOfSInt8) ||
1411 (custom_format == eFormatVectorOfUInt128) ||
1412 (custom_format == eFormatVectorOfUInt16) ||
1413 (custom_format == eFormatVectorOfUInt32) ||
1414 (custom_format == eFormatVectorOfUInt64) ||
1415 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001416 return true;
1417 }
1418 }
1419 return false;
1420}
1421
Enrico Granata9fc19442011-07-06 02:13:41 +00001422bool
1423ValueObject::DumpPrintableRepresentation(Stream& s,
1424 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001425 Format custom_format,
Enrico Granata86cc9822012-03-19 22:58:49 +00001426 PrintableRepresentationSpecialCases special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001427{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001428
1429 clang_type_t elem_or_pointee_type;
1430 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001431
Enrico Granata86cc9822012-03-19 22:58:49 +00001432 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1433 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1434
1435 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001436 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001437 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1438 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001439 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001440 // when being asked to get a printable display an array or pointer type directly,
1441 // try to "do the right thing"
1442
1443 if (IsCStringContainer(true) &&
1444 (custom_format == eFormatCString ||
1445 custom_format == eFormatCharArray ||
1446 custom_format == eFormatChar ||
1447 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001448 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001449 Error error;
1450 ReadPointedString(s,
1451 error,
1452 0,
1453 (custom_format == eFormatVectorOfChar) ||
1454 (custom_format == eFormatCharArray));
1455 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001456 }
1457
Enrico Granata86cc9822012-03-19 22:58:49 +00001458 if (custom_format == eFormatEnum)
1459 return false;
1460
1461 // this only works for arrays, because I have no way to know when
1462 // the pointed memory ends, and no special \0 end of data marker
1463 if (flags.Test(ClangASTContext::eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001464 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001465 if ((custom_format == eFormatBytes) ||
1466 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001467 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001468 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001469
1470 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001471 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001472 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001473
1474 if (low)
1475 s << ',';
1476
1477 ValueObjectSP child = GetChildAtIndex(low,true);
1478 if (!child.get())
1479 {
1480 s << "<invalid child>";
1481 continue;
1482 }
1483 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1484 }
1485
1486 s << ']';
1487
1488 return true;
1489 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001490
Enrico Granata86cc9822012-03-19 22:58:49 +00001491 if ((custom_format == eFormatVectorOfChar) ||
1492 (custom_format == eFormatVectorOfFloat32) ||
1493 (custom_format == eFormatVectorOfFloat64) ||
1494 (custom_format == eFormatVectorOfSInt16) ||
1495 (custom_format == eFormatVectorOfSInt32) ||
1496 (custom_format == eFormatVectorOfSInt64) ||
1497 (custom_format == eFormatVectorOfSInt8) ||
1498 (custom_format == eFormatVectorOfUInt128) ||
1499 (custom_format == eFormatVectorOfUInt16) ||
1500 (custom_format == eFormatVectorOfUInt32) ||
1501 (custom_format == eFormatVectorOfUInt64) ||
1502 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1503 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001504 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001505
1506 Format format = FormatManager::GetSingleItemFormat(custom_format);
1507
1508 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001509 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001510 {
1511
1512 if (low)
1513 s << ',';
1514
1515 ValueObjectSP child = GetChildAtIndex(low,true);
1516 if (!child.get())
1517 {
1518 s << "<invalid child>";
1519 continue;
1520 }
1521 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1522 }
1523
1524 s << ']';
1525
1526 return true;
1527 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001528 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001529
1530 if ((custom_format == eFormatBoolean) ||
1531 (custom_format == eFormatBinary) ||
1532 (custom_format == eFormatChar) ||
1533 (custom_format == eFormatCharPrintable) ||
1534 (custom_format == eFormatComplexFloat) ||
1535 (custom_format == eFormatDecimal) ||
1536 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001537 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001538 (custom_format == eFormatFloat) ||
1539 (custom_format == eFormatOctal) ||
1540 (custom_format == eFormatOSType) ||
1541 (custom_format == eFormatUnicode16) ||
1542 (custom_format == eFormatUnicode32) ||
1543 (custom_format == eFormatUnsigned) ||
1544 (custom_format == eFormatPointer) ||
1545 (custom_format == eFormatComplexInteger) ||
1546 (custom_format == eFormatComplex) ||
1547 (custom_format == eFormatDefault)) // use the [] operator
1548 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001549 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001550 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001551
1552 if (only_special)
1553 return false;
1554
Enrico Granata86cc9822012-03-19 22:58:49 +00001555 bool var_success = false;
1556
1557 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001558 const char *cstr = NULL;
1559 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001560
1561 if (custom_format != eFormatInvalid)
1562 SetFormat(custom_format);
1563
1564 switch(val_obj_display)
1565 {
1566 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001567 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001568 break;
1569
1570 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001571 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001572 break;
1573
1574 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001575 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001576 break;
1577
1578 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001579 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001580 break;
1581
1582 case eValueObjectRepresentationStyleChildrenCount:
Greg Claytonc7bece562013-01-25 18:06:21 +00001583 strm.Printf("%zu", GetNumChildren());
1584 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001585 break;
1586
1587 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001588 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001589 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001590 }
1591
Greg Claytonc7bece562013-01-25 18:06:21 +00001592 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001593 {
1594 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001595 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001596 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1597 {
1598 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1599 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001600 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1601 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001602 }
1603 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001604 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001605 }
1606 }
1607
Greg Claytonc7bece562013-01-25 18:06:21 +00001608 if (cstr)
1609 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001610 else
1611 {
1612 if (m_error.Fail())
1613 s.Printf("<%s>", m_error.AsCString());
1614 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1615 s.PutCString("<no summary available>");
1616 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1617 s.PutCString("<no value available>");
1618 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1619 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1620 else
1621 s.PutCString("<no printable representation>");
1622 }
1623
1624 // we should only return false here if we could not do *anything*
1625 // even if we have an error message as output, that's a success
1626 // from our callers' perspective, so return true
1627 var_success = true;
1628
1629 if (custom_format != eFormatInvalid)
1630 SetFormat(eFormatDefault);
1631 }
1632
Enrico Granataf4efecd2011-07-12 22:56:10 +00001633 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001634}
1635
Greg Clayton737b9322010-09-13 03:32:57 +00001636addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001637ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001638{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001639 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001640 return LLDB_INVALID_ADDRESS;
1641
Greg Clayton73b472d2010-10-27 03:32:59 +00001642 switch (m_value.GetValueType())
1643 {
1644 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001645 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001646 if (scalar_is_load_address)
1647 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001648 if(address_type)
1649 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001650 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1651 }
1652 break;
1653
1654 case Value::eValueTypeLoadAddress:
1655 case Value::eValueTypeFileAddress:
1656 case Value::eValueTypeHostAddress:
1657 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001658 if(address_type)
1659 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001660 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1661 }
1662 break;
1663 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001664 if (address_type)
1665 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001666 return LLDB_INVALID_ADDRESS;
1667}
1668
1669addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001670ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001671{
Greg Claytonafacd142011-09-02 01:15:17 +00001672 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001673 if(address_type)
1674 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001675
Enrico Granatac3e320a2011-08-02 17:27:39 +00001676 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001677 return address;
1678
Greg Clayton73b472d2010-10-27 03:32:59 +00001679 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001680 {
1681 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001682 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001683 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001684 break;
1685
Enrico Granata9128ee22011-09-06 19:20:51 +00001686 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001687 case Value::eValueTypeLoadAddress:
1688 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001689 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001690 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001691 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001692 }
1693 break;
1694 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001695
Enrico Granata9128ee22011-09-06 19:20:51 +00001696 if (address_type)
1697 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001698
Greg Clayton737b9322010-09-13 03:32:57 +00001699 return address;
1700}
1701
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001702bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001703ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001704{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001705 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001706 // Make sure our value is up to date first so that our location and location
1707 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001708 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001709 {
1710 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001711 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001712 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001713
1714 uint32_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001715 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001716
Greg Claytonb1320972010-07-14 00:18:15 +00001717 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001718
Jim Ingham16e0c682011-08-12 23:34:31 +00001719 Value::ValueType value_type = m_value.GetValueType();
1720
1721 if (value_type == Value::eValueTypeScalar)
1722 {
1723 // If the value is already a scalar, then let the scalar change itself:
1724 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1725 }
1726 else if (byte_size <= Scalar::GetMaxByteSize())
1727 {
1728 // If the value fits in a scalar, then make a new scalar and again let the
1729 // scalar code do the conversion, then figure out where to put the new value.
1730 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001731 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1732 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001733 {
Jim Ingham4b536182011-08-09 02:12:22 +00001734 switch (value_type)
1735 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001736 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001737 {
1738 // If it is a load address, then the scalar value is the storage location
1739 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001740 ExecutionContext exe_ctx (GetExecutionContextRef());
1741 Process *process = exe_ctx.GetProcessPtr();
1742 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001743 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001744 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001745 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1746 new_scalar,
1747 byte_size,
1748 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001749 if (!error.Success())
1750 return false;
1751 if (bytes_written != byte_size)
1752 {
1753 error.SetErrorString("unable to write value to memory");
1754 return false;
1755 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001756 }
1757 }
Jim Ingham4b536182011-08-09 02:12:22 +00001758 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001759 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001760 {
1761 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1762 DataExtractor new_data;
1763 new_data.SetByteOrder (m_data.GetByteOrder());
1764
1765 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1766 m_data.SetData(buffer_sp, 0);
1767 bool success = new_scalar.GetData(new_data);
1768 if (success)
1769 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001770 new_data.CopyByteOrderedData (0,
1771 byte_size,
1772 const_cast<uint8_t *>(m_data.GetDataStart()),
1773 byte_size,
1774 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001775 }
1776 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1777
1778 }
Jim Ingham4b536182011-08-09 02:12:22 +00001779 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001780 case Value::eValueTypeFileAddress:
1781 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001782 case Value::eValueTypeVector:
1783 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001784 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001785 }
1786 else
1787 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001788 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001789 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001790 }
1791 else
1792 {
1793 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001794 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001795 return false;
1796 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001797
1798 // If we have reached this point, then we have successfully changed the value.
1799 SetNeedsUpdate();
1800 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001801}
1802
Greg Clayton81e871e2012-02-04 02:27:34 +00001803bool
1804ValueObject::GetDeclaration (Declaration &decl)
1805{
1806 decl.Clear();
1807 return false;
1808}
1809
Greg Clayton84db9102012-03-26 23:03:23 +00001810ConstString
1811ValueObject::GetTypeName()
1812{
1813 return ClangASTType::GetConstTypeName (GetClangAST(), GetClangType());
1814}
1815
1816ConstString
1817ValueObject::GetQualifiedTypeName()
1818{
1819 return ClangASTType::GetConstQualifiedTypeName (GetClangAST(), GetClangType());
1820}
1821
1822
Greg Claytonafacd142011-09-02 01:15:17 +00001823LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001824ValueObject::GetObjectRuntimeLanguage ()
1825{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001826 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1827 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001828}
1829
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001830void
Jim Ingham58b59f92011-04-22 23:53:53 +00001831ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001832{
Jim Ingham58b59f92011-04-22 23:53:53 +00001833 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001834}
1835
1836ValueObjectSP
1837ValueObject::GetSyntheticChild (const ConstString &key) const
1838{
1839 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001840 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001841 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001842 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001843 return synthetic_child_sp;
1844}
1845
1846bool
1847ValueObject::IsPointerType ()
1848{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001849 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001850}
1851
Jim Inghamb7603bb2011-03-18 00:05:18 +00001852bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001853ValueObject::IsArrayType ()
1854{
Greg Clayton4ef877f2012-12-06 02:33:54 +00001855 return ClangASTContext::IsArrayType (GetClangType(), NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00001856}
1857
1858bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001859ValueObject::IsScalarType ()
1860{
1861 return ClangASTContext::IsScalarType (GetClangType());
1862}
1863
1864bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001865ValueObject::IsIntegerType (bool &is_signed)
1866{
1867 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1868}
Greg Clayton73b472d2010-10-27 03:32:59 +00001869
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001870bool
1871ValueObject::IsPointerOrReferenceType ()
1872{
Greg Clayton007d5be2011-05-30 00:49:24 +00001873 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1874}
1875
1876bool
Greg Claytondea8cb42011-06-29 22:09:02 +00001877ValueObject::IsPossibleDynamicType ()
1878{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00001879 ExecutionContext exe_ctx (GetExecutionContextRef());
1880 Process *process = exe_ctx.GetProcessPtr();
1881 if (process)
1882 return process->IsPossibleDynamicValue(*this);
1883 else
Greg Clayton70364252012-08-31 18:56:24 +00001884 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType(), NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00001885}
1886
Enrico Granata9e7b3882012-12-13 23:50:33 +00001887bool
1888ValueObject::IsObjCNil ()
1889{
1890 bool isObjCpointer = ClangASTContext::IsObjCObjectPointerType(GetClangType(), NULL);
1891 bool canReadValue = true;
1892 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
1893 return canReadValue && isZero && isObjCpointer;
1894}
1895
Greg Claytonafacd142011-09-02 01:15:17 +00001896ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00001897ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001898{
1899 if (IsArrayType())
1900 return GetSyntheticArrayMemberFromArray(index, can_create);
1901
1902 if (IsPointerType())
1903 return GetSyntheticArrayMemberFromPointer(index, can_create);
1904
1905 return ValueObjectSP();
1906
1907}
1908
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001909ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00001910ValueObject::GetSyntheticArrayMemberFromPointer (size_t index, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001911{
1912 ValueObjectSP synthetic_child_sp;
1913 if (IsPointerType ())
1914 {
1915 char index_str[64];
Greg Claytonc7bece562013-01-25 18:06:21 +00001916 snprintf(index_str, sizeof(index_str), "[%zu]", index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001917 ConstString index_const_str(index_str);
1918 // Check if we have already created a synthetic array member in this
1919 // valid object. If we have we will re-use it.
1920 synthetic_child_sp = GetSyntheticChild (index_const_str);
1921 if (!synthetic_child_sp)
1922 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001923 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001924 // We haven't made a synthetic array member for INDEX yet, so
1925 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001926 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001927
1928 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001929 if (synthetic_child)
1930 {
1931 AddSyntheticChild(index_const_str, synthetic_child);
1932 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001933 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001934 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001935 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001936 }
1937 }
1938 return synthetic_child_sp;
1939}
Jim Ingham22777012010-09-23 02:01:19 +00001940
Greg Claytondaf515f2011-07-09 20:12:33 +00001941// This allows you to create an array member using and index
1942// that doesn't not fall in the normal bounds of the array.
1943// Many times structure can be defined as:
1944// struct Collection
1945// {
1946// uint32_t item_count;
1947// Item item_array[0];
1948// };
1949// The size of the "item_array" is 1, but many times in practice
1950// there are more items in "item_array".
1951
1952ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00001953ValueObject::GetSyntheticArrayMemberFromArray (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00001954{
1955 ValueObjectSP synthetic_child_sp;
1956 if (IsArrayType ())
1957 {
1958 char index_str[64];
Greg Claytonc7bece562013-01-25 18:06:21 +00001959 snprintf(index_str, sizeof(index_str), "[%zu]", index);
Greg Claytondaf515f2011-07-09 20:12:33 +00001960 ConstString index_const_str(index_str);
1961 // Check if we have already created a synthetic array member in this
1962 // valid object. If we have we will re-use it.
1963 synthetic_child_sp = GetSyntheticChild (index_const_str);
1964 if (!synthetic_child_sp)
1965 {
1966 ValueObject *synthetic_child;
1967 // We haven't made a synthetic array member for INDEX yet, so
1968 // lets make one and cache it for any future reference.
1969 synthetic_child = CreateChildAtIndex(0, true, index);
1970
1971 // Cache the value if we got one back...
1972 if (synthetic_child)
1973 {
1974 AddSyntheticChild(index_const_str, synthetic_child);
1975 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001976 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001977 synthetic_child_sp->m_is_array_item_for_pointer = true;
1978 }
1979 }
1980 }
1981 return synthetic_child_sp;
1982}
1983
Enrico Granata9fc19442011-07-06 02:13:41 +00001984ValueObjectSP
1985ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1986{
1987 ValueObjectSP synthetic_child_sp;
1988 if (IsScalarType ())
1989 {
1990 char index_str[64];
1991 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1992 ConstString index_const_str(index_str);
1993 // Check if we have already created a synthetic array member in this
1994 // valid object. If we have we will re-use it.
1995 synthetic_child_sp = GetSyntheticChild (index_const_str);
1996 if (!synthetic_child_sp)
1997 {
1998 ValueObjectChild *synthetic_child;
1999 // We haven't made a synthetic array member for INDEX yet, so
2000 // lets make one and cache it for any future reference.
2001 synthetic_child = new ValueObjectChild(*this,
2002 GetClangAST(),
2003 GetClangType(),
2004 index_const_str,
2005 GetByteSize(),
2006 0,
2007 to-from+1,
2008 from,
2009 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002010 false,
2011 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002012
2013 // Cache the value if we got one back...
2014 if (synthetic_child)
2015 {
2016 AddSyntheticChild(index_const_str, synthetic_child);
2017 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002018 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002019 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2020 }
2021 }
2022 }
2023 return synthetic_child_sp;
2024}
2025
Greg Claytonafacd142011-09-02 01:15:17 +00002026ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00002027ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
2028{
2029
2030 ValueObjectSP synthetic_child_sp;
2031
2032 char name_str[64];
2033 snprintf(name_str, sizeof(name_str), "@%i", offset);
2034 ConstString name_const_str(name_str);
2035
2036 // Check if we have already created a synthetic array member in this
2037 // valid object. If we have we will re-use it.
2038 synthetic_child_sp = GetSyntheticChild (name_const_str);
2039
2040 if (synthetic_child_sp.get())
2041 return synthetic_child_sp;
2042
2043 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002044 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002045
2046 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2047 type.GetASTContext(),
2048 type.GetOpaqueQualType(),
2049 name_const_str,
2050 type.GetTypeByteSize(),
2051 offset,
2052 0,
2053 0,
2054 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002055 false,
2056 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002057 if (synthetic_child)
2058 {
2059 AddSyntheticChild(name_const_str, synthetic_child);
2060 synthetic_child_sp = synthetic_child->GetSP();
2061 synthetic_child_sp->SetName(name_const_str);
2062 synthetic_child_sp->m_is_child_at_offset = true;
2063 }
2064 return synthetic_child_sp;
2065}
2066
Enrico Granatad55546b2011-07-22 00:16:08 +00002067// your expression path needs to have a leading . or ->
2068// (unless it somehow "looks like" an array, in which case it has
2069// a leading [ symbol). while the [ is meaningful and should be shown
2070// to the user, . and -> are just parser design, but by no means
2071// added information for the user.. strip them off
2072static const char*
2073SkipLeadingExpressionPathSeparators(const char* expression)
2074{
2075 if (!expression || !expression[0])
2076 return expression;
2077 if (expression[0] == '.')
2078 return expression+1;
2079 if (expression[0] == '-' && expression[1] == '>')
2080 return expression+2;
2081 return expression;
2082}
2083
Greg Claytonafacd142011-09-02 01:15:17 +00002084ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002085ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2086{
2087 ValueObjectSP synthetic_child_sp;
2088 ConstString name_const_string(expression);
2089 // Check if we have already created a synthetic array member in this
2090 // valid object. If we have we will re-use it.
2091 synthetic_child_sp = GetSyntheticChild (name_const_string);
2092 if (!synthetic_child_sp)
2093 {
2094 // We haven't made a synthetic array member for expression yet, so
2095 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002096 synthetic_child_sp = GetValueForExpressionPath(expression,
2097 NULL, NULL, NULL,
2098 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
Enrico Granatad55546b2011-07-22 00:16:08 +00002099
2100 // Cache the value if we got one back...
2101 if (synthetic_child_sp.get())
2102 {
2103 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002104 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002105 synthetic_child_sp->m_is_expression_path_child = true;
2106 }
2107 }
2108 return synthetic_child_sp;
2109}
2110
2111void
Enrico Granata86cc9822012-03-19 22:58:49 +00002112ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002113{
Enrico Granata86cc9822012-03-19 22:58:49 +00002114 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002115 return;
2116
Enrico Granatac5bc4122012-03-27 02:35:13 +00002117 TargetSP target_sp(GetTargetSP());
2118 if (target_sp && (target_sp->GetEnableSyntheticValue() == false || target_sp->GetSuppressSyntheticValue() == true))
2119 {
2120 m_synthetic_value = NULL;
2121 return;
2122 }
2123
Enrico Granatae3e91512012-10-22 18:18:36 +00002124 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2125
Enrico Granata5548cb52013-01-28 23:47:25 +00002126 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002127 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002128
Enrico Granata0c489f52012-03-01 04:24:26 +00002129 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002130 return;
2131
Enrico Granatae3e91512012-10-22 18:18:36 +00002132 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2133 return;
2134
Enrico Granata86cc9822012-03-19 22:58:49 +00002135 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002136}
2137
Jim Ingham78a685a2011-04-16 00:01:13 +00002138void
Greg Claytonafacd142011-09-02 01:15:17 +00002139ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002140{
Greg Claytonafacd142011-09-02 01:15:17 +00002141 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002142 return;
2143
Jim Ingham58b59f92011-04-22 23:53:53 +00002144 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002145 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002146 ExecutionContext exe_ctx (GetExecutionContextRef());
2147 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002148 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002149 {
2150 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002151 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002152 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002153 }
2154}
2155
Jim Ingham58b59f92011-04-22 23:53:53 +00002156ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002157ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002158{
Greg Claytonafacd142011-09-02 01:15:17 +00002159 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002160 return ValueObjectSP();
2161
2162 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002163 {
Jim Ingham2837b762011-05-04 03:43:18 +00002164 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002165 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002166 if (m_dynamic_value)
2167 return m_dynamic_value->GetSP();
2168 else
2169 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002170}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002171
Jim Ingham60dbabb2011-12-08 19:44:08 +00002172ValueObjectSP
2173ValueObject::GetStaticValue()
2174{
2175 return GetSP();
2176}
2177
Enrico Granata886147f2012-05-08 18:47:08 +00002178lldb::ValueObjectSP
2179ValueObject::GetNonSyntheticValue ()
2180{
2181 return GetSP();
2182}
2183
Enrico Granatad55546b2011-07-22 00:16:08 +00002184ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002185ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002186{
Enrico Granata86cc9822012-03-19 22:58:49 +00002187 if (use_synthetic == false)
2188 return ValueObjectSP();
2189
Enrico Granatad55546b2011-07-22 00:16:08 +00002190 CalculateSyntheticValue(use_synthetic);
2191
2192 if (m_synthetic_value)
2193 return m_synthetic_value->GetSP();
2194 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002195 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002196}
2197
Greg Claytone221f822011-01-21 01:59:00 +00002198bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002199ValueObject::HasSyntheticValue()
2200{
Enrico Granata5548cb52013-01-28 23:47:25 +00002201 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002202
Enrico Granata0c489f52012-03-01 04:24:26 +00002203 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002204 return false;
2205
Enrico Granata86cc9822012-03-19 22:58:49 +00002206 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002207
2208 if (m_synthetic_value)
2209 return true;
2210 else
2211 return false;
2212}
2213
2214bool
Greg Claytone221f822011-01-21 01:59:00 +00002215ValueObject::GetBaseClassPath (Stream &s)
2216{
2217 if (IsBaseClass())
2218 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002219 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00002220 clang_type_t clang_type = GetClangType();
2221 std::string cxx_class_name;
2222 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
2223 if (this_had_base_class)
2224 {
2225 if (parent_had_base_class)
2226 s.PutCString("::");
2227 s.PutCString(cxx_class_name.c_str());
2228 }
2229 return parent_had_base_class || this_had_base_class;
2230 }
2231 return false;
2232}
2233
2234
2235ValueObject *
2236ValueObject::GetNonBaseClassParent()
2237{
Jim Ingham78a685a2011-04-16 00:01:13 +00002238 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002239 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002240 if (GetParent()->IsBaseClass())
2241 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002242 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002243 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002244 }
2245 return NULL;
2246}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002247
2248void
Enrico Granata4becb372011-06-29 22:27:15 +00002249ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002250{
Greg Claytone221f822011-01-21 01:59:00 +00002251 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002252
Enrico Granata86cc9822012-03-19 22:58:49 +00002253 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002254 {
Enrico Granata4becb372011-06-29 22:27:15 +00002255 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2256 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2257 // the eHonorPointers mode is meant to produce strings in this latter format
2258 s.PutCString("*(");
2259 }
Greg Claytone221f822011-01-21 01:59:00 +00002260
Enrico Granata4becb372011-06-29 22:27:15 +00002261 ValueObject* parent = GetParent();
2262
2263 if (parent)
2264 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002265
2266 // if we are a deref_of_parent just because we are synthetic array
2267 // members made up to allow ptr[%d] syntax to work in variable
2268 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002269 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002270 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002271
Greg Claytone221f822011-01-21 01:59:00 +00002272 if (!IsBaseClass())
2273 {
2274 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002275 {
Greg Claytone221f822011-01-21 01:59:00 +00002276 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2277 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002278 {
Greg Claytone221f822011-01-21 01:59:00 +00002279 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2280 if (non_base_class_parent_clang_type)
2281 {
2282 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2283
Enrico Granata86cc9822012-03-19 22:58:49 +00002284 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002285 {
2286 s.PutCString("->");
2287 }
Enrico Granata4becb372011-06-29 22:27:15 +00002288 else
2289 {
2290 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2291 {
2292 s.PutCString("->");
2293 }
2294 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2295 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2296 {
2297 s.PutChar('.');
2298 }
Greg Claytone221f822011-01-21 01:59:00 +00002299 }
2300 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002301 }
Greg Claytone221f822011-01-21 01:59:00 +00002302
2303 const char *name = GetName().GetCString();
2304 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002305 {
Greg Claytone221f822011-01-21 01:59:00 +00002306 if (qualify_cxx_base_classes)
2307 {
2308 if (GetBaseClassPath (s))
2309 s.PutCString("::");
2310 }
2311 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002312 }
2313 }
2314 }
2315
Enrico Granata86cc9822012-03-19 22:58:49 +00002316 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002317 {
Greg Claytone221f822011-01-21 01:59:00 +00002318 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002319 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002320}
2321
Greg Claytonafacd142011-09-02 01:15:17 +00002322ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002323ValueObject::GetValueForExpressionPath(const char* expression,
2324 const char** first_unparsed,
2325 ExpressionPathScanEndReason* reason_to_stop,
2326 ExpressionPathEndResultType* final_value_type,
2327 const GetValueForExpressionPathOptions& options,
2328 ExpressionPathAftermath* final_task_on_target)
2329{
2330
2331 const char* dummy_first_unparsed;
2332 ExpressionPathScanEndReason dummy_reason_to_stop;
2333 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002334 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002335
2336 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2337 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2338 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2339 final_value_type ? final_value_type : &dummy_final_value_type,
2340 options,
2341 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2342
Enrico Granata86cc9822012-03-19 22:58:49 +00002343 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002344 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002345
Enrico Granata86cc9822012-03-19 22:58:49 +00002346 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 +00002347 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002348 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002349 {
2350 Error error;
2351 ValueObjectSP final_value = ret_val->Dereference(error);
2352 if (error.Fail() || !final_value.get())
2353 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002354 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002355 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002356 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002357 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002358 return ValueObjectSP();
2359 }
2360 else
2361 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002362 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002363 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002364 return final_value;
2365 }
2366 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002367 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002368 {
2369 Error error;
2370 ValueObjectSP final_value = ret_val->AddressOf(error);
2371 if (error.Fail() || !final_value.get())
2372 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002373 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002374 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002375 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002376 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002377 return ValueObjectSP();
2378 }
2379 else
2380 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002381 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002382 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002383 return final_value;
2384 }
2385 }
2386 }
2387 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2388}
2389
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002390int
2391ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002392 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002393 const char** first_unparsed,
2394 ExpressionPathScanEndReason* reason_to_stop,
2395 ExpressionPathEndResultType* final_value_type,
2396 const GetValueForExpressionPathOptions& options,
2397 ExpressionPathAftermath* final_task_on_target)
2398{
2399 const char* dummy_first_unparsed;
2400 ExpressionPathScanEndReason dummy_reason_to_stop;
2401 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002402 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002403
2404 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2405 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2406 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2407 final_value_type ? final_value_type : &dummy_final_value_type,
2408 options,
2409 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2410
2411 if (!ret_val.get()) // if there are errors, I add nothing to the list
2412 return 0;
2413
Enrico Granata86ea8d82012-03-29 01:34:34 +00002414 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002415 {
2416 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002417 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002418 {
2419 list->Append(ret_val);
2420 return 1;
2421 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002422 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 +00002423 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002424 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002425 {
2426 Error error;
2427 ValueObjectSP final_value = ret_val->Dereference(error);
2428 if (error.Fail() || !final_value.get())
2429 {
Greg Clayton23f59502012-07-17 03:23:13 +00002430 if (reason_to_stop)
2431 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2432 if (final_value_type)
2433 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002434 return 0;
2435 }
2436 else
2437 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002438 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002439 list->Append(final_value);
2440 return 1;
2441 }
2442 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002443 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002444 {
2445 Error error;
2446 ValueObjectSP final_value = ret_val->AddressOf(error);
2447 if (error.Fail() || !final_value.get())
2448 {
Greg Clayton23f59502012-07-17 03:23:13 +00002449 if (reason_to_stop)
2450 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2451 if (final_value_type)
2452 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002453 return 0;
2454 }
2455 else
2456 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002457 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002458 list->Append(final_value);
2459 return 1;
2460 }
2461 }
2462 }
2463 }
2464 else
2465 {
2466 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2467 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2468 ret_val,
2469 list,
2470 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2471 final_value_type ? final_value_type : &dummy_final_value_type,
2472 options,
2473 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2474 }
2475 // in any non-covered case, just do the obviously right thing
2476 list->Append(ret_val);
2477 return 1;
2478}
2479
Greg Claytonafacd142011-09-02 01:15:17 +00002480ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002481ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2482 const char** first_unparsed,
2483 ExpressionPathScanEndReason* reason_to_stop,
2484 ExpressionPathEndResultType* final_result,
2485 const GetValueForExpressionPathOptions& options,
2486 ExpressionPathAftermath* what_next)
2487{
2488 ValueObjectSP root = GetSP();
2489
2490 if (!root.get())
2491 return ValueObjectSP();
2492
2493 *first_unparsed = expression_cstr;
2494
2495 while (true)
2496 {
2497
2498 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2499
Greg Claytonafacd142011-09-02 01:15:17 +00002500 clang_type_t root_clang_type = root->GetClangType();
2501 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002502 Flags root_clang_type_info,pointee_clang_type_info;
2503
2504 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2505 if (pointee_clang_type)
2506 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002507
2508 if (!expression_cstr || *expression_cstr == '\0')
2509 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002510 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002511 return root;
2512 }
2513
2514 switch (*expression_cstr)
2515 {
2516 case '-':
2517 {
2518 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002519 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 +00002520 {
2521 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002522 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2523 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002524 return ValueObjectSP();
2525 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002526 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2527 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002528 options.m_no_fragile_ivar)
2529 {
2530 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002531 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2532 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002533 return ValueObjectSP();
2534 }
2535 if (expression_cstr[1] != '>')
2536 {
2537 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002538 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2539 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002540 return ValueObjectSP();
2541 }
2542 expression_cstr++; // skip the -
2543 }
2544 case '.': // or fallthrough from ->
2545 {
2546 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002547 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 +00002548 {
2549 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002550 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2551 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002552 return ValueObjectSP();
2553 }
2554 expression_cstr++; // skip .
2555 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2556 ConstString child_name;
2557 if (!next_separator) // if no other separator just expand this last layer
2558 {
2559 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002560 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2561
2562 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002563 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002564 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002565 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2566 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002567 return child_valobj_sp;
2568 }
2569 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2570 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002571 if (root->IsSynthetic())
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002572 {
2573 *first_unparsed = expression_cstr;
2574 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2575 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2576 return ValueObjectSP();
2577 }
2578
2579 child_valobj_sp = root->GetSyntheticValue();
Enrico Granata86cc9822012-03-19 22:58:49 +00002580 if (child_valobj_sp.get())
2581 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002582 }
2583
2584 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2585 // so we hit the "else" branch, and return an error
2586 if(child_valobj_sp.get()) // if it worked, just return
2587 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002588 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002589 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2590 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002591 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002592 }
2593 else
2594 {
2595 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002596 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2597 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002598 return ValueObjectSP();
2599 }
2600 }
2601 else // other layers do expand
2602 {
2603 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002604 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2605 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002606 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002607 root = child_valobj_sp;
2608 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002609 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002610 continue;
2611 }
2612 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2613 {
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002614 if (root->IsSynthetic())
2615 {
2616 *first_unparsed = expression_cstr;
2617 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2618 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2619 return ValueObjectSP();
2620 }
2621
Enrico Granata86cc9822012-03-19 22:58:49 +00002622 child_valobj_sp = root->GetSyntheticValue(true);
2623 if (child_valobj_sp)
2624 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002625 }
2626
2627 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2628 // so we hit the "else" branch, and return an error
2629 if(child_valobj_sp.get()) // if it worked, move on
2630 {
2631 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002632 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002633 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002634 continue;
2635 }
2636 else
2637 {
2638 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002639 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2640 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002641 return ValueObjectSP();
2642 }
2643 }
2644 break;
2645 }
2646 case '[':
2647 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002648 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 +00002649 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002650 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002651 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002652 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2653 {
2654 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002655 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2656 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002657 return ValueObjectSP();
2658 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002659 }
2660 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2661 {
2662 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002663 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2664 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002665 return ValueObjectSP();
2666 }
2667 }
2668 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2669 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002670 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002671 {
2672 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002673 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2674 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002675 return ValueObjectSP();
2676 }
2677 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2678 {
2679 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002680 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2681 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002682 return root;
2683 }
2684 }
2685 const char *separator_position = ::strchr(expression_cstr+1,'-');
2686 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2687 if (!close_bracket_position) // if there is no ], this is a syntax error
2688 {
2689 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002690 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2691 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002692 return ValueObjectSP();
2693 }
2694 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2695 {
2696 char *end = NULL;
2697 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2698 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2699 {
2700 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002701 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2702 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002703 return ValueObjectSP();
2704 }
2705 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2706 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002707 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002708 {
2709 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002710 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2711 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002712 return root;
2713 }
2714 else
2715 {
2716 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002717 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2718 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002719 return ValueObjectSP();
2720 }
2721 }
2722 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002723 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002724 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002725 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2726 if (!child_valobj_sp)
2727 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002728 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002729 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2730 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002731 if (child_valobj_sp)
2732 {
2733 root = child_valobj_sp;
2734 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002735 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002736 continue;
2737 }
2738 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002739 {
2740 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002741 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2742 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002743 return ValueObjectSP();
2744 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002745 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002746 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002747 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002748 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 +00002749 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002750 {
2751 Error error;
2752 root = root->Dereference(error);
2753 if (error.Fail() || !root.get())
2754 {
2755 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002756 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2757 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002758 return ValueObjectSP();
2759 }
2760 else
2761 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002762 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002763 continue;
2764 }
2765 }
2766 else
2767 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002768 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Clayton84db9102012-03-26 23:03:23 +00002769 root->GetClangType()) == eLanguageTypeObjC
2770 && ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2771 && root->HasSyntheticValue()
2772 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002773 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002774 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002775 }
2776 else
2777 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002778 if (!root.get())
2779 {
2780 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002781 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2782 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002783 return ValueObjectSP();
2784 }
2785 else
2786 {
2787 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002788 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002789 continue;
2790 }
2791 }
2792 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002793 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002794 {
2795 root = root->GetSyntheticBitFieldChild(index, index, true);
2796 if (!root.get())
2797 {
2798 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002799 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2800 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002801 return ValueObjectSP();
2802 }
2803 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2804 {
2805 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002806 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2807 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002808 return root;
2809 }
2810 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002811 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002812 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002813 if (root->HasSyntheticValue())
2814 root = root->GetSyntheticValue();
2815 else if (!root->IsSynthetic())
2816 {
2817 *first_unparsed = expression_cstr;
2818 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2819 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2820 return ValueObjectSP();
2821 }
2822 // if we are here, then root itself is a synthetic VO.. should be good to go
2823
Enrico Granata27b625e2011-08-09 01:04:56 +00002824 if (!root.get())
2825 {
2826 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002827 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2828 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2829 return ValueObjectSP();
2830 }
2831 root = root->GetChildAtIndex(index, true);
2832 if (!root.get())
2833 {
2834 *first_unparsed = expression_cstr;
2835 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2836 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002837 return ValueObjectSP();
2838 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002839 else
2840 {
2841 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002842 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002843 continue;
2844 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002845 }
2846 else
2847 {
2848 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002849 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2850 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002851 return ValueObjectSP();
2852 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002853 }
2854 else // we have a low and a high index
2855 {
2856 char *end = NULL;
2857 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2858 if (!end || end != separator_position) // if something weird is in our way return an error
2859 {
2860 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002861 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2862 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002863 return ValueObjectSP();
2864 }
2865 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2866 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2867 {
2868 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002869 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2870 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002871 return ValueObjectSP();
2872 }
2873 if (index_lower > index_higher) // swap indices if required
2874 {
2875 unsigned long temp = index_lower;
2876 index_lower = index_higher;
2877 index_higher = temp;
2878 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002879 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002880 {
2881 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2882 if (!root.get())
2883 {
2884 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002885 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2886 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002887 return ValueObjectSP();
2888 }
2889 else
2890 {
2891 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002892 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2893 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002894 return root;
2895 }
2896 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002897 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 +00002898 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002899 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002900 {
2901 Error error;
2902 root = root->Dereference(error);
2903 if (error.Fail() || !root.get())
2904 {
2905 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002906 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2907 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002908 return ValueObjectSP();
2909 }
2910 else
2911 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002912 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002913 continue;
2914 }
2915 }
2916 else
2917 {
2918 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002919 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2920 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002921 return root;
2922 }
2923 }
2924 break;
2925 }
2926 default: // some non-separator is in the way
2927 {
2928 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002929 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2930 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002931 return ValueObjectSP();
2932 break;
2933 }
2934 }
2935 }
2936}
2937
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002938int
2939ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2940 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002941 ValueObjectSP root,
2942 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002943 ExpressionPathScanEndReason* reason_to_stop,
2944 ExpressionPathEndResultType* final_result,
2945 const GetValueForExpressionPathOptions& options,
2946 ExpressionPathAftermath* what_next)
2947{
2948 if (!root.get())
2949 return 0;
2950
2951 *first_unparsed = expression_cstr;
2952
2953 while (true)
2954 {
2955
2956 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2957
Greg Claytonafacd142011-09-02 01:15:17 +00002958 clang_type_t root_clang_type = root->GetClangType();
2959 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002960 Flags root_clang_type_info,pointee_clang_type_info;
2961
2962 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2963 if (pointee_clang_type)
2964 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2965
2966 if (!expression_cstr || *expression_cstr == '\0')
2967 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002968 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002969 list->Append(root);
2970 return 1;
2971 }
2972
2973 switch (*expression_cstr)
2974 {
2975 case '[':
2976 {
2977 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2978 {
2979 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2980 {
2981 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002982 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2983 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002984 return 0;
2985 }
2986 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2987 {
2988 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002989 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2990 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002991 return 0;
2992 }
2993 }
2994 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2995 {
2996 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2997 {
2998 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002999 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3000 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003001 return 0;
3002 }
3003 else // expand this into list
3004 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003005 const size_t max_index = root->GetNumChildren() - 1;
3006 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003007 {
3008 ValueObjectSP child =
3009 root->GetChildAtIndex(index, true);
3010 list->Append(child);
3011 }
3012 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003013 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3014 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003015 return max_index; // tell me number of items I added to the VOList
3016 }
3017 }
3018 const char *separator_position = ::strchr(expression_cstr+1,'-');
3019 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3020 if (!close_bracket_position) // if there is no ], this is a syntax error
3021 {
3022 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003023 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3024 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003025 return 0;
3026 }
3027 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3028 {
3029 char *end = NULL;
3030 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3031 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3032 {
3033 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003034 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3035 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003036 return 0;
3037 }
3038 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3039 {
3040 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3041 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003042 const size_t max_index = root->GetNumChildren() - 1;
3043 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003044 {
3045 ValueObjectSP child =
3046 root->GetChildAtIndex(index, true);
3047 list->Append(child);
3048 }
3049 *first_unparsed = expression_cstr+2;
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 max_index; // tell me number of items I added to the VOList
3053 }
3054 else
3055 {
3056 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003057 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3058 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003059 return 0;
3060 }
3061 }
3062 // from here on we do have a valid index
3063 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3064 {
3065 root = root->GetChildAtIndex(index, true);
3066 if (!root.get())
3067 {
3068 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003069 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3070 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003071 return 0;
3072 }
3073 else
3074 {
3075 list->Append(root);
3076 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003077 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3078 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003079 return 1;
3080 }
3081 }
3082 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
3083 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003084 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 +00003085 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3086 {
3087 Error error;
3088 root = root->Dereference(error);
3089 if (error.Fail() || !root.get())
3090 {
3091 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003092 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3093 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003094 return 0;
3095 }
3096 else
3097 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003098 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003099 continue;
3100 }
3101 }
3102 else
3103 {
3104 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3105 if (!root.get())
3106 {
3107 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003108 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3109 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003110 return 0;
3111 }
3112 else
3113 {
3114 list->Append(root);
3115 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003116 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3117 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003118 return 1;
3119 }
3120 }
3121 }
3122 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3123 {
3124 root = root->GetSyntheticBitFieldChild(index, index, true);
3125 if (!root.get())
3126 {
3127 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003128 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3129 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003130 return 0;
3131 }
3132 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3133 {
3134 list->Append(root);
3135 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003136 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3137 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003138 return 1;
3139 }
3140 }
3141 }
3142 else // we have a low and a high index
3143 {
3144 char *end = NULL;
3145 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3146 if (!end || end != separator_position) // if something weird is in our way return an error
3147 {
3148 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003149 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3150 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003151 return 0;
3152 }
3153 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3154 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3155 {
3156 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003157 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3158 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003159 return 0;
3160 }
3161 if (index_lower > index_higher) // swap indices if required
3162 {
3163 unsigned long temp = index_lower;
3164 index_lower = index_higher;
3165 index_higher = temp;
3166 }
3167 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
3168 {
3169 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3170 if (!root.get())
3171 {
3172 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003173 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3174 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003175 return 0;
3176 }
3177 else
3178 {
3179 list->Append(root);
3180 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003181 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3182 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003183 return 1;
3184 }
3185 }
3186 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 +00003187 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003188 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3189 {
3190 Error error;
3191 root = root->Dereference(error);
3192 if (error.Fail() || !root.get())
3193 {
3194 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003195 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3196 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003197 return 0;
3198 }
3199 else
3200 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003201 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003202 continue;
3203 }
3204 }
3205 else
3206 {
Johnny Chen44805302011-07-19 19:48:13 +00003207 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003208 index <= index_higher; index++)
3209 {
3210 ValueObjectSP child =
3211 root->GetChildAtIndex(index, true);
3212 list->Append(child);
3213 }
3214 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003215 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3216 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003217 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3218 }
3219 }
3220 break;
3221 }
3222 default: // some non-[ separator, or something entirely wrong, is in the way
3223 {
3224 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003225 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3226 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003227 return 0;
3228 break;
3229 }
3230 }
3231 }
3232}
3233
Enrico Granata0c489f52012-03-01 04:24:26 +00003234static void
3235DumpValueObject_Impl (Stream &s,
3236 ValueObject *valobj,
3237 const ValueObject::DumpValueObjectOptions& options,
3238 uint32_t ptr_depth,
3239 uint32_t curr_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003240{
Greg Clayton007d5be2011-05-30 00:49:24 +00003241 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003242 {
Enrico Granata5548cb52013-01-28 23:47:25 +00003243 bool update_success = valobj->UpdateValueIfNeeded (true);
Greg Clayton007d5be2011-05-30 00:49:24 +00003244
Enrico Granata0c489f52012-03-01 04:24:26 +00003245 const char *root_valobj_name =
3246 options.m_root_valobj_name.empty() ?
3247 valobj->GetName().AsCString() :
3248 options.m_root_valobj_name.c_str();
3249
3250 if (update_success && options.m_use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00003251 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003252 ValueObject *dynamic_value = valobj->GetDynamicValue(options.m_use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003253 if (dynamic_value)
3254 valobj = dynamic_value;
3255 }
3256
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003257 clang_type_t clang_type = valobj->GetClangType();
3258
Greg Clayton73b472d2010-10-27 03:32:59 +00003259 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003260 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00003261 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
3262 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003263
Enrico Granata0c489f52012-03-01 04:24:26 +00003264 const bool print_valobj = options.m_flat_output == false || has_value;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003265
3266 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003267 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003268 if (options.m_show_location)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003269 {
Jim Ingham6035b672011-03-31 00:19:25 +00003270 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003271 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003272
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003273 s.Indent();
Enrico Granata2b2631c2012-08-09 16:51:25 +00003274
3275 bool show_type = true;
3276 // if we are at the root-level and been asked to hide the root's type, then hide it
3277 if (curr_depth == 0 && options.m_hide_root_type)
3278 show_type = false;
3279 else
3280 // otherwise decide according to the usual rules (asked to show types - always at the root level)
3281 show_type = options.m_show_types || (curr_depth == 0 && !options.m_flat_output);
3282
3283 if (show_type)
Enrico Granataf7b1a342013-01-23 01:17:27 +00003284 s.Printf("(%s) ", valobj->GetQualifiedTypeName().AsCString("<invalid type>"));
Greg Clayton1d3afba2010-10-05 00:00:42 +00003285
Enrico Granata0c489f52012-03-01 04:24:26 +00003286 if (options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003287 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003288 // If we are showing types, also qualify the C++ base classes
Enrico Granata0c489f52012-03-01 04:24:26 +00003289 const bool qualify_cxx_base_classes = options.m_show_types;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003290 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003291 s.PutCString(" =");
3292 }
3293 else
3294 {
3295 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3296 s.Printf ("%s =", name_cstr);
3297 }
3298
Enrico Granata0c489f52012-03-01 04:24:26 +00003299 if (!options.m_scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003300 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003301 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003302 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003303 }
3304
Enrico Granata0c489f52012-03-01 04:24:26 +00003305 std::string summary_str;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003306 std::string value_str;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003307 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003308 const char *sum_cstr = NULL;
Enrico Granata0c489f52012-03-01 04:24:26 +00003309 TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003310
Enrico Granata0c489f52012-03-01 04:24:26 +00003311 if (options.m_omit_summary_depth > 0)
Enrico Granata0c5ef692011-07-16 01:22:04 +00003312 entry = NULL;
3313
Enrico Granata9e7b3882012-12-13 23:50:33 +00003314 bool is_nil = valobj->IsObjCNil();
3315
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003316 if (err_cstr == NULL)
3317 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003318 if (options.m_format != eFormatDefault && options.m_format != valobj->GetFormat())
Greg Clayton6efba4f2012-01-26 21:08:30 +00003319 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003320 valobj->GetValueAsCString(options.m_format,
3321 value_str);
Greg Clayton6efba4f2012-01-26 21:08:30 +00003322 }
Enrico Granata0c489f52012-03-01 04:24:26 +00003323 else
Greg Clayton6efba4f2012-01-26 21:08:30 +00003324 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003325 val_cstr = valobj->GetValueAsCString();
3326 if (val_cstr)
3327 value_str = val_cstr;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003328 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003329 err_cstr = valobj->GetError().AsCString();
3330 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003331
3332 if (err_cstr)
3333 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003334 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003335 }
3336 else
3337 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003338 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003339 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003340 {
Enrico Granata9e7b3882012-12-13 23:50:33 +00003341 if (is_nil)
3342 sum_cstr = "nil";
3343 else if (options.m_omit_summary_depth == 0)
Enrico Granata0c489f52012-03-01 04:24:26 +00003344 {
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
Enrico Granata9e7b3882012-12-13 23:50:33 +00003355 // specify that the value should not be printed - and do not print
3356 // the value if this thing is nil
3357 if (!is_nil && !value_str.empty() && (entry == NULL || entry->DoesPrintValue() || sum_cstr == NULL))
Greg Clayton6efba4f2012-01-26 21:08:30 +00003358 s.Printf(" %s", value_str.c_str());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003359
Enrico Granata9dd75c82011-07-15 23:30:15 +00003360 if (sum_cstr)
Enrico Granata0c489f52012-03-01 04:24:26 +00003361 s.Printf(" %s", sum_cstr);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003362
Enrico Granata9e7b3882012-12-13 23:50:33 +00003363 // let's avoid the overly verbose no description error for a nil thing
3364 if (options.m_use_objc && !is_nil)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003365 {
Jim Ingham6035b672011-03-31 00:19:25 +00003366 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003367 if (object_desc)
3368 s.Printf(" %s\n", object_desc);
3369 else
Sean Callanan672ad942010-10-23 00:18:49 +00003370 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003371 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003372 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003373 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003374
Enrico Granata0c489f52012-03-01 04:24:26 +00003375 if (curr_depth < options.m_max_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003376 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003377 // We will show children for all concrete types. We won't show
3378 // pointer contents unless a pointer depth has been specified.
3379 // We won't reference contents unless the reference is the
3380 // root object (depth of zero).
3381 bool print_children = true;
3382
3383 // Use a new temporary pointer depth in case we override the
3384 // current pointer depth below...
3385 uint32_t curr_ptr_depth = ptr_depth;
3386
3387 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3388 if (is_ptr || is_ref)
3389 {
3390 // We have a pointer or reference whose value is an address.
3391 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003392 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003393 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003394 print_children = false;
3395
3396 else if (is_ref && curr_depth == 0)
3397 {
3398 // If this is the root object (depth is zero) that we are showing
3399 // and it is a reference, and no pointer depth has been supplied
3400 // print out what it references. Don't do this at deeper depths
3401 // otherwise we can end up with infinite recursion...
3402 curr_ptr_depth = 1;
3403 }
3404
3405 if (curr_ptr_depth == 0)
3406 print_children = false;
3407 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003408
Enrico Granata0a3958e2011-07-02 00:25:22 +00003409 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003410 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003411 ValueObject* synth_valobj;
3412 ValueObjectSP synth_valobj_sp = valobj->GetSyntheticValue (options.m_use_synthetic);
3413 synth_valobj = (synth_valobj_sp ? synth_valobj_sp.get() : valobj);
Enrico Granatac5bc4122012-03-27 02:35:13 +00003414
Greg Claytonc7bece562013-01-25 18:06:21 +00003415 size_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003416 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003417 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003418 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003419 if (options.m_flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003420 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003421 if (print_valobj)
3422 s.EOL();
3423 }
3424 else
3425 {
3426 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003427 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003428 s.IndentMore();
3429 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003430
Greg Claytonc7bece562013-01-25 18:06:21 +00003431 const size_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00003432
Enrico Granata0c489f52012-03-01 04:24:26 +00003433 if (num_children > max_num_children && !options.m_ignore_cap)
Enrico Granata22c55d12011-08-12 02:00:06 +00003434 {
3435 num_children = max_num_children;
3436 print_dotdotdot = true;
3437 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003438
Enrico Granata0c489f52012-03-01 04:24:26 +00003439 ValueObject::DumpValueObjectOptions child_options(options);
Enrico Granatac953a6a2012-12-11 02:17:22 +00003440 child_options.SetFormat(options.m_format).SetSummary().SetRootValueObjectName();
Enrico Granata0c489f52012-03-01 04:24:26 +00003441 child_options.SetScopeChecked(true)
3442 .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0);
Greg Claytonc7bece562013-01-25 18:06:21 +00003443 for (size_t idx=0; idx<num_children; ++idx)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003444 {
Enrico Granatac482a192011-08-17 22:13:59 +00003445 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003446 if (child_sp.get())
3447 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003448 DumpValueObject_Impl (s,
3449 child_sp.get(),
3450 child_options,
3451 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
3452 curr_depth + 1);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003453 }
3454 }
3455
Enrico Granata0c489f52012-03-01 04:24:26 +00003456 if (!options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003457 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003458 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003459 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003460 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3461 Target *target = exe_ctx.GetTargetPtr();
3462 if (target)
3463 target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003464 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003465 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003466 s.IndentLess();
3467 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003468 }
3469 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003470 else if (has_children)
3471 {
3472 // Aggregate, no children...
3473 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003474 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003475 }
3476 else
3477 {
3478 if (print_valobj)
3479 s.EOL();
3480 }
3481
Greg Clayton1d3afba2010-10-05 00:00:42 +00003482 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003483 else
3484 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003485 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003486 }
3487 }
3488 else
3489 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003490 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003491 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003492 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003493 }
3494 }
3495 }
3496 }
3497}
3498
Enrico Granata0c489f52012-03-01 04:24:26 +00003499void
Greg Claytonf830dbb2012-03-22 18:15:37 +00003500ValueObject::LogValueObject (Log *log,
3501 ValueObject *valobj)
3502{
3503 if (log && valobj)
3504 return LogValueObject (log, valobj, DumpValueObjectOptions::DefaultOptions());
3505}
3506
3507void
3508ValueObject::LogValueObject (Log *log,
3509 ValueObject *valobj,
3510 const DumpValueObjectOptions& options)
3511{
3512 if (log && valobj)
3513 {
3514 StreamString s;
3515 ValueObject::DumpValueObject (s, valobj, options);
3516 if (s.GetSize())
3517 log->PutCString(s.GetData());
3518 }
3519}
3520
3521void
Enrico Granata0c489f52012-03-01 04:24:26 +00003522ValueObject::DumpValueObject (Stream &s,
3523 ValueObject *valobj)
3524{
3525
3526 if (!valobj)
3527 return;
3528
3529 DumpValueObject_Impl(s,
3530 valobj,
3531 DumpValueObjectOptions::DefaultOptions(),
3532 0,
3533 0);
3534}
3535
3536void
3537ValueObject::DumpValueObject (Stream &s,
3538 ValueObject *valobj,
3539 const DumpValueObjectOptions& options)
3540{
3541 DumpValueObject_Impl(s,
3542 valobj,
3543 options,
3544 options.m_max_ptr_depth, // max pointer depth allowed, we will go down from here
3545 0 // current object depth is 0 since we are just starting
3546 );
3547}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003548
3549ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003550ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003551{
3552 ValueObjectSP valobj_sp;
3553
Enrico Granatac3e320a2011-08-02 17:27:39 +00003554 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003555 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003556 ExecutionContext exe_ctx (GetExecutionContextRef());
3557 clang::ASTContext *ast = GetClangAST ();
3558
3559 DataExtractor data;
3560 data.SetByteOrder (m_data.GetByteOrder());
3561 data.SetAddressByteSize(m_data.GetAddressByteSize());
3562
Enrico Granata9f1e2042012-04-24 22:15:37 +00003563 if (IsBitfield())
3564 {
3565 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
3566 m_error = v.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
3567 }
3568 else
3569 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003570
3571 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3572 ast,
3573 GetClangType(),
3574 name,
3575 data,
3576 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003577 }
Jim Ingham6035b672011-03-31 00:19:25 +00003578
3579 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003580 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003581 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003582 }
3583 return valobj_sp;
3584}
3585
Greg Claytonafacd142011-09-02 01:15:17 +00003586ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003587ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003588{
Jim Ingham58b59f92011-04-22 23:53:53 +00003589 if (m_deref_valobj)
3590 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003591
Greg Clayton54979cd2010-12-15 05:08:08 +00003592 const bool is_pointer_type = IsPointerType();
3593 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003594 {
3595 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003596 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003597
3598 std::string child_name_str;
3599 uint32_t child_byte_size = 0;
3600 int32_t child_byte_offset = 0;
3601 uint32_t child_bitfield_bit_size = 0;
3602 uint32_t child_bitfield_bit_offset = 0;
3603 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003604 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003605 const bool transparent_pointers = false;
3606 clang::ASTContext *clang_ast = GetClangAST();
3607 clang_type_t clang_type = GetClangType();
3608 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003609
Greg Claytoncc4d0142012-02-17 07:49:44 +00003610 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003611
3612 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3613 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003614 GetName().GetCString(),
3615 clang_type,
3616 0,
3617 transparent_pointers,
3618 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003619 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003620 child_name_str,
3621 child_byte_size,
3622 child_byte_offset,
3623 child_bitfield_bit_size,
3624 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003625 child_is_base_class,
3626 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003627 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003628 {
3629 ConstString child_name;
3630 if (!child_name_str.empty())
3631 child_name.SetCString (child_name_str.c_str());
3632
Jim Ingham58b59f92011-04-22 23:53:53 +00003633 m_deref_valobj = new ValueObjectChild (*this,
3634 clang_ast,
3635 child_clang_type,
3636 child_name,
3637 child_byte_size,
3638 child_byte_offset,
3639 child_bitfield_bit_size,
3640 child_bitfield_bit_offset,
3641 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003642 child_is_deref_of_parent,
3643 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003644 }
3645 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003646
Jim Ingham58b59f92011-04-22 23:53:53 +00003647 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003648 {
3649 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003650 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003651 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003652 else
3653 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003654 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003655 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003656
3657 if (is_pointer_type)
3658 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3659 else
3660 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003661 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003662 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003663}
3664
Greg Claytonafacd142011-09-02 01:15:17 +00003665ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003666ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003667{
Jim Ingham78a685a2011-04-16 00:01:13 +00003668 if (m_addr_of_valobj_sp)
3669 return m_addr_of_valobj_sp;
3670
Greg Claytone0d378b2011-03-24 21:19:54 +00003671 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003672 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003673 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003674 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003675 if (addr != LLDB_INVALID_ADDRESS)
3676 {
3677 switch (address_type)
3678 {
3679 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003680 {
3681 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003682 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003683 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3684 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003685 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003686
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003687 case eAddressTypeFile:
3688 case eAddressTypeLoad:
3689 case eAddressTypeHost:
3690 {
3691 clang::ASTContext *ast = GetClangAST();
3692 clang_type_t clang_type = GetClangType();
3693 if (ast && clang_type)
3694 {
3695 std::string name (1, '&');
3696 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003697 ExecutionContext exe_ctx (GetExecutionContextRef());
3698 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003699 ast,
3700 ClangASTContext::CreatePointerType (ast, clang_type),
3701 ConstString (name.c_str()),
3702 addr,
3703 eAddressTypeInvalid,
3704 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003705 }
3706 }
3707 break;
3708 }
3709 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003710 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003711}
3712
Greg Clayton9a142cf2012-02-03 05:34:10 +00003713ValueObjectSP
3714ValueObject::Cast (const ClangASTType &clang_ast_type)
3715{
Greg Clayton81e871e2012-02-04 02:27:34 +00003716 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003717}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003718
Greg Claytonafacd142011-09-02 01:15:17 +00003719ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003720ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3721{
Greg Claytonafacd142011-09-02 01:15:17 +00003722 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003723 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003724 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003725
3726 if (ptr_value != LLDB_INVALID_ADDRESS)
3727 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003728 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003729 ExecutionContext exe_ctx (GetExecutionContextRef());
3730 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003731 name,
3732 ptr_addr,
3733 clang_ast_type);
3734 }
3735 return valobj_sp;
3736}
3737
Greg Claytonafacd142011-09-02 01:15:17 +00003738ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003739ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3740{
Greg Claytonafacd142011-09-02 01:15:17 +00003741 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003742 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003743 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003744
3745 if (ptr_value != LLDB_INVALID_ADDRESS)
3746 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003747 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003748 ExecutionContext exe_ctx (GetExecutionContextRef());
3749 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003750 name,
3751 ptr_addr,
3752 type_sp);
3753 }
3754 return valobj_sp;
3755}
3756
Jim Ingham6035b672011-03-31 00:19:25 +00003757ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003758 m_mod_id(),
3759 m_exe_ctx_ref(),
3760 m_needs_update (true),
3761 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003762{
3763}
3764
3765ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003766 m_mod_id(),
3767 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003768 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003769 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003770{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003771 ExecutionContext exe_ctx(exe_scope);
3772 TargetSP target_sp (exe_ctx.GetTargetSP());
3773 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003774 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003775 m_exe_ctx_ref.SetTargetSP (target_sp);
3776 ProcessSP process_sp (exe_ctx.GetProcessSP());
3777 if (!process_sp)
3778 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003779
Greg Claytoncc4d0142012-02-17 07:49:44 +00003780 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003781 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003782 m_mod_id = process_sp->GetModID();
3783 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003784
Greg Claytoncc4d0142012-02-17 07:49:44 +00003785 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003786
Greg Claytoncc4d0142012-02-17 07:49:44 +00003787 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003788 {
3789 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003790 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003791 }
Jim Ingham6035b672011-03-31 00:19:25 +00003792
Greg Claytoncc4d0142012-02-17 07:49:44 +00003793 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003794 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003795 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003796
Greg Claytoncc4d0142012-02-17 07:49:44 +00003797 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3798 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003799 {
3800 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003801 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003802 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003803 if (frame_sp)
3804 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003805 }
3806 }
3807 }
Jim Ingham6035b672011-03-31 00:19:25 +00003808}
3809
3810ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003811 m_mod_id(),
3812 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3813 m_needs_update (true),
3814 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003815{
3816}
3817
3818ValueObject::EvaluationPoint::~EvaluationPoint ()
3819{
3820}
3821
Jim Ingham6035b672011-03-31 00:19:25 +00003822// This function checks the EvaluationPoint against the current process state. If the current
3823// state matches the evaluation point, or the evaluation point is already invalid, then we return
3824// false, meaning "no change". If the current state is different, we update our state, and return
3825// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3826// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003827// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003828
3829bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003830ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003831{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003832
3833 // 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 +00003834 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00003835
Greg Claytoncc4d0142012-02-17 07:49:44 +00003836 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003837 return false;
3838
Jim Ingham6035b672011-03-31 00:19:25 +00003839 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003840 Process *process = exe_ctx.GetProcessPtr();
3841 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003842 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003843
Jim Ingham6035b672011-03-31 00:19:25 +00003844 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003845 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003846
Jim Ingham78a685a2011-04-16 00:01:13 +00003847 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3848 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003849 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003850 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003851
Greg Clayton23f59502012-07-17 03:23:13 +00003852 bool changed = false;
3853 const bool was_valid = m_mod_id.IsValid();
3854 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003855 {
3856 if (m_mod_id == current_mod_id)
3857 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003858 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003859 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003860 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003861 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003862 else
3863 {
3864 m_mod_id = current_mod_id;
3865 m_needs_update = true;
3866 changed = true;
3867 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003868 }
Jim Ingham6035b672011-03-31 00:19:25 +00003869
Jim Ingham73ca05a2011-12-17 01:35:57 +00003870 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3871 // That way we'll be sure to return a valid exe_scope.
3872 // 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 +00003873
Greg Claytoncc4d0142012-02-17 07:49:44 +00003874 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003875 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003876 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3877 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003878 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003879 if (m_exe_ctx_ref.HasFrameRef())
3880 {
3881 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3882 if (!frame_sp)
3883 {
3884 // We used to have a frame, but now it is gone
3885 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003886 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00003887 }
3888 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003889 }
Jim Ingham6035b672011-03-31 00:19:25 +00003890 else
3891 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003892 // We used to have a thread, but now it is gone
3893 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003894 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00003895 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003896
Jim Ingham6035b672011-03-31 00:19:25 +00003897 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003898 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003899}
3900
Jim Ingham61be0902011-05-02 18:13:59 +00003901void
3902ValueObject::EvaluationPoint::SetUpdated ()
3903{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003904 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3905 if (process_sp)
3906 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003907 m_first_update = false;
3908 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003909}
3910
3911
Greg Claytoncc4d0142012-02-17 07:49:44 +00003912//bool
3913//ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3914//{
3915// if (!IsValid())
3916// return false;
3917//
3918// bool needs_update = false;
3919//
3920// // The target has to be non-null, and the
3921// Target *target = exe_scope->CalculateTarget();
3922// if (target != NULL)
3923// {
3924// Target *old_target = m_target_sp.get();
3925// assert (target == old_target);
3926// Process *process = exe_scope->CalculateProcess();
3927// if (process != NULL)
3928// {
3929// // FOR NOW - assume you can't update variable objects across process boundaries.
3930// Process *old_process = m_process_sp.get();
3931// assert (process == old_process);
3932// ProcessModID current_mod_id = process->GetModID();
3933// if (m_mod_id != current_mod_id)
3934// {
3935// needs_update = true;
3936// m_mod_id = current_mod_id;
3937// }
3938// // See if we're switching the thread or stack context. If no thread is given, this is
3939// // being evaluated in a global context.
3940// Thread *thread = exe_scope->CalculateThread();
3941// if (thread != NULL)
3942// {
3943// user_id_t new_thread_index = thread->GetIndexID();
3944// if (new_thread_index != m_thread_id)
3945// {
3946// needs_update = true;
3947// m_thread_id = new_thread_index;
3948// m_stack_id.Clear();
3949// }
3950//
3951// StackFrame *new_frame = exe_scope->CalculateStackFrame();
3952// if (new_frame != NULL)
3953// {
3954// if (new_frame->GetStackID() != m_stack_id)
3955// {
3956// needs_update = true;
3957// m_stack_id = new_frame->GetStackID();
3958// }
3959// }
3960// else
3961// {
3962// m_stack_id.Clear();
3963// needs_update = true;
3964// }
3965// }
3966// else
3967// {
3968// // If this had been given a thread, and now there is none, we should update.
3969// // Otherwise we don't have to do anything.
3970// if (m_thread_id != LLDB_INVALID_UID)
3971// {
3972// m_thread_id = LLDB_INVALID_UID;
3973// m_stack_id.Clear();
3974// needs_update = true;
3975// }
3976// }
3977// }
3978// else
3979// {
3980// // If there is no process, then we don't need to update anything.
3981// // But if we're switching from having a process to not, we should try to update.
3982// if (m_process_sp.get() != NULL)
3983// {
3984// needs_update = true;
3985// m_process_sp.reset();
3986// m_thread_id = LLDB_INVALID_UID;
3987// m_stack_id.Clear();
3988// }
3989// }
3990// }
3991// else
3992// {
3993// // If there's no target, nothing can change so we don't need to update anything.
3994// // But if we're switching from having a target to not, we should try to update.
3995// if (m_target_sp.get() != NULL)
3996// {
3997// needs_update = true;
3998// m_target_sp.reset();
3999// m_process_sp.reset();
4000// m_thread_id = LLDB_INVALID_UID;
4001// m_stack_id.Clear();
4002// }
4003// }
4004// if (!m_needs_update)
4005// m_needs_update = needs_update;
4006//
4007// return needs_update;
4008//}
Enrico Granataf2bbf712011-07-15 02:26:42 +00004009
4010void
Enrico Granata86cc9822012-03-19 22:58:49 +00004011ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004012{
Enrico Granata86cc9822012-03-19 22:58:49 +00004013 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4014 m_value_str.clear();
4015
4016 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4017 m_location_str.clear();
4018
4019 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
4020 {
Enrico Granata86cc9822012-03-19 22:58:49 +00004021 m_summary_str.clear();
4022 }
4023
4024 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4025 m_object_desc_str.clear();
4026
4027 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4028 {
4029 if (m_synthetic_value)
4030 m_synthetic_value = NULL;
4031 }
Johnny Chen44805302011-07-19 19:48:13 +00004032}
Enrico Granata9128ee22011-09-06 19:20:51 +00004033
4034SymbolContextScope *
4035ValueObject::GetSymbolContextScope()
4036{
4037 if (m_parent)
4038 {
4039 if (!m_parent->IsPointerOrReferenceType())
4040 return m_parent->GetSymbolContextScope();
4041 }
4042 return NULL;
4043}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004044
4045lldb::ValueObjectSP
4046ValueObject::CreateValueObjectFromExpression (const char* name,
4047 const char* expression,
4048 const ExecutionContext& exe_ctx)
4049{
4050 lldb::ValueObjectSP retval_sp;
4051 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4052 if (!target_sp)
4053 return retval_sp;
4054 if (!expression || !*expression)
4055 return retval_sp;
4056 target_sp->EvaluateExpression (expression,
4057 exe_ctx.GetFrameSP().get(),
4058 retval_sp);
4059 if (retval_sp && name && *name)
4060 retval_sp->SetName(ConstString(name));
4061 return retval_sp;
4062}
4063
4064lldb::ValueObjectSP
4065ValueObject::CreateValueObjectFromAddress (const char* name,
4066 uint64_t address,
4067 const ExecutionContext& exe_ctx,
4068 ClangASTType type)
4069{
4070 ClangASTType pointer_type(type.GetASTContext(),type.GetPointerType());
4071 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4072 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4073 pointer_type.GetASTContext(),
4074 pointer_type.GetOpaqueQualType(),
4075 ConstString(name),
4076 buffer,
4077 lldb::endian::InlHostByteOrder(),
4078 exe_ctx.GetAddressByteSize()));
4079 if (ptr_result_valobj_sp)
4080 {
4081 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4082 Error err;
4083 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4084 if (ptr_result_valobj_sp && name && *name)
4085 ptr_result_valobj_sp->SetName(ConstString(name));
4086 }
4087 return ptr_result_valobj_sp;
4088}
4089
4090lldb::ValueObjectSP
4091ValueObject::CreateValueObjectFromData (const char* name,
4092 DataExtractor& data,
4093 const ExecutionContext& exe_ctx,
4094 ClangASTType type)
4095{
4096 lldb::ValueObjectSP new_value_sp;
4097 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4098 type.GetASTContext() ,
4099 type.GetOpaqueQualType(),
4100 ConstString(name),
4101 data,
4102 LLDB_INVALID_ADDRESS);
4103 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4104 if (new_value_sp && name && *name)
4105 new_value_sp->SetName(ConstString(name));
4106 return new_value_sp;
4107}