blob: 50ca804cf30b82711f31744785392ae82dcef7f6 [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 Granata6f3533f2011-07-29 19:53:35 +000099 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000100 m_is_getting_summary(false),
101 m_did_calculate_complete_objc_class_type(false)
Jim Ingham6035b672011-03-31 00:19:25 +0000102{
Jim Ingham58b59f92011-04-22 23:53:53 +0000103 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000104}
105
106//----------------------------------------------------------------------
107// ValueObject constructor
108//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000109ValueObject::ValueObject (ExecutionContextScope *exe_scope,
110 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000111 UserID (++g_value_obj_uid), // Unique identifier for every value object
112 m_parent (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000113 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000114 m_name (),
115 m_data (),
116 m_value (),
117 m_error (),
118 m_value_str (),
119 m_old_value_str (),
120 m_location_str (),
121 m_summary_str (),
122 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000123 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000124 m_children (),
125 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000126 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000127 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000128 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000129 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000130 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +0000131 m_type_summary_sp(),
132 m_type_format_sp(),
133 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000134 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000135 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Jim Ingham6035b672011-03-31 00:19:25 +0000136 m_value_is_valid (false),
137 m_value_did_change (false),
138 m_children_count_valid (false),
139 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000140 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000141 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000142 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000143 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000144 m_is_getting_summary(false),
145 m_did_calculate_complete_objc_class_type(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000146{
Jim Ingham58b59f92011-04-22 23:53:53 +0000147 m_manager = new ValueObjectManager();
148 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000149}
150
151//----------------------------------------------------------------------
152// Destructor
153//----------------------------------------------------------------------
154ValueObject::~ValueObject ()
155{
156}
157
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000158bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000159ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000160{
Enrico Granata4becb372011-06-29 22:27:15 +0000161
Enrico Granata9128ee22011-09-06 19:20:51 +0000162 bool did_change_formats = false;
163
Enrico Granata0a3958e2011-07-02 00:25:22 +0000164 if (update_format)
Enrico Granata5548cb52013-01-28 23:47:25 +0000165 did_change_formats = UpdateFormatsIfNeeded();
Enrico Granata4becb372011-06-29 22:27:15 +0000166
Greg Claytonb71f3842010-10-05 03:13:51 +0000167 // If this is a constant value, then our success is predicated on whether
168 // we have an error or not
169 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000170 {
171 // if you were asked to update your formatters, but did not get a chance to do it
172 // clear your own values (this serves the purpose of faking a stop-id for frozen
173 // objects (which are regarded as constant, but could have changes behind their backs
174 // because of the frozen-pointer depth limit)
175 // TODO: decouple summary from value and then remove this code and only force-clear the summary
176 if (update_format && !did_change_formats)
Enrico Granata86cc9822012-03-19 22:58:49 +0000177 ClearUserVisibleData(eClearUserVisibleDataItemsSummary);
Greg Claytonb71f3842010-10-05 03:13:51 +0000178 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000179 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000180
Jim Ingham6035b672011-03-31 00:19:25 +0000181 bool first_update = m_update_point.IsFirstEvaluation();
182
183 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000184 {
Jim Ingham6035b672011-03-31 00:19:25 +0000185 m_update_point.SetUpdated();
186
187 // Save the old value using swap to avoid a string copy which
188 // also will clear our m_value_str
189 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000190 {
Jim Ingham6035b672011-03-31 00:19:25 +0000191 m_old_value_valid = false;
192 }
193 else
194 {
195 m_old_value_valid = true;
196 m_old_value_str.swap (m_value_str);
Enrico Granata86cc9822012-03-19 22:58:49 +0000197 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham6035b672011-03-31 00:19:25 +0000198 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000199
Enrico Granataf2bbf712011-07-15 02:26:42 +0000200 ClearUserVisibleData();
201
Greg Claytonefbc7d22012-03-09 04:23:44 +0000202 if (IsInScope())
Jim Ingham6035b672011-03-31 00:19:25 +0000203 {
Greg Claytonefbc7d22012-03-09 04:23:44 +0000204 const bool value_was_valid = GetValueIsValid();
205 SetValueDidChange (false);
206
207 m_error.Clear();
208
209 // Call the pure virtual function to update the value
210 bool success = UpdateValue ();
211
212 SetValueIsValid (success);
213
214 if (first_update)
215 SetValueDidChange (false);
216 else if (!m_value_did_change && success == false)
217 {
218 // The value wasn't gotten successfully, so we mark this
219 // as changed if the value used to be valid and now isn't
220 SetValueDidChange (value_was_valid);
221 }
222 }
223 else
224 {
225 m_error.SetErrorString("out of scope");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000226 }
227 }
228 return m_error.Success();
229}
230
Enrico Granata9128ee22011-09-06 19:20:51 +0000231bool
Enrico Granata5548cb52013-01-28 23:47:25 +0000232ValueObject::UpdateFormatsIfNeeded()
Enrico Granata4becb372011-06-29 22:27:15 +0000233{
Enrico Granata6f3533f2011-07-29 19:53:35 +0000234 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
235 if (log)
Enrico Granatad2284832012-10-17 22:23:56 +0000236 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
Enrico Granata6f3533f2011-07-29 19:53:35 +0000237 GetName().GetCString(),
Enrico Granatad2284832012-10-17 22:23:56 +0000238 this,
Enrico Granata4becb372011-06-29 22:27:15 +0000239 m_last_format_mgr_revision,
Enrico Granata85933ed2011-08-18 16:38:26 +0000240 DataVisualization::GetCurrentRevision());
Enrico Granata9128ee22011-09-06 19:20:51 +0000241
242 bool any_change = false;
243
Enrico Granata5548cb52013-01-28 23:47:25 +0000244 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()))
Enrico Granata4becb372011-06-29 22:27:15 +0000245 {
Enrico Granata78d06382011-09-09 23:33:14 +0000246 SetValueFormat(DataVisualization::ValueFormats::GetFormat (*this, eNoDynamicValues));
Enrico Granata5548cb52013-01-28 23:47:25 +0000247 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000248#ifndef LLDB_DISABLE_PYTHON
Enrico Granata5548cb52013-01-28 23:47:25 +0000249 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000250#endif
Enrico Granata1490c6f2011-07-19 02:34:21 +0000251
Enrico Granata85933ed2011-08-18 16:38:26 +0000252 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
Enrico Granata855cd902011-09-06 22:59:55 +0000253
254 any_change = true;
Enrico Granata4becb372011-06-29 22:27:15 +0000255 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000256
257 return any_change;
258
Enrico Granata4becb372011-06-29 22:27:15 +0000259}
260
Jim Ingham16e0c682011-08-12 23:34:31 +0000261void
262ValueObject::SetNeedsUpdate ()
263{
264 m_update_point.SetNeedsUpdate();
265 // We have to clear the value string here so ConstResult children will notice if their values are
266 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000267 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000268}
269
Enrico Granata13ac0e22012-10-17 19:03:34 +0000270void
Enrico Granatae3e91512012-10-22 18:18:36 +0000271ValueObject::ClearDynamicTypeInformation ()
Enrico Granata13ac0e22012-10-17 19:03:34 +0000272{
273 m_did_calculate_complete_objc_class_type = false;
Enrico Granatae3e91512012-10-22 18:18:36 +0000274 m_last_format_mgr_revision = 0;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000275 m_override_type = ClangASTType();
Enrico Granatae3e91512012-10-22 18:18:36 +0000276 SetValueFormat(lldb::TypeFormatImplSP());
277 SetSummaryFormat(lldb::TypeSummaryImplSP());
278 SetSyntheticChildren(lldb::SyntheticChildrenSP());
Enrico Granata13ac0e22012-10-17 19:03:34 +0000279}
280
Sean Callanan72772842012-02-22 23:57:45 +0000281ClangASTType
282ValueObject::MaybeCalculateCompleteType ()
283{
284 ClangASTType ret(GetClangASTImpl(), GetClangTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000285
Sean Callanan72772842012-02-22 23:57:45 +0000286 if (m_did_calculate_complete_objc_class_type)
287 {
288 if (m_override_type.IsValid())
289 return m_override_type;
290 else
291 return ret;
292 }
293
294 clang_type_t ast_type(GetClangTypeImpl());
295 clang_type_t class_type;
296 bool is_pointer_type;
297
298 if (ClangASTContext::IsObjCObjectPointerType(ast_type, &class_type))
299 {
300 is_pointer_type = true;
301 }
302 else if (ClangASTContext::IsObjCClassType(ast_type))
303 {
304 is_pointer_type = false;
305 class_type = ast_type;
306 }
307 else
308 {
309 return ret;
310 }
311
312 m_did_calculate_complete_objc_class_type = true;
313
314 if (!class_type)
315 return ret;
316
317 std::string class_name;
318
319 if (!ClangASTContext::GetObjCClassName(class_type, class_name))
320 return ret;
321
322 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
323
324 if (!process_sp)
325 return ret;
326
327 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
328
329 if (!objc_language_runtime)
330 return ret;
331
332 ConstString class_name_cs(class_name.c_str());
333
334 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name_cs);
335
336 if (!complete_objc_class_type_sp)
337 return ret;
338
339 ClangASTType complete_class(complete_objc_class_type_sp->GetClangAST(),
340 complete_objc_class_type_sp->GetClangFullType());
341
342 if (!ClangASTContext::GetCompleteType(complete_class.GetASTContext(),
343 complete_class.GetOpaqueQualType()))
344 return ret;
345
346 if (is_pointer_type)
347 {
348 clang_type_t pointer_type = ClangASTContext::CreatePointerType(complete_class.GetASTContext(),
349 complete_class.GetOpaqueQualType());
350
351 m_override_type = ClangASTType(complete_class.GetASTContext(),
352 pointer_type);
353 }
354 else
355 {
356 m_override_type = complete_class;
357 }
358
Sean Callanan356e17c2012-03-30 02:04:38 +0000359 if (m_override_type.IsValid())
360 return m_override_type;
361 else
362 return ret;
Sean Callanan72772842012-02-22 23:57:45 +0000363}
364
365clang::ASTContext *
366ValueObject::GetClangAST ()
367{
368 ClangASTType type = MaybeCalculateCompleteType();
369
370 return type.GetASTContext();
371}
372
373lldb::clang_type_t
374ValueObject::GetClangType ()
375{
376 ClangASTType type = MaybeCalculateCompleteType();
377
378 return type.GetOpaqueQualType();
379}
380
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000381DataExtractor &
382ValueObject::GetDataExtractor ()
383{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000384 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000385 return m_data;
386}
387
388const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000389ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000390{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000391 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000392 return m_error;
393}
394
395const ConstString &
396ValueObject::GetName() const
397{
398 return m_name;
399}
400
401const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000402ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000403{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000404 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000405 {
406 if (m_location_str.empty())
407 {
408 StreamString sstr;
409
410 switch (m_value.GetValueType())
411 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000412 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +0000413 case Value::eValueTypeVector:
Greg Clayton526e5af2010-11-13 03:52:47 +0000414 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000415 {
416 RegisterInfo *reg_info = m_value.GetRegisterInfo();
417 if (reg_info)
418 {
419 if (reg_info->name)
420 m_location_str = reg_info->name;
421 else if (reg_info->alt_name)
422 m_location_str = reg_info->alt_name;
Greg Clayton0665a0f2012-10-30 18:18:43 +0000423
424 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000425 }
426 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000427 break;
428
429 case Value::eValueTypeLoadAddress:
430 case Value::eValueTypeFileAddress:
431 case Value::eValueTypeHostAddress:
432 {
433 uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2;
434 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
435 m_location_str.swap(sstr.GetString());
436 }
437 break;
438 }
439 }
440 }
441 return m_location_str.c_str();
442}
443
444Value &
445ValueObject::GetValue()
446{
447 return m_value;
448}
449
450const Value &
451ValueObject::GetValue() const
452{
453 return m_value;
454}
455
456bool
Jim Ingham6035b672011-03-31 00:19:25 +0000457ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000458{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000459 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
460 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000461 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000462 Value tmp_value(m_value);
463 scalar = tmp_value.ResolveValue(&exe_ctx, GetClangAST ());
Greg Claytondcad5022011-12-29 01:26:56 +0000464 if (scalar.IsValid())
465 {
466 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
467 if (bitfield_bit_size)
468 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
469 return true;
470 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000471 }
Greg Claytondcad5022011-12-29 01:26:56 +0000472 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000473}
474
475bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000476ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000477{
Greg Clayton288bdf92010-09-02 02:59:18 +0000478 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000479}
480
481
482void
483ValueObject::SetValueIsValid (bool b)
484{
Greg Clayton288bdf92010-09-02 02:59:18 +0000485 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000486}
487
488bool
Jim Ingham6035b672011-03-31 00:19:25 +0000489ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000490{
Jim Ingham6035b672011-03-31 00:19:25 +0000491 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000492 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000493}
494
495void
496ValueObject::SetValueDidChange (bool value_changed)
497{
Greg Clayton288bdf92010-09-02 02:59:18 +0000498 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000499}
500
501ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000502ValueObject::GetChildAtIndex (size_t idx, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000503{
504 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000505 // We may need to update our value if we are dynamic
506 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000507 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000508 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000509 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000510 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000511 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000512 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000513 // No we haven't created the child at this index, so lets have our
514 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000515 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000516 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000517
Enrico Granata9d60f602012-03-09 03:09:58 +0000518 ValueObject* child = m_children.GetChildAtIndex(idx);
519 if (child != NULL)
520 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000521 }
522 return child_sp;
523}
524
Enrico Granata3309d882013-01-12 01:00:22 +0000525ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000526ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
527 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000528{
529 if (idxs.size() == 0)
530 return GetSP();
531 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000532 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000533 {
534 root = root->GetChildAtIndex(idx, true);
535 if (!root)
536 {
537 if (index_of_error)
538 *index_of_error = idx;
539 return root;
540 }
541 }
542 return root;
543}
544
545ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000546ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
547 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000548{
549 if (idxs.size() == 0)
550 return GetSP();
551 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000552 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000553 {
554 root = root->GetChildAtIndex(idx.first, idx.second);
555 if (!root)
556 {
557 if (index_of_error)
558 *index_of_error = idx.first;
559 return root;
560 }
561 }
562 return root;
563}
564
565lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000566ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
567 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000568{
569 if (idxs.size() == 0)
570 return GetSP();
571 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000572 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000573 {
574 root = root->GetChildAtIndex(idx, true);
575 if (!root)
576 {
577 if (index_of_error)
578 *index_of_error = idx;
579 return root;
580 }
581 }
582 return root;
583}
584
585lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000586ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
587 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000588{
589 if (idxs.size() == 0)
590 return GetSP();
591 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000592 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000593 {
594 root = root->GetChildAtIndex(idx.first, idx.second);
595 if (!root)
596 {
597 if (index_of_error)
598 *index_of_error = idx.first;
599 return root;
600 }
601 }
602 return root;
603}
604
Greg Claytonc7bece562013-01-25 18:06:21 +0000605size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000606ValueObject::GetIndexOfChildWithName (const ConstString &name)
607{
608 bool omit_empty_base_classes = true;
609 return ClangASTContext::GetIndexOfChildWithName (GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +0000610 GetClangType(),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000611 name.GetCString(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000612 omit_empty_base_classes);
613}
614
615ValueObjectSP
616ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
617{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000618 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000619 // classes (which really aren't part of the expression path), so we
620 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000621 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000622
Greg Claytondea8cb42011-06-29 22:09:02 +0000623 // We may need to update our value if we are dynamic
624 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000625 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000626
627 std::vector<uint32_t> child_indexes;
628 clang::ASTContext *clang_ast = GetClangAST();
629 void *clang_type = GetClangType();
630 bool omit_empty_base_classes = true;
631 const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast,
632 clang_type,
633 name.GetCString(),
634 omit_empty_base_classes,
635 child_indexes);
636 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000637 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000638 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
639 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
640
641 child_sp = GetChildAtIndex(*pos, can_create);
642 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000643 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000644 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000645 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000646 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
647 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000648 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000649 else
650 {
651 child_sp.reset();
652 }
653
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000654 }
655 }
656 return child_sp;
657}
658
659
Greg Claytonc7bece562013-01-25 18:06:21 +0000660size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000661ValueObject::GetNumChildren ()
662{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000663 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000664 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000665 {
666 SetNumChildren (CalculateNumChildren());
667 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000668 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000669}
Greg Clayton4a792072012-10-23 01:50:10 +0000670
671bool
672ValueObject::MightHaveChildren()
673{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000674 bool has_children = false;
Greg Clayton2452ab72013-02-08 22:02:02 +0000675 const uint32_t type_info = GetTypeInfo();
676 if (type_info)
Greg Clayton4a792072012-10-23 01:50:10 +0000677 {
Greg Clayton4a792072012-10-23 01:50:10 +0000678 if (type_info & (ClangASTContext::eTypeHasChildren |
679 ClangASTContext::eTypeIsPointer |
680 ClangASTContext::eTypeIsReference))
681 has_children = true;
682 }
683 else
684 {
685 has_children = GetNumChildren () > 0;
686 }
687 return has_children;
688}
689
690// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000691void
Greg Claytonc7bece562013-01-25 18:06:21 +0000692ValueObject::SetNumChildren (size_t num_children)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000693{
Greg Clayton288bdf92010-09-02 02:59:18 +0000694 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000695 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000696}
697
698void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000699ValueObject::SetName (const ConstString &name)
700{
701 m_name = name;
702}
703
Jim Ingham58b59f92011-04-22 23:53:53 +0000704ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000705ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000706{
Jim Ingham2eec4872011-05-07 00:10:58 +0000707 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000708
Greg Claytondea8cb42011-06-29 22:09:02 +0000709 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000710 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000711 std::string child_name_str;
712 uint32_t child_byte_size = 0;
713 int32_t child_byte_offset = 0;
714 uint32_t child_bitfield_bit_size = 0;
715 uint32_t child_bitfield_bit_offset = 0;
716 bool child_is_base_class = false;
717 bool child_is_deref_of_parent = false;
718
719 const bool transparent_pointers = synthetic_array_member == false;
720 clang::ASTContext *clang_ast = GetClangAST();
721 clang_type_t clang_type = GetClangType();
722 clang_type_t child_clang_type;
723
Greg Claytoncc4d0142012-02-17 07:49:44 +0000724 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000725
726 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
727 clang_ast,
728 GetName().GetCString(),
729 clang_type,
730 idx,
731 transparent_pointers,
732 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +0000733 ignore_array_bounds,
Greg Claytondea8cb42011-06-29 22:09:02 +0000734 child_name_str,
735 child_byte_size,
736 child_byte_offset,
737 child_bitfield_bit_size,
738 child_bitfield_bit_offset,
739 child_is_base_class,
740 child_is_deref_of_parent);
Greg Clayton4ef877f2012-12-06 02:33:54 +0000741 if (child_clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000742 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000743 if (synthetic_index)
744 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000745
Greg Claytondea8cb42011-06-29 22:09:02 +0000746 ConstString child_name;
747 if (!child_name_str.empty())
748 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000749
Greg Claytondea8cb42011-06-29 22:09:02 +0000750 valobj = new ValueObjectChild (*this,
751 clang_ast,
752 child_clang_type,
753 child_name,
754 child_byte_size,
755 child_byte_offset,
756 child_bitfield_bit_size,
757 child_bitfield_bit_offset,
758 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000759 child_is_deref_of_parent,
760 eAddressTypeInvalid);
761 //if (valobj)
762 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
763 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000764
Jim Ingham58b59f92011-04-22 23:53:53 +0000765 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000766}
767
Enrico Granata0c489f52012-03-01 04:24:26 +0000768bool
769ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
770 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000771{
Enrico Granata0c489f52012-03-01 04:24:26 +0000772 destination.clear();
773
774 // ideally we would like to bail out if passing NULL, but if we do so
775 // we end up not providing the summary for function pointers anymore
776 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
777 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000778
779 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000780
781 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
782 // information that we might care to see in a crash log. might be useful in very specific situations though.
783 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
784 GetTypeName().GetCString(),
785 GetName().GetCString(),
786 summary_ptr->GetDescription().c_str());*/
787
Enrico Granata0c489f52012-03-01 04:24:26 +0000788 if (UpdateValueIfNeeded (false))
789 {
790 if (summary_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000791 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000792 if (HasSyntheticValue())
793 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
794 summary_ptr->FormatObject(this, destination);
Enrico Granata0c489f52012-03-01 04:24:26 +0000795 }
796 else
797 {
798 clang_type_t clang_type = GetClangType();
799
800 // Do some default printout for function pointers
801 if (clang_type)
Enrico Granata4becb372011-06-29 22:27:15 +0000802 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000803 StreamString sstr;
804 clang_type_t elem_or_pointee_clang_type;
805 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
806 GetClangAST(),
807 &elem_or_pointee_clang_type));
808
809 if (ClangASTContext::IsFunctionPointerType (clang_type))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000810 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000811 AddressType func_ptr_address_type = eAddressTypeInvalid;
812 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
813 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000814 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000815 switch (func_ptr_address_type)
Jim Ingham6035b672011-03-31 00:19:25 +0000816 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000817 case eAddressTypeInvalid:
818 case eAddressTypeFile:
819 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000820
Greg Claytoncc4d0142012-02-17 07:49:44 +0000821 case eAddressTypeLoad:
Enrico Granata0c489f52012-03-01 04:24:26 +0000822 {
823 ExecutionContext exe_ctx (GetExecutionContextRef());
824
825 Address so_addr;
826 Target *target = exe_ctx.GetTargetPtr();
827 if (target && target->GetSectionLoadList().IsEmpty() == false)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000828 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000829 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000830 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000831 so_addr.Dump (&sstr,
832 exe_ctx.GetBestExecutionContextScope(),
833 Address::DumpStyleResolvedDescription,
834 Address::DumpStyleSectionNameOffset);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000835 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000836 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000837 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000838 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000839
Greg Claytoncc4d0142012-02-17 07:49:44 +0000840 case eAddressTypeHost:
841 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +0000842 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000843 }
844 if (sstr.GetSize() > 0)
845 {
846 destination.assign (1, '(');
847 destination.append (sstr.GetData(), sstr.GetSize());
848 destination.append (1, ')');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000849 }
850 }
851 }
852 }
853 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000854 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000855 return !destination.empty();
856}
857
858const char *
859ValueObject::GetSummaryAsCString ()
860{
861 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
862 {
863 GetSummaryAsCString(GetSummaryFormat().get(),
864 m_summary_str);
865 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000866 if (m_summary_str.empty())
867 return NULL;
868 return m_summary_str.c_str();
869}
870
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000871bool
872ValueObject::IsCStringContainer(bool check_pointer)
873{
874 clang_type_t elem_or_pointee_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +0000875 const Flags type_flags (GetTypeInfo (&elem_or_pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000876 bool is_char_arr_ptr (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
Greg Clayton2452ab72013-02-08 22:02:02 +0000877 ClangASTContext::IsCharType (elem_or_pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000878 if (!is_char_arr_ptr)
879 return false;
880 if (!check_pointer)
881 return true;
882 if (type_flags.Test(ClangASTContext::eTypeIsArray))
883 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000884 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000885 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000886 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000887 return (cstr_address != LLDB_INVALID_ADDRESS);
888}
889
Enrico Granata9128ee22011-09-06 19:20:51 +0000890size_t
891ValueObject::GetPointeeData (DataExtractor& data,
892 uint32_t item_idx,
893 uint32_t item_count)
894{
Greg Clayton2452ab72013-02-08 22:02:02 +0000895 clang_type_t pointee_or_element_clang_type;
896 const uint32_t type_info = GetTypeInfo (&pointee_or_element_clang_type);
897 const bool is_pointer_type = type_info & ClangASTContext::eTypeIsPointer;
898 const bool is_array_type = type_info & ClangASTContext::eTypeIsArray;
899 if (!(is_pointer_type || is_array_type))
Enrico Granata9128ee22011-09-06 19:20:51 +0000900 return 0;
901
902 if (item_count == 0)
903 return 0;
904
Greg Clayton2452ab72013-02-08 22:02:02 +0000905 clang::ASTContext *ast = GetClangAST();
906 ClangASTType pointee_or_element_type(ast, pointee_or_element_clang_type);
Enrico Granata9128ee22011-09-06 19:20:51 +0000907
Greg Clayton2452ab72013-02-08 22:02:02 +0000908 const uint64_t item_type_size = pointee_or_element_type.GetClangTypeByteSize();
Enrico Granata9128ee22011-09-06 19:20:51 +0000909
910 const uint64_t bytes = item_count * item_type_size;
911
912 const uint64_t offset = item_idx * item_type_size;
913
914 if (item_idx == 0 && item_count == 1) // simply a deref
915 {
Greg Clayton2452ab72013-02-08 22:02:02 +0000916 if (is_pointer_type)
Enrico Granata9128ee22011-09-06 19:20:51 +0000917 {
918 Error error;
919 ValueObjectSP pointee_sp = Dereference(error);
920 if (error.Fail() || pointee_sp.get() == NULL)
921 return 0;
922 return pointee_sp->GetDataExtractor().Copy(data);
923 }
924 else
925 {
926 ValueObjectSP child_sp = GetChildAtIndex(0, true);
927 if (child_sp.get() == NULL)
928 return 0;
929 return child_sp->GetDataExtractor().Copy(data);
930 }
931 return true;
932 }
933 else /* (items > 1) */
934 {
935 Error error;
936 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
937 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
938
939 AddressType addr_type;
Greg Clayton2452ab72013-02-08 22:02:02 +0000940 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +0000941
Enrico Granata9128ee22011-09-06 19:20:51 +0000942 switch (addr_type)
943 {
944 case eAddressTypeFile:
945 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000946 ModuleSP module_sp (GetModule());
947 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000948 {
Enrico Granata9c2efe32012-08-07 01:49:34 +0000949 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +0000950 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +0000951 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000952 ExecutionContext exe_ctx (GetExecutionContextRef());
953 Target* target = exe_ctx.GetTargetPtr();
954 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +0000955 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000956 heap_buf_ptr->SetByteSize(bytes);
957 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
958 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +0000959 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000960 data.SetData(data_sp);
961 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +0000962 }
963 }
964 }
965 }
966 break;
967 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +0000968 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000969 ExecutionContext exe_ctx (GetExecutionContextRef());
970 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +0000971 if (process)
972 {
973 heap_buf_ptr->SetByteSize(bytes);
974 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
975 if (error.Success())
976 {
977 data.SetData(data_sp);
978 return bytes_read;
979 }
980 }
981 }
982 break;
983 case eAddressTypeHost:
984 {
Greg Clayton2452ab72013-02-08 22:02:02 +0000985 ClangASTType valobj_type(ast, GetClangType());
986 uint64_t max_bytes = valobj_type.GetClangTypeByteSize();
987 if (max_bytes > offset)
988 {
989 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
990 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
991 data.SetData(data_sp);
992 return bytes_read;
993 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000994 }
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++;
Greg Clayton2452ab72013-02-08 22:02:02 +00001034 if (len >= maxlen)
Greg Clayton8dd5c172011-10-05 22:19:51 +00001035 return maxlen_value;
1036 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001037 }
1038 return len;
1039}
1040
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001041size_t
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
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001054 size_t bytes_read = 0;
1055 size_t total_bytes_read = 0;
1056
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001057 clang_type_t clang_type = GetClangType();
1058 clang_type_t elem_or_pointee_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001059 const Flags type_flags (GetTypeInfo (&elem_or_pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001060 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
1061 ClangASTContext::IsCharType (elem_or_pointee_clang_type))
1062 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001063 if (target == NULL)
1064 {
1065 s << "<no target to read from>";
1066 }
1067 else
1068 {
1069 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1070 AddressType cstr_address_type = eAddressTypeInvalid;
1071
1072 size_t cstr_len = 0;
1073 bool capped_data = false;
1074 if (type_flags.Test (ClangASTContext::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001075 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001076 // We have an array
1077 cstr_len = ClangASTContext::GetArraySize (clang_type);
1078 if (cstr_len > max_length)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001079 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001080 capped_data = true;
1081 cstr_len = max_length;
1082 }
1083 cstr_address = GetAddressOf (true, &cstr_address_type);
1084 }
1085 else
1086 {
1087 // We have a pointer
1088 cstr_address = GetPointerValue (&cstr_address_type);
1089 }
1090 if (cstr_address != 0 && cstr_address != LLDB_INVALID_ADDRESS)
1091 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001092 Address cstr_so_addr (cstr_address);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001093 DataExtractor data;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001094 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 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001102 total_bytes_read = bytes_read;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001103 s << '"';
1104 data.Dump (&s,
1105 0, // Start offset in "data"
1106 item_format,
1107 1, // Size of item (1 byte for a char!)
1108 bytes_read, // How many bytes to print?
1109 UINT32_MAX, // num per line
1110 LLDB_INVALID_ADDRESS,// base address
1111 0, // bitfield bit size
1112 0); // bitfield bit offset
1113 if (capped_data)
1114 s << "...";
1115 s << '"';
1116 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00001117 }
1118 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001119 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001120 cstr_len = max_length;
1121 const size_t k_max_buf_size = 64;
1122
1123 size_t offset = 0;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001124
Greg Claytoncc4d0142012-02-17 07:49:44 +00001125 int cstr_len_displayed = -1;
1126 bool capped_cstr = false;
1127 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1128 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1129 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001130 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001131 total_bytes_read += bytes_read;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001132 const char *cstr = data.PeekCStr(0);
1133 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1134 if (len > k_max_buf_size)
1135 len = k_max_buf_size;
1136 if (cstr && cstr_len_displayed < 0)
1137 s << '"';
1138
1139 if (cstr_len_displayed < 0)
1140 cstr_len_displayed = len;
1141
1142 if (len == 0)
1143 break;
1144 cstr_len_displayed += len;
1145 if (len > bytes_read)
1146 len = bytes_read;
1147 if (len > cstr_len)
1148 len = cstr_len;
1149
1150 data.Dump (&s,
1151 0, // Start offset in "data"
1152 item_format,
1153 1, // Size of item (1 byte for a char!)
1154 len, // How many bytes to print?
1155 UINT32_MAX, // num per line
1156 LLDB_INVALID_ADDRESS,// base address
1157 0, // bitfield bit size
1158 0); // bitfield bit offset
1159
1160 if (len < k_max_buf_size)
1161 break;
1162
1163 if (len >= cstr_len)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001164 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001165 capped_cstr = true;
1166 break;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001167 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001168
1169 cstr_len -= len;
1170 offset += len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001171 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001172
1173 if (cstr_len_displayed >= 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001174 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001175 s << '"';
1176 if (capped_cstr)
1177 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001178 }
1179 }
1180 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001181 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001182 }
1183 else
1184 {
1185 error.SetErrorString("impossible to read a string from this object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001186 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001187 }
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001188 return total_bytes_read;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001189}
1190
Jim Ingham53c47f12010-09-10 23:12:17 +00001191const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001192ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001193{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001194
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001195 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001196 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001197
1198 if (!m_object_desc_str.empty())
1199 return m_object_desc_str.c_str();
1200
Greg Claytoncc4d0142012-02-17 07:49:44 +00001201 ExecutionContext exe_ctx (GetExecutionContextRef());
1202 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001203 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001204 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001205
Jim Ingham53c47f12010-09-10 23:12:17 +00001206 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001207
Greg Claytonafacd142011-09-02 01:15:17 +00001208 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001209 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1210
Jim Inghama2cf2632010-12-23 02:29:54 +00001211 if (runtime == NULL)
1212 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001213 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Jim Inghama2cf2632010-12-23 02:29:54 +00001214 clang_type_t opaque_qual_type = GetClangType();
1215 if (opaque_qual_type != NULL)
1216 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001217 bool is_signed;
1218 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed)
1219 || ClangASTContext::IsPointerType (opaque_qual_type))
1220 {
Greg Claytonafacd142011-09-02 01:15:17 +00001221 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001222 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001223 }
1224 }
1225
Jim Ingham8d543de2011-03-31 23:01:21 +00001226 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001227 {
1228 m_object_desc_str.append (s.GetData());
1229 }
Sean Callanan672ad942010-10-23 00:18:49 +00001230
1231 if (m_object_desc_str.empty())
1232 return NULL;
1233 else
1234 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001235}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001236
Enrico Granata0c489f52012-03-01 04:24:26 +00001237bool
1238ValueObject::GetValueAsCString (lldb::Format format,
1239 std::string& destination)
1240{
1241 if (ClangASTContext::IsAggregateType (GetClangType()) == false &&
1242 UpdateValueIfNeeded(false))
1243 {
1244 const Value::ContextType context_type = m_value.GetContextType();
1245
1246 switch (context_type)
1247 {
1248 case Value::eContextTypeClangType:
1249 case Value::eContextTypeLLDBType:
1250 case Value::eContextTypeVariable:
1251 {
1252 clang_type_t clang_type = GetClangType ();
1253 if (clang_type)
1254 {
1255 StreamString sstr;
1256 ExecutionContext exe_ctx (GetExecutionContextRef());
1257 ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
1258 clang_type, // The clang type to display
1259 &sstr,
1260 format, // Format to display this type with
1261 m_data, // Data to extract from
1262 0, // Byte offset into "m_data"
1263 GetByteSize(), // Byte size of item in "m_data"
1264 GetBitfieldBitSize(), // Bitfield bit size
1265 GetBitfieldBitOffset(), // Bitfield bit offset
1266 exe_ctx.GetBestExecutionContextScope());
1267 // Don't set the m_error to anything here otherwise
1268 // we won't be able to re-format as anything else. The
1269 // code for ClangASTType::DumpTypeValue() should always
1270 // return something, even if that something contains
1271 // an error messsage. "m_error" is used to detect errors
1272 // when reading the valid object, not for formatting errors.
1273 if (sstr.GetString().empty())
1274 destination.clear();
1275 else
1276 destination.swap(sstr.GetString());
1277 }
1278 }
1279 break;
1280
1281 case Value::eContextTypeRegisterInfo:
1282 {
1283 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1284 if (reg_info)
1285 {
1286 ExecutionContext exe_ctx (GetExecutionContextRef());
1287
1288 StreamString reg_sstr;
1289 m_data.Dump (&reg_sstr,
1290 0,
1291 format,
1292 reg_info->byte_size,
1293 1,
1294 UINT32_MAX,
1295 LLDB_INVALID_ADDRESS,
1296 0,
1297 0,
1298 exe_ctx.GetBestExecutionContextScope());
1299 destination.swap(reg_sstr.GetString());
1300 }
1301 }
1302 break;
1303
1304 default:
1305 break;
1306 }
1307 return !destination.empty();
1308 }
1309 else
1310 return false;
1311}
1312
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001313const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001314ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001315{
Enrico Granata0c489f52012-03-01 04:24:26 +00001316 if (UpdateValueIfNeeded(true) && m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001317 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001318 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001319 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001320 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001321 if (m_type_format_sp)
1322 my_format = m_type_format_sp->GetFormat();
1323 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001324 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001325 if (m_is_bitfield_for_scalar)
1326 my_format = eFormatUnsigned;
1327 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001328 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001329 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001330 {
1331 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1332 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001333 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001334 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001335 else
1336 {
1337 clang_type_t clang_type = GetClangType ();
1338 my_format = ClangASTType::GetFormat(clang_type);
1339 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001340 }
1341 }
1342 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001343 if (GetValueAsCString(my_format, m_value_str))
1344 {
1345 if (!m_value_did_change && m_old_value_valid)
1346 {
1347 // The value was gotten successfully, so we consider the
1348 // value as changed if the value string differs
1349 SetValueDidChange (m_old_value_str != m_value_str);
1350 }
1351 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001352 }
1353 if (m_value_str.empty())
1354 return NULL;
1355 return m_value_str.c_str();
1356}
1357
Enrico Granatac3e320a2011-08-02 17:27:39 +00001358// if > 8bytes, 0 is returned. this method should mostly be used
1359// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001360uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001361ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001362{
1363 // If our byte size is zero this is an aggregate type that has children
1364 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
1365 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001366 Scalar scalar;
1367 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001368 {
1369 if (success)
1370 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001371 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001372 }
1373 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001374 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001375
1376 if (success)
1377 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001378 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001379}
1380
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001381// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1382// this call up to date by returning true for your new special cases. We will eventually move
1383// to checking this call result before trying to display special cases
1384bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001385ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1386 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001387{
1388 clang_type_t elem_or_pointee_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001389 Flags flags(GetTypeInfo(&elem_or_pointee_type));
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001390
1391 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001392 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001393 {
1394 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001395 (custom_format == eFormatCString ||
1396 custom_format == eFormatCharArray ||
1397 custom_format == eFormatChar ||
1398 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001399 return true;
1400
1401 if (flags.Test(ClangASTContext::eTypeIsArray))
1402 {
Greg Claytonafacd142011-09-02 01:15:17 +00001403 if ((custom_format == eFormatBytes) ||
1404 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001405 return true;
1406
Greg Claytonafacd142011-09-02 01:15:17 +00001407 if ((custom_format == eFormatVectorOfChar) ||
1408 (custom_format == eFormatVectorOfFloat32) ||
1409 (custom_format == eFormatVectorOfFloat64) ||
1410 (custom_format == eFormatVectorOfSInt16) ||
1411 (custom_format == eFormatVectorOfSInt32) ||
1412 (custom_format == eFormatVectorOfSInt64) ||
1413 (custom_format == eFormatVectorOfSInt8) ||
1414 (custom_format == eFormatVectorOfUInt128) ||
1415 (custom_format == eFormatVectorOfUInt16) ||
1416 (custom_format == eFormatVectorOfUInt32) ||
1417 (custom_format == eFormatVectorOfUInt64) ||
1418 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001419 return true;
1420 }
1421 }
1422 return false;
1423}
1424
Enrico Granata9fc19442011-07-06 02:13:41 +00001425bool
1426ValueObject::DumpPrintableRepresentation(Stream& s,
1427 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001428 Format custom_format,
Enrico Granata86cc9822012-03-19 22:58:49 +00001429 PrintableRepresentationSpecialCases special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001430{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001431
1432 clang_type_t elem_or_pointee_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001433 Flags flags(GetTypeInfo(&elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001434
Enrico Granata86cc9822012-03-19 22:58:49 +00001435 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1436 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1437
1438 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001439 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001440 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1441 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001442 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001443 // when being asked to get a printable display an array or pointer type directly,
1444 // try to "do the right thing"
1445
1446 if (IsCStringContainer(true) &&
1447 (custom_format == eFormatCString ||
1448 custom_format == eFormatCharArray ||
1449 custom_format == eFormatChar ||
1450 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001451 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001452 Error error;
1453 ReadPointedString(s,
1454 error,
1455 0,
1456 (custom_format == eFormatVectorOfChar) ||
1457 (custom_format == eFormatCharArray));
1458 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001459 }
1460
Enrico Granata86cc9822012-03-19 22:58:49 +00001461 if (custom_format == eFormatEnum)
1462 return false;
1463
1464 // this only works for arrays, because I have no way to know when
1465 // the pointed memory ends, and no special \0 end of data marker
1466 if (flags.Test(ClangASTContext::eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001467 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001468 if ((custom_format == eFormatBytes) ||
1469 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001470 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001471 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001472
1473 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001474 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001475 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001476
1477 if (low)
1478 s << ',';
1479
1480 ValueObjectSP child = GetChildAtIndex(low,true);
1481 if (!child.get())
1482 {
1483 s << "<invalid child>";
1484 continue;
1485 }
1486 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1487 }
1488
1489 s << ']';
1490
1491 return true;
1492 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001493
Enrico Granata86cc9822012-03-19 22:58:49 +00001494 if ((custom_format == eFormatVectorOfChar) ||
1495 (custom_format == eFormatVectorOfFloat32) ||
1496 (custom_format == eFormatVectorOfFloat64) ||
1497 (custom_format == eFormatVectorOfSInt16) ||
1498 (custom_format == eFormatVectorOfSInt32) ||
1499 (custom_format == eFormatVectorOfSInt64) ||
1500 (custom_format == eFormatVectorOfSInt8) ||
1501 (custom_format == eFormatVectorOfUInt128) ||
1502 (custom_format == eFormatVectorOfUInt16) ||
1503 (custom_format == eFormatVectorOfUInt32) ||
1504 (custom_format == eFormatVectorOfUInt64) ||
1505 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1506 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001507 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001508
1509 Format format = FormatManager::GetSingleItemFormat(custom_format);
1510
1511 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001512 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001513 {
1514
1515 if (low)
1516 s << ',';
1517
1518 ValueObjectSP child = GetChildAtIndex(low,true);
1519 if (!child.get())
1520 {
1521 s << "<invalid child>";
1522 continue;
1523 }
1524 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1525 }
1526
1527 s << ']';
1528
1529 return true;
1530 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001531 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001532
1533 if ((custom_format == eFormatBoolean) ||
1534 (custom_format == eFormatBinary) ||
1535 (custom_format == eFormatChar) ||
1536 (custom_format == eFormatCharPrintable) ||
1537 (custom_format == eFormatComplexFloat) ||
1538 (custom_format == eFormatDecimal) ||
1539 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001540 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001541 (custom_format == eFormatFloat) ||
1542 (custom_format == eFormatOctal) ||
1543 (custom_format == eFormatOSType) ||
1544 (custom_format == eFormatUnicode16) ||
1545 (custom_format == eFormatUnicode32) ||
1546 (custom_format == eFormatUnsigned) ||
1547 (custom_format == eFormatPointer) ||
1548 (custom_format == eFormatComplexInteger) ||
1549 (custom_format == eFormatComplex) ||
1550 (custom_format == eFormatDefault)) // use the [] operator
1551 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001552 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001553 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001554
1555 if (only_special)
1556 return false;
1557
Enrico Granata86cc9822012-03-19 22:58:49 +00001558 bool var_success = false;
1559
1560 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001561 const char *cstr = NULL;
1562 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001563
1564 if (custom_format != eFormatInvalid)
1565 SetFormat(custom_format);
1566
1567 switch(val_obj_display)
1568 {
1569 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001570 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001571 break;
1572
1573 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001574 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001575 break;
1576
1577 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001578 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001579 break;
1580
1581 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001582 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001583 break;
1584
1585 case eValueObjectRepresentationStyleChildrenCount:
Greg Claytonc7bece562013-01-25 18:06:21 +00001586 strm.Printf("%zu", GetNumChildren());
1587 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001588 break;
1589
1590 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001591 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001592 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001593 }
1594
Greg Claytonc7bece562013-01-25 18:06:21 +00001595 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001596 {
1597 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001598 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001599 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1600 {
1601 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1602 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001603 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1604 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001605 }
1606 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001607 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001608 }
1609 }
1610
Greg Claytonc7bece562013-01-25 18:06:21 +00001611 if (cstr)
1612 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001613 else
1614 {
1615 if (m_error.Fail())
1616 s.Printf("<%s>", m_error.AsCString());
1617 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1618 s.PutCString("<no summary available>");
1619 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1620 s.PutCString("<no value available>");
1621 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1622 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1623 else
1624 s.PutCString("<no printable representation>");
1625 }
1626
1627 // we should only return false here if we could not do *anything*
1628 // even if we have an error message as output, that's a success
1629 // from our callers' perspective, so return true
1630 var_success = true;
1631
1632 if (custom_format != eFormatInvalid)
1633 SetFormat(eFormatDefault);
1634 }
1635
Enrico Granataf4efecd2011-07-12 22:56:10 +00001636 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001637}
1638
Greg Clayton737b9322010-09-13 03:32:57 +00001639addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001640ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001641{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001642 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001643 return LLDB_INVALID_ADDRESS;
1644
Greg Clayton73b472d2010-10-27 03:32:59 +00001645 switch (m_value.GetValueType())
1646 {
1647 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001648 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001649 if (scalar_is_load_address)
1650 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001651 if(address_type)
1652 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001653 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1654 }
1655 break;
1656
1657 case Value::eValueTypeLoadAddress:
1658 case Value::eValueTypeFileAddress:
1659 case Value::eValueTypeHostAddress:
1660 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001661 if(address_type)
1662 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001663 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1664 }
1665 break;
1666 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001667 if (address_type)
1668 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001669 return LLDB_INVALID_ADDRESS;
1670}
1671
1672addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001673ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001674{
Greg Claytonafacd142011-09-02 01:15:17 +00001675 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001676 if(address_type)
1677 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001678
Enrico Granatac3e320a2011-08-02 17:27:39 +00001679 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001680 return address;
1681
Greg Clayton73b472d2010-10-27 03:32:59 +00001682 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001683 {
1684 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001685 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001686 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001687 break;
1688
Enrico Granata9128ee22011-09-06 19:20:51 +00001689 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001690 case Value::eValueTypeLoadAddress:
1691 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001692 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001693 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001694 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001695 }
1696 break;
1697 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001698
Enrico Granata9128ee22011-09-06 19:20:51 +00001699 if (address_type)
1700 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001701
Greg Clayton737b9322010-09-13 03:32:57 +00001702 return address;
1703}
1704
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001705bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001706ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001707{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001708 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001709 // Make sure our value is up to date first so that our location and location
1710 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001711 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001712 {
1713 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001714 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001715 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001716
1717 uint32_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001718 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001719
Greg Claytonb1320972010-07-14 00:18:15 +00001720 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001721
Jim Ingham16e0c682011-08-12 23:34:31 +00001722 Value::ValueType value_type = m_value.GetValueType();
1723
1724 if (value_type == Value::eValueTypeScalar)
1725 {
1726 // If the value is already a scalar, then let the scalar change itself:
1727 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1728 }
1729 else if (byte_size <= Scalar::GetMaxByteSize())
1730 {
1731 // If the value fits in a scalar, then make a new scalar and again let the
1732 // scalar code do the conversion, then figure out where to put the new value.
1733 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001734 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1735 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001736 {
Jim Ingham4b536182011-08-09 02:12:22 +00001737 switch (value_type)
1738 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001739 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001740 {
1741 // If it is a load address, then the scalar value is the storage location
1742 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001743 ExecutionContext exe_ctx (GetExecutionContextRef());
1744 Process *process = exe_ctx.GetProcessPtr();
1745 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001746 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001747 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001748 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1749 new_scalar,
1750 byte_size,
1751 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001752 if (!error.Success())
1753 return false;
1754 if (bytes_written != byte_size)
1755 {
1756 error.SetErrorString("unable to write value to memory");
1757 return false;
1758 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001759 }
1760 }
Jim Ingham4b536182011-08-09 02:12:22 +00001761 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001762 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001763 {
1764 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1765 DataExtractor new_data;
1766 new_data.SetByteOrder (m_data.GetByteOrder());
1767
1768 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1769 m_data.SetData(buffer_sp, 0);
1770 bool success = new_scalar.GetData(new_data);
1771 if (success)
1772 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001773 new_data.CopyByteOrderedData (0,
1774 byte_size,
1775 const_cast<uint8_t *>(m_data.GetDataStart()),
1776 byte_size,
1777 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001778 }
1779 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1780
1781 }
Jim Ingham4b536182011-08-09 02:12:22 +00001782 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001783 case Value::eValueTypeFileAddress:
1784 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001785 case Value::eValueTypeVector:
1786 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001787 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001788 }
1789 else
1790 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001791 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001792 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001793 }
1794 else
1795 {
1796 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001797 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001798 return false;
1799 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001800
1801 // If we have reached this point, then we have successfully changed the value.
1802 SetNeedsUpdate();
1803 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001804}
1805
Greg Clayton81e871e2012-02-04 02:27:34 +00001806bool
1807ValueObject::GetDeclaration (Declaration &decl)
1808{
1809 decl.Clear();
1810 return false;
1811}
1812
Greg Clayton84db9102012-03-26 23:03:23 +00001813ConstString
1814ValueObject::GetTypeName()
1815{
1816 return ClangASTType::GetConstTypeName (GetClangAST(), GetClangType());
1817}
1818
1819ConstString
1820ValueObject::GetQualifiedTypeName()
1821{
1822 return ClangASTType::GetConstQualifiedTypeName (GetClangAST(), GetClangType());
1823}
1824
1825
Greg Claytonafacd142011-09-02 01:15:17 +00001826LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001827ValueObject::GetObjectRuntimeLanguage ()
1828{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001829 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1830 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001831}
1832
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001833void
Jim Ingham58b59f92011-04-22 23:53:53 +00001834ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001835{
Jim Ingham58b59f92011-04-22 23:53:53 +00001836 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001837}
1838
1839ValueObjectSP
1840ValueObject::GetSyntheticChild (const ConstString &key) const
1841{
1842 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001843 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001844 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001845 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001846 return synthetic_child_sp;
1847}
1848
Greg Clayton2452ab72013-02-08 22:02:02 +00001849uint32_t
1850ValueObject::GetTypeInfo (clang_type_t *pointee_or_element_clang_type)
1851{
1852 return ClangASTContext::GetTypeInfo (GetClangType(), GetClangAST(), pointee_or_element_clang_type);
1853}
1854
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001855bool
1856ValueObject::IsPointerType ()
1857{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001858 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001859}
1860
Jim Inghamb7603bb2011-03-18 00:05:18 +00001861bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001862ValueObject::IsArrayType ()
1863{
Greg Clayton4ef877f2012-12-06 02:33:54 +00001864 return ClangASTContext::IsArrayType (GetClangType(), NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00001865}
1866
1867bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001868ValueObject::IsScalarType ()
1869{
1870 return ClangASTContext::IsScalarType (GetClangType());
1871}
1872
1873bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001874ValueObject::IsIntegerType (bool &is_signed)
1875{
1876 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1877}
Greg Clayton73b472d2010-10-27 03:32:59 +00001878
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001879bool
1880ValueObject::IsPointerOrReferenceType ()
1881{
Greg Clayton007d5be2011-05-30 00:49:24 +00001882 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1883}
1884
1885bool
Greg Claytondea8cb42011-06-29 22:09:02 +00001886ValueObject::IsPossibleDynamicType ()
1887{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00001888 ExecutionContext exe_ctx (GetExecutionContextRef());
1889 Process *process = exe_ctx.GetProcessPtr();
1890 if (process)
1891 return process->IsPossibleDynamicValue(*this);
1892 else
Greg Clayton70364252012-08-31 18:56:24 +00001893 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType(), NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00001894}
1895
Enrico Granata9e7b3882012-12-13 23:50:33 +00001896bool
1897ValueObject::IsObjCNil ()
1898{
1899 bool isObjCpointer = ClangASTContext::IsObjCObjectPointerType(GetClangType(), NULL);
1900 bool canReadValue = true;
1901 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
1902 return canReadValue && isZero && isObjCpointer;
1903}
1904
Greg Claytonafacd142011-09-02 01:15:17 +00001905ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00001906ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001907{
Greg Clayton2452ab72013-02-08 22:02:02 +00001908 const uint32_t type_info = GetTypeInfo ();
1909 if (type_info & ClangASTContext::eTypeIsArray)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001910 return GetSyntheticArrayMemberFromArray(index, can_create);
1911
Greg Clayton2452ab72013-02-08 22:02:02 +00001912 if (type_info & ClangASTContext::eTypeIsPointer)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001913 return GetSyntheticArrayMemberFromPointer(index, can_create);
1914
1915 return ValueObjectSP();
1916
1917}
1918
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001919ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00001920ValueObject::GetSyntheticArrayMemberFromPointer (size_t index, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001921{
1922 ValueObjectSP synthetic_child_sp;
1923 if (IsPointerType ())
1924 {
1925 char index_str[64];
Greg Claytonc7bece562013-01-25 18:06:21 +00001926 snprintf(index_str, sizeof(index_str), "[%zu]", index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001927 ConstString index_const_str(index_str);
1928 // Check if we have already created a synthetic array member in this
1929 // valid object. If we have we will re-use it.
1930 synthetic_child_sp = GetSyntheticChild (index_const_str);
1931 if (!synthetic_child_sp)
1932 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001933 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001934 // We haven't made a synthetic array member for INDEX yet, so
1935 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001936 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001937
1938 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001939 if (synthetic_child)
1940 {
1941 AddSyntheticChild(index_const_str, synthetic_child);
1942 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001943 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001944 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001945 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001946 }
1947 }
1948 return synthetic_child_sp;
1949}
Jim Ingham22777012010-09-23 02:01:19 +00001950
Greg Claytondaf515f2011-07-09 20:12:33 +00001951// This allows you to create an array member using and index
1952// that doesn't not fall in the normal bounds of the array.
1953// Many times structure can be defined as:
1954// struct Collection
1955// {
1956// uint32_t item_count;
1957// Item item_array[0];
1958// };
1959// The size of the "item_array" is 1, but many times in practice
1960// there are more items in "item_array".
1961
1962ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00001963ValueObject::GetSyntheticArrayMemberFromArray (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00001964{
1965 ValueObjectSP synthetic_child_sp;
1966 if (IsArrayType ())
1967 {
1968 char index_str[64];
Greg Claytonc7bece562013-01-25 18:06:21 +00001969 snprintf(index_str, sizeof(index_str), "[%zu]", index);
Greg Claytondaf515f2011-07-09 20:12:33 +00001970 ConstString index_const_str(index_str);
1971 // Check if we have already created a synthetic array member in this
1972 // valid object. If we have we will re-use it.
1973 synthetic_child_sp = GetSyntheticChild (index_const_str);
1974 if (!synthetic_child_sp)
1975 {
1976 ValueObject *synthetic_child;
1977 // We haven't made a synthetic array member for INDEX yet, so
1978 // lets make one and cache it for any future reference.
1979 synthetic_child = CreateChildAtIndex(0, true, index);
1980
1981 // Cache the value if we got one back...
1982 if (synthetic_child)
1983 {
1984 AddSyntheticChild(index_const_str, synthetic_child);
1985 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001986 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001987 synthetic_child_sp->m_is_array_item_for_pointer = true;
1988 }
1989 }
1990 }
1991 return synthetic_child_sp;
1992}
1993
Enrico Granata9fc19442011-07-06 02:13:41 +00001994ValueObjectSP
1995ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1996{
1997 ValueObjectSP synthetic_child_sp;
1998 if (IsScalarType ())
1999 {
2000 char index_str[64];
2001 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2002 ConstString index_const_str(index_str);
2003 // Check if we have already created a synthetic array member in this
2004 // valid object. If we have we will re-use it.
2005 synthetic_child_sp = GetSyntheticChild (index_const_str);
2006 if (!synthetic_child_sp)
2007 {
2008 ValueObjectChild *synthetic_child;
2009 // We haven't made a synthetic array member for INDEX yet, so
2010 // lets make one and cache it for any future reference.
2011 synthetic_child = new ValueObjectChild(*this,
2012 GetClangAST(),
2013 GetClangType(),
2014 index_const_str,
2015 GetByteSize(),
2016 0,
2017 to-from+1,
2018 from,
2019 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002020 false,
2021 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002022
2023 // Cache the value if we got one back...
2024 if (synthetic_child)
2025 {
2026 AddSyntheticChild(index_const_str, synthetic_child);
2027 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002028 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002029 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2030 }
2031 }
2032 }
2033 return synthetic_child_sp;
2034}
2035
Greg Claytonafacd142011-09-02 01:15:17 +00002036ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00002037ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
2038{
2039
2040 ValueObjectSP synthetic_child_sp;
2041
2042 char name_str[64];
2043 snprintf(name_str, sizeof(name_str), "@%i", offset);
2044 ConstString name_const_str(name_str);
2045
2046 // Check if we have already created a synthetic array member in this
2047 // valid object. If we have we will re-use it.
2048 synthetic_child_sp = GetSyntheticChild (name_const_str);
2049
2050 if (synthetic_child_sp.get())
2051 return synthetic_child_sp;
2052
2053 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002054 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002055
2056 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2057 type.GetASTContext(),
2058 type.GetOpaqueQualType(),
2059 name_const_str,
2060 type.GetTypeByteSize(),
2061 offset,
2062 0,
2063 0,
2064 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002065 false,
2066 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002067 if (synthetic_child)
2068 {
2069 AddSyntheticChild(name_const_str, synthetic_child);
2070 synthetic_child_sp = synthetic_child->GetSP();
2071 synthetic_child_sp->SetName(name_const_str);
2072 synthetic_child_sp->m_is_child_at_offset = true;
2073 }
2074 return synthetic_child_sp;
2075}
2076
Enrico Granatad55546b2011-07-22 00:16:08 +00002077// your expression path needs to have a leading . or ->
2078// (unless it somehow "looks like" an array, in which case it has
2079// a leading [ symbol). while the [ is meaningful and should be shown
2080// to the user, . and -> are just parser design, but by no means
2081// added information for the user.. strip them off
2082static const char*
2083SkipLeadingExpressionPathSeparators(const char* expression)
2084{
2085 if (!expression || !expression[0])
2086 return expression;
2087 if (expression[0] == '.')
2088 return expression+1;
2089 if (expression[0] == '-' && expression[1] == '>')
2090 return expression+2;
2091 return expression;
2092}
2093
Greg Claytonafacd142011-09-02 01:15:17 +00002094ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002095ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2096{
2097 ValueObjectSP synthetic_child_sp;
2098 ConstString name_const_string(expression);
2099 // Check if we have already created a synthetic array member in this
2100 // valid object. If we have we will re-use it.
2101 synthetic_child_sp = GetSyntheticChild (name_const_string);
2102 if (!synthetic_child_sp)
2103 {
2104 // We haven't made a synthetic array member for expression yet, so
2105 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002106 synthetic_child_sp = GetValueForExpressionPath(expression,
2107 NULL, NULL, NULL,
2108 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
Enrico Granatad55546b2011-07-22 00:16:08 +00002109
2110 // Cache the value if we got one back...
2111 if (synthetic_child_sp.get())
2112 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002113 // FIXME: this causes a "real" child to end up with its name changed to the contents of expression
Enrico Granatad55546b2011-07-22 00:16:08 +00002114 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002115 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002116 }
2117 }
2118 return synthetic_child_sp;
2119}
2120
2121void
Enrico Granata86cc9822012-03-19 22:58:49 +00002122ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002123{
Enrico Granata86cc9822012-03-19 22:58:49 +00002124 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002125 return;
2126
Enrico Granatac5bc4122012-03-27 02:35:13 +00002127 TargetSP target_sp(GetTargetSP());
2128 if (target_sp && (target_sp->GetEnableSyntheticValue() == false || target_sp->GetSuppressSyntheticValue() == true))
2129 {
2130 m_synthetic_value = NULL;
2131 return;
2132 }
2133
Enrico Granatae3e91512012-10-22 18:18:36 +00002134 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2135
Enrico Granata5548cb52013-01-28 23:47:25 +00002136 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002137 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002138
Enrico Granata0c489f52012-03-01 04:24:26 +00002139 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002140 return;
2141
Enrico Granatae3e91512012-10-22 18:18:36 +00002142 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2143 return;
2144
Enrico Granata86cc9822012-03-19 22:58:49 +00002145 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002146}
2147
Jim Ingham78a685a2011-04-16 00:01:13 +00002148void
Greg Claytonafacd142011-09-02 01:15:17 +00002149ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002150{
Greg Claytonafacd142011-09-02 01:15:17 +00002151 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002152 return;
2153
Jim Ingham58b59f92011-04-22 23:53:53 +00002154 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002155 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002156 ExecutionContext exe_ctx (GetExecutionContextRef());
2157 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002158 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002159 {
2160 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002161 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002162 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002163 }
2164}
2165
Jim Ingham58b59f92011-04-22 23:53:53 +00002166ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002167ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002168{
Greg Claytonafacd142011-09-02 01:15:17 +00002169 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002170 return ValueObjectSP();
2171
2172 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002173 {
Jim Ingham2837b762011-05-04 03:43:18 +00002174 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002175 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002176 if (m_dynamic_value)
2177 return m_dynamic_value->GetSP();
2178 else
2179 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002180}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002181
Jim Ingham60dbabb2011-12-08 19:44:08 +00002182ValueObjectSP
2183ValueObject::GetStaticValue()
2184{
2185 return GetSP();
2186}
2187
Enrico Granata886147f2012-05-08 18:47:08 +00002188lldb::ValueObjectSP
2189ValueObject::GetNonSyntheticValue ()
2190{
2191 return GetSP();
2192}
2193
Enrico Granatad55546b2011-07-22 00:16:08 +00002194ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002195ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002196{
Enrico Granata86cc9822012-03-19 22:58:49 +00002197 if (use_synthetic == false)
2198 return ValueObjectSP();
2199
Enrico Granatad55546b2011-07-22 00:16:08 +00002200 CalculateSyntheticValue(use_synthetic);
2201
2202 if (m_synthetic_value)
2203 return m_synthetic_value->GetSP();
2204 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002205 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002206}
2207
Greg Claytone221f822011-01-21 01:59:00 +00002208bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002209ValueObject::HasSyntheticValue()
2210{
Enrico Granata5548cb52013-01-28 23:47:25 +00002211 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002212
Enrico Granata0c489f52012-03-01 04:24:26 +00002213 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002214 return false;
2215
Enrico Granata86cc9822012-03-19 22:58:49 +00002216 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002217
2218 if (m_synthetic_value)
2219 return true;
2220 else
2221 return false;
2222}
2223
2224bool
Greg Claytone221f822011-01-21 01:59:00 +00002225ValueObject::GetBaseClassPath (Stream &s)
2226{
2227 if (IsBaseClass())
2228 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002229 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00002230 clang_type_t clang_type = GetClangType();
2231 std::string cxx_class_name;
2232 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
2233 if (this_had_base_class)
2234 {
2235 if (parent_had_base_class)
2236 s.PutCString("::");
2237 s.PutCString(cxx_class_name.c_str());
2238 }
2239 return parent_had_base_class || this_had_base_class;
2240 }
2241 return false;
2242}
2243
2244
2245ValueObject *
2246ValueObject::GetNonBaseClassParent()
2247{
Jim Ingham78a685a2011-04-16 00:01:13 +00002248 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002249 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002250 if (GetParent()->IsBaseClass())
2251 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002252 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002253 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002254 }
2255 return NULL;
2256}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002257
2258void
Enrico Granata4becb372011-06-29 22:27:15 +00002259ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002260{
Greg Claytone221f822011-01-21 01:59:00 +00002261 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002262
Enrico Granata86cc9822012-03-19 22:58:49 +00002263 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002264 {
Enrico Granata4becb372011-06-29 22:27:15 +00002265 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2266 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2267 // the eHonorPointers mode is meant to produce strings in this latter format
2268 s.PutCString("*(");
2269 }
Greg Claytone221f822011-01-21 01:59:00 +00002270
Enrico Granata4becb372011-06-29 22:27:15 +00002271 ValueObject* parent = GetParent();
2272
2273 if (parent)
2274 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002275
2276 // if we are a deref_of_parent just because we are synthetic array
2277 // members made up to allow ptr[%d] syntax to work in variable
2278 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002279 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002280 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002281
Greg Claytone221f822011-01-21 01:59:00 +00002282 if (!IsBaseClass())
2283 {
2284 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002285 {
Greg Claytone221f822011-01-21 01:59:00 +00002286 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2287 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002288 {
Greg Claytone221f822011-01-21 01:59:00 +00002289 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2290 if (non_base_class_parent_clang_type)
2291 {
2292 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2293
Enrico Granata86cc9822012-03-19 22:58:49 +00002294 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002295 {
2296 s.PutCString("->");
2297 }
Enrico Granata4becb372011-06-29 22:27:15 +00002298 else
2299 {
2300 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2301 {
2302 s.PutCString("->");
2303 }
2304 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2305 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2306 {
2307 s.PutChar('.');
2308 }
Greg Claytone221f822011-01-21 01:59:00 +00002309 }
2310 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002311 }
Greg Claytone221f822011-01-21 01:59:00 +00002312
2313 const char *name = GetName().GetCString();
2314 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002315 {
Greg Claytone221f822011-01-21 01:59:00 +00002316 if (qualify_cxx_base_classes)
2317 {
2318 if (GetBaseClassPath (s))
2319 s.PutCString("::");
2320 }
2321 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002322 }
2323 }
2324 }
2325
Enrico Granata86cc9822012-03-19 22:58:49 +00002326 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002327 {
Greg Claytone221f822011-01-21 01:59:00 +00002328 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002329 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002330}
2331
Greg Claytonafacd142011-09-02 01:15:17 +00002332ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002333ValueObject::GetValueForExpressionPath(const char* expression,
2334 const char** first_unparsed,
2335 ExpressionPathScanEndReason* reason_to_stop,
2336 ExpressionPathEndResultType* final_value_type,
2337 const GetValueForExpressionPathOptions& options,
2338 ExpressionPathAftermath* final_task_on_target)
2339{
2340
2341 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002342 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2343 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002344 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002345
2346 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2347 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2348 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2349 final_value_type ? final_value_type : &dummy_final_value_type,
2350 options,
2351 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2352
Enrico Granata86cc9822012-03-19 22:58:49 +00002353 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002354 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002355
Enrico Granata86cc9822012-03-19 22:58:49 +00002356 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 +00002357 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002358 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002359 {
2360 Error error;
2361 ValueObjectSP final_value = ret_val->Dereference(error);
2362 if (error.Fail() || !final_value.get())
2363 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002364 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002365 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002366 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002367 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002368 return ValueObjectSP();
2369 }
2370 else
2371 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002372 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002373 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002374 return final_value;
2375 }
2376 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002377 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002378 {
2379 Error error;
2380 ValueObjectSP final_value = ret_val->AddressOf(error);
2381 if (error.Fail() || !final_value.get())
2382 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002383 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002384 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002385 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002386 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002387 return ValueObjectSP();
2388 }
2389 else
2390 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002391 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002392 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002393 return final_value;
2394 }
2395 }
2396 }
2397 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2398}
2399
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002400int
2401ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002402 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002403 const char** first_unparsed,
2404 ExpressionPathScanEndReason* reason_to_stop,
2405 ExpressionPathEndResultType* final_value_type,
2406 const GetValueForExpressionPathOptions& options,
2407 ExpressionPathAftermath* final_task_on_target)
2408{
2409 const char* dummy_first_unparsed;
2410 ExpressionPathScanEndReason dummy_reason_to_stop;
2411 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002412 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002413
2414 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2415 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2416 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2417 final_value_type ? final_value_type : &dummy_final_value_type,
2418 options,
2419 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2420
2421 if (!ret_val.get()) // if there are errors, I add nothing to the list
2422 return 0;
2423
Enrico Granata86ea8d82012-03-29 01:34:34 +00002424 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002425 {
2426 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002427 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002428 {
2429 list->Append(ret_val);
2430 return 1;
2431 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002432 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 +00002433 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002434 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002435 {
2436 Error error;
2437 ValueObjectSP final_value = ret_val->Dereference(error);
2438 if (error.Fail() || !final_value.get())
2439 {
Greg Clayton23f59502012-07-17 03:23:13 +00002440 if (reason_to_stop)
2441 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2442 if (final_value_type)
2443 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002444 return 0;
2445 }
2446 else
2447 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002448 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002449 list->Append(final_value);
2450 return 1;
2451 }
2452 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002453 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002454 {
2455 Error error;
2456 ValueObjectSP final_value = ret_val->AddressOf(error);
2457 if (error.Fail() || !final_value.get())
2458 {
Greg Clayton23f59502012-07-17 03:23:13 +00002459 if (reason_to_stop)
2460 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2461 if (final_value_type)
2462 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002463 return 0;
2464 }
2465 else
2466 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002467 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002468 list->Append(final_value);
2469 return 1;
2470 }
2471 }
2472 }
2473 }
2474 else
2475 {
2476 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2477 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2478 ret_val,
2479 list,
2480 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2481 final_value_type ? final_value_type : &dummy_final_value_type,
2482 options,
2483 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2484 }
2485 // in any non-covered case, just do the obviously right thing
2486 list->Append(ret_val);
2487 return 1;
2488}
2489
Greg Claytonafacd142011-09-02 01:15:17 +00002490ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002491ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2492 const char** first_unparsed,
2493 ExpressionPathScanEndReason* reason_to_stop,
2494 ExpressionPathEndResultType* final_result,
2495 const GetValueForExpressionPathOptions& options,
2496 ExpressionPathAftermath* what_next)
2497{
2498 ValueObjectSP root = GetSP();
2499
2500 if (!root.get())
2501 return ValueObjectSP();
2502
2503 *first_unparsed = expression_cstr;
2504
2505 while (true)
2506 {
2507
2508 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2509
Greg Claytonafacd142011-09-02 01:15:17 +00002510 clang_type_t root_clang_type = root->GetClangType();
2511 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002512 Flags root_clang_type_info,pointee_clang_type_info;
2513
2514 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2515 if (pointee_clang_type)
2516 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002517
2518 if (!expression_cstr || *expression_cstr == '\0')
2519 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002520 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002521 return root;
2522 }
2523
2524 switch (*expression_cstr)
2525 {
2526 case '-':
2527 {
2528 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002529 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 +00002530 {
2531 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002532 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2533 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002534 return ValueObjectSP();
2535 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002536 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2537 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002538 options.m_no_fragile_ivar)
2539 {
2540 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002541 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2542 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002543 return ValueObjectSP();
2544 }
2545 if (expression_cstr[1] != '>')
2546 {
2547 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002548 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2549 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002550 return ValueObjectSP();
2551 }
2552 expression_cstr++; // skip the -
2553 }
2554 case '.': // or fallthrough from ->
2555 {
2556 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002557 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 +00002558 {
2559 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002560 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2561 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002562 return ValueObjectSP();
2563 }
2564 expression_cstr++; // skip .
2565 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2566 ConstString child_name;
2567 if (!next_separator) // if no other separator just expand this last layer
2568 {
2569 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002570 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2571
2572 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002573 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002574 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002575 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2576 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002577 return child_valobj_sp;
2578 }
2579 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2580 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002581 if (root->IsSynthetic())
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002582 {
2583 *first_unparsed = expression_cstr;
2584 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2585 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2586 return ValueObjectSP();
2587 }
2588
2589 child_valobj_sp = root->GetSyntheticValue();
Enrico Granata86cc9822012-03-19 22:58:49 +00002590 if (child_valobj_sp.get())
2591 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002592 }
2593
2594 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2595 // so we hit the "else" branch, and return an error
2596 if(child_valobj_sp.get()) // if it worked, just return
2597 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002598 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002599 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2600 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002601 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002602 }
2603 else
2604 {
2605 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002606 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2607 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002608 return ValueObjectSP();
2609 }
2610 }
2611 else // other layers do expand
2612 {
2613 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002614 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2615 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002616 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002617 root = child_valobj_sp;
2618 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002619 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002620 continue;
2621 }
2622 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2623 {
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002624 if (root->IsSynthetic())
2625 {
2626 *first_unparsed = expression_cstr;
2627 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2628 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2629 return ValueObjectSP();
2630 }
2631
Enrico Granata86cc9822012-03-19 22:58:49 +00002632 child_valobj_sp = root->GetSyntheticValue(true);
2633 if (child_valobj_sp)
2634 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002635 }
2636
2637 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2638 // so we hit the "else" branch, and return an error
2639 if(child_valobj_sp.get()) // if it worked, move on
2640 {
2641 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002642 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002643 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002644 continue;
2645 }
2646 else
2647 {
2648 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002649 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2650 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002651 return ValueObjectSP();
2652 }
2653 }
2654 break;
2655 }
2656 case '[':
2657 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002658 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 +00002659 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002660 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002661 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002662 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2663 {
2664 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002665 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2666 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002667 return ValueObjectSP();
2668 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002669 }
2670 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2671 {
2672 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002673 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2674 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002675 return ValueObjectSP();
2676 }
2677 }
2678 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2679 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002680 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002681 {
2682 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002683 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2684 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002685 return ValueObjectSP();
2686 }
2687 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2688 {
2689 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002690 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2691 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002692 return root;
2693 }
2694 }
2695 const char *separator_position = ::strchr(expression_cstr+1,'-');
2696 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2697 if (!close_bracket_position) // if there is no ], this is a syntax error
2698 {
2699 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002700 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2701 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002702 return ValueObjectSP();
2703 }
2704 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2705 {
2706 char *end = NULL;
2707 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2708 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2709 {
2710 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002711 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2712 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002713 return ValueObjectSP();
2714 }
2715 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2716 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002717 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002718 {
2719 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002720 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2721 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002722 return root;
2723 }
2724 else
2725 {
2726 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002727 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2728 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002729 return ValueObjectSP();
2730 }
2731 }
2732 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002733 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002734 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002735 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2736 if (!child_valobj_sp)
2737 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002738 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002739 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2740 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002741 if (child_valobj_sp)
2742 {
2743 root = child_valobj_sp;
2744 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002745 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002746 continue;
2747 }
2748 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002749 {
2750 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002751 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2752 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002753 return ValueObjectSP();
2754 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002755 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002756 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002757 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002758 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 +00002759 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002760 {
2761 Error error;
2762 root = root->Dereference(error);
2763 if (error.Fail() || !root.get())
2764 {
2765 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002766 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2767 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002768 return ValueObjectSP();
2769 }
2770 else
2771 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002772 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002773 continue;
2774 }
2775 }
2776 else
2777 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002778 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Clayton84db9102012-03-26 23:03:23 +00002779 root->GetClangType()) == eLanguageTypeObjC
2780 && ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2781 && root->HasSyntheticValue()
2782 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002783 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002784 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002785 }
2786 else
2787 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002788 if (!root.get())
2789 {
2790 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002791 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2792 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002793 return ValueObjectSP();
2794 }
2795 else
2796 {
2797 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002798 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002799 continue;
2800 }
2801 }
2802 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002803 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002804 {
2805 root = root->GetSyntheticBitFieldChild(index, index, true);
2806 if (!root.get())
2807 {
2808 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002809 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2810 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002811 return ValueObjectSP();
2812 }
2813 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2814 {
2815 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002816 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2817 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002818 return root;
2819 }
2820 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002821 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002822 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002823 if (root->HasSyntheticValue())
2824 root = root->GetSyntheticValue();
2825 else if (!root->IsSynthetic())
2826 {
2827 *first_unparsed = expression_cstr;
2828 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2829 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2830 return ValueObjectSP();
2831 }
2832 // if we are here, then root itself is a synthetic VO.. should be good to go
2833
Enrico Granata27b625e2011-08-09 01:04:56 +00002834 if (!root.get())
2835 {
2836 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002837 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2838 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2839 return ValueObjectSP();
2840 }
2841 root = root->GetChildAtIndex(index, true);
2842 if (!root.get())
2843 {
2844 *first_unparsed = expression_cstr;
2845 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2846 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002847 return ValueObjectSP();
2848 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002849 else
2850 {
2851 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002852 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002853 continue;
2854 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002855 }
2856 else
2857 {
2858 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002859 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2860 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002861 return ValueObjectSP();
2862 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002863 }
2864 else // we have a low and a high index
2865 {
2866 char *end = NULL;
2867 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2868 if (!end || end != separator_position) // if something weird is in our way return an error
2869 {
2870 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002871 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2872 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002873 return ValueObjectSP();
2874 }
2875 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2876 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2877 {
2878 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002879 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2880 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002881 return ValueObjectSP();
2882 }
2883 if (index_lower > index_higher) // swap indices if required
2884 {
2885 unsigned long temp = index_lower;
2886 index_lower = index_higher;
2887 index_higher = temp;
2888 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002889 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002890 {
2891 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2892 if (!root.get())
2893 {
2894 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002895 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2896 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002897 return ValueObjectSP();
2898 }
2899 else
2900 {
2901 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002902 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2903 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002904 return root;
2905 }
2906 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002907 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 +00002908 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002909 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002910 {
2911 Error error;
2912 root = root->Dereference(error);
2913 if (error.Fail() || !root.get())
2914 {
2915 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002916 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2917 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002918 return ValueObjectSP();
2919 }
2920 else
2921 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002922 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002923 continue;
2924 }
2925 }
2926 else
2927 {
2928 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002929 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2930 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002931 return root;
2932 }
2933 }
2934 break;
2935 }
2936 default: // some non-separator is in the way
2937 {
2938 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002939 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2940 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002941 return ValueObjectSP();
2942 break;
2943 }
2944 }
2945 }
2946}
2947
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002948int
2949ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2950 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002951 ValueObjectSP root,
2952 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002953 ExpressionPathScanEndReason* reason_to_stop,
2954 ExpressionPathEndResultType* final_result,
2955 const GetValueForExpressionPathOptions& options,
2956 ExpressionPathAftermath* what_next)
2957{
2958 if (!root.get())
2959 return 0;
2960
2961 *first_unparsed = expression_cstr;
2962
2963 while (true)
2964 {
2965
2966 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2967
Greg Claytonafacd142011-09-02 01:15:17 +00002968 clang_type_t root_clang_type = root->GetClangType();
2969 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002970 Flags root_clang_type_info,pointee_clang_type_info;
2971
2972 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2973 if (pointee_clang_type)
2974 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2975
2976 if (!expression_cstr || *expression_cstr == '\0')
2977 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002978 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002979 list->Append(root);
2980 return 1;
2981 }
2982
2983 switch (*expression_cstr)
2984 {
2985 case '[':
2986 {
2987 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2988 {
2989 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2990 {
2991 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002992 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2993 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002994 return 0;
2995 }
2996 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2997 {
2998 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002999 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3000 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003001 return 0;
3002 }
3003 }
3004 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3005 {
3006 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3007 {
3008 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003009 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3010 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003011 return 0;
3012 }
3013 else // expand this into list
3014 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003015 const size_t max_index = root->GetNumChildren() - 1;
3016 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003017 {
3018 ValueObjectSP child =
3019 root->GetChildAtIndex(index, true);
3020 list->Append(child);
3021 }
3022 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003023 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3024 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003025 return max_index; // tell me number of items I added to the VOList
3026 }
3027 }
3028 const char *separator_position = ::strchr(expression_cstr+1,'-');
3029 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3030 if (!close_bracket_position) // if there is no ], this is a syntax error
3031 {
3032 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003033 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3034 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003035 return 0;
3036 }
3037 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3038 {
3039 char *end = NULL;
3040 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3041 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3042 {
3043 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003044 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3045 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003046 return 0;
3047 }
3048 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3049 {
3050 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3051 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003052 const size_t max_index = root->GetNumChildren() - 1;
3053 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003054 {
3055 ValueObjectSP child =
3056 root->GetChildAtIndex(index, true);
3057 list->Append(child);
3058 }
3059 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003060 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3061 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003062 return max_index; // tell me number of items I added to the VOList
3063 }
3064 else
3065 {
3066 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003067 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3068 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003069 return 0;
3070 }
3071 }
3072 // from here on we do have a valid index
3073 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3074 {
3075 root = root->GetChildAtIndex(index, true);
3076 if (!root.get())
3077 {
3078 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003079 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3080 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003081 return 0;
3082 }
3083 else
3084 {
3085 list->Append(root);
3086 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003087 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3088 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003089 return 1;
3090 }
3091 }
3092 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
3093 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003094 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 +00003095 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3096 {
3097 Error error;
3098 root = root->Dereference(error);
3099 if (error.Fail() || !root.get())
3100 {
3101 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003102 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3103 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003104 return 0;
3105 }
3106 else
3107 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003108 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003109 continue;
3110 }
3111 }
3112 else
3113 {
3114 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3115 if (!root.get())
3116 {
3117 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003118 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3119 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003120 return 0;
3121 }
3122 else
3123 {
3124 list->Append(root);
3125 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003126 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3127 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003128 return 1;
3129 }
3130 }
3131 }
3132 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3133 {
3134 root = root->GetSyntheticBitFieldChild(index, index, true);
3135 if (!root.get())
3136 {
3137 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003138 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3139 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003140 return 0;
3141 }
3142 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3143 {
3144 list->Append(root);
3145 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003146 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3147 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003148 return 1;
3149 }
3150 }
3151 }
3152 else // we have a low and a high index
3153 {
3154 char *end = NULL;
3155 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3156 if (!end || end != separator_position) // if something weird is in our way return an error
3157 {
3158 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003159 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3160 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003161 return 0;
3162 }
3163 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3164 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3165 {
3166 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003167 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3168 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003169 return 0;
3170 }
3171 if (index_lower > index_higher) // swap indices if required
3172 {
3173 unsigned long temp = index_lower;
3174 index_lower = index_higher;
3175 index_higher = temp;
3176 }
3177 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
3178 {
3179 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3180 if (!root.get())
3181 {
3182 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003183 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3184 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003185 return 0;
3186 }
3187 else
3188 {
3189 list->Append(root);
3190 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003191 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3192 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003193 return 1;
3194 }
3195 }
3196 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 +00003197 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003198 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3199 {
3200 Error error;
3201 root = root->Dereference(error);
3202 if (error.Fail() || !root.get())
3203 {
3204 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003205 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3206 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003207 return 0;
3208 }
3209 else
3210 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003211 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003212 continue;
3213 }
3214 }
3215 else
3216 {
Johnny Chen44805302011-07-19 19:48:13 +00003217 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003218 index <= index_higher; index++)
3219 {
3220 ValueObjectSP child =
3221 root->GetChildAtIndex(index, true);
3222 list->Append(child);
3223 }
3224 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003225 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3226 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003227 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3228 }
3229 }
3230 break;
3231 }
3232 default: // some non-[ separator, or something entirely wrong, is in the way
3233 {
3234 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003235 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3236 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003237 return 0;
3238 break;
3239 }
3240 }
3241 }
3242}
3243
Enrico Granata0c489f52012-03-01 04:24:26 +00003244static void
3245DumpValueObject_Impl (Stream &s,
3246 ValueObject *valobj,
3247 const ValueObject::DumpValueObjectOptions& options,
3248 uint32_t ptr_depth,
3249 uint32_t curr_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003250{
Greg Clayton007d5be2011-05-30 00:49:24 +00003251 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003252 {
Enrico Granata5548cb52013-01-28 23:47:25 +00003253 bool update_success = valobj->UpdateValueIfNeeded (true);
Greg Clayton007d5be2011-05-30 00:49:24 +00003254
Enrico Granata0c489f52012-03-01 04:24:26 +00003255 const char *root_valobj_name =
3256 options.m_root_valobj_name.empty() ?
3257 valobj->GetName().AsCString() :
3258 options.m_root_valobj_name.c_str();
3259
3260 if (update_success && options.m_use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00003261 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003262 ValueObject *dynamic_value = valobj->GetDynamicValue(options.m_use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003263 if (dynamic_value)
3264 valobj = dynamic_value;
3265 }
3266
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003267 clang_type_t clang_type = valobj->GetClangType();
3268
Greg Clayton73b472d2010-10-27 03:32:59 +00003269 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003270 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00003271 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
3272 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003273
Enrico Granata0c489f52012-03-01 04:24:26 +00003274 const bool print_valobj = options.m_flat_output == false || has_value;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003275
3276 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003277 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003278 if (options.m_show_location)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003279 {
Jim Ingham6035b672011-03-31 00:19:25 +00003280 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003281 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003282
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003283 s.Indent();
Enrico Granata2b2631c2012-08-09 16:51:25 +00003284
3285 bool show_type = true;
3286 // if we are at the root-level and been asked to hide the root's type, then hide it
3287 if (curr_depth == 0 && options.m_hide_root_type)
3288 show_type = false;
3289 else
3290 // otherwise decide according to the usual rules (asked to show types - always at the root level)
3291 show_type = options.m_show_types || (curr_depth == 0 && !options.m_flat_output);
3292
3293 if (show_type)
Enrico Granataf7b1a342013-01-23 01:17:27 +00003294 s.Printf("(%s) ", valobj->GetQualifiedTypeName().AsCString("<invalid type>"));
Greg Clayton1d3afba2010-10-05 00:00:42 +00003295
Enrico Granata0c489f52012-03-01 04:24:26 +00003296 if (options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003297 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003298 // If we are showing types, also qualify the C++ base classes
Enrico Granata0c489f52012-03-01 04:24:26 +00003299 const bool qualify_cxx_base_classes = options.m_show_types;
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003300 if (!options.m_hide_name)
3301 {
3302 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
3303 s.PutCString(" =");
3304 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003305 }
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003306 else if (!options.m_hide_name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003307 {
3308 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3309 s.Printf ("%s =", name_cstr);
3310 }
3311
Enrico Granata0c489f52012-03-01 04:24:26 +00003312 if (!options.m_scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003313 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003314 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003315 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003316 }
3317
Enrico Granata0c489f52012-03-01 04:24:26 +00003318 std::string summary_str;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003319 std::string value_str;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003320 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003321 const char *sum_cstr = NULL;
Enrico Granata0c489f52012-03-01 04:24:26 +00003322 TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003323
Enrico Granata0c489f52012-03-01 04:24:26 +00003324 if (options.m_omit_summary_depth > 0)
Enrico Granata0c5ef692011-07-16 01:22:04 +00003325 entry = NULL;
3326
Enrico Granata9e7b3882012-12-13 23:50:33 +00003327 bool is_nil = valobj->IsObjCNil();
3328
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003329 if (err_cstr == NULL)
3330 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003331 if (options.m_format != eFormatDefault && options.m_format != valobj->GetFormat())
Greg Clayton6efba4f2012-01-26 21:08:30 +00003332 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003333 valobj->GetValueAsCString(options.m_format,
3334 value_str);
Greg Clayton6efba4f2012-01-26 21:08:30 +00003335 }
Enrico Granata0c489f52012-03-01 04:24:26 +00003336 else
Greg Clayton6efba4f2012-01-26 21:08:30 +00003337 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003338 val_cstr = valobj->GetValueAsCString();
3339 if (val_cstr)
3340 value_str = val_cstr;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003341 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003342 err_cstr = valobj->GetError().AsCString();
3343 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003344
3345 if (err_cstr)
3346 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003347 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003348 }
3349 else
3350 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003351 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003352 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003353 {
Enrico Granata9e7b3882012-12-13 23:50:33 +00003354 if (is_nil)
3355 sum_cstr = "nil";
3356 else if (options.m_omit_summary_depth == 0)
Enrico Granata0c489f52012-03-01 04:24:26 +00003357 {
3358 if (options.m_summary_sp)
3359 {
3360 valobj->GetSummaryAsCString(entry, summary_str);
3361 sum_cstr = summary_str.c_str();
3362 }
3363 else
3364 sum_cstr = valobj->GetSummaryAsCString();
3365 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003366
Greg Clayton6efba4f2012-01-26 21:08:30 +00003367 // Make sure we have a value and make sure the summary didn't
Enrico Granata9e7b3882012-12-13 23:50:33 +00003368 // specify that the value should not be printed - and do not print
3369 // the value if this thing is nil
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003370 if (!is_nil && !value_str.empty() && (entry == NULL || entry->DoesPrintValue() || sum_cstr == NULL) && !options.m_hide_value)
Greg Clayton6efba4f2012-01-26 21:08:30 +00003371 s.Printf(" %s", value_str.c_str());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003372
Enrico Granata9dd75c82011-07-15 23:30:15 +00003373 if (sum_cstr)
Enrico Granata0c489f52012-03-01 04:24:26 +00003374 s.Printf(" %s", sum_cstr);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003375
Enrico Granata9e7b3882012-12-13 23:50:33 +00003376 // let's avoid the overly verbose no description error for a nil thing
3377 if (options.m_use_objc && !is_nil)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003378 {
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003379 if (!options.m_hide_value || !options.m_hide_name)
3380 s.Printf(" ");
Jim Ingham6035b672011-03-31 00:19:25 +00003381 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003382 if (object_desc)
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003383 s.Printf("%s\n", object_desc);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003384 else
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003385 s.Printf ("[no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003386 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003387 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003388 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003389
Enrico Granata0c489f52012-03-01 04:24:26 +00003390 if (curr_depth < options.m_max_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003391 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003392 // We will show children for all concrete types. We won't show
3393 // pointer contents unless a pointer depth has been specified.
3394 // We won't reference contents unless the reference is the
3395 // root object (depth of zero).
3396 bool print_children = true;
3397
3398 // Use a new temporary pointer depth in case we override the
3399 // current pointer depth below...
3400 uint32_t curr_ptr_depth = ptr_depth;
3401
3402 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3403 if (is_ptr || is_ref)
3404 {
3405 // We have a pointer or reference whose value is an address.
3406 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003407 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003408 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003409 print_children = false;
3410
3411 else if (is_ref && curr_depth == 0)
3412 {
3413 // If this is the root object (depth is zero) that we are showing
3414 // and it is a reference, and no pointer depth has been supplied
3415 // print out what it references. Don't do this at deeper depths
3416 // otherwise we can end up with infinite recursion...
3417 curr_ptr_depth = 1;
3418 }
3419
3420 if (curr_ptr_depth == 0)
3421 print_children = false;
3422 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003423
Enrico Granata0a3958e2011-07-02 00:25:22 +00003424 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003425 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003426 ValueObject* synth_valobj;
3427 ValueObjectSP synth_valobj_sp = valobj->GetSyntheticValue (options.m_use_synthetic);
3428 synth_valobj = (synth_valobj_sp ? synth_valobj_sp.get() : valobj);
Enrico Granatac5bc4122012-03-27 02:35:13 +00003429
Greg Claytonc7bece562013-01-25 18:06:21 +00003430 size_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003431 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003432 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003433 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003434 if (options.m_flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003435 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003436 if (print_valobj)
3437 s.EOL();
3438 }
3439 else
3440 {
3441 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003442 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003443 s.IndentMore();
3444 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003445
Greg Claytonc7bece562013-01-25 18:06:21 +00003446 const size_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00003447
Enrico Granata0c489f52012-03-01 04:24:26 +00003448 if (num_children > max_num_children && !options.m_ignore_cap)
Enrico Granata22c55d12011-08-12 02:00:06 +00003449 {
3450 num_children = max_num_children;
3451 print_dotdotdot = true;
3452 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003453
Enrico Granata0c489f52012-03-01 04:24:26 +00003454 ValueObject::DumpValueObjectOptions child_options(options);
Enrico Granatac953a6a2012-12-11 02:17:22 +00003455 child_options.SetFormat(options.m_format).SetSummary().SetRootValueObjectName();
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003456 child_options.SetScopeChecked(true).SetHideName(options.m_hide_name).SetHideValue(options.m_hide_value)
Enrico Granata0c489f52012-03-01 04:24:26 +00003457 .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0);
Greg Claytonc7bece562013-01-25 18:06:21 +00003458 for (size_t idx=0; idx<num_children; ++idx)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003459 {
Enrico Granatac482a192011-08-17 22:13:59 +00003460 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003461 if (child_sp.get())
3462 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003463 DumpValueObject_Impl (s,
3464 child_sp.get(),
3465 child_options,
3466 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
3467 curr_depth + 1);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003468 }
3469 }
3470
Enrico Granata0c489f52012-03-01 04:24:26 +00003471 if (!options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003472 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003473 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003474 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003475 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3476 Target *target = exe_ctx.GetTargetPtr();
3477 if (target)
3478 target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003479 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003480 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003481 s.IndentLess();
3482 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003483 }
3484 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003485 else if (has_children)
3486 {
3487 // Aggregate, no children...
3488 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003489 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003490 }
3491 else
3492 {
3493 if (print_valobj)
3494 s.EOL();
3495 }
3496
Greg Clayton1d3afba2010-10-05 00:00:42 +00003497 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003498 else
3499 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003500 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003501 }
3502 }
3503 else
3504 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003505 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003506 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003507 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003508 }
3509 }
3510 }
3511 }
3512}
3513
Enrico Granata0c489f52012-03-01 04:24:26 +00003514void
Greg Claytonf830dbb2012-03-22 18:15:37 +00003515ValueObject::LogValueObject (Log *log,
3516 ValueObject *valobj)
3517{
3518 if (log && valobj)
3519 return LogValueObject (log, valobj, DumpValueObjectOptions::DefaultOptions());
3520}
3521
3522void
3523ValueObject::LogValueObject (Log *log,
3524 ValueObject *valobj,
3525 const DumpValueObjectOptions& options)
3526{
3527 if (log && valobj)
3528 {
3529 StreamString s;
3530 ValueObject::DumpValueObject (s, valobj, options);
3531 if (s.GetSize())
3532 log->PutCString(s.GetData());
3533 }
3534}
3535
3536void
Enrico Granata0c489f52012-03-01 04:24:26 +00003537ValueObject::DumpValueObject (Stream &s,
3538 ValueObject *valobj)
3539{
3540
3541 if (!valobj)
3542 return;
3543
3544 DumpValueObject_Impl(s,
3545 valobj,
3546 DumpValueObjectOptions::DefaultOptions(),
3547 0,
3548 0);
3549}
3550
3551void
3552ValueObject::DumpValueObject (Stream &s,
3553 ValueObject *valobj,
3554 const DumpValueObjectOptions& options)
3555{
3556 DumpValueObject_Impl(s,
3557 valobj,
3558 options,
3559 options.m_max_ptr_depth, // max pointer depth allowed, we will go down from here
3560 0 // current object depth is 0 since we are just starting
3561 );
3562}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003563
3564ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003565ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003566{
3567 ValueObjectSP valobj_sp;
3568
Enrico Granatac3e320a2011-08-02 17:27:39 +00003569 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003570 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003571 ExecutionContext exe_ctx (GetExecutionContextRef());
3572 clang::ASTContext *ast = GetClangAST ();
3573
3574 DataExtractor data;
3575 data.SetByteOrder (m_data.GetByteOrder());
3576 data.SetAddressByteSize(m_data.GetAddressByteSize());
3577
Enrico Granata9f1e2042012-04-24 22:15:37 +00003578 if (IsBitfield())
3579 {
3580 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
3581 m_error = v.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
3582 }
3583 else
3584 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003585
3586 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3587 ast,
3588 GetClangType(),
3589 name,
3590 data,
3591 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003592 }
Jim Ingham6035b672011-03-31 00:19:25 +00003593
3594 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003595 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003596 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003597 }
3598 return valobj_sp;
3599}
3600
Greg Claytonafacd142011-09-02 01:15:17 +00003601ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003602ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003603{
Jim Ingham58b59f92011-04-22 23:53:53 +00003604 if (m_deref_valobj)
3605 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003606
Greg Clayton54979cd2010-12-15 05:08:08 +00003607 const bool is_pointer_type = IsPointerType();
3608 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003609 {
3610 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003611 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003612
3613 std::string child_name_str;
3614 uint32_t child_byte_size = 0;
3615 int32_t child_byte_offset = 0;
3616 uint32_t child_bitfield_bit_size = 0;
3617 uint32_t child_bitfield_bit_offset = 0;
3618 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003619 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003620 const bool transparent_pointers = false;
3621 clang::ASTContext *clang_ast = GetClangAST();
3622 clang_type_t clang_type = GetClangType();
3623 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003624
Greg Claytoncc4d0142012-02-17 07:49:44 +00003625 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003626
3627 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3628 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003629 GetName().GetCString(),
3630 clang_type,
3631 0,
3632 transparent_pointers,
3633 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003634 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003635 child_name_str,
3636 child_byte_size,
3637 child_byte_offset,
3638 child_bitfield_bit_size,
3639 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003640 child_is_base_class,
3641 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003642 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003643 {
3644 ConstString child_name;
3645 if (!child_name_str.empty())
3646 child_name.SetCString (child_name_str.c_str());
3647
Jim Ingham58b59f92011-04-22 23:53:53 +00003648 m_deref_valobj = new ValueObjectChild (*this,
3649 clang_ast,
3650 child_clang_type,
3651 child_name,
3652 child_byte_size,
3653 child_byte_offset,
3654 child_bitfield_bit_size,
3655 child_bitfield_bit_offset,
3656 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003657 child_is_deref_of_parent,
3658 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003659 }
3660 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003661
Jim Ingham58b59f92011-04-22 23:53:53 +00003662 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003663 {
3664 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003665 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003666 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003667 else
3668 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003669 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003670 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003671
3672 if (is_pointer_type)
3673 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3674 else
3675 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003676 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003677 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003678}
3679
Greg Claytonafacd142011-09-02 01:15:17 +00003680ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003681ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003682{
Jim Ingham78a685a2011-04-16 00:01:13 +00003683 if (m_addr_of_valobj_sp)
3684 return m_addr_of_valobj_sp;
3685
Greg Claytone0d378b2011-03-24 21:19:54 +00003686 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003687 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003688 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003689 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003690 if (addr != LLDB_INVALID_ADDRESS)
3691 {
3692 switch (address_type)
3693 {
3694 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003695 {
3696 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003697 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003698 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3699 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003700 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003701
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003702 case eAddressTypeFile:
3703 case eAddressTypeLoad:
3704 case eAddressTypeHost:
3705 {
3706 clang::ASTContext *ast = GetClangAST();
3707 clang_type_t clang_type = GetClangType();
3708 if (ast && clang_type)
3709 {
3710 std::string name (1, '&');
3711 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003712 ExecutionContext exe_ctx (GetExecutionContextRef());
3713 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003714 ast,
3715 ClangASTContext::CreatePointerType (ast, clang_type),
3716 ConstString (name.c_str()),
3717 addr,
3718 eAddressTypeInvalid,
3719 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003720 }
3721 }
3722 break;
3723 }
3724 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003725 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003726}
3727
Greg Clayton9a142cf2012-02-03 05:34:10 +00003728ValueObjectSP
3729ValueObject::Cast (const ClangASTType &clang_ast_type)
3730{
Greg Clayton81e871e2012-02-04 02:27:34 +00003731 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003732}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003733
Greg Claytonafacd142011-09-02 01:15:17 +00003734ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003735ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3736{
Greg Claytonafacd142011-09-02 01:15:17 +00003737 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003738 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003739 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003740
3741 if (ptr_value != LLDB_INVALID_ADDRESS)
3742 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003743 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003744 ExecutionContext exe_ctx (GetExecutionContextRef());
3745 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003746 name,
3747 ptr_addr,
3748 clang_ast_type);
3749 }
3750 return valobj_sp;
3751}
3752
Greg Claytonafacd142011-09-02 01:15:17 +00003753ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003754ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3755{
Greg Claytonafacd142011-09-02 01:15:17 +00003756 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003757 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003758 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003759
3760 if (ptr_value != LLDB_INVALID_ADDRESS)
3761 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003762 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003763 ExecutionContext exe_ctx (GetExecutionContextRef());
3764 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003765 name,
3766 ptr_addr,
3767 type_sp);
3768 }
3769 return valobj_sp;
3770}
3771
Jim Ingham6035b672011-03-31 00:19:25 +00003772ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003773 m_mod_id(),
3774 m_exe_ctx_ref(),
3775 m_needs_update (true),
3776 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003777{
3778}
3779
3780ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003781 m_mod_id(),
3782 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003783 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003784 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003785{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003786 ExecutionContext exe_ctx(exe_scope);
3787 TargetSP target_sp (exe_ctx.GetTargetSP());
3788 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003789 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003790 m_exe_ctx_ref.SetTargetSP (target_sp);
3791 ProcessSP process_sp (exe_ctx.GetProcessSP());
3792 if (!process_sp)
3793 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003794
Greg Claytoncc4d0142012-02-17 07:49:44 +00003795 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003796 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003797 m_mod_id = process_sp->GetModID();
3798 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003799
Greg Claytoncc4d0142012-02-17 07:49:44 +00003800 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003801
Greg Claytoncc4d0142012-02-17 07:49:44 +00003802 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003803 {
3804 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003805 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003806 }
Jim Ingham6035b672011-03-31 00:19:25 +00003807
Greg Claytoncc4d0142012-02-17 07:49:44 +00003808 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003809 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003810 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003811
Greg Claytoncc4d0142012-02-17 07:49:44 +00003812 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3813 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003814 {
3815 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003816 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003817 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003818 if (frame_sp)
3819 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003820 }
3821 }
3822 }
Jim Ingham6035b672011-03-31 00:19:25 +00003823}
3824
3825ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003826 m_mod_id(),
3827 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3828 m_needs_update (true),
3829 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003830{
3831}
3832
3833ValueObject::EvaluationPoint::~EvaluationPoint ()
3834{
3835}
3836
Jim Ingham6035b672011-03-31 00:19:25 +00003837// This function checks the EvaluationPoint against the current process state. If the current
3838// state matches the evaluation point, or the evaluation point is already invalid, then we return
3839// false, meaning "no change". If the current state is different, we update our state, and return
3840// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3841// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003842// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003843
3844bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003845ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003846{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003847
3848 // 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 +00003849 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00003850
Greg Claytoncc4d0142012-02-17 07:49:44 +00003851 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003852 return false;
3853
Jim Ingham6035b672011-03-31 00:19:25 +00003854 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003855 Process *process = exe_ctx.GetProcessPtr();
3856 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003857 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003858
Jim Ingham6035b672011-03-31 00:19:25 +00003859 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003860 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003861
Jim Ingham78a685a2011-04-16 00:01:13 +00003862 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3863 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003864 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003865 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003866
Greg Clayton23f59502012-07-17 03:23:13 +00003867 bool changed = false;
3868 const bool was_valid = m_mod_id.IsValid();
3869 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003870 {
3871 if (m_mod_id == current_mod_id)
3872 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003873 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003874 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003875 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003876 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003877 else
3878 {
3879 m_mod_id = current_mod_id;
3880 m_needs_update = true;
3881 changed = true;
3882 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003883 }
Jim Ingham6035b672011-03-31 00:19:25 +00003884
Jim Ingham73ca05a2011-12-17 01:35:57 +00003885 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3886 // That way we'll be sure to return a valid exe_scope.
3887 // 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 +00003888
Greg Claytoncc4d0142012-02-17 07:49:44 +00003889 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003890 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003891 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3892 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003893 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003894 if (m_exe_ctx_ref.HasFrameRef())
3895 {
3896 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3897 if (!frame_sp)
3898 {
3899 // We used to have a frame, but now it is gone
3900 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003901 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00003902 }
3903 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003904 }
Jim Ingham6035b672011-03-31 00:19:25 +00003905 else
3906 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003907 // We used to have a thread, but now it is gone
3908 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003909 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00003910 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003911
Jim Ingham6035b672011-03-31 00:19:25 +00003912 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003913 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003914}
3915
Jim Ingham61be0902011-05-02 18:13:59 +00003916void
3917ValueObject::EvaluationPoint::SetUpdated ()
3918{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003919 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3920 if (process_sp)
3921 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003922 m_first_update = false;
3923 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003924}
3925
3926
Greg Claytoncc4d0142012-02-17 07:49:44 +00003927//bool
3928//ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3929//{
3930// if (!IsValid())
3931// return false;
3932//
3933// bool needs_update = false;
3934//
3935// // The target has to be non-null, and the
3936// Target *target = exe_scope->CalculateTarget();
3937// if (target != NULL)
3938// {
3939// Target *old_target = m_target_sp.get();
3940// assert (target == old_target);
3941// Process *process = exe_scope->CalculateProcess();
3942// if (process != NULL)
3943// {
3944// // FOR NOW - assume you can't update variable objects across process boundaries.
3945// Process *old_process = m_process_sp.get();
3946// assert (process == old_process);
3947// ProcessModID current_mod_id = process->GetModID();
3948// if (m_mod_id != current_mod_id)
3949// {
3950// needs_update = true;
3951// m_mod_id = current_mod_id;
3952// }
3953// // See if we're switching the thread or stack context. If no thread is given, this is
3954// // being evaluated in a global context.
3955// Thread *thread = exe_scope->CalculateThread();
3956// if (thread != NULL)
3957// {
3958// user_id_t new_thread_index = thread->GetIndexID();
3959// if (new_thread_index != m_thread_id)
3960// {
3961// needs_update = true;
3962// m_thread_id = new_thread_index;
3963// m_stack_id.Clear();
3964// }
3965//
3966// StackFrame *new_frame = exe_scope->CalculateStackFrame();
3967// if (new_frame != NULL)
3968// {
3969// if (new_frame->GetStackID() != m_stack_id)
3970// {
3971// needs_update = true;
3972// m_stack_id = new_frame->GetStackID();
3973// }
3974// }
3975// else
3976// {
3977// m_stack_id.Clear();
3978// needs_update = true;
3979// }
3980// }
3981// else
3982// {
3983// // If this had been given a thread, and now there is none, we should update.
3984// // Otherwise we don't have to do anything.
3985// if (m_thread_id != LLDB_INVALID_UID)
3986// {
3987// m_thread_id = LLDB_INVALID_UID;
3988// m_stack_id.Clear();
3989// needs_update = true;
3990// }
3991// }
3992// }
3993// else
3994// {
3995// // If there is no process, then we don't need to update anything.
3996// // But if we're switching from having a process to not, we should try to update.
3997// if (m_process_sp.get() != NULL)
3998// {
3999// needs_update = true;
4000// m_process_sp.reset();
4001// m_thread_id = LLDB_INVALID_UID;
4002// m_stack_id.Clear();
4003// }
4004// }
4005// }
4006// else
4007// {
4008// // If there's no target, nothing can change so we don't need to update anything.
4009// // But if we're switching from having a target to not, we should try to update.
4010// if (m_target_sp.get() != NULL)
4011// {
4012// needs_update = true;
4013// m_target_sp.reset();
4014// m_process_sp.reset();
4015// m_thread_id = LLDB_INVALID_UID;
4016// m_stack_id.Clear();
4017// }
4018// }
4019// if (!m_needs_update)
4020// m_needs_update = needs_update;
4021//
4022// return needs_update;
4023//}
Enrico Granataf2bbf712011-07-15 02:26:42 +00004024
4025void
Enrico Granata86cc9822012-03-19 22:58:49 +00004026ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004027{
Enrico Granata86cc9822012-03-19 22:58:49 +00004028 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4029 m_value_str.clear();
4030
4031 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4032 m_location_str.clear();
4033
4034 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
4035 {
Enrico Granata86cc9822012-03-19 22:58:49 +00004036 m_summary_str.clear();
4037 }
4038
4039 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4040 m_object_desc_str.clear();
4041
4042 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4043 {
4044 if (m_synthetic_value)
4045 m_synthetic_value = NULL;
4046 }
Johnny Chen44805302011-07-19 19:48:13 +00004047}
Enrico Granata9128ee22011-09-06 19:20:51 +00004048
4049SymbolContextScope *
4050ValueObject::GetSymbolContextScope()
4051{
4052 if (m_parent)
4053 {
4054 if (!m_parent->IsPointerOrReferenceType())
4055 return m_parent->GetSymbolContextScope();
4056 }
4057 return NULL;
4058}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004059
4060lldb::ValueObjectSP
4061ValueObject::CreateValueObjectFromExpression (const char* name,
4062 const char* expression,
4063 const ExecutionContext& exe_ctx)
4064{
4065 lldb::ValueObjectSP retval_sp;
4066 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4067 if (!target_sp)
4068 return retval_sp;
4069 if (!expression || !*expression)
4070 return retval_sp;
4071 target_sp->EvaluateExpression (expression,
4072 exe_ctx.GetFrameSP().get(),
4073 retval_sp);
4074 if (retval_sp && name && *name)
4075 retval_sp->SetName(ConstString(name));
4076 return retval_sp;
4077}
4078
4079lldb::ValueObjectSP
4080ValueObject::CreateValueObjectFromAddress (const char* name,
4081 uint64_t address,
4082 const ExecutionContext& exe_ctx,
4083 ClangASTType type)
4084{
4085 ClangASTType pointer_type(type.GetASTContext(),type.GetPointerType());
4086 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4087 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4088 pointer_type.GetASTContext(),
4089 pointer_type.GetOpaqueQualType(),
4090 ConstString(name),
4091 buffer,
4092 lldb::endian::InlHostByteOrder(),
4093 exe_ctx.GetAddressByteSize()));
4094 if (ptr_result_valobj_sp)
4095 {
4096 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4097 Error err;
4098 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4099 if (ptr_result_valobj_sp && name && *name)
4100 ptr_result_valobj_sp->SetName(ConstString(name));
4101 }
4102 return ptr_result_valobj_sp;
4103}
4104
4105lldb::ValueObjectSP
4106ValueObject::CreateValueObjectFromData (const char* name,
4107 DataExtractor& data,
4108 const ExecutionContext& exe_ctx,
4109 ClangASTType type)
4110{
4111 lldb::ValueObjectSP new_value_sp;
4112 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4113 type.GetASTContext() ,
4114 type.GetOpaqueQualType(),
4115 ConstString(name),
4116 data,
4117 LLDB_INVALID_ADDRESS);
4118 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4119 if (new_value_sp && name && *name)
4120 new_value_sp->SetName(ConstString(name));
4121 return new_value_sp;
4122}