blob: 41c7dbe94fdf4dc900c7ec0f093b5f4315b35579 [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
10#include "lldb/Core/ValueObject.h"
11
12// C Includes
Greg Claytonf5e56de2010-09-14 23:36:40 +000013#include <stdlib.h>
14
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015// C++ Includes
16// Other libraries and framework includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "llvm/Support/raw_ostream.h"
Jim Ingham5a369122010-09-28 01:25:32 +000018#include "clang/AST/Type.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019
20// Project includes
21#include "lldb/Core/DataBufferHeap.h"
Enrico Granata0a976142011-08-22 22:03:47 +000022#include "lldb/Core/DataVisualization.h"
Enrico Granata4becb372011-06-29 22:27:15 +000023#include "lldb/Core/Debugger.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000024#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000025#include "lldb/Core/Module.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026#include "lldb/Core/StreamString.h"
27#include "lldb/Core/ValueObjectChild.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000028#include "lldb/Core/ValueObjectConstResult.h"
Jim Ingham78a685a2011-04-16 00:01:13 +000029#include "lldb/Core/ValueObjectDynamicValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030#include "lldb/Core/ValueObjectList.h"
Greg Claytonb2dcc362011-05-05 23:32:56 +000031#include "lldb/Core/ValueObjectMemory.h"
Enrico Granatad55546b2011-07-22 00:16:08 +000032#include "lldb/Core/ValueObjectSyntheticFilter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033
Greg Clayton7fb56d02011-02-01 01:31:41 +000034#include "lldb/Host/Endian.h"
35
Enrico Granata61a80ba2011-08-12 16:42:31 +000036#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granataf2bbf712011-07-15 02:26:42 +000037#include "lldb/Interpreter/ScriptInterpreterPython.h"
38
Greg Claytone1a916a2010-07-21 22:12:05 +000039#include "lldb/Symbol/ClangASTType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000040#include "lldb/Symbol/ClangASTContext.h"
41#include "lldb/Symbol/Type.h"
42
Jim Ingham53c47f12010-09-10 23:12:17 +000043#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000044#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000045#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046#include "lldb/Target/Process.h"
47#include "lldb/Target/RegisterContext.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000048#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000050
Enrico Granataf4efecd2011-07-12 22:56:10 +000051#include "lldb/Utility/RefCounter.h"
52
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053using namespace lldb;
54using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000055using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056
Greg Claytonafacd142011-09-02 01:15:17 +000057static user_id_t g_value_obj_uid = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058
59//----------------------------------------------------------------------
60// ValueObject constructor
61//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000062ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000064 m_parent (&parent),
Stephen Wilson71c21d12011-04-11 19:41:40 +000065 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066 m_name (),
67 m_data (),
68 m_value (),
69 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000070 m_value_str (),
71 m_old_value_str (),
72 m_location_str (),
73 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000074 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +000075 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000076 m_children (),
77 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000078 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000079 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000080 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000081 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000082 m_last_format_mgr_revision(0),
Enrico Granatad8b5fce2011-08-02 23:12:24 +000083 m_last_format_mgr_dynamic(parent.m_last_format_mgr_dynamic),
Enrico Granata0c489f52012-03-01 04:24:26 +000084 m_type_summary_sp(),
85 m_type_format_sp(),
86 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +000087 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +000088 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
Greg Clayton288bdf92010-09-02 02:59:18 +000089 m_value_is_valid (false),
90 m_value_did_change (false),
91 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000092 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +000093 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +000094 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +000095 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +000096 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +000097 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +000098 m_is_getting_summary(false),
99 m_did_calculate_complete_objc_class_type(false)
Jim Ingham6035b672011-03-31 00:19:25 +0000100{
Jim Ingham58b59f92011-04-22 23:53:53 +0000101 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000102}
103
104//----------------------------------------------------------------------
105// ValueObject constructor
106//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000107ValueObject::ValueObject (ExecutionContextScope *exe_scope,
108 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000109 UserID (++g_value_obj_uid), // Unique identifier for every value object
110 m_parent (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000111 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000112 m_name (),
113 m_data (),
114 m_value (),
115 m_error (),
116 m_value_str (),
117 m_old_value_str (),
118 m_location_str (),
119 m_summary_str (),
120 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000121 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000122 m_children (),
123 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000124 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000125 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000126 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000127 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000128 m_last_format_mgr_revision(0),
Greg Claytonafacd142011-09-02 01:15:17 +0000129 m_last_format_mgr_dynamic(eNoDynamicValues),
Enrico Granata0c489f52012-03-01 04:24:26 +0000130 m_type_summary_sp(),
131 m_type_format_sp(),
132 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000133 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000134 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Jim Ingham6035b672011-03-31 00:19:25 +0000135 m_value_is_valid (false),
136 m_value_did_change (false),
137 m_children_count_valid (false),
138 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000139 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000140 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000141 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +0000142 m_is_expression_path_child(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 Granatac3e320a2011-08-02 17:27:39 +0000161 return UpdateValueIfNeeded(m_last_format_mgr_dynamic, update_format);
162}
163
164bool
Greg Claytonafacd142011-09-02 01:15:17 +0000165ValueObject::UpdateValueIfNeeded (DynamicValueType use_dynamic, bool update_format)
Enrico Granatac3e320a2011-08-02 17:27:39 +0000166{
Enrico Granata4becb372011-06-29 22:27:15 +0000167
Enrico Granata9128ee22011-09-06 19:20:51 +0000168 bool did_change_formats = false;
169
Enrico Granata0a3958e2011-07-02 00:25:22 +0000170 if (update_format)
Enrico Granata9128ee22011-09-06 19:20:51 +0000171 did_change_formats = UpdateFormatsIfNeeded(use_dynamic);
Enrico Granata4becb372011-06-29 22:27:15 +0000172
Greg Claytonb71f3842010-10-05 03:13:51 +0000173 // If this is a constant value, then our success is predicated on whether
174 // we have an error or not
175 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000176 {
177 // if you were asked to update your formatters, but did not get a chance to do it
178 // clear your own values (this serves the purpose of faking a stop-id for frozen
179 // objects (which are regarded as constant, but could have changes behind their backs
180 // because of the frozen-pointer depth limit)
181 // TODO: decouple summary from value and then remove this code and only force-clear the summary
182 if (update_format && !did_change_formats)
Enrico Granata86cc9822012-03-19 22:58:49 +0000183 ClearUserVisibleData(eClearUserVisibleDataItemsSummary);
Greg Claytonb71f3842010-10-05 03:13:51 +0000184 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000185 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000186
Jim Ingham6035b672011-03-31 00:19:25 +0000187 bool first_update = m_update_point.IsFirstEvaluation();
188
189 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000190 {
Jim Ingham6035b672011-03-31 00:19:25 +0000191 m_update_point.SetUpdated();
192
193 // Save the old value using swap to avoid a string copy which
194 // also will clear our m_value_str
195 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000196 {
Jim Ingham6035b672011-03-31 00:19:25 +0000197 m_old_value_valid = false;
198 }
199 else
200 {
201 m_old_value_valid = true;
202 m_old_value_str.swap (m_value_str);
Enrico Granata86cc9822012-03-19 22:58:49 +0000203 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham6035b672011-03-31 00:19:25 +0000204 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000205
Enrico Granataf2bbf712011-07-15 02:26:42 +0000206 ClearUserVisibleData();
207
Greg Claytonefbc7d22012-03-09 04:23:44 +0000208 if (IsInScope())
Jim Ingham6035b672011-03-31 00:19:25 +0000209 {
Greg Claytonefbc7d22012-03-09 04:23:44 +0000210 const bool value_was_valid = GetValueIsValid();
211 SetValueDidChange (false);
212
213 m_error.Clear();
214
215 // Call the pure virtual function to update the value
216 bool success = UpdateValue ();
217
218 SetValueIsValid (success);
219
220 if (first_update)
221 SetValueDidChange (false);
222 else if (!m_value_did_change && success == false)
223 {
224 // The value wasn't gotten successfully, so we mark this
225 // as changed if the value used to be valid and now isn't
226 SetValueDidChange (value_was_valid);
227 }
228 }
229 else
230 {
231 m_error.SetErrorString("out of scope");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000232 }
233 }
234 return m_error.Success();
235}
236
Enrico Granata9128ee22011-09-06 19:20:51 +0000237bool
Greg Claytonafacd142011-09-02 01:15:17 +0000238ValueObject::UpdateFormatsIfNeeded(DynamicValueType use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000239{
Enrico Granata6f3533f2011-07-29 19:53:35 +0000240 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
241 if (log)
Enrico Granatad2284832012-10-17 22:23:56 +0000242 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
Enrico Granata6f3533f2011-07-29 19:53:35 +0000243 GetName().GetCString(),
Enrico Granatad2284832012-10-17 22:23:56 +0000244 this,
Enrico Granata4becb372011-06-29 22:27:15 +0000245 m_last_format_mgr_revision,
Enrico Granata85933ed2011-08-18 16:38:26 +0000246 DataVisualization::GetCurrentRevision());
Enrico Granata9128ee22011-09-06 19:20:51 +0000247
248 bool any_change = false;
249
Enrico Granata85933ed2011-08-18 16:38:26 +0000250 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()) ||
Enrico Granatac3e320a2011-08-02 17:27:39 +0000251 m_last_format_mgr_dynamic != use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000252 {
Enrico Granata78d06382011-09-09 23:33:14 +0000253 SetValueFormat(DataVisualization::ValueFormats::GetFormat (*this, eNoDynamicValues));
254 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, use_dynamic));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000255#ifndef LLDB_DISABLE_PYTHON
Enrico Granata78d06382011-09-09 23:33:14 +0000256 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, use_dynamic));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000257#endif
Enrico Granata1490c6f2011-07-19 02:34:21 +0000258
Enrico Granata85933ed2011-08-18 16:38:26 +0000259 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
Enrico Granatac3e320a2011-08-02 17:27:39 +0000260 m_last_format_mgr_dynamic = use_dynamic;
Enrico Granata855cd902011-09-06 22:59:55 +0000261
262 any_change = true;
Enrico Granata4becb372011-06-29 22:27:15 +0000263 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000264
265 return any_change;
266
Enrico Granata4becb372011-06-29 22:27:15 +0000267}
268
Jim Ingham16e0c682011-08-12 23:34:31 +0000269void
270ValueObject::SetNeedsUpdate ()
271{
272 m_update_point.SetNeedsUpdate();
273 // We have to clear the value string here so ConstResult children will notice if their values are
274 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000275 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000276}
277
Enrico Granata13ac0e22012-10-17 19:03:34 +0000278void
Enrico Granatae3e91512012-10-22 18:18:36 +0000279ValueObject::ClearDynamicTypeInformation ()
Enrico Granata13ac0e22012-10-17 19:03:34 +0000280{
281 m_did_calculate_complete_objc_class_type = false;
Enrico Granatae3e91512012-10-22 18:18:36 +0000282 m_last_format_mgr_revision = 0;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000283 m_override_type = ClangASTType();
Enrico Granatae3e91512012-10-22 18:18:36 +0000284 SetValueFormat(lldb::TypeFormatImplSP());
285 SetSummaryFormat(lldb::TypeSummaryImplSP());
286 SetSyntheticChildren(lldb::SyntheticChildrenSP());
Enrico Granata13ac0e22012-10-17 19:03:34 +0000287}
288
Sean Callanan72772842012-02-22 23:57:45 +0000289ClangASTType
290ValueObject::MaybeCalculateCompleteType ()
291{
292 ClangASTType ret(GetClangASTImpl(), GetClangTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000293
Sean Callanan72772842012-02-22 23:57:45 +0000294 if (m_did_calculate_complete_objc_class_type)
295 {
296 if (m_override_type.IsValid())
297 return m_override_type;
298 else
299 return ret;
300 }
301
302 clang_type_t ast_type(GetClangTypeImpl());
303 clang_type_t class_type;
304 bool is_pointer_type;
305
306 if (ClangASTContext::IsObjCObjectPointerType(ast_type, &class_type))
307 {
308 is_pointer_type = true;
309 }
310 else if (ClangASTContext::IsObjCClassType(ast_type))
311 {
312 is_pointer_type = false;
313 class_type = ast_type;
314 }
315 else
316 {
317 return ret;
318 }
319
320 m_did_calculate_complete_objc_class_type = true;
321
322 if (!class_type)
323 return ret;
324
325 std::string class_name;
326
327 if (!ClangASTContext::GetObjCClassName(class_type, class_name))
328 return ret;
329
330 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
331
332 if (!process_sp)
333 return ret;
334
335 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
336
337 if (!objc_language_runtime)
338 return ret;
339
340 ConstString class_name_cs(class_name.c_str());
341
342 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name_cs);
343
344 if (!complete_objc_class_type_sp)
345 return ret;
346
347 ClangASTType complete_class(complete_objc_class_type_sp->GetClangAST(),
348 complete_objc_class_type_sp->GetClangFullType());
349
350 if (!ClangASTContext::GetCompleteType(complete_class.GetASTContext(),
351 complete_class.GetOpaqueQualType()))
352 return ret;
353
354 if (is_pointer_type)
355 {
356 clang_type_t pointer_type = ClangASTContext::CreatePointerType(complete_class.GetASTContext(),
357 complete_class.GetOpaqueQualType());
358
359 m_override_type = ClangASTType(complete_class.GetASTContext(),
360 pointer_type);
361 }
362 else
363 {
364 m_override_type = complete_class;
365 }
366
Sean Callanan356e17c2012-03-30 02:04:38 +0000367 if (m_override_type.IsValid())
368 return m_override_type;
369 else
370 return ret;
Sean Callanan72772842012-02-22 23:57:45 +0000371}
372
373clang::ASTContext *
374ValueObject::GetClangAST ()
375{
376 ClangASTType type = MaybeCalculateCompleteType();
377
378 return type.GetASTContext();
379}
380
381lldb::clang_type_t
382ValueObject::GetClangType ()
383{
384 ClangASTType type = MaybeCalculateCompleteType();
385
386 return type.GetOpaqueQualType();
387}
388
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000389DataExtractor &
390ValueObject::GetDataExtractor ()
391{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000392 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000393 return m_data;
394}
395
396const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000397ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000398{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000399 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000400 return m_error;
401}
402
403const ConstString &
404ValueObject::GetName() const
405{
406 return m_name;
407}
408
409const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000410ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000411{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000412 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000413 {
414 if (m_location_str.empty())
415 {
416 StreamString sstr;
417
418 switch (m_value.GetValueType())
419 {
420 default:
421 break;
422
423 case Value::eValueTypeScalar:
Greg Clayton526e5af2010-11-13 03:52:47 +0000424 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000425 {
426 RegisterInfo *reg_info = m_value.GetRegisterInfo();
427 if (reg_info)
428 {
429 if (reg_info->name)
430 m_location_str = reg_info->name;
431 else if (reg_info->alt_name)
432 m_location_str = reg_info->alt_name;
433 break;
434 }
435 }
436 m_location_str = "scalar";
437 break;
438
439 case Value::eValueTypeLoadAddress:
440 case Value::eValueTypeFileAddress:
441 case Value::eValueTypeHostAddress:
442 {
443 uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2;
444 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
445 m_location_str.swap(sstr.GetString());
446 }
447 break;
448 }
449 }
450 }
451 return m_location_str.c_str();
452}
453
454Value &
455ValueObject::GetValue()
456{
457 return m_value;
458}
459
460const Value &
461ValueObject::GetValue() const
462{
463 return m_value;
464}
465
466bool
Jim Ingham6035b672011-03-31 00:19:25 +0000467ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000468{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000469 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
470 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000471 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000472 Value tmp_value(m_value);
473 scalar = tmp_value.ResolveValue(&exe_ctx, GetClangAST ());
Greg Claytondcad5022011-12-29 01:26:56 +0000474 if (scalar.IsValid())
475 {
476 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
477 if (bitfield_bit_size)
478 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
479 return true;
480 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000481 }
Greg Claytondcad5022011-12-29 01:26:56 +0000482 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000483}
484
485bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000486ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000487{
Greg Clayton288bdf92010-09-02 02:59:18 +0000488 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000489}
490
491
492void
493ValueObject::SetValueIsValid (bool b)
494{
Greg Clayton288bdf92010-09-02 02:59:18 +0000495 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000496}
497
498bool
Jim Ingham6035b672011-03-31 00:19:25 +0000499ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000500{
Jim Ingham6035b672011-03-31 00:19:25 +0000501 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000502 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000503}
504
505void
506ValueObject::SetValueDidChange (bool value_changed)
507{
Greg Clayton288bdf92010-09-02 02:59:18 +0000508 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000509}
510
511ValueObjectSP
512ValueObject::GetChildAtIndex (uint32_t idx, bool can_create)
513{
514 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000515 // We may need to update our value if we are dynamic
516 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000517 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000518 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000519 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000520 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000521 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000522 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000523 // No we haven't created the child at this index, so lets have our
524 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000525 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000526 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000527
Enrico Granata9d60f602012-03-09 03:09:58 +0000528 ValueObject* child = m_children.GetChildAtIndex(idx);
529 if (child != NULL)
530 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000531 }
532 return child_sp;
533}
534
535uint32_t
536ValueObject::GetIndexOfChildWithName (const ConstString &name)
537{
538 bool omit_empty_base_classes = true;
539 return ClangASTContext::GetIndexOfChildWithName (GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +0000540 GetClangType(),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000541 name.GetCString(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000542 omit_empty_base_classes);
543}
544
545ValueObjectSP
546ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
547{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000548 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000549 // classes (which really aren't part of the expression path), so we
550 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000551 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000552
Greg Claytondea8cb42011-06-29 22:09:02 +0000553 // We may need to update our value if we are dynamic
554 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000555 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000556
557 std::vector<uint32_t> child_indexes;
558 clang::ASTContext *clang_ast = GetClangAST();
559 void *clang_type = GetClangType();
560 bool omit_empty_base_classes = true;
561 const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast,
562 clang_type,
563 name.GetCString(),
564 omit_empty_base_classes,
565 child_indexes);
566 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000567 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000568 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
569 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
570
571 child_sp = GetChildAtIndex(*pos, can_create);
572 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000573 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000574 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000575 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000576 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
577 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000578 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000579 else
580 {
581 child_sp.reset();
582 }
583
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000584 }
585 }
586 return child_sp;
587}
588
589
590uint32_t
591ValueObject::GetNumChildren ()
592{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000593 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000594 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000595 {
596 SetNumChildren (CalculateNumChildren());
597 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000598 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000599}
Greg Clayton4a792072012-10-23 01:50:10 +0000600
601bool
602ValueObject::MightHaveChildren()
603{
604 bool has_children;
605 clang_type_t clang_type = GetClangType();
606 if (clang_type)
607 {
608 const uint32_t type_info = ClangASTContext::GetTypeInfo (clang_type,
609 GetClangAST(),
610 NULL);
611 if (type_info & (ClangASTContext::eTypeHasChildren |
612 ClangASTContext::eTypeIsPointer |
613 ClangASTContext::eTypeIsReference))
614 has_children = true;
615 }
616 else
617 {
618 has_children = GetNumChildren () > 0;
619 }
620 return has_children;
621}
622
623// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000624void
625ValueObject::SetNumChildren (uint32_t num_children)
626{
Greg Clayton288bdf92010-09-02 02:59:18 +0000627 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000628 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000629}
630
631void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000632ValueObject::SetName (const ConstString &name)
633{
634 m_name = name;
635}
636
Jim Ingham58b59f92011-04-22 23:53:53 +0000637ValueObject *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000638ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index)
639{
Jim Ingham2eec4872011-05-07 00:10:58 +0000640 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000641
Greg Claytondea8cb42011-06-29 22:09:02 +0000642 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000643 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000644 std::string child_name_str;
645 uint32_t child_byte_size = 0;
646 int32_t child_byte_offset = 0;
647 uint32_t child_bitfield_bit_size = 0;
648 uint32_t child_bitfield_bit_offset = 0;
649 bool child_is_base_class = false;
650 bool child_is_deref_of_parent = false;
651
652 const bool transparent_pointers = synthetic_array_member == false;
653 clang::ASTContext *clang_ast = GetClangAST();
654 clang_type_t clang_type = GetClangType();
655 clang_type_t child_clang_type;
656
Greg Claytoncc4d0142012-02-17 07:49:44 +0000657 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000658
659 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
660 clang_ast,
661 GetName().GetCString(),
662 clang_type,
663 idx,
664 transparent_pointers,
665 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +0000666 ignore_array_bounds,
Greg Claytondea8cb42011-06-29 22:09:02 +0000667 child_name_str,
668 child_byte_size,
669 child_byte_offset,
670 child_bitfield_bit_size,
671 child_bitfield_bit_offset,
672 child_is_base_class,
673 child_is_deref_of_parent);
674 if (child_clang_type && child_byte_size)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000675 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000676 if (synthetic_index)
677 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000678
Greg Claytondea8cb42011-06-29 22:09:02 +0000679 ConstString child_name;
680 if (!child_name_str.empty())
681 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000682
Greg Claytondea8cb42011-06-29 22:09:02 +0000683 valobj = new ValueObjectChild (*this,
684 clang_ast,
685 child_clang_type,
686 child_name,
687 child_byte_size,
688 child_byte_offset,
689 child_bitfield_bit_size,
690 child_bitfield_bit_offset,
691 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000692 child_is_deref_of_parent,
693 eAddressTypeInvalid);
694 //if (valobj)
695 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
696 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000697
Jim Ingham58b59f92011-04-22 23:53:53 +0000698 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000699}
700
Enrico Granata0c489f52012-03-01 04:24:26 +0000701bool
702ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
703 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000704{
Enrico Granata0c489f52012-03-01 04:24:26 +0000705 destination.clear();
706
707 // ideally we would like to bail out if passing NULL, but if we do so
708 // we end up not providing the summary for function pointers anymore
709 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
710 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000711
712 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000713
714 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
715 // information that we might care to see in a crash log. might be useful in very specific situations though.
716 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
717 GetTypeName().GetCString(),
718 GetName().GetCString(),
719 summary_ptr->GetDescription().c_str());*/
720
Enrico Granata0c489f52012-03-01 04:24:26 +0000721 if (UpdateValueIfNeeded (false))
722 {
723 if (summary_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000724 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000725 if (HasSyntheticValue())
726 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
727 summary_ptr->FormatObject(this, destination);
Enrico Granata0c489f52012-03-01 04:24:26 +0000728 }
729 else
730 {
731 clang_type_t clang_type = GetClangType();
732
733 // Do some default printout for function pointers
734 if (clang_type)
Enrico Granata4becb372011-06-29 22:27:15 +0000735 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000736 StreamString sstr;
737 clang_type_t elem_or_pointee_clang_type;
738 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
739 GetClangAST(),
740 &elem_or_pointee_clang_type));
741
742 if (ClangASTContext::IsFunctionPointerType (clang_type))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000743 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000744 AddressType func_ptr_address_type = eAddressTypeInvalid;
745 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
746 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000747 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000748 switch (func_ptr_address_type)
Jim Ingham6035b672011-03-31 00:19:25 +0000749 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000750 case eAddressTypeInvalid:
751 case eAddressTypeFile:
752 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000753
Greg Claytoncc4d0142012-02-17 07:49:44 +0000754 case eAddressTypeLoad:
Enrico Granata0c489f52012-03-01 04:24:26 +0000755 {
756 ExecutionContext exe_ctx (GetExecutionContextRef());
757
758 Address so_addr;
759 Target *target = exe_ctx.GetTargetPtr();
760 if (target && target->GetSectionLoadList().IsEmpty() == false)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000761 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000762 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000763 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000764 so_addr.Dump (&sstr,
765 exe_ctx.GetBestExecutionContextScope(),
766 Address::DumpStyleResolvedDescription,
767 Address::DumpStyleSectionNameOffset);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000768 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000769 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000770 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000771 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000772
Greg Claytoncc4d0142012-02-17 07:49:44 +0000773 case eAddressTypeHost:
774 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +0000775 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000776 }
777 if (sstr.GetSize() > 0)
778 {
779 destination.assign (1, '(');
780 destination.append (sstr.GetData(), sstr.GetSize());
781 destination.append (1, ')');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000782 }
783 }
784 }
785 }
786 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000787 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000788 return !destination.empty();
789}
790
791const char *
792ValueObject::GetSummaryAsCString ()
793{
794 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
795 {
796 GetSummaryAsCString(GetSummaryFormat().get(),
797 m_summary_str);
798 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000799 if (m_summary_str.empty())
800 return NULL;
801 return m_summary_str.c_str();
802}
803
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000804bool
805ValueObject::IsCStringContainer(bool check_pointer)
806{
807 clang_type_t elem_or_pointee_clang_type;
808 const Flags type_flags (ClangASTContext::GetTypeInfo (GetClangType(),
809 GetClangAST(),
810 &elem_or_pointee_clang_type));
811 bool is_char_arr_ptr (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
812 ClangASTContext::IsCharType (elem_or_pointee_clang_type));
813 if (!is_char_arr_ptr)
814 return false;
815 if (!check_pointer)
816 return true;
817 if (type_flags.Test(ClangASTContext::eTypeIsArray))
818 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000819 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000820 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000821 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000822 return (cstr_address != LLDB_INVALID_ADDRESS);
823}
824
Enrico Granata9128ee22011-09-06 19:20:51 +0000825size_t
826ValueObject::GetPointeeData (DataExtractor& data,
827 uint32_t item_idx,
828 uint32_t item_count)
829{
830 if (!IsPointerType() && !IsArrayType())
831 return 0;
832
833 if (item_count == 0)
834 return 0;
835
836 uint32_t stride = 0;
837
838 ClangASTType type(GetClangAST(),
839 GetClangType());
840
841 const uint64_t item_type_size = (IsPointerType() ? ClangASTType::GetTypeByteSize(GetClangAST(), type.GetPointeeType()) :
842 ClangASTType::GetTypeByteSize(GetClangAST(), type.GetArrayElementType(stride)));
843
844 const uint64_t bytes = item_count * item_type_size;
845
846 const uint64_t offset = item_idx * item_type_size;
847
848 if (item_idx == 0 && item_count == 1) // simply a deref
849 {
850 if (IsPointerType())
851 {
852 Error error;
853 ValueObjectSP pointee_sp = Dereference(error);
854 if (error.Fail() || pointee_sp.get() == NULL)
855 return 0;
856 return pointee_sp->GetDataExtractor().Copy(data);
857 }
858 else
859 {
860 ValueObjectSP child_sp = GetChildAtIndex(0, true);
861 if (child_sp.get() == NULL)
862 return 0;
863 return child_sp->GetDataExtractor().Copy(data);
864 }
865 return true;
866 }
867 else /* (items > 1) */
868 {
869 Error error;
870 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
871 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
872
873 AddressType addr_type;
874 lldb::addr_t addr = IsPointerType() ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
875
Enrico Granata9128ee22011-09-06 19:20:51 +0000876 switch (addr_type)
877 {
878 case eAddressTypeFile:
879 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000880 ModuleSP module_sp (GetModule());
881 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000882 {
Enrico Granata9c2efe32012-08-07 01:49:34 +0000883 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +0000884 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +0000885 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000886 ExecutionContext exe_ctx (GetExecutionContextRef());
887 Target* target = exe_ctx.GetTargetPtr();
888 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +0000889 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000890 heap_buf_ptr->SetByteSize(bytes);
891 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
892 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +0000893 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000894 data.SetData(data_sp);
895 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +0000896 }
897 }
898 }
899 }
900 break;
901 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +0000902 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000903 ExecutionContext exe_ctx (GetExecutionContextRef());
904 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +0000905 if (process)
906 {
907 heap_buf_ptr->SetByteSize(bytes);
908 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
909 if (error.Success())
910 {
911 data.SetData(data_sp);
912 return bytes_read;
913 }
914 }
915 }
916 break;
917 case eAddressTypeHost:
918 {
919 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes);
920 data.SetData(data_sp);
921 return bytes;
922 }
923 break;
924 case eAddressTypeInvalid:
925 default:
926 break;
927 }
928 }
929 return 0;
930}
931
932size_t
933ValueObject::GetData (DataExtractor& data)
934{
935 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000936 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytone72dfb32012-02-24 01:59:29 +0000937 Error error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +0000938 if (error.Fail())
939 return 0;
940 data.SetAddressByteSize(m_data.GetAddressByteSize());
941 data.SetByteOrder(m_data.GetByteOrder());
942 return data.GetByteSize();
943}
944
945// will compute strlen(str), but without consuming more than
946// maxlen bytes out of str (this serves the purpose of reading
947// chunks of a string without having to worry about
948// missing NULL terminators in the chunk)
949// of course, if strlen(str) > maxlen, the function will return
950// maxlen_value (which should be != maxlen, because that allows you
951// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
952static uint32_t
953strlen_or_inf (const char* str,
954 uint32_t maxlen,
955 uint32_t maxlen_value)
956{
957 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +0000958 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +0000959 {
Greg Clayton8dd5c172011-10-05 22:19:51 +0000960 while(*str)
961 {
962 len++;str++;
963 if (len > maxlen)
964 return maxlen_value;
965 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000966 }
967 return len;
968}
969
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000970void
Greg Claytoncc4d0142012-02-17 07:49:44 +0000971ValueObject::ReadPointedString (Stream& s,
972 Error& error,
973 uint32_t max_length,
974 bool honor_array,
975 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000976{
Greg Claytoncc4d0142012-02-17 07:49:44 +0000977 ExecutionContext exe_ctx (GetExecutionContextRef());
978 Target* target = exe_ctx.GetTargetPtr();
979
980 if (target && max_length == 0)
981 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000982
983 clang_type_t clang_type = GetClangType();
984 clang_type_t elem_or_pointee_clang_type;
985 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
986 GetClangAST(),
987 &elem_or_pointee_clang_type));
988 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
989 ClangASTContext::IsCharType (elem_or_pointee_clang_type))
990 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000991 if (target == NULL)
992 {
993 s << "<no target to read from>";
994 }
995 else
996 {
997 addr_t cstr_address = LLDB_INVALID_ADDRESS;
998 AddressType cstr_address_type = eAddressTypeInvalid;
999
1000 size_t cstr_len = 0;
1001 bool capped_data = false;
1002 if (type_flags.Test (ClangASTContext::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001003 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001004 // We have an array
1005 cstr_len = ClangASTContext::GetArraySize (clang_type);
1006 if (cstr_len > max_length)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001007 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001008 capped_data = true;
1009 cstr_len = max_length;
1010 }
1011 cstr_address = GetAddressOf (true, &cstr_address_type);
1012 }
1013 else
1014 {
1015 // We have a pointer
1016 cstr_address = GetPointerValue (&cstr_address_type);
1017 }
1018 if (cstr_address != 0 && cstr_address != LLDB_INVALID_ADDRESS)
1019 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001020 Address cstr_so_addr (cstr_address);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001021 DataExtractor data;
1022 size_t bytes_read = 0;
1023 if (cstr_len > 0 && honor_array)
1024 {
1025 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1026 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1027 GetPointeeData(data, 0, cstr_len);
1028
1029 if ((bytes_read = data.GetByteSize()) > 0)
1030 {
1031 s << '"';
1032 data.Dump (&s,
1033 0, // Start offset in "data"
1034 item_format,
1035 1, // Size of item (1 byte for a char!)
1036 bytes_read, // How many bytes to print?
1037 UINT32_MAX, // num per line
1038 LLDB_INVALID_ADDRESS,// base address
1039 0, // bitfield bit size
1040 0); // bitfield bit offset
1041 if (capped_data)
1042 s << "...";
1043 s << '"';
1044 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00001045 }
1046 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001047 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001048 cstr_len = max_length;
1049 const size_t k_max_buf_size = 64;
1050
1051 size_t offset = 0;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001052
Greg Claytoncc4d0142012-02-17 07:49:44 +00001053 int cstr_len_displayed = -1;
1054 bool capped_cstr = false;
1055 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1056 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1057 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001058 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001059 const char *cstr = data.PeekCStr(0);
1060 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1061 if (len > k_max_buf_size)
1062 len = k_max_buf_size;
1063 if (cstr && cstr_len_displayed < 0)
1064 s << '"';
1065
1066 if (cstr_len_displayed < 0)
1067 cstr_len_displayed = len;
1068
1069 if (len == 0)
1070 break;
1071 cstr_len_displayed += len;
1072 if (len > bytes_read)
1073 len = bytes_read;
1074 if (len > cstr_len)
1075 len = cstr_len;
1076
1077 data.Dump (&s,
1078 0, // Start offset in "data"
1079 item_format,
1080 1, // Size of item (1 byte for a char!)
1081 len, // How many bytes to print?
1082 UINT32_MAX, // num per line
1083 LLDB_INVALID_ADDRESS,// base address
1084 0, // bitfield bit size
1085 0); // bitfield bit offset
1086
1087 if (len < k_max_buf_size)
1088 break;
1089
1090 if (len >= cstr_len)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001091 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001092 capped_cstr = true;
1093 break;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001094 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001095
1096 cstr_len -= len;
1097 offset += len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001098 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001099
1100 if (cstr_len_displayed >= 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001101 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001102 s << '"';
1103 if (capped_cstr)
1104 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001105 }
1106 }
1107 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001108 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001109 }
1110 else
1111 {
1112 error.SetErrorString("impossible to read a string from this object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001113 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001114 }
1115}
1116
Jim Ingham53c47f12010-09-10 23:12:17 +00001117const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001118ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001119{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001120
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001121 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001122 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001123
1124 if (!m_object_desc_str.empty())
1125 return m_object_desc_str.c_str();
1126
Greg Claytoncc4d0142012-02-17 07:49:44 +00001127 ExecutionContext exe_ctx (GetExecutionContextRef());
1128 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001129 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001130 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001131
Jim Ingham53c47f12010-09-10 23:12:17 +00001132 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001133
Greg Claytonafacd142011-09-02 01:15:17 +00001134 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001135 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1136
Jim Inghama2cf2632010-12-23 02:29:54 +00001137 if (runtime == NULL)
1138 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001139 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Jim Inghama2cf2632010-12-23 02:29:54 +00001140 clang_type_t opaque_qual_type = GetClangType();
1141 if (opaque_qual_type != NULL)
1142 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001143 bool is_signed;
1144 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed)
1145 || ClangASTContext::IsPointerType (opaque_qual_type))
1146 {
Greg Claytonafacd142011-09-02 01:15:17 +00001147 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001148 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001149 }
1150 }
1151
Jim Ingham8d543de2011-03-31 23:01:21 +00001152 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001153 {
1154 m_object_desc_str.append (s.GetData());
1155 }
Sean Callanan672ad942010-10-23 00:18:49 +00001156
1157 if (m_object_desc_str.empty())
1158 return NULL;
1159 else
1160 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001161}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001162
Enrico Granata0c489f52012-03-01 04:24:26 +00001163bool
1164ValueObject::GetValueAsCString (lldb::Format format,
1165 std::string& destination)
1166{
1167 if (ClangASTContext::IsAggregateType (GetClangType()) == false &&
1168 UpdateValueIfNeeded(false))
1169 {
1170 const Value::ContextType context_type = m_value.GetContextType();
1171
1172 switch (context_type)
1173 {
1174 case Value::eContextTypeClangType:
1175 case Value::eContextTypeLLDBType:
1176 case Value::eContextTypeVariable:
1177 {
1178 clang_type_t clang_type = GetClangType ();
1179 if (clang_type)
1180 {
1181 StreamString sstr;
1182 ExecutionContext exe_ctx (GetExecutionContextRef());
1183 ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
1184 clang_type, // The clang type to display
1185 &sstr,
1186 format, // Format to display this type with
1187 m_data, // Data to extract from
1188 0, // Byte offset into "m_data"
1189 GetByteSize(), // Byte size of item in "m_data"
1190 GetBitfieldBitSize(), // Bitfield bit size
1191 GetBitfieldBitOffset(), // Bitfield bit offset
1192 exe_ctx.GetBestExecutionContextScope());
1193 // Don't set the m_error to anything here otherwise
1194 // we won't be able to re-format as anything else. The
1195 // code for ClangASTType::DumpTypeValue() should always
1196 // return something, even if that something contains
1197 // an error messsage. "m_error" is used to detect errors
1198 // when reading the valid object, not for formatting errors.
1199 if (sstr.GetString().empty())
1200 destination.clear();
1201 else
1202 destination.swap(sstr.GetString());
1203 }
1204 }
1205 break;
1206
1207 case Value::eContextTypeRegisterInfo:
1208 {
1209 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1210 if (reg_info)
1211 {
1212 ExecutionContext exe_ctx (GetExecutionContextRef());
1213
1214 StreamString reg_sstr;
1215 m_data.Dump (&reg_sstr,
1216 0,
1217 format,
1218 reg_info->byte_size,
1219 1,
1220 UINT32_MAX,
1221 LLDB_INVALID_ADDRESS,
1222 0,
1223 0,
1224 exe_ctx.GetBestExecutionContextScope());
1225 destination.swap(reg_sstr.GetString());
1226 }
1227 }
1228 break;
1229
1230 default:
1231 break;
1232 }
1233 return !destination.empty();
1234 }
1235 else
1236 return false;
1237}
1238
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001239const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001240ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001241{
Enrico Granata0c489f52012-03-01 04:24:26 +00001242 if (UpdateValueIfNeeded(true) && m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001243 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001244 lldb::Format my_format = GetFormat();
1245 if (m_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001246 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001247 if (m_type_format_sp)
1248 my_format = m_type_format_sp->GetFormat();
1249 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001250 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001251 if (m_is_bitfield_for_scalar)
1252 my_format = eFormatUnsigned;
1253 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001254 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001255 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001256 {
1257 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1258 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001259 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001260 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001261 else
1262 {
1263 clang_type_t clang_type = GetClangType ();
1264 my_format = ClangASTType::GetFormat(clang_type);
1265 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001266 }
1267 }
1268 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001269 if (GetValueAsCString(my_format, m_value_str))
1270 {
1271 if (!m_value_did_change && m_old_value_valid)
1272 {
1273 // The value was gotten successfully, so we consider the
1274 // value as changed if the value string differs
1275 SetValueDidChange (m_old_value_str != m_value_str);
1276 }
1277 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001278 }
1279 if (m_value_str.empty())
1280 return NULL;
1281 return m_value_str.c_str();
1282}
1283
Enrico Granatac3e320a2011-08-02 17:27:39 +00001284// if > 8bytes, 0 is returned. this method should mostly be used
1285// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001286uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001287ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001288{
1289 // If our byte size is zero this is an aggregate type that has children
1290 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
1291 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001292 Scalar scalar;
1293 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001294 {
1295 if (success)
1296 *success = true;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001297 return scalar.GetRawBits64(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001298 }
1299 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001300 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001301
1302 if (success)
1303 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001304 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001305}
1306
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001307// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1308// this call up to date by returning true for your new special cases. We will eventually move
1309// to checking this call result before trying to display special cases
1310bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001311ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1312 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001313{
1314 clang_type_t elem_or_pointee_type;
1315 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
1316
1317 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001318 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001319 {
1320 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001321 (custom_format == eFormatCString ||
1322 custom_format == eFormatCharArray ||
1323 custom_format == eFormatChar ||
1324 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001325 return true;
1326
1327 if (flags.Test(ClangASTContext::eTypeIsArray))
1328 {
Greg Claytonafacd142011-09-02 01:15:17 +00001329 if ((custom_format == eFormatBytes) ||
1330 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001331 return true;
1332
Greg Claytonafacd142011-09-02 01:15:17 +00001333 if ((custom_format == eFormatVectorOfChar) ||
1334 (custom_format == eFormatVectorOfFloat32) ||
1335 (custom_format == eFormatVectorOfFloat64) ||
1336 (custom_format == eFormatVectorOfSInt16) ||
1337 (custom_format == eFormatVectorOfSInt32) ||
1338 (custom_format == eFormatVectorOfSInt64) ||
1339 (custom_format == eFormatVectorOfSInt8) ||
1340 (custom_format == eFormatVectorOfUInt128) ||
1341 (custom_format == eFormatVectorOfUInt16) ||
1342 (custom_format == eFormatVectorOfUInt32) ||
1343 (custom_format == eFormatVectorOfUInt64) ||
1344 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001345 return true;
1346 }
1347 }
1348 return false;
1349}
1350
Enrico Granata9fc19442011-07-06 02:13:41 +00001351bool
1352ValueObject::DumpPrintableRepresentation(Stream& s,
1353 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001354 Format custom_format,
Enrico Granata86cc9822012-03-19 22:58:49 +00001355 PrintableRepresentationSpecialCases special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001356{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001357
1358 clang_type_t elem_or_pointee_type;
1359 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001360
Enrico Granata86cc9822012-03-19 22:58:49 +00001361 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1362 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1363
1364 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001365 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001366 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1367 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001368 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001369 // when being asked to get a printable display an array or pointer type directly,
1370 // try to "do the right thing"
1371
1372 if (IsCStringContainer(true) &&
1373 (custom_format == eFormatCString ||
1374 custom_format == eFormatCharArray ||
1375 custom_format == eFormatChar ||
1376 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001377 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001378 Error error;
1379 ReadPointedString(s,
1380 error,
1381 0,
1382 (custom_format == eFormatVectorOfChar) ||
1383 (custom_format == eFormatCharArray));
1384 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001385 }
1386
Enrico Granata86cc9822012-03-19 22:58:49 +00001387 if (custom_format == eFormatEnum)
1388 return false;
1389
1390 // this only works for arrays, because I have no way to know when
1391 // the pointed memory ends, and no special \0 end of data marker
1392 if (flags.Test(ClangASTContext::eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001393 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001394 if ((custom_format == eFormatBytes) ||
1395 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001396 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001397 uint32_t count = GetNumChildren();
1398
1399 s << '[';
1400 for (uint32_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001401 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001402
1403 if (low)
1404 s << ',';
1405
1406 ValueObjectSP child = GetChildAtIndex(low,true);
1407 if (!child.get())
1408 {
1409 s << "<invalid child>";
1410 continue;
1411 }
1412 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1413 }
1414
1415 s << ']';
1416
1417 return true;
1418 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001419
Enrico Granata86cc9822012-03-19 22:58:49 +00001420 if ((custom_format == eFormatVectorOfChar) ||
1421 (custom_format == eFormatVectorOfFloat32) ||
1422 (custom_format == eFormatVectorOfFloat64) ||
1423 (custom_format == eFormatVectorOfSInt16) ||
1424 (custom_format == eFormatVectorOfSInt32) ||
1425 (custom_format == eFormatVectorOfSInt64) ||
1426 (custom_format == eFormatVectorOfSInt8) ||
1427 (custom_format == eFormatVectorOfUInt128) ||
1428 (custom_format == eFormatVectorOfUInt16) ||
1429 (custom_format == eFormatVectorOfUInt32) ||
1430 (custom_format == eFormatVectorOfUInt64) ||
1431 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1432 {
1433 uint32_t count = GetNumChildren();
1434
1435 Format format = FormatManager::GetSingleItemFormat(custom_format);
1436
1437 s << '[';
1438 for (uint32_t low = 0; low < count; low++)
1439 {
1440
1441 if (low)
1442 s << ',';
1443
1444 ValueObjectSP child = GetChildAtIndex(low,true);
1445 if (!child.get())
1446 {
1447 s << "<invalid child>";
1448 continue;
1449 }
1450 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1451 }
1452
1453 s << ']';
1454
1455 return true;
1456 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001457 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001458
1459 if ((custom_format == eFormatBoolean) ||
1460 (custom_format == eFormatBinary) ||
1461 (custom_format == eFormatChar) ||
1462 (custom_format == eFormatCharPrintable) ||
1463 (custom_format == eFormatComplexFloat) ||
1464 (custom_format == eFormatDecimal) ||
1465 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001466 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001467 (custom_format == eFormatFloat) ||
1468 (custom_format == eFormatOctal) ||
1469 (custom_format == eFormatOSType) ||
1470 (custom_format == eFormatUnicode16) ||
1471 (custom_format == eFormatUnicode32) ||
1472 (custom_format == eFormatUnsigned) ||
1473 (custom_format == eFormatPointer) ||
1474 (custom_format == eFormatComplexInteger) ||
1475 (custom_format == eFormatComplex) ||
1476 (custom_format == eFormatDefault)) // use the [] operator
1477 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001478 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001479 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001480
1481 if (only_special)
1482 return false;
1483
Enrico Granata86cc9822012-03-19 22:58:49 +00001484 bool var_success = false;
1485
1486 {
1487 const char * return_value;
1488 std::string alloc_mem;
1489
1490 if (custom_format != eFormatInvalid)
1491 SetFormat(custom_format);
1492
1493 switch(val_obj_display)
1494 {
1495 case eValueObjectRepresentationStyleValue:
1496 return_value = GetValueAsCString();
1497 break;
1498
1499 case eValueObjectRepresentationStyleSummary:
1500 return_value = GetSummaryAsCString();
1501 break;
1502
1503 case eValueObjectRepresentationStyleLanguageSpecific:
1504 return_value = GetObjectDescription();
1505 break;
1506
1507 case eValueObjectRepresentationStyleLocation:
1508 return_value = GetLocationAsCString();
1509 break;
1510
1511 case eValueObjectRepresentationStyleChildrenCount:
1512 {
1513 alloc_mem.resize(512);
1514 return_value = &alloc_mem[0];
1515 int count = GetNumChildren();
1516 snprintf((char*)return_value, 512, "%d", count);
1517 }
1518 break;
1519
1520 case eValueObjectRepresentationStyleType:
1521 return_value = GetTypeName().AsCString();
1522 break;
1523
1524 default:
1525 break;
1526 }
1527
1528 if (!return_value)
1529 {
1530 if (val_obj_display == eValueObjectRepresentationStyleValue)
1531 return_value = GetSummaryAsCString();
1532 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1533 {
1534 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1535 {
1536 // this thing has no value, and it seems to have no summary
1537 // some combination of unitialized data and other factors can also
1538 // raise this condition, so let's print a nice generic description
1539 {
1540 alloc_mem.resize(684);
1541 return_value = &alloc_mem[0];
1542 snprintf((char*)return_value, 684, "%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1543 }
1544 }
1545 else
1546 return_value = GetValueAsCString();
1547 }
1548 }
1549
1550 if (return_value)
1551 s.PutCString(return_value);
1552 else
1553 {
1554 if (m_error.Fail())
1555 s.Printf("<%s>", m_error.AsCString());
1556 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1557 s.PutCString("<no summary available>");
1558 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1559 s.PutCString("<no value available>");
1560 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1561 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1562 else
1563 s.PutCString("<no printable representation>");
1564 }
1565
1566 // we should only return false here if we could not do *anything*
1567 // even if we have an error message as output, that's a success
1568 // from our callers' perspective, so return true
1569 var_success = true;
1570
1571 if (custom_format != eFormatInvalid)
1572 SetFormat(eFormatDefault);
1573 }
1574
Enrico Granataf4efecd2011-07-12 22:56:10 +00001575 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001576}
1577
Greg Clayton737b9322010-09-13 03:32:57 +00001578addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001579ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001580{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001581 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001582 return LLDB_INVALID_ADDRESS;
1583
Greg Clayton73b472d2010-10-27 03:32:59 +00001584 switch (m_value.GetValueType())
1585 {
1586 case Value::eValueTypeScalar:
1587 if (scalar_is_load_address)
1588 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001589 if(address_type)
1590 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001591 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1592 }
1593 break;
1594
1595 case Value::eValueTypeLoadAddress:
1596 case Value::eValueTypeFileAddress:
1597 case Value::eValueTypeHostAddress:
1598 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001599 if(address_type)
1600 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001601 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1602 }
1603 break;
1604 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001605 if (address_type)
1606 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001607 return LLDB_INVALID_ADDRESS;
1608}
1609
1610addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001611ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001612{
Greg Claytonafacd142011-09-02 01:15:17 +00001613 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001614 if(address_type)
1615 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001616
Enrico Granatac3e320a2011-08-02 17:27:39 +00001617 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001618 return address;
1619
Greg Clayton73b472d2010-10-27 03:32:59 +00001620 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001621 {
1622 case Value::eValueTypeScalar:
Enrico Granata9128ee22011-09-06 19:20:51 +00001623 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001624 break;
1625
Enrico Granata9128ee22011-09-06 19:20:51 +00001626 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001627 case Value::eValueTypeLoadAddress:
1628 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001629 {
1630 uint32_t data_offset = 0;
1631 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001632 }
1633 break;
1634 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001635
Enrico Granata9128ee22011-09-06 19:20:51 +00001636 if (address_type)
1637 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001638
Greg Clayton737b9322010-09-13 03:32:57 +00001639 return address;
1640}
1641
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001642bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001643ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001644{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001645 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001646 // Make sure our value is up to date first so that our location and location
1647 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001648 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001649 {
1650 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001651 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001652 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001653
1654 uint32_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001655 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001656
Greg Claytonb1320972010-07-14 00:18:15 +00001657 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001658
Jim Ingham16e0c682011-08-12 23:34:31 +00001659 Value::ValueType value_type = m_value.GetValueType();
1660
1661 if (value_type == Value::eValueTypeScalar)
1662 {
1663 // If the value is already a scalar, then let the scalar change itself:
1664 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1665 }
1666 else if (byte_size <= Scalar::GetMaxByteSize())
1667 {
1668 // If the value fits in a scalar, then make a new scalar and again let the
1669 // scalar code do the conversion, then figure out where to put the new value.
1670 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001671 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1672 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001673 {
Jim Ingham4b536182011-08-09 02:12:22 +00001674 switch (value_type)
1675 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001676 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001677 {
1678 // If it is a load address, then the scalar value is the storage location
1679 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001680 ExecutionContext exe_ctx (GetExecutionContextRef());
1681 Process *process = exe_ctx.GetProcessPtr();
1682 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001683 {
Greg Claytonafacd142011-09-02 01:15:17 +00001684 addr_t target_addr = m_value.GetScalar().GetRawBits64(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001685 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1686 new_scalar,
1687 byte_size,
1688 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001689 if (!error.Success())
1690 return false;
1691 if (bytes_written != byte_size)
1692 {
1693 error.SetErrorString("unable to write value to memory");
1694 return false;
1695 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001696 }
1697 }
Jim Ingham4b536182011-08-09 02:12:22 +00001698 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001699 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001700 {
1701 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1702 DataExtractor new_data;
1703 new_data.SetByteOrder (m_data.GetByteOrder());
1704
1705 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1706 m_data.SetData(buffer_sp, 0);
1707 bool success = new_scalar.GetData(new_data);
1708 if (success)
1709 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001710 new_data.CopyByteOrderedData (0,
1711 byte_size,
1712 const_cast<uint8_t *>(m_data.GetDataStart()),
1713 byte_size,
1714 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001715 }
1716 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1717
1718 }
Jim Ingham4b536182011-08-09 02:12:22 +00001719 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001720 case Value::eValueTypeFileAddress:
1721 case Value::eValueTypeScalar:
Jim Ingham16e0c682011-08-12 23:34:31 +00001722 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001723 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001724 }
1725 else
1726 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001727 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001728 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001729 }
1730 else
1731 {
1732 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001733 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001734 return false;
1735 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001736
1737 // If we have reached this point, then we have successfully changed the value.
1738 SetNeedsUpdate();
1739 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001740}
1741
Greg Clayton81e871e2012-02-04 02:27:34 +00001742bool
1743ValueObject::GetDeclaration (Declaration &decl)
1744{
1745 decl.Clear();
1746 return false;
1747}
1748
Greg Clayton84db9102012-03-26 23:03:23 +00001749ConstString
1750ValueObject::GetTypeName()
1751{
1752 return ClangASTType::GetConstTypeName (GetClangAST(), GetClangType());
1753}
1754
1755ConstString
1756ValueObject::GetQualifiedTypeName()
1757{
1758 return ClangASTType::GetConstQualifiedTypeName (GetClangAST(), GetClangType());
1759}
1760
1761
Greg Claytonafacd142011-09-02 01:15:17 +00001762LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001763ValueObject::GetObjectRuntimeLanguage ()
1764{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001765 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1766 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001767}
1768
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001769void
Jim Ingham58b59f92011-04-22 23:53:53 +00001770ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001771{
Jim Ingham58b59f92011-04-22 23:53:53 +00001772 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001773}
1774
1775ValueObjectSP
1776ValueObject::GetSyntheticChild (const ConstString &key) const
1777{
1778 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001779 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001780 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001781 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001782 return synthetic_child_sp;
1783}
1784
1785bool
1786ValueObject::IsPointerType ()
1787{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001788 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001789}
1790
Jim Inghamb7603bb2011-03-18 00:05:18 +00001791bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001792ValueObject::IsArrayType ()
1793{
1794 return ClangASTContext::IsArrayType (GetClangType());
1795}
1796
1797bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001798ValueObject::IsScalarType ()
1799{
1800 return ClangASTContext::IsScalarType (GetClangType());
1801}
1802
1803bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001804ValueObject::IsIntegerType (bool &is_signed)
1805{
1806 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1807}
Greg Clayton73b472d2010-10-27 03:32:59 +00001808
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001809bool
1810ValueObject::IsPointerOrReferenceType ()
1811{
Greg Clayton007d5be2011-05-30 00:49:24 +00001812 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1813}
1814
1815bool
Greg Claytondea8cb42011-06-29 22:09:02 +00001816ValueObject::IsPossibleDynamicType ()
1817{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00001818 ExecutionContext exe_ctx (GetExecutionContextRef());
1819 Process *process = exe_ctx.GetProcessPtr();
1820 if (process)
1821 return process->IsPossibleDynamicValue(*this);
1822 else
Greg Clayton70364252012-08-31 18:56:24 +00001823 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType(), NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00001824}
1825
Greg Claytonafacd142011-09-02 01:15:17 +00001826ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001827ValueObject::GetSyntheticArrayMember (int32_t index, bool can_create)
1828{
1829 if (IsArrayType())
1830 return GetSyntheticArrayMemberFromArray(index, can_create);
1831
1832 if (IsPointerType())
1833 return GetSyntheticArrayMemberFromPointer(index, can_create);
1834
1835 return ValueObjectSP();
1836
1837}
1838
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001839ValueObjectSP
1840ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1841{
1842 ValueObjectSP synthetic_child_sp;
1843 if (IsPointerType ())
1844 {
1845 char index_str[64];
1846 snprintf(index_str, sizeof(index_str), "[%i]", index);
1847 ConstString index_const_str(index_str);
1848 // Check if we have already created a synthetic array member in this
1849 // valid object. If we have we will re-use it.
1850 synthetic_child_sp = GetSyntheticChild (index_const_str);
1851 if (!synthetic_child_sp)
1852 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001853 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001854 // We haven't made a synthetic array member for INDEX yet, so
1855 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001856 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001857
1858 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001859 if (synthetic_child)
1860 {
1861 AddSyntheticChild(index_const_str, synthetic_child);
1862 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001863 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001864 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001865 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001866 }
1867 }
1868 return synthetic_child_sp;
1869}
Jim Ingham22777012010-09-23 02:01:19 +00001870
Greg Claytondaf515f2011-07-09 20:12:33 +00001871// This allows you to create an array member using and index
1872// that doesn't not fall in the normal bounds of the array.
1873// Many times structure can be defined as:
1874// struct Collection
1875// {
1876// uint32_t item_count;
1877// Item item_array[0];
1878// };
1879// The size of the "item_array" is 1, but many times in practice
1880// there are more items in "item_array".
1881
1882ValueObjectSP
1883ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1884{
1885 ValueObjectSP synthetic_child_sp;
1886 if (IsArrayType ())
1887 {
1888 char index_str[64];
1889 snprintf(index_str, sizeof(index_str), "[%i]", index);
1890 ConstString index_const_str(index_str);
1891 // Check if we have already created a synthetic array member in this
1892 // valid object. If we have we will re-use it.
1893 synthetic_child_sp = GetSyntheticChild (index_const_str);
1894 if (!synthetic_child_sp)
1895 {
1896 ValueObject *synthetic_child;
1897 // We haven't made a synthetic array member for INDEX yet, so
1898 // lets make one and cache it for any future reference.
1899 synthetic_child = CreateChildAtIndex(0, true, index);
1900
1901 // Cache the value if we got one back...
1902 if (synthetic_child)
1903 {
1904 AddSyntheticChild(index_const_str, synthetic_child);
1905 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001906 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001907 synthetic_child_sp->m_is_array_item_for_pointer = true;
1908 }
1909 }
1910 }
1911 return synthetic_child_sp;
1912}
1913
Enrico Granata9fc19442011-07-06 02:13:41 +00001914ValueObjectSP
1915ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1916{
1917 ValueObjectSP synthetic_child_sp;
1918 if (IsScalarType ())
1919 {
1920 char index_str[64];
1921 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1922 ConstString index_const_str(index_str);
1923 // Check if we have already created a synthetic array member in this
1924 // valid object. If we have we will re-use it.
1925 synthetic_child_sp = GetSyntheticChild (index_const_str);
1926 if (!synthetic_child_sp)
1927 {
1928 ValueObjectChild *synthetic_child;
1929 // We haven't made a synthetic array member for INDEX yet, so
1930 // lets make one and cache it for any future reference.
1931 synthetic_child = new ValueObjectChild(*this,
1932 GetClangAST(),
1933 GetClangType(),
1934 index_const_str,
1935 GetByteSize(),
1936 0,
1937 to-from+1,
1938 from,
1939 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001940 false,
1941 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00001942
1943 // Cache the value if we got one back...
1944 if (synthetic_child)
1945 {
1946 AddSyntheticChild(index_const_str, synthetic_child);
1947 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001948 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00001949 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1950 }
1951 }
1952 }
1953 return synthetic_child_sp;
1954}
1955
Greg Claytonafacd142011-09-02 01:15:17 +00001956ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001957ValueObject::GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create)
1958{
1959 ValueObjectSP synthetic_child_sp;
1960 if (IsArrayType () || IsPointerType ())
1961 {
1962 char index_str[64];
1963 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1964 ConstString index_const_str(index_str);
1965 // Check if we have already created a synthetic array member in this
1966 // valid object. If we have we will re-use it.
1967 synthetic_child_sp = GetSyntheticChild (index_const_str);
1968 if (!synthetic_child_sp)
1969 {
1970 ValueObjectSynthetic *synthetic_child;
1971
1972 // We haven't made a synthetic array member for INDEX yet, so
1973 // lets make one and cache it for any future reference.
Enrico Granata061858c2012-02-15 02:34:21 +00001974 SyntheticArrayView *view = new SyntheticArrayView(SyntheticChildren::Flags());
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001975 view->AddRange(from,to);
1976 SyntheticChildrenSP view_sp(view);
1977 synthetic_child = new ValueObjectSynthetic(*this, view_sp);
1978
1979 // Cache the value if we got one back...
1980 if (synthetic_child)
1981 {
1982 AddSyntheticChild(index_const_str, synthetic_child);
1983 synthetic_child_sp = synthetic_child->GetSP();
1984 synthetic_child_sp->SetName(ConstString(index_str));
1985 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1986 }
1987 }
1988 }
1989 return synthetic_child_sp;
1990}
1991
Greg Claytonafacd142011-09-02 01:15:17 +00001992ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00001993ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
1994{
1995
1996 ValueObjectSP synthetic_child_sp;
1997
1998 char name_str[64];
1999 snprintf(name_str, sizeof(name_str), "@%i", offset);
2000 ConstString name_const_str(name_str);
2001
2002 // Check if we have already created a synthetic array member in this
2003 // valid object. If we have we will re-use it.
2004 synthetic_child_sp = GetSyntheticChild (name_const_str);
2005
2006 if (synthetic_child_sp.get())
2007 return synthetic_child_sp;
2008
2009 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002010 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002011
2012 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2013 type.GetASTContext(),
2014 type.GetOpaqueQualType(),
2015 name_const_str,
2016 type.GetTypeByteSize(),
2017 offset,
2018 0,
2019 0,
2020 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002021 false,
2022 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002023 if (synthetic_child)
2024 {
2025 AddSyntheticChild(name_const_str, synthetic_child);
2026 synthetic_child_sp = synthetic_child->GetSP();
2027 synthetic_child_sp->SetName(name_const_str);
2028 synthetic_child_sp->m_is_child_at_offset = true;
2029 }
2030 return synthetic_child_sp;
2031}
2032
Enrico Granatad55546b2011-07-22 00:16:08 +00002033// your expression path needs to have a leading . or ->
2034// (unless it somehow "looks like" an array, in which case it has
2035// a leading [ symbol). while the [ is meaningful and should be shown
2036// to the user, . and -> are just parser design, but by no means
2037// added information for the user.. strip them off
2038static const char*
2039SkipLeadingExpressionPathSeparators(const char* expression)
2040{
2041 if (!expression || !expression[0])
2042 return expression;
2043 if (expression[0] == '.')
2044 return expression+1;
2045 if (expression[0] == '-' && expression[1] == '>')
2046 return expression+2;
2047 return expression;
2048}
2049
Greg Claytonafacd142011-09-02 01:15:17 +00002050ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002051ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2052{
2053 ValueObjectSP synthetic_child_sp;
2054 ConstString name_const_string(expression);
2055 // Check if we have already created a synthetic array member in this
2056 // valid object. If we have we will re-use it.
2057 synthetic_child_sp = GetSyntheticChild (name_const_string);
2058 if (!synthetic_child_sp)
2059 {
2060 // We haven't made a synthetic array member for expression yet, so
2061 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002062 synthetic_child_sp = GetValueForExpressionPath(expression,
2063 NULL, NULL, NULL,
2064 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
Enrico Granatad55546b2011-07-22 00:16:08 +00002065
2066 // Cache the value if we got one back...
2067 if (synthetic_child_sp.get())
2068 {
2069 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002070 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002071 synthetic_child_sp->m_is_expression_path_child = true;
2072 }
2073 }
2074 return synthetic_child_sp;
2075}
2076
2077void
Enrico Granata86cc9822012-03-19 22:58:49 +00002078ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002079{
Enrico Granata86cc9822012-03-19 22:58:49 +00002080 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002081 return;
2082
Enrico Granatac5bc4122012-03-27 02:35:13 +00002083 TargetSP target_sp(GetTargetSP());
2084 if (target_sp && (target_sp->GetEnableSyntheticValue() == false || target_sp->GetSuppressSyntheticValue() == true))
2085 {
2086 m_synthetic_value = NULL;
2087 return;
2088 }
2089
Enrico Granatae3e91512012-10-22 18:18:36 +00002090 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2091
Enrico Granata86cc9822012-03-19 22:58:49 +00002092 if (!UpdateFormatsIfNeeded(m_last_format_mgr_dynamic) && m_synthetic_value)
2093 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002094
Enrico Granata0c489f52012-03-01 04:24:26 +00002095 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002096 return;
2097
Enrico Granatae3e91512012-10-22 18:18:36 +00002098 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2099 return;
2100
Enrico Granata86cc9822012-03-19 22:58:49 +00002101 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002102}
2103
Jim Ingham78a685a2011-04-16 00:01:13 +00002104void
Greg Claytonafacd142011-09-02 01:15:17 +00002105ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002106{
Greg Claytonafacd142011-09-02 01:15:17 +00002107 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002108 return;
2109
Jim Ingham58b59f92011-04-22 23:53:53 +00002110 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002111 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002112 ExecutionContext exe_ctx (GetExecutionContextRef());
2113 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002114 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002115 {
2116 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002117 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002118 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002119 }
2120}
2121
Jim Ingham58b59f92011-04-22 23:53:53 +00002122ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002123ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002124{
Greg Claytonafacd142011-09-02 01:15:17 +00002125 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002126 return ValueObjectSP();
2127
2128 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002129 {
Jim Ingham2837b762011-05-04 03:43:18 +00002130 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002131 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002132 if (m_dynamic_value)
2133 return m_dynamic_value->GetSP();
2134 else
2135 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002136}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002137
Jim Ingham60dbabb2011-12-08 19:44:08 +00002138ValueObjectSP
2139ValueObject::GetStaticValue()
2140{
2141 return GetSP();
2142}
2143
Enrico Granata886147f2012-05-08 18:47:08 +00002144lldb::ValueObjectSP
2145ValueObject::GetNonSyntheticValue ()
2146{
2147 return GetSP();
2148}
2149
Enrico Granatad55546b2011-07-22 00:16:08 +00002150ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002151ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002152{
Enrico Granata86cc9822012-03-19 22:58:49 +00002153 if (use_synthetic == false)
2154 return ValueObjectSP();
2155
Enrico Granatad55546b2011-07-22 00:16:08 +00002156 CalculateSyntheticValue(use_synthetic);
2157
2158 if (m_synthetic_value)
2159 return m_synthetic_value->GetSP();
2160 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002161 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002162}
2163
Greg Claytone221f822011-01-21 01:59:00 +00002164bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002165ValueObject::HasSyntheticValue()
2166{
2167 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
2168
Enrico Granata0c489f52012-03-01 04:24:26 +00002169 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002170 return false;
2171
Enrico Granata86cc9822012-03-19 22:58:49 +00002172 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002173
2174 if (m_synthetic_value)
2175 return true;
2176 else
2177 return false;
2178}
2179
2180bool
Greg Claytone221f822011-01-21 01:59:00 +00002181ValueObject::GetBaseClassPath (Stream &s)
2182{
2183 if (IsBaseClass())
2184 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002185 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00002186 clang_type_t clang_type = GetClangType();
2187 std::string cxx_class_name;
2188 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
2189 if (this_had_base_class)
2190 {
2191 if (parent_had_base_class)
2192 s.PutCString("::");
2193 s.PutCString(cxx_class_name.c_str());
2194 }
2195 return parent_had_base_class || this_had_base_class;
2196 }
2197 return false;
2198}
2199
2200
2201ValueObject *
2202ValueObject::GetNonBaseClassParent()
2203{
Jim Ingham78a685a2011-04-16 00:01:13 +00002204 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002205 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002206 if (GetParent()->IsBaseClass())
2207 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002208 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002209 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002210 }
2211 return NULL;
2212}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002213
2214void
Enrico Granata4becb372011-06-29 22:27:15 +00002215ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002216{
Greg Claytone221f822011-01-21 01:59:00 +00002217 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002218
Enrico Granata86cc9822012-03-19 22:58:49 +00002219 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002220 {
Enrico Granata4becb372011-06-29 22:27:15 +00002221 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2222 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2223 // the eHonorPointers mode is meant to produce strings in this latter format
2224 s.PutCString("*(");
2225 }
Greg Claytone221f822011-01-21 01:59:00 +00002226
Enrico Granata4becb372011-06-29 22:27:15 +00002227 ValueObject* parent = GetParent();
2228
2229 if (parent)
2230 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002231
2232 // if we are a deref_of_parent just because we are synthetic array
2233 // members made up to allow ptr[%d] syntax to work in variable
2234 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002235 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002236 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002237
Greg Claytone221f822011-01-21 01:59:00 +00002238 if (!IsBaseClass())
2239 {
2240 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002241 {
Greg Claytone221f822011-01-21 01:59:00 +00002242 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2243 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002244 {
Greg Claytone221f822011-01-21 01:59:00 +00002245 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2246 if (non_base_class_parent_clang_type)
2247 {
2248 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2249
Enrico Granata86cc9822012-03-19 22:58:49 +00002250 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002251 {
2252 s.PutCString("->");
2253 }
Enrico Granata4becb372011-06-29 22:27:15 +00002254 else
2255 {
2256 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2257 {
2258 s.PutCString("->");
2259 }
2260 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2261 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2262 {
2263 s.PutChar('.');
2264 }
Greg Claytone221f822011-01-21 01:59:00 +00002265 }
2266 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002267 }
Greg Claytone221f822011-01-21 01:59:00 +00002268
2269 const char *name = GetName().GetCString();
2270 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002271 {
Greg Claytone221f822011-01-21 01:59:00 +00002272 if (qualify_cxx_base_classes)
2273 {
2274 if (GetBaseClassPath (s))
2275 s.PutCString("::");
2276 }
2277 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002278 }
2279 }
2280 }
2281
Enrico Granata86cc9822012-03-19 22:58:49 +00002282 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002283 {
Greg Claytone221f822011-01-21 01:59:00 +00002284 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002285 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002286}
2287
Greg Claytonafacd142011-09-02 01:15:17 +00002288ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002289ValueObject::GetValueForExpressionPath(const char* expression,
2290 const char** first_unparsed,
2291 ExpressionPathScanEndReason* reason_to_stop,
2292 ExpressionPathEndResultType* final_value_type,
2293 const GetValueForExpressionPathOptions& options,
2294 ExpressionPathAftermath* final_task_on_target)
2295{
2296
2297 const char* dummy_first_unparsed;
2298 ExpressionPathScanEndReason dummy_reason_to_stop;
2299 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002300 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002301
2302 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2303 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2304 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2305 final_value_type ? final_value_type : &dummy_final_value_type,
2306 options,
2307 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2308
Enrico Granata86cc9822012-03-19 22:58:49 +00002309 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002310 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002311
Enrico Granata86cc9822012-03-19 22:58:49 +00002312 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 +00002313 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002314 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002315 {
2316 Error error;
2317 ValueObjectSP final_value = ret_val->Dereference(error);
2318 if (error.Fail() || !final_value.get())
2319 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002320 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002321 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002322 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002323 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002324 return ValueObjectSP();
2325 }
2326 else
2327 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002328 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002329 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002330 return final_value;
2331 }
2332 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002333 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002334 {
2335 Error error;
2336 ValueObjectSP final_value = ret_val->AddressOf(error);
2337 if (error.Fail() || !final_value.get())
2338 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002339 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002340 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002341 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002342 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002343 return ValueObjectSP();
2344 }
2345 else
2346 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002347 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002348 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002349 return final_value;
2350 }
2351 }
2352 }
2353 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2354}
2355
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002356int
2357ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002358 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002359 const char** first_unparsed,
2360 ExpressionPathScanEndReason* reason_to_stop,
2361 ExpressionPathEndResultType* final_value_type,
2362 const GetValueForExpressionPathOptions& options,
2363 ExpressionPathAftermath* final_task_on_target)
2364{
2365 const char* dummy_first_unparsed;
2366 ExpressionPathScanEndReason dummy_reason_to_stop;
2367 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002368 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002369
2370 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2371 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2372 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2373 final_value_type ? final_value_type : &dummy_final_value_type,
2374 options,
2375 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2376
2377 if (!ret_val.get()) // if there are errors, I add nothing to the list
2378 return 0;
2379
Enrico Granata86ea8d82012-03-29 01:34:34 +00002380 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002381 {
2382 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002383 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002384 {
2385 list->Append(ret_val);
2386 return 1;
2387 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002388 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 +00002389 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002390 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002391 {
2392 Error error;
2393 ValueObjectSP final_value = ret_val->Dereference(error);
2394 if (error.Fail() || !final_value.get())
2395 {
Greg Clayton23f59502012-07-17 03:23:13 +00002396 if (reason_to_stop)
2397 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2398 if (final_value_type)
2399 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002400 return 0;
2401 }
2402 else
2403 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002404 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002405 list->Append(final_value);
2406 return 1;
2407 }
2408 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002409 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002410 {
2411 Error error;
2412 ValueObjectSP final_value = ret_val->AddressOf(error);
2413 if (error.Fail() || !final_value.get())
2414 {
Greg Clayton23f59502012-07-17 03:23:13 +00002415 if (reason_to_stop)
2416 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2417 if (final_value_type)
2418 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002419 return 0;
2420 }
2421 else
2422 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002423 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002424 list->Append(final_value);
2425 return 1;
2426 }
2427 }
2428 }
2429 }
2430 else
2431 {
2432 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2433 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2434 ret_val,
2435 list,
2436 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2437 final_value_type ? final_value_type : &dummy_final_value_type,
2438 options,
2439 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2440 }
2441 // in any non-covered case, just do the obviously right thing
2442 list->Append(ret_val);
2443 return 1;
2444}
2445
Greg Claytonafacd142011-09-02 01:15:17 +00002446ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002447ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2448 const char** first_unparsed,
2449 ExpressionPathScanEndReason* reason_to_stop,
2450 ExpressionPathEndResultType* final_result,
2451 const GetValueForExpressionPathOptions& options,
2452 ExpressionPathAftermath* what_next)
2453{
2454 ValueObjectSP root = GetSP();
2455
2456 if (!root.get())
2457 return ValueObjectSP();
2458
2459 *first_unparsed = expression_cstr;
2460
2461 while (true)
2462 {
2463
2464 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2465
Greg Claytonafacd142011-09-02 01:15:17 +00002466 clang_type_t root_clang_type = root->GetClangType();
2467 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002468 Flags root_clang_type_info,pointee_clang_type_info;
2469
2470 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2471 if (pointee_clang_type)
2472 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002473
2474 if (!expression_cstr || *expression_cstr == '\0')
2475 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002476 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002477 return root;
2478 }
2479
2480 switch (*expression_cstr)
2481 {
2482 case '-':
2483 {
2484 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002485 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 +00002486 {
2487 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002488 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2489 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002490 return ValueObjectSP();
2491 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002492 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2493 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002494 options.m_no_fragile_ivar)
2495 {
2496 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002497 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2498 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002499 return ValueObjectSP();
2500 }
2501 if (expression_cstr[1] != '>')
2502 {
2503 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002504 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2505 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002506 return ValueObjectSP();
2507 }
2508 expression_cstr++; // skip the -
2509 }
2510 case '.': // or fallthrough from ->
2511 {
2512 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002513 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 +00002514 {
2515 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002516 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2517 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002518 return ValueObjectSP();
2519 }
2520 expression_cstr++; // skip .
2521 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2522 ConstString child_name;
2523 if (!next_separator) // if no other separator just expand this last layer
2524 {
2525 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002526 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2527
2528 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002529 {
2530 *first_unparsed = '\0';
Enrico Granata86cc9822012-03-19 22:58:49 +00002531 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2532 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002533 return child_valobj_sp;
2534 }
2535 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2536 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002537 if (root->IsSynthetic())
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002538 {
2539 *first_unparsed = expression_cstr;
2540 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2541 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2542 return ValueObjectSP();
2543 }
2544
2545 child_valobj_sp = root->GetSyntheticValue();
Enrico Granata86cc9822012-03-19 22:58:49 +00002546 if (child_valobj_sp.get())
2547 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002548 }
2549
2550 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2551 // so we hit the "else" branch, and return an error
2552 if(child_valobj_sp.get()) // if it worked, just return
2553 {
2554 *first_unparsed = '\0';
Enrico Granata86cc9822012-03-19 22:58:49 +00002555 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2556 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002557 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002558 }
2559 else
2560 {
2561 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002562 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2563 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002564 return ValueObjectSP();
2565 }
2566 }
2567 else // other layers do expand
2568 {
2569 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002570 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2571 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002572 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002573 root = child_valobj_sp;
2574 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002575 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002576 continue;
2577 }
2578 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2579 {
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002580 if (root->IsSynthetic())
2581 {
2582 *first_unparsed = expression_cstr;
2583 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2584 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2585 return ValueObjectSP();
2586 }
2587
Enrico Granata86cc9822012-03-19 22:58:49 +00002588 child_valobj_sp = root->GetSyntheticValue(true);
2589 if (child_valobj_sp)
2590 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002591 }
2592
2593 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2594 // so we hit the "else" branch, and return an error
2595 if(child_valobj_sp.get()) // if it worked, move on
2596 {
2597 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002598 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002599 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002600 continue;
2601 }
2602 else
2603 {
2604 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002605 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2606 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002607 return ValueObjectSP();
2608 }
2609 }
2610 break;
2611 }
2612 case '[':
2613 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002614 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 +00002615 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002616 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002617 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002618 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2619 {
2620 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002621 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2622 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002623 return ValueObjectSP();
2624 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002625 }
2626 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2627 {
2628 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002629 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2630 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002631 return ValueObjectSP();
2632 }
2633 }
2634 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2635 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002636 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002637 {
2638 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002639 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2640 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002641 return ValueObjectSP();
2642 }
2643 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2644 {
2645 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002646 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2647 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002648 return root;
2649 }
2650 }
2651 const char *separator_position = ::strchr(expression_cstr+1,'-');
2652 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2653 if (!close_bracket_position) // if there is no ], this is a syntax error
2654 {
2655 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002656 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2657 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002658 return ValueObjectSP();
2659 }
2660 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2661 {
2662 char *end = NULL;
2663 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2664 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2665 {
2666 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002667 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2668 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002669 return ValueObjectSP();
2670 }
2671 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2672 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002673 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002674 {
2675 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002676 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2677 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002678 return root;
2679 }
2680 else
2681 {
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 }
2688 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002689 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002690 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002691 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2692 if (!child_valobj_sp)
2693 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002694 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002695 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2696 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002697 if (child_valobj_sp)
2698 {
2699 root = child_valobj_sp;
2700 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002701 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002702 continue;
2703 }
2704 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002705 {
2706 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002707 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2708 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002709 return ValueObjectSP();
2710 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002711 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002712 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002713 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002714 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 +00002715 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002716 {
2717 Error error;
2718 root = root->Dereference(error);
2719 if (error.Fail() || !root.get())
2720 {
2721 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002722 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2723 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002724 return ValueObjectSP();
2725 }
2726 else
2727 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002728 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002729 continue;
2730 }
2731 }
2732 else
2733 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002734 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Clayton84db9102012-03-26 23:03:23 +00002735 root->GetClangType()) == eLanguageTypeObjC
2736 && ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2737 && root->HasSyntheticValue()
2738 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002739 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002740 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002741 }
2742 else
2743 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002744 if (!root.get())
2745 {
2746 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002747 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2748 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002749 return ValueObjectSP();
2750 }
2751 else
2752 {
2753 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002754 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002755 continue;
2756 }
2757 }
2758 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002759 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002760 {
2761 root = root->GetSyntheticBitFieldChild(index, index, true);
2762 if (!root.get())
2763 {
2764 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002765 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2766 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002767 return ValueObjectSP();
2768 }
2769 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2770 {
2771 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002772 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2773 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002774 return root;
2775 }
2776 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002777 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002778 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002779 if (root->HasSyntheticValue())
2780 root = root->GetSyntheticValue();
2781 else if (!root->IsSynthetic())
2782 {
2783 *first_unparsed = expression_cstr;
2784 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2785 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2786 return ValueObjectSP();
2787 }
2788 // if we are here, then root itself is a synthetic VO.. should be good to go
2789
Enrico Granata27b625e2011-08-09 01:04:56 +00002790 if (!root.get())
2791 {
2792 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002793 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2794 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2795 return ValueObjectSP();
2796 }
2797 root = root->GetChildAtIndex(index, true);
2798 if (!root.get())
2799 {
2800 *first_unparsed = expression_cstr;
2801 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2802 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002803 return ValueObjectSP();
2804 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002805 else
2806 {
2807 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002808 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002809 continue;
2810 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002811 }
2812 else
2813 {
2814 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002815 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2816 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002817 return ValueObjectSP();
2818 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002819 }
2820 else // we have a low and a high index
2821 {
2822 char *end = NULL;
2823 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2824 if (!end || end != separator_position) // if something weird is in our way return an error
2825 {
2826 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002827 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2828 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002829 return ValueObjectSP();
2830 }
2831 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2832 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2833 {
2834 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002835 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2836 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002837 return ValueObjectSP();
2838 }
2839 if (index_lower > index_higher) // swap indices if required
2840 {
2841 unsigned long temp = index_lower;
2842 index_lower = index_higher;
2843 index_higher = temp;
2844 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002845 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002846 {
2847 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2848 if (!root.get())
2849 {
2850 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002851 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2852 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002853 return ValueObjectSP();
2854 }
2855 else
2856 {
2857 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002858 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2859 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002860 return root;
2861 }
2862 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002863 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 +00002864 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002865 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002866 {
2867 Error error;
2868 root = root->Dereference(error);
2869 if (error.Fail() || !root.get())
2870 {
2871 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002872 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2873 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002874 return ValueObjectSP();
2875 }
2876 else
2877 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002878 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002879 continue;
2880 }
2881 }
2882 else
2883 {
2884 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002885 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2886 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002887 return root;
2888 }
2889 }
2890 break;
2891 }
2892 default: // some non-separator is in the way
2893 {
2894 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002895 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2896 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002897 return ValueObjectSP();
2898 break;
2899 }
2900 }
2901 }
2902}
2903
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002904int
2905ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2906 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002907 ValueObjectSP root,
2908 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002909 ExpressionPathScanEndReason* reason_to_stop,
2910 ExpressionPathEndResultType* final_result,
2911 const GetValueForExpressionPathOptions& options,
2912 ExpressionPathAftermath* what_next)
2913{
2914 if (!root.get())
2915 return 0;
2916
2917 *first_unparsed = expression_cstr;
2918
2919 while (true)
2920 {
2921
2922 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2923
Greg Claytonafacd142011-09-02 01:15:17 +00002924 clang_type_t root_clang_type = root->GetClangType();
2925 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002926 Flags root_clang_type_info,pointee_clang_type_info;
2927
2928 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2929 if (pointee_clang_type)
2930 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2931
2932 if (!expression_cstr || *expression_cstr == '\0')
2933 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002934 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002935 list->Append(root);
2936 return 1;
2937 }
2938
2939 switch (*expression_cstr)
2940 {
2941 case '[':
2942 {
2943 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2944 {
2945 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2946 {
2947 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002948 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2949 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002950 return 0;
2951 }
2952 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2953 {
2954 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002955 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2956 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002957 return 0;
2958 }
2959 }
2960 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2961 {
2962 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2963 {
2964 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002965 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2966 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002967 return 0;
2968 }
2969 else // expand this into list
2970 {
2971 int max_index = root->GetNumChildren() - 1;
2972 for (int index = 0; index < max_index; index++)
2973 {
2974 ValueObjectSP child =
2975 root->GetChildAtIndex(index, true);
2976 list->Append(child);
2977 }
2978 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002979 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
2980 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002981 return max_index; // tell me number of items I added to the VOList
2982 }
2983 }
2984 const char *separator_position = ::strchr(expression_cstr+1,'-');
2985 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2986 if (!close_bracket_position) // if there is no ], this is a syntax error
2987 {
2988 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002989 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2990 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002991 return 0;
2992 }
2993 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2994 {
2995 char *end = NULL;
2996 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2997 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2998 {
2999 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003000 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3001 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003002 return 0;
3003 }
3004 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3005 {
3006 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3007 {
3008 int max_index = root->GetNumChildren() - 1;
3009 for (int index = 0; index < max_index; index++)
3010 {
3011 ValueObjectSP child =
3012 root->GetChildAtIndex(index, true);
3013 list->Append(child);
3014 }
3015 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003016 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3017 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003018 return max_index; // tell me number of items I added to the VOList
3019 }
3020 else
3021 {
3022 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003023 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3024 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003025 return 0;
3026 }
3027 }
3028 // from here on we do have a valid index
3029 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3030 {
3031 root = root->GetChildAtIndex(index, true);
3032 if (!root.get())
3033 {
3034 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003035 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3036 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003037 return 0;
3038 }
3039 else
3040 {
3041 list->Append(root);
3042 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003043 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3044 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003045 return 1;
3046 }
3047 }
3048 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
3049 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003050 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 +00003051 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3052 {
3053 Error error;
3054 root = root->Dereference(error);
3055 if (error.Fail() || !root.get())
3056 {
3057 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003058 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3059 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003060 return 0;
3061 }
3062 else
3063 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003064 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003065 continue;
3066 }
3067 }
3068 else
3069 {
3070 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3071 if (!root.get())
3072 {
3073 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003074 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3075 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003076 return 0;
3077 }
3078 else
3079 {
3080 list->Append(root);
3081 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003082 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3083 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003084 return 1;
3085 }
3086 }
3087 }
3088 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3089 {
3090 root = root->GetSyntheticBitFieldChild(index, index, true);
3091 if (!root.get())
3092 {
3093 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003094 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3095 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003096 return 0;
3097 }
3098 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3099 {
3100 list->Append(root);
3101 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003102 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3103 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003104 return 1;
3105 }
3106 }
3107 }
3108 else // we have a low and a high index
3109 {
3110 char *end = NULL;
3111 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3112 if (!end || end != separator_position) // if something weird is in our way return an error
3113 {
3114 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003115 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3116 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003117 return 0;
3118 }
3119 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3120 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3121 {
3122 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003123 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3124 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003125 return 0;
3126 }
3127 if (index_lower > index_higher) // swap indices if required
3128 {
3129 unsigned long temp = index_lower;
3130 index_lower = index_higher;
3131 index_higher = temp;
3132 }
3133 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
3134 {
3135 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3136 if (!root.get())
3137 {
3138 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003139 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3140 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003141 return 0;
3142 }
3143 else
3144 {
3145 list->Append(root);
3146 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003147 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3148 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003149 return 1;
3150 }
3151 }
3152 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 +00003153 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003154 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3155 {
3156 Error error;
3157 root = root->Dereference(error);
3158 if (error.Fail() || !root.get())
3159 {
3160 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003161 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3162 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003163 return 0;
3164 }
3165 else
3166 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003167 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003168 continue;
3169 }
3170 }
3171 else
3172 {
Johnny Chen44805302011-07-19 19:48:13 +00003173 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003174 index <= index_higher; index++)
3175 {
3176 ValueObjectSP child =
3177 root->GetChildAtIndex(index, true);
3178 list->Append(child);
3179 }
3180 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003181 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3182 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003183 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3184 }
3185 }
3186 break;
3187 }
3188 default: // some non-[ separator, or something entirely wrong, is in the way
3189 {
3190 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003191 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3192 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003193 return 0;
3194 break;
3195 }
3196 }
3197 }
3198}
3199
Enrico Granata0c489f52012-03-01 04:24:26 +00003200static void
3201DumpValueObject_Impl (Stream &s,
3202 ValueObject *valobj,
3203 const ValueObject::DumpValueObjectOptions& options,
3204 uint32_t ptr_depth,
3205 uint32_t curr_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003206{
Greg Clayton007d5be2011-05-30 00:49:24 +00003207 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003208 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003209 bool update_success = valobj->UpdateValueIfNeeded (options.m_use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00003210
Enrico Granata0c489f52012-03-01 04:24:26 +00003211 const char *root_valobj_name =
3212 options.m_root_valobj_name.empty() ?
3213 valobj->GetName().AsCString() :
3214 options.m_root_valobj_name.c_str();
3215
3216 if (update_success && options.m_use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00003217 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003218 ValueObject *dynamic_value = valobj->GetDynamicValue(options.m_use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003219 if (dynamic_value)
3220 valobj = dynamic_value;
3221 }
3222
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003223 clang_type_t clang_type = valobj->GetClangType();
3224
Greg Clayton73b472d2010-10-27 03:32:59 +00003225 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003226 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00003227 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
3228 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003229
Enrico Granata0c489f52012-03-01 04:24:26 +00003230 const bool print_valobj = options.m_flat_output == false || has_value;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003231
3232 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003233 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003234 if (options.m_show_location)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003235 {
Jim Ingham6035b672011-03-31 00:19:25 +00003236 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003237 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003238
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003239 s.Indent();
Enrico Granata2b2631c2012-08-09 16:51:25 +00003240
3241 bool show_type = true;
3242 // if we are at the root-level and been asked to hide the root's type, then hide it
3243 if (curr_depth == 0 && options.m_hide_root_type)
3244 show_type = false;
3245 else
3246 // otherwise decide according to the usual rules (asked to show types - always at the root level)
3247 show_type = options.m_show_types || (curr_depth == 0 && !options.m_flat_output);
3248
3249 if (show_type)
Enrico Granatac3e320a2011-08-02 17:27:39 +00003250 {
Greg Clayton84db9102012-03-26 23:03:23 +00003251 const char* typeName = valobj->GetQualifiedTypeName().AsCString("<invalid type>");
3252 //const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
Enrico Granata9910bc82011-08-03 02:18:51 +00003253 s.Printf("(%s", typeName);
3254 // only show dynamic types if the user really wants to see types
Enrico Granata0c489f52012-03-01 04:24:26 +00003255 if (options.m_show_types && options.m_use_dynamic != eNoDynamicValues &&
Enrico Granata9910bc82011-08-03 02:18:51 +00003256 (/*strstr(typeName, "id") == typeName ||*/
Greg Claytonafacd142011-09-02 01:15:17 +00003257 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003258 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003259 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3260 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatac3e320a2011-08-02 17:27:39 +00003261 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003262 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003263 else
3264 {
3265 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
3266 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003267 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003268 else
3269 {
Greg Claytonf0246d12012-10-11 18:07:21 +00003270 ObjCLanguageRuntime::ClassDescriptorSP objc_class_sp (runtime->GetNonKVOClassDescriptor(*valobj));
3271 if (objc_class_sp)
3272 s.Printf(", dynamic type: %s) ", objc_class_sp->GetClassName().GetCString());
Enrico Granatac3e320a2011-08-02 17:27:39 +00003273 else
Greg Claytonf0246d12012-10-11 18:07:21 +00003274 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003275 }
3276 }
3277 }
3278 else
3279 s.Printf(") ");
3280 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003281
Greg Clayton1d3afba2010-10-05 00:00:42 +00003282
Enrico Granata0c489f52012-03-01 04:24:26 +00003283 if (options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003284 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003285 // If we are showing types, also qualify the C++ base classes
Enrico Granata0c489f52012-03-01 04:24:26 +00003286 const bool qualify_cxx_base_classes = options.m_show_types;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003287 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003288 s.PutCString(" =");
3289 }
3290 else
3291 {
3292 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3293 s.Printf ("%s =", name_cstr);
3294 }
3295
Enrico Granata0c489f52012-03-01 04:24:26 +00003296 if (!options.m_scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003297 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003298 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003299 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003300 }
3301
Enrico Granata0c489f52012-03-01 04:24:26 +00003302 std::string summary_str;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003303 std::string value_str;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003304 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003305 const char *sum_cstr = NULL;
Enrico Granata0c489f52012-03-01 04:24:26 +00003306 TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003307
Enrico Granata0c489f52012-03-01 04:24:26 +00003308 if (options.m_omit_summary_depth > 0)
Enrico Granata0c5ef692011-07-16 01:22:04 +00003309 entry = NULL;
3310
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003311 if (err_cstr == NULL)
3312 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003313 if (options.m_format != eFormatDefault && options.m_format != valobj->GetFormat())
Greg Clayton6efba4f2012-01-26 21:08:30 +00003314 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003315 valobj->GetValueAsCString(options.m_format,
3316 value_str);
Greg Clayton6efba4f2012-01-26 21:08:30 +00003317 }
Enrico Granata0c489f52012-03-01 04:24:26 +00003318 else
Greg Clayton6efba4f2012-01-26 21:08:30 +00003319 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003320 val_cstr = valobj->GetValueAsCString();
3321 if (val_cstr)
3322 value_str = val_cstr;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003323 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003324 err_cstr = valobj->GetError().AsCString();
3325 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003326
3327 if (err_cstr)
3328 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003329 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003330 }
3331 else
3332 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003333 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003334 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003335 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003336 if (options.m_omit_summary_depth == 0)
3337 {
3338 if (options.m_summary_sp)
3339 {
3340 valobj->GetSummaryAsCString(entry, summary_str);
3341 sum_cstr = summary_str.c_str();
3342 }
3343 else
3344 sum_cstr = valobj->GetSummaryAsCString();
3345 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003346
Greg Clayton6efba4f2012-01-26 21:08:30 +00003347 // Make sure we have a value and make sure the summary didn't
3348 // specify that the value should not be printed
3349 if (!value_str.empty() && (entry == NULL || entry->DoesPrintValue() || sum_cstr == NULL))
3350 s.Printf(" %s", value_str.c_str());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003351
Enrico Granata9dd75c82011-07-15 23:30:15 +00003352 if (sum_cstr)
Enrico Granata0c489f52012-03-01 04:24:26 +00003353 s.Printf(" %s", sum_cstr);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003354
Enrico Granata0c489f52012-03-01 04:24:26 +00003355 if (options.m_use_objc)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003356 {
Jim Ingham6035b672011-03-31 00:19:25 +00003357 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003358 if (object_desc)
3359 s.Printf(" %s\n", object_desc);
3360 else
Sean Callanan672ad942010-10-23 00:18:49 +00003361 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003362 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003363 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003364 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003365
Enrico Granata0c489f52012-03-01 04:24:26 +00003366 if (curr_depth < options.m_max_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003367 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003368 // We will show children for all concrete types. We won't show
3369 // pointer contents unless a pointer depth has been specified.
3370 // We won't reference contents unless the reference is the
3371 // root object (depth of zero).
3372 bool print_children = true;
3373
3374 // Use a new temporary pointer depth in case we override the
3375 // current pointer depth below...
3376 uint32_t curr_ptr_depth = ptr_depth;
3377
3378 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3379 if (is_ptr || is_ref)
3380 {
3381 // We have a pointer or reference whose value is an address.
3382 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003383 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003384 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003385 print_children = false;
3386
3387 else if (is_ref && curr_depth == 0)
3388 {
3389 // If this is the root object (depth is zero) that we are showing
3390 // and it is a reference, and no pointer depth has been supplied
3391 // print out what it references. Don't do this at deeper depths
3392 // otherwise we can end up with infinite recursion...
3393 curr_ptr_depth = 1;
3394 }
3395
3396 if (curr_ptr_depth == 0)
3397 print_children = false;
3398 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003399
Enrico Granata0a3958e2011-07-02 00:25:22 +00003400 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003401 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003402 ValueObject* synth_valobj;
3403 ValueObjectSP synth_valobj_sp = valobj->GetSyntheticValue (options.m_use_synthetic);
3404 synth_valobj = (synth_valobj_sp ? synth_valobj_sp.get() : valobj);
Enrico Granatac5bc4122012-03-27 02:35:13 +00003405
Enrico Granatac482a192011-08-17 22:13:59 +00003406 uint32_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003407 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003408 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003409 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003410 if (options.m_flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003411 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003412 if (print_valobj)
3413 s.EOL();
3414 }
3415 else
3416 {
3417 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003418 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003419 s.IndentMore();
3420 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003421
Greg Claytoncc4d0142012-02-17 07:49:44 +00003422 uint32_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00003423
Enrico Granata0c489f52012-03-01 04:24:26 +00003424 if (num_children > max_num_children && !options.m_ignore_cap)
Enrico Granata22c55d12011-08-12 02:00:06 +00003425 {
3426 num_children = max_num_children;
3427 print_dotdotdot = true;
3428 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003429
Enrico Granata0c489f52012-03-01 04:24:26 +00003430 ValueObject::DumpValueObjectOptions child_options(options);
3431 child_options.SetFormat().SetSummary().SetRootValueObjectName();
3432 child_options.SetScopeChecked(true)
3433 .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003434 for (uint32_t idx=0; idx<num_children; ++idx)
3435 {
Enrico Granatac482a192011-08-17 22:13:59 +00003436 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003437 if (child_sp.get())
3438 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003439 DumpValueObject_Impl (s,
3440 child_sp.get(),
3441 child_options,
3442 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
3443 curr_depth + 1);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003444 }
3445 }
3446
Enrico Granata0c489f52012-03-01 04:24:26 +00003447 if (!options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003448 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003449 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003450 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003451 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3452 Target *target = exe_ctx.GetTargetPtr();
3453 if (target)
3454 target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003455 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003456 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003457 s.IndentLess();
3458 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003459 }
3460 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003461 else if (has_children)
3462 {
3463 // Aggregate, no children...
3464 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003465 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003466 }
3467 else
3468 {
3469 if (print_valobj)
3470 s.EOL();
3471 }
3472
Greg Clayton1d3afba2010-10-05 00:00:42 +00003473 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003474 else
3475 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003476 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003477 }
3478 }
3479 else
3480 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003481 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003482 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003483 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003484 }
3485 }
3486 }
3487 }
3488}
3489
Enrico Granata0c489f52012-03-01 04:24:26 +00003490void
Greg Claytonf830dbb2012-03-22 18:15:37 +00003491ValueObject::LogValueObject (Log *log,
3492 ValueObject *valobj)
3493{
3494 if (log && valobj)
3495 return LogValueObject (log, valobj, DumpValueObjectOptions::DefaultOptions());
3496}
3497
3498void
3499ValueObject::LogValueObject (Log *log,
3500 ValueObject *valobj,
3501 const DumpValueObjectOptions& options)
3502{
3503 if (log && valobj)
3504 {
3505 StreamString s;
3506 ValueObject::DumpValueObject (s, valobj, options);
3507 if (s.GetSize())
3508 log->PutCString(s.GetData());
3509 }
3510}
3511
3512void
Enrico Granata0c489f52012-03-01 04:24:26 +00003513ValueObject::DumpValueObject (Stream &s,
3514 ValueObject *valobj)
3515{
3516
3517 if (!valobj)
3518 return;
3519
3520 DumpValueObject_Impl(s,
3521 valobj,
3522 DumpValueObjectOptions::DefaultOptions(),
3523 0,
3524 0);
3525}
3526
3527void
3528ValueObject::DumpValueObject (Stream &s,
3529 ValueObject *valobj,
3530 const DumpValueObjectOptions& options)
3531{
3532 DumpValueObject_Impl(s,
3533 valobj,
3534 options,
3535 options.m_max_ptr_depth, // max pointer depth allowed, we will go down from here
3536 0 // current object depth is 0 since we are just starting
3537 );
3538}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003539
3540ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003541ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003542{
3543 ValueObjectSP valobj_sp;
3544
Enrico Granatac3e320a2011-08-02 17:27:39 +00003545 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003546 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003547 ExecutionContext exe_ctx (GetExecutionContextRef());
3548 clang::ASTContext *ast = GetClangAST ();
3549
3550 DataExtractor data;
3551 data.SetByteOrder (m_data.GetByteOrder());
3552 data.SetAddressByteSize(m_data.GetAddressByteSize());
3553
Enrico Granata9f1e2042012-04-24 22:15:37 +00003554 if (IsBitfield())
3555 {
3556 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
3557 m_error = v.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
3558 }
3559 else
3560 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003561
3562 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3563 ast,
3564 GetClangType(),
3565 name,
3566 data,
3567 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003568 }
Jim Ingham6035b672011-03-31 00:19:25 +00003569
3570 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003571 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003572 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003573 }
3574 return valobj_sp;
3575}
3576
Greg Claytonafacd142011-09-02 01:15:17 +00003577ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003578ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003579{
Jim Ingham58b59f92011-04-22 23:53:53 +00003580 if (m_deref_valobj)
3581 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003582
Greg Clayton54979cd2010-12-15 05:08:08 +00003583 const bool is_pointer_type = IsPointerType();
3584 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003585 {
3586 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003587 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003588
3589 std::string child_name_str;
3590 uint32_t child_byte_size = 0;
3591 int32_t child_byte_offset = 0;
3592 uint32_t child_bitfield_bit_size = 0;
3593 uint32_t child_bitfield_bit_offset = 0;
3594 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003595 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003596 const bool transparent_pointers = false;
3597 clang::ASTContext *clang_ast = GetClangAST();
3598 clang_type_t clang_type = GetClangType();
3599 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003600
Greg Claytoncc4d0142012-02-17 07:49:44 +00003601 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003602
3603 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3604 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003605 GetName().GetCString(),
3606 clang_type,
3607 0,
3608 transparent_pointers,
3609 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003610 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003611 child_name_str,
3612 child_byte_size,
3613 child_byte_offset,
3614 child_bitfield_bit_size,
3615 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003616 child_is_base_class,
3617 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003618 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003619 {
3620 ConstString child_name;
3621 if (!child_name_str.empty())
3622 child_name.SetCString (child_name_str.c_str());
3623
Jim Ingham58b59f92011-04-22 23:53:53 +00003624 m_deref_valobj = new ValueObjectChild (*this,
3625 clang_ast,
3626 child_clang_type,
3627 child_name,
3628 child_byte_size,
3629 child_byte_offset,
3630 child_bitfield_bit_size,
3631 child_bitfield_bit_offset,
3632 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003633 child_is_deref_of_parent,
3634 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003635 }
3636 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003637
Jim Ingham58b59f92011-04-22 23:53:53 +00003638 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003639 {
3640 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003641 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003642 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003643 else
3644 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003645 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003646 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003647
3648 if (is_pointer_type)
3649 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3650 else
3651 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003652 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003653 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003654}
3655
Greg Claytonafacd142011-09-02 01:15:17 +00003656ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003657ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003658{
Jim Ingham78a685a2011-04-16 00:01:13 +00003659 if (m_addr_of_valobj_sp)
3660 return m_addr_of_valobj_sp;
3661
Greg Claytone0d378b2011-03-24 21:19:54 +00003662 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003663 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003664 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003665 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003666 if (addr != LLDB_INVALID_ADDRESS)
3667 {
3668 switch (address_type)
3669 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003670 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003671 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003672 {
3673 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003674 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003675 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3676 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003677 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003678
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003679 case eAddressTypeFile:
3680 case eAddressTypeLoad:
3681 case eAddressTypeHost:
3682 {
3683 clang::ASTContext *ast = GetClangAST();
3684 clang_type_t clang_type = GetClangType();
3685 if (ast && clang_type)
3686 {
3687 std::string name (1, '&');
3688 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003689 ExecutionContext exe_ctx (GetExecutionContextRef());
3690 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003691 ast,
3692 ClangASTContext::CreatePointerType (ast, clang_type),
3693 ConstString (name.c_str()),
3694 addr,
3695 eAddressTypeInvalid,
3696 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003697 }
3698 }
3699 break;
3700 }
3701 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003702 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003703}
3704
Greg Clayton9a142cf2012-02-03 05:34:10 +00003705ValueObjectSP
3706ValueObject::Cast (const ClangASTType &clang_ast_type)
3707{
Greg Clayton81e871e2012-02-04 02:27:34 +00003708 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003709}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003710
Greg Claytonafacd142011-09-02 01:15:17 +00003711ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003712ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3713{
Greg Claytonafacd142011-09-02 01:15:17 +00003714 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003715 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003716 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003717
3718 if (ptr_value != LLDB_INVALID_ADDRESS)
3719 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003720 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003721 ExecutionContext exe_ctx (GetExecutionContextRef());
3722 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003723 name,
3724 ptr_addr,
3725 clang_ast_type);
3726 }
3727 return valobj_sp;
3728}
3729
Greg Claytonafacd142011-09-02 01:15:17 +00003730ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003731ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3732{
Greg Claytonafacd142011-09-02 01:15:17 +00003733 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003734 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003735 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003736
3737 if (ptr_value != LLDB_INVALID_ADDRESS)
3738 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003739 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003740 ExecutionContext exe_ctx (GetExecutionContextRef());
3741 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003742 name,
3743 ptr_addr,
3744 type_sp);
3745 }
3746 return valobj_sp;
3747}
3748
Jim Ingham6035b672011-03-31 00:19:25 +00003749ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003750 m_mod_id(),
3751 m_exe_ctx_ref(),
3752 m_needs_update (true),
3753 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003754{
3755}
3756
3757ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003758 m_mod_id(),
3759 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003760 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003761 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003762{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003763 ExecutionContext exe_ctx(exe_scope);
3764 TargetSP target_sp (exe_ctx.GetTargetSP());
3765 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003766 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003767 m_exe_ctx_ref.SetTargetSP (target_sp);
3768 ProcessSP process_sp (exe_ctx.GetProcessSP());
3769 if (!process_sp)
3770 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003771
Greg Claytoncc4d0142012-02-17 07:49:44 +00003772 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003773 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003774 m_mod_id = process_sp->GetModID();
3775 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003776
Greg Claytoncc4d0142012-02-17 07:49:44 +00003777 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003778
Greg Claytoncc4d0142012-02-17 07:49:44 +00003779 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003780 {
3781 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003782 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003783 }
Jim Ingham6035b672011-03-31 00:19:25 +00003784
Greg Claytoncc4d0142012-02-17 07:49:44 +00003785 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003786 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003787 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003788
Greg Claytoncc4d0142012-02-17 07:49:44 +00003789 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3790 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003791 {
3792 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003793 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003794 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003795 if (frame_sp)
3796 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003797 }
3798 }
3799 }
Jim Ingham6035b672011-03-31 00:19:25 +00003800}
3801
3802ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003803 m_mod_id(),
3804 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3805 m_needs_update (true),
3806 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003807{
3808}
3809
3810ValueObject::EvaluationPoint::~EvaluationPoint ()
3811{
3812}
3813
Jim Ingham6035b672011-03-31 00:19:25 +00003814// This function checks the EvaluationPoint against the current process state. If the current
3815// state matches the evaluation point, or the evaluation point is already invalid, then we return
3816// false, meaning "no change". If the current state is different, we update our state, and return
3817// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3818// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003819// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003820
3821bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003822ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003823{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003824
3825 // 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 +00003826 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00003827
Greg Claytoncc4d0142012-02-17 07:49:44 +00003828 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003829 return false;
3830
Jim Ingham6035b672011-03-31 00:19:25 +00003831 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003832 Process *process = exe_ctx.GetProcessPtr();
3833 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003834 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003835
Jim Ingham6035b672011-03-31 00:19:25 +00003836 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003837 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003838
Jim Ingham78a685a2011-04-16 00:01:13 +00003839 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3840 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003841 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003842 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003843
Greg Clayton23f59502012-07-17 03:23:13 +00003844 bool changed = false;
3845 const bool was_valid = m_mod_id.IsValid();
3846 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003847 {
3848 if (m_mod_id == current_mod_id)
3849 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003850 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003851 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003852 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003853 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003854 else
3855 {
3856 m_mod_id = current_mod_id;
3857 m_needs_update = true;
3858 changed = true;
3859 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003860 }
Jim Ingham6035b672011-03-31 00:19:25 +00003861
Jim Ingham73ca05a2011-12-17 01:35:57 +00003862 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3863 // That way we'll be sure to return a valid exe_scope.
3864 // 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 +00003865
Greg Claytoncc4d0142012-02-17 07:49:44 +00003866 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003867 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003868 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3869 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003870 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003871 if (m_exe_ctx_ref.HasFrameRef())
3872 {
3873 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3874 if (!frame_sp)
3875 {
3876 // We used to have a frame, but now it is gone
3877 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003878 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00003879 }
3880 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003881 }
Jim Ingham6035b672011-03-31 00:19:25 +00003882 else
3883 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003884 // We used to have a thread, but now it is gone
3885 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003886 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00003887 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003888
Jim Ingham6035b672011-03-31 00:19:25 +00003889 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003890 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003891}
3892
Jim Ingham61be0902011-05-02 18:13:59 +00003893void
3894ValueObject::EvaluationPoint::SetUpdated ()
3895{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003896 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3897 if (process_sp)
3898 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003899 m_first_update = false;
3900 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003901}
3902
3903
Greg Claytoncc4d0142012-02-17 07:49:44 +00003904//bool
3905//ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3906//{
3907// if (!IsValid())
3908// return false;
3909//
3910// bool needs_update = false;
3911//
3912// // The target has to be non-null, and the
3913// Target *target = exe_scope->CalculateTarget();
3914// if (target != NULL)
3915// {
3916// Target *old_target = m_target_sp.get();
3917// assert (target == old_target);
3918// Process *process = exe_scope->CalculateProcess();
3919// if (process != NULL)
3920// {
3921// // FOR NOW - assume you can't update variable objects across process boundaries.
3922// Process *old_process = m_process_sp.get();
3923// assert (process == old_process);
3924// ProcessModID current_mod_id = process->GetModID();
3925// if (m_mod_id != current_mod_id)
3926// {
3927// needs_update = true;
3928// m_mod_id = current_mod_id;
3929// }
3930// // See if we're switching the thread or stack context. If no thread is given, this is
3931// // being evaluated in a global context.
3932// Thread *thread = exe_scope->CalculateThread();
3933// if (thread != NULL)
3934// {
3935// user_id_t new_thread_index = thread->GetIndexID();
3936// if (new_thread_index != m_thread_id)
3937// {
3938// needs_update = true;
3939// m_thread_id = new_thread_index;
3940// m_stack_id.Clear();
3941// }
3942//
3943// StackFrame *new_frame = exe_scope->CalculateStackFrame();
3944// if (new_frame != NULL)
3945// {
3946// if (new_frame->GetStackID() != m_stack_id)
3947// {
3948// needs_update = true;
3949// m_stack_id = new_frame->GetStackID();
3950// }
3951// }
3952// else
3953// {
3954// m_stack_id.Clear();
3955// needs_update = true;
3956// }
3957// }
3958// else
3959// {
3960// // If this had been given a thread, and now there is none, we should update.
3961// // Otherwise we don't have to do anything.
3962// if (m_thread_id != LLDB_INVALID_UID)
3963// {
3964// m_thread_id = LLDB_INVALID_UID;
3965// m_stack_id.Clear();
3966// needs_update = true;
3967// }
3968// }
3969// }
3970// else
3971// {
3972// // If there is no process, then we don't need to update anything.
3973// // But if we're switching from having a process to not, we should try to update.
3974// if (m_process_sp.get() != NULL)
3975// {
3976// needs_update = true;
3977// m_process_sp.reset();
3978// m_thread_id = LLDB_INVALID_UID;
3979// m_stack_id.Clear();
3980// }
3981// }
3982// }
3983// else
3984// {
3985// // If there's no target, nothing can change so we don't need to update anything.
3986// // But if we're switching from having a target to not, we should try to update.
3987// if (m_target_sp.get() != NULL)
3988// {
3989// needs_update = true;
3990// m_target_sp.reset();
3991// m_process_sp.reset();
3992// m_thread_id = LLDB_INVALID_UID;
3993// m_stack_id.Clear();
3994// }
3995// }
3996// if (!m_needs_update)
3997// m_needs_update = needs_update;
3998//
3999// return needs_update;
4000//}
Enrico Granataf2bbf712011-07-15 02:26:42 +00004001
4002void
Enrico Granata86cc9822012-03-19 22:58:49 +00004003ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004004{
Enrico Granata86cc9822012-03-19 22:58:49 +00004005 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4006 m_value_str.clear();
4007
4008 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4009 m_location_str.clear();
4010
4011 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
4012 {
Enrico Granata86cc9822012-03-19 22:58:49 +00004013 m_summary_str.clear();
4014 }
4015
4016 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4017 m_object_desc_str.clear();
4018
4019 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4020 {
4021 if (m_synthetic_value)
4022 m_synthetic_value = NULL;
4023 }
Johnny Chen44805302011-07-19 19:48:13 +00004024}
Enrico Granata9128ee22011-09-06 19:20:51 +00004025
4026SymbolContextScope *
4027ValueObject::GetSymbolContextScope()
4028{
4029 if (m_parent)
4030 {
4031 if (!m_parent->IsPointerOrReferenceType())
4032 return m_parent->GetSymbolContextScope();
4033 }
4034 return NULL;
4035}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004036
4037lldb::ValueObjectSP
4038ValueObject::CreateValueObjectFromExpression (const char* name,
4039 const char* expression,
4040 const ExecutionContext& exe_ctx)
4041{
4042 lldb::ValueObjectSP retval_sp;
4043 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4044 if (!target_sp)
4045 return retval_sp;
4046 if (!expression || !*expression)
4047 return retval_sp;
4048 target_sp->EvaluateExpression (expression,
4049 exe_ctx.GetFrameSP().get(),
4050 retval_sp);
4051 if (retval_sp && name && *name)
4052 retval_sp->SetName(ConstString(name));
4053 return retval_sp;
4054}
4055
4056lldb::ValueObjectSP
4057ValueObject::CreateValueObjectFromAddress (const char* name,
4058 uint64_t address,
4059 const ExecutionContext& exe_ctx,
4060 ClangASTType type)
4061{
4062 ClangASTType pointer_type(type.GetASTContext(),type.GetPointerType());
4063 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4064 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4065 pointer_type.GetASTContext(),
4066 pointer_type.GetOpaqueQualType(),
4067 ConstString(name),
4068 buffer,
4069 lldb::endian::InlHostByteOrder(),
4070 exe_ctx.GetAddressByteSize()));
4071 if (ptr_result_valobj_sp)
4072 {
4073 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4074 Error err;
4075 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4076 if (ptr_result_valobj_sp && name && *name)
4077 ptr_result_valobj_sp->SetName(ConstString(name));
4078 }
4079 return ptr_result_valobj_sp;
4080}
4081
4082lldb::ValueObjectSP
4083ValueObject::CreateValueObjectFromData (const char* name,
4084 DataExtractor& data,
4085 const ExecutionContext& exe_ctx,
4086 ClangASTType type)
4087{
4088 lldb::ValueObjectSP new_value_sp;
4089 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4090 type.GetASTContext() ,
4091 type.GetOpaqueQualType(),
4092 ConstString(name),
4093 data,
4094 LLDB_INVALID_ADDRESS);
4095 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4096 if (new_value_sp && name && *name)
4097 new_value_sp->SetName(ConstString(name));
4098 return new_value_sp;
4099}