blob: 08f43085015a1bf0e5f11cca7fb99a4dbb1181d5 [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"
Enrico Granata21fd13f2012-10-27 02:05:48 +000027#include "lldb/Core/ValueObjectCast.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028#include "lldb/Core/ValueObjectChild.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000029#include "lldb/Core/ValueObjectConstResult.h"
Jim Ingham78a685a2011-04-16 00:01:13 +000030#include "lldb/Core/ValueObjectDynamicValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031#include "lldb/Core/ValueObjectList.h"
Greg Claytonb2dcc362011-05-05 23:32:56 +000032#include "lldb/Core/ValueObjectMemory.h"
Enrico Granatad55546b2011-07-22 00:16:08 +000033#include "lldb/Core/ValueObjectSyntheticFilter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000034
Greg Clayton7fb56d02011-02-01 01:31:41 +000035#include "lldb/Host/Endian.h"
36
Enrico Granata61a80ba2011-08-12 16:42:31 +000037#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granataf2bbf712011-07-15 02:26:42 +000038#include "lldb/Interpreter/ScriptInterpreterPython.h"
39
Greg Claytone1a916a2010-07-21 22:12:05 +000040#include "lldb/Symbol/ClangASTType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000041#include "lldb/Symbol/ClangASTContext.h"
42#include "lldb/Symbol/Type.h"
43
Jim Ingham53c47f12010-09-10 23:12:17 +000044#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000045#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000046#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000047#include "lldb/Target/Process.h"
48#include "lldb/Target/RegisterContext.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000049#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000050#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051
Enrico Granataf4efecd2011-07-12 22:56:10 +000052#include "lldb/Utility/RefCounter.h"
53
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054using namespace lldb;
55using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000056using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057
Greg Claytonafacd142011-09-02 01:15:17 +000058static user_id_t g_value_obj_uid = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000059
60//----------------------------------------------------------------------
61// ValueObject constructor
62//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000063ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000064 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000065 m_parent (&parent),
Stephen Wilson71c21d12011-04-11 19:41:40 +000066 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000067 m_name (),
68 m_data (),
69 m_value (),
70 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000071 m_value_str (),
72 m_old_value_str (),
73 m_location_str (),
74 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000075 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +000076 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000077 m_children (),
78 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000079 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000080 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000081 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000082 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000083 m_last_format_mgr_revision(0),
Enrico Granatad8b5fce2011-08-02 23:12:24 +000084 m_last_format_mgr_dynamic(parent.m_last_format_mgr_dynamic),
Enrico Granata0c489f52012-03-01 04:24:26 +000085 m_type_summary_sp(),
86 m_type_format_sp(),
87 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +000088 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +000089 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
Greg Clayton288bdf92010-09-02 02:59:18 +000090 m_value_is_valid (false),
91 m_value_did_change (false),
92 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000093 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +000094 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +000095 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +000096 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +000097 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +000098 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +000099 m_is_getting_summary(false),
100 m_did_calculate_complete_objc_class_type(false)
Jim Ingham6035b672011-03-31 00:19:25 +0000101{
Jim Ingham58b59f92011-04-22 23:53:53 +0000102 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000103}
104
105//----------------------------------------------------------------------
106// ValueObject constructor
107//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000108ValueObject::ValueObject (ExecutionContextScope *exe_scope,
109 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000110 UserID (++g_value_obj_uid), // Unique identifier for every value object
111 m_parent (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000112 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000113 m_name (),
114 m_data (),
115 m_value (),
116 m_error (),
117 m_value_str (),
118 m_old_value_str (),
119 m_location_str (),
120 m_summary_str (),
121 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000122 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000123 m_children (),
124 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000125 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000126 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000127 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000128 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000129 m_last_format_mgr_revision(0),
Greg Claytonafacd142011-09-02 01:15:17 +0000130 m_last_format_mgr_dynamic(eNoDynamicValues),
Enrico Granata0c489f52012-03-01 04:24:26 +0000131 m_type_summary_sp(),
132 m_type_format_sp(),
133 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000134 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000135 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Jim Ingham6035b672011-03-31 00:19:25 +0000136 m_value_is_valid (false),
137 m_value_did_change (false),
138 m_children_count_valid (false),
139 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000140 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000141 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000142 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +0000143 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000144 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000145 m_is_getting_summary(false),
146 m_did_calculate_complete_objc_class_type(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000147{
Jim Ingham58b59f92011-04-22 23:53:53 +0000148 m_manager = new ValueObjectManager();
149 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000150}
151
152//----------------------------------------------------------------------
153// Destructor
154//----------------------------------------------------------------------
155ValueObject::~ValueObject ()
156{
157}
158
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000159bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000160ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000161{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000162 return UpdateValueIfNeeded(m_last_format_mgr_dynamic, update_format);
163}
164
165bool
Greg Claytonafacd142011-09-02 01:15:17 +0000166ValueObject::UpdateValueIfNeeded (DynamicValueType use_dynamic, bool update_format)
Enrico Granatac3e320a2011-08-02 17:27:39 +0000167{
Enrico Granata4becb372011-06-29 22:27:15 +0000168
Enrico Granata9128ee22011-09-06 19:20:51 +0000169 bool did_change_formats = false;
170
Enrico Granata0a3958e2011-07-02 00:25:22 +0000171 if (update_format)
Enrico Granata9128ee22011-09-06 19:20:51 +0000172 did_change_formats = UpdateFormatsIfNeeded(use_dynamic);
Enrico Granata4becb372011-06-29 22:27:15 +0000173
Greg Claytonb71f3842010-10-05 03:13:51 +0000174 // If this is a constant value, then our success is predicated on whether
175 // we have an error or not
176 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000177 {
178 // if you were asked to update your formatters, but did not get a chance to do it
179 // clear your own values (this serves the purpose of faking a stop-id for frozen
180 // objects (which are regarded as constant, but could have changes behind their backs
181 // because of the frozen-pointer depth limit)
182 // TODO: decouple summary from value and then remove this code and only force-clear the summary
183 if (update_format && !did_change_formats)
Enrico Granata86cc9822012-03-19 22:58:49 +0000184 ClearUserVisibleData(eClearUserVisibleDataItemsSummary);
Greg Claytonb71f3842010-10-05 03:13:51 +0000185 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000186 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000187
Jim Ingham6035b672011-03-31 00:19:25 +0000188 bool first_update = m_update_point.IsFirstEvaluation();
189
190 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000191 {
Jim Ingham6035b672011-03-31 00:19:25 +0000192 m_update_point.SetUpdated();
193
194 // Save the old value using swap to avoid a string copy which
195 // also will clear our m_value_str
196 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000197 {
Jim Ingham6035b672011-03-31 00:19:25 +0000198 m_old_value_valid = false;
199 }
200 else
201 {
202 m_old_value_valid = true;
203 m_old_value_str.swap (m_value_str);
Enrico Granata86cc9822012-03-19 22:58:49 +0000204 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham6035b672011-03-31 00:19:25 +0000205 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000206
Enrico Granataf2bbf712011-07-15 02:26:42 +0000207 ClearUserVisibleData();
208
Greg Claytonefbc7d22012-03-09 04:23:44 +0000209 if (IsInScope())
Jim Ingham6035b672011-03-31 00:19:25 +0000210 {
Greg Claytonefbc7d22012-03-09 04:23:44 +0000211 const bool value_was_valid = GetValueIsValid();
212 SetValueDidChange (false);
213
214 m_error.Clear();
215
216 // Call the pure virtual function to update the value
217 bool success = UpdateValue ();
218
219 SetValueIsValid (success);
220
221 if (first_update)
222 SetValueDidChange (false);
223 else if (!m_value_did_change && success == false)
224 {
225 // The value wasn't gotten successfully, so we mark this
226 // as changed if the value used to be valid and now isn't
227 SetValueDidChange (value_was_valid);
228 }
229 }
230 else
231 {
232 m_error.SetErrorString("out of scope");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000233 }
234 }
235 return m_error.Success();
236}
237
Enrico Granata9128ee22011-09-06 19:20:51 +0000238bool
Greg Claytonafacd142011-09-02 01:15:17 +0000239ValueObject::UpdateFormatsIfNeeded(DynamicValueType use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000240{
Enrico Granata6f3533f2011-07-29 19:53:35 +0000241 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
242 if (log)
Enrico Granatad2284832012-10-17 22:23:56 +0000243 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
Enrico Granata6f3533f2011-07-29 19:53:35 +0000244 GetName().GetCString(),
Enrico Granatad2284832012-10-17 22:23:56 +0000245 this,
Enrico Granata4becb372011-06-29 22:27:15 +0000246 m_last_format_mgr_revision,
Enrico Granata85933ed2011-08-18 16:38:26 +0000247 DataVisualization::GetCurrentRevision());
Enrico Granata9128ee22011-09-06 19:20:51 +0000248
249 bool any_change = false;
250
Enrico Granata85933ed2011-08-18 16:38:26 +0000251 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()) ||
Enrico Granatac3e320a2011-08-02 17:27:39 +0000252 m_last_format_mgr_dynamic != use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000253 {
Enrico Granata78d06382011-09-09 23:33:14 +0000254 SetValueFormat(DataVisualization::ValueFormats::GetFormat (*this, eNoDynamicValues));
255 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, use_dynamic));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000256#ifndef LLDB_DISABLE_PYTHON
Enrico Granata78d06382011-09-09 23:33:14 +0000257 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, use_dynamic));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000258#endif
Enrico Granata1490c6f2011-07-19 02:34:21 +0000259
Enrico Granata85933ed2011-08-18 16:38:26 +0000260 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
Enrico Granatac3e320a2011-08-02 17:27:39 +0000261 m_last_format_mgr_dynamic = use_dynamic;
Enrico Granata855cd902011-09-06 22:59:55 +0000262
263 any_change = true;
Enrico Granata4becb372011-06-29 22:27:15 +0000264 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000265
266 return any_change;
267
Enrico Granata4becb372011-06-29 22:27:15 +0000268}
269
Jim Ingham16e0c682011-08-12 23:34:31 +0000270void
271ValueObject::SetNeedsUpdate ()
272{
273 m_update_point.SetNeedsUpdate();
274 // We have to clear the value string here so ConstResult children will notice if their values are
275 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000276 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000277}
278
Enrico Granata13ac0e22012-10-17 19:03:34 +0000279void
Enrico Granatae3e91512012-10-22 18:18:36 +0000280ValueObject::ClearDynamicTypeInformation ()
Enrico Granata13ac0e22012-10-17 19:03:34 +0000281{
282 m_did_calculate_complete_objc_class_type = false;
Enrico Granatae3e91512012-10-22 18:18:36 +0000283 m_last_format_mgr_revision = 0;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000284 m_override_type = ClangASTType();
Enrico Granatae3e91512012-10-22 18:18:36 +0000285 SetValueFormat(lldb::TypeFormatImplSP());
286 SetSummaryFormat(lldb::TypeSummaryImplSP());
287 SetSyntheticChildren(lldb::SyntheticChildrenSP());
Enrico Granata13ac0e22012-10-17 19:03:34 +0000288}
289
Sean Callanan72772842012-02-22 23:57:45 +0000290ClangASTType
291ValueObject::MaybeCalculateCompleteType ()
292{
293 ClangASTType ret(GetClangASTImpl(), GetClangTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000294
Sean Callanan72772842012-02-22 23:57:45 +0000295 if (m_did_calculate_complete_objc_class_type)
296 {
297 if (m_override_type.IsValid())
298 return m_override_type;
299 else
300 return ret;
301 }
302
303 clang_type_t ast_type(GetClangTypeImpl());
304 clang_type_t class_type;
305 bool is_pointer_type;
306
307 if (ClangASTContext::IsObjCObjectPointerType(ast_type, &class_type))
308 {
309 is_pointer_type = true;
310 }
311 else if (ClangASTContext::IsObjCClassType(ast_type))
312 {
313 is_pointer_type = false;
314 class_type = ast_type;
315 }
316 else
317 {
318 return ret;
319 }
320
321 m_did_calculate_complete_objc_class_type = true;
322
323 if (!class_type)
324 return ret;
325
326 std::string class_name;
327
328 if (!ClangASTContext::GetObjCClassName(class_type, class_name))
329 return ret;
330
331 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
332
333 if (!process_sp)
334 return ret;
335
336 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
337
338 if (!objc_language_runtime)
339 return ret;
340
341 ConstString class_name_cs(class_name.c_str());
342
343 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name_cs);
344
345 if (!complete_objc_class_type_sp)
346 return ret;
347
348 ClangASTType complete_class(complete_objc_class_type_sp->GetClangAST(),
349 complete_objc_class_type_sp->GetClangFullType());
350
351 if (!ClangASTContext::GetCompleteType(complete_class.GetASTContext(),
352 complete_class.GetOpaqueQualType()))
353 return ret;
354
355 if (is_pointer_type)
356 {
357 clang_type_t pointer_type = ClangASTContext::CreatePointerType(complete_class.GetASTContext(),
358 complete_class.GetOpaqueQualType());
359
360 m_override_type = ClangASTType(complete_class.GetASTContext(),
361 pointer_type);
362 }
363 else
364 {
365 m_override_type = complete_class;
366 }
367
Sean Callanan356e17c2012-03-30 02:04:38 +0000368 if (m_override_type.IsValid())
369 return m_override_type;
370 else
371 return ret;
Sean Callanan72772842012-02-22 23:57:45 +0000372}
373
374clang::ASTContext *
375ValueObject::GetClangAST ()
376{
377 ClangASTType type = MaybeCalculateCompleteType();
378
379 return type.GetASTContext();
380}
381
382lldb::clang_type_t
383ValueObject::GetClangType ()
384{
385 ClangASTType type = MaybeCalculateCompleteType();
386
387 return type.GetOpaqueQualType();
388}
389
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000390DataExtractor &
391ValueObject::GetDataExtractor ()
392{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000393 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000394 return m_data;
395}
396
397const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000398ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000399{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000400 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000401 return m_error;
402}
403
404const ConstString &
405ValueObject::GetName() const
406{
407 return m_name;
408}
409
410const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000411ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000412{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000413 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000414 {
415 if (m_location_str.empty())
416 {
417 StreamString sstr;
418
419 switch (m_value.GetValueType())
420 {
421 default:
422 break;
423
424 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +0000425 case Value::eValueTypeVector:
Greg Clayton526e5af2010-11-13 03:52:47 +0000426 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000427 {
428 RegisterInfo *reg_info = m_value.GetRegisterInfo();
429 if (reg_info)
430 {
431 if (reg_info->name)
432 m_location_str = reg_info->name;
433 else if (reg_info->alt_name)
434 m_location_str = reg_info->alt_name;
Greg Clayton0665a0f2012-10-30 18:18:43 +0000435
436 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000437 }
438 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000439 break;
440
441 case Value::eValueTypeLoadAddress:
442 case Value::eValueTypeFileAddress:
443 case Value::eValueTypeHostAddress:
444 {
445 uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2;
446 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
447 m_location_str.swap(sstr.GetString());
448 }
449 break;
450 }
451 }
452 }
453 return m_location_str.c_str();
454}
455
456Value &
457ValueObject::GetValue()
458{
459 return m_value;
460}
461
462const Value &
463ValueObject::GetValue() const
464{
465 return m_value;
466}
467
468bool
Jim Ingham6035b672011-03-31 00:19:25 +0000469ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000470{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000471 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
472 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000473 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000474 Value tmp_value(m_value);
475 scalar = tmp_value.ResolveValue(&exe_ctx, GetClangAST ());
Greg Claytondcad5022011-12-29 01:26:56 +0000476 if (scalar.IsValid())
477 {
478 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
479 if (bitfield_bit_size)
480 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
481 return true;
482 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000483 }
Greg Claytondcad5022011-12-29 01:26:56 +0000484 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000485}
486
487bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000488ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000489{
Greg Clayton288bdf92010-09-02 02:59:18 +0000490 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000491}
492
493
494void
495ValueObject::SetValueIsValid (bool b)
496{
Greg Clayton288bdf92010-09-02 02:59:18 +0000497 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000498}
499
500bool
Jim Ingham6035b672011-03-31 00:19:25 +0000501ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000502{
Jim Ingham6035b672011-03-31 00:19:25 +0000503 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000504 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000505}
506
507void
508ValueObject::SetValueDidChange (bool value_changed)
509{
Greg Clayton288bdf92010-09-02 02:59:18 +0000510 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000511}
512
513ValueObjectSP
514ValueObject::GetChildAtIndex (uint32_t idx, bool can_create)
515{
516 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000517 // We may need to update our value if we are dynamic
518 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000519 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000520 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000521 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000522 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000523 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000524 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000525 // No we haven't created the child at this index, so lets have our
526 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000527 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000528 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000529
Enrico Granata9d60f602012-03-09 03:09:58 +0000530 ValueObject* child = m_children.GetChildAtIndex(idx);
531 if (child != NULL)
532 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000533 }
534 return child_sp;
535}
536
537uint32_t
538ValueObject::GetIndexOfChildWithName (const ConstString &name)
539{
540 bool omit_empty_base_classes = true;
541 return ClangASTContext::GetIndexOfChildWithName (GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +0000542 GetClangType(),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000543 name.GetCString(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000544 omit_empty_base_classes);
545}
546
547ValueObjectSP
548ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
549{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000550 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000551 // classes (which really aren't part of the expression path), so we
552 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000553 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000554
Greg Claytondea8cb42011-06-29 22:09:02 +0000555 // We may need to update our value if we are dynamic
556 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000557 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000558
559 std::vector<uint32_t> child_indexes;
560 clang::ASTContext *clang_ast = GetClangAST();
561 void *clang_type = GetClangType();
562 bool omit_empty_base_classes = true;
563 const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast,
564 clang_type,
565 name.GetCString(),
566 omit_empty_base_classes,
567 child_indexes);
568 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000569 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000570 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
571 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
572
573 child_sp = GetChildAtIndex(*pos, can_create);
574 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000575 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000576 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000577 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000578 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
579 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000580 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000581 else
582 {
583 child_sp.reset();
584 }
585
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000586 }
587 }
588 return child_sp;
589}
590
591
592uint32_t
593ValueObject::GetNumChildren ()
594{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000595 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000596 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000597 {
598 SetNumChildren (CalculateNumChildren());
599 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000600 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000601}
Greg Clayton4a792072012-10-23 01:50:10 +0000602
603bool
604ValueObject::MightHaveChildren()
605{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000606 bool has_children = false;
Greg Clayton4a792072012-10-23 01:50:10 +0000607 clang_type_t clang_type = GetClangType();
608 if (clang_type)
609 {
610 const uint32_t type_info = ClangASTContext::GetTypeInfo (clang_type,
611 GetClangAST(),
612 NULL);
613 if (type_info & (ClangASTContext::eTypeHasChildren |
614 ClangASTContext::eTypeIsPointer |
615 ClangASTContext::eTypeIsReference))
616 has_children = true;
617 }
618 else
619 {
620 has_children = GetNumChildren () > 0;
621 }
622 return has_children;
623}
624
625// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000626void
627ValueObject::SetNumChildren (uint32_t num_children)
628{
Greg Clayton288bdf92010-09-02 02:59:18 +0000629 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000630 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000631}
632
633void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000634ValueObject::SetName (const ConstString &name)
635{
636 m_name = name;
637}
638
Jim Ingham58b59f92011-04-22 23:53:53 +0000639ValueObject *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000640ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index)
641{
Jim Ingham2eec4872011-05-07 00:10:58 +0000642 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000643
Greg Claytondea8cb42011-06-29 22:09:02 +0000644 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000645 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000646 std::string child_name_str;
647 uint32_t child_byte_size = 0;
648 int32_t child_byte_offset = 0;
649 uint32_t child_bitfield_bit_size = 0;
650 uint32_t child_bitfield_bit_offset = 0;
651 bool child_is_base_class = false;
652 bool child_is_deref_of_parent = false;
653
654 const bool transparent_pointers = synthetic_array_member == false;
655 clang::ASTContext *clang_ast = GetClangAST();
656 clang_type_t clang_type = GetClangType();
657 clang_type_t child_clang_type;
658
Greg Claytoncc4d0142012-02-17 07:49:44 +0000659 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000660
661 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
662 clang_ast,
663 GetName().GetCString(),
664 clang_type,
665 idx,
666 transparent_pointers,
667 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +0000668 ignore_array_bounds,
Greg Claytondea8cb42011-06-29 22:09:02 +0000669 child_name_str,
670 child_byte_size,
671 child_byte_offset,
672 child_bitfield_bit_size,
673 child_bitfield_bit_offset,
674 child_is_base_class,
675 child_is_deref_of_parent);
676 if (child_clang_type && child_byte_size)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000677 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000678 if (synthetic_index)
679 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000680
Greg Claytondea8cb42011-06-29 22:09:02 +0000681 ConstString child_name;
682 if (!child_name_str.empty())
683 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000684
Greg Claytondea8cb42011-06-29 22:09:02 +0000685 valobj = new ValueObjectChild (*this,
686 clang_ast,
687 child_clang_type,
688 child_name,
689 child_byte_size,
690 child_byte_offset,
691 child_bitfield_bit_size,
692 child_bitfield_bit_offset,
693 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000694 child_is_deref_of_parent,
695 eAddressTypeInvalid);
696 //if (valobj)
697 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
698 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000699
Jim Ingham58b59f92011-04-22 23:53:53 +0000700 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000701}
702
Enrico Granata0c489f52012-03-01 04:24:26 +0000703bool
704ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
705 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000706{
Enrico Granata0c489f52012-03-01 04:24:26 +0000707 destination.clear();
708
709 // ideally we would like to bail out if passing NULL, but if we do so
710 // we end up not providing the summary for function pointers anymore
711 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
712 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000713
714 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000715
716 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
717 // information that we might care to see in a crash log. might be useful in very specific situations though.
718 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
719 GetTypeName().GetCString(),
720 GetName().GetCString(),
721 summary_ptr->GetDescription().c_str());*/
722
Enrico Granata0c489f52012-03-01 04:24:26 +0000723 if (UpdateValueIfNeeded (false))
724 {
725 if (summary_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000726 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000727 if (HasSyntheticValue())
728 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
729 summary_ptr->FormatObject(this, destination);
Enrico Granata0c489f52012-03-01 04:24:26 +0000730 }
731 else
732 {
733 clang_type_t clang_type = GetClangType();
734
735 // Do some default printout for function pointers
736 if (clang_type)
Enrico Granata4becb372011-06-29 22:27:15 +0000737 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000738 StreamString sstr;
739 clang_type_t elem_or_pointee_clang_type;
740 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
741 GetClangAST(),
742 &elem_or_pointee_clang_type));
743
744 if (ClangASTContext::IsFunctionPointerType (clang_type))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000745 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000746 AddressType func_ptr_address_type = eAddressTypeInvalid;
747 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
748 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000749 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000750 switch (func_ptr_address_type)
Jim Ingham6035b672011-03-31 00:19:25 +0000751 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000752 case eAddressTypeInvalid:
753 case eAddressTypeFile:
754 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000755
Greg Claytoncc4d0142012-02-17 07:49:44 +0000756 case eAddressTypeLoad:
Enrico Granata0c489f52012-03-01 04:24:26 +0000757 {
758 ExecutionContext exe_ctx (GetExecutionContextRef());
759
760 Address so_addr;
761 Target *target = exe_ctx.GetTargetPtr();
762 if (target && target->GetSectionLoadList().IsEmpty() == false)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000763 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000764 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000765 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000766 so_addr.Dump (&sstr,
767 exe_ctx.GetBestExecutionContextScope(),
768 Address::DumpStyleResolvedDescription,
769 Address::DumpStyleSectionNameOffset);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000770 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000771 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000772 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000773 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000774
Greg Claytoncc4d0142012-02-17 07:49:44 +0000775 case eAddressTypeHost:
776 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +0000777 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000778 }
779 if (sstr.GetSize() > 0)
780 {
781 destination.assign (1, '(');
782 destination.append (sstr.GetData(), sstr.GetSize());
783 destination.append (1, ')');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000784 }
785 }
786 }
787 }
788 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000789 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000790 return !destination.empty();
791}
792
793const char *
794ValueObject::GetSummaryAsCString ()
795{
796 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
797 {
798 GetSummaryAsCString(GetSummaryFormat().get(),
799 m_summary_str);
800 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000801 if (m_summary_str.empty())
802 return NULL;
803 return m_summary_str.c_str();
804}
805
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000806bool
807ValueObject::IsCStringContainer(bool check_pointer)
808{
809 clang_type_t elem_or_pointee_clang_type;
810 const Flags type_flags (ClangASTContext::GetTypeInfo (GetClangType(),
811 GetClangAST(),
812 &elem_or_pointee_clang_type));
813 bool is_char_arr_ptr (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
814 ClangASTContext::IsCharType (elem_or_pointee_clang_type));
815 if (!is_char_arr_ptr)
816 return false;
817 if (!check_pointer)
818 return true;
819 if (type_flags.Test(ClangASTContext::eTypeIsArray))
820 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000821 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000822 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000823 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000824 return (cstr_address != LLDB_INVALID_ADDRESS);
825}
826
Enrico Granata9128ee22011-09-06 19:20:51 +0000827size_t
828ValueObject::GetPointeeData (DataExtractor& data,
829 uint32_t item_idx,
830 uint32_t item_count)
831{
832 if (!IsPointerType() && !IsArrayType())
833 return 0;
834
835 if (item_count == 0)
836 return 0;
837
838 uint32_t stride = 0;
839
840 ClangASTType type(GetClangAST(),
841 GetClangType());
842
843 const uint64_t item_type_size = (IsPointerType() ? ClangASTType::GetTypeByteSize(GetClangAST(), type.GetPointeeType()) :
844 ClangASTType::GetTypeByteSize(GetClangAST(), type.GetArrayElementType(stride)));
845
846 const uint64_t bytes = item_count * item_type_size;
847
848 const uint64_t offset = item_idx * item_type_size;
849
850 if (item_idx == 0 && item_count == 1) // simply a deref
851 {
852 if (IsPointerType())
853 {
854 Error error;
855 ValueObjectSP pointee_sp = Dereference(error);
856 if (error.Fail() || pointee_sp.get() == NULL)
857 return 0;
858 return pointee_sp->GetDataExtractor().Copy(data);
859 }
860 else
861 {
862 ValueObjectSP child_sp = GetChildAtIndex(0, true);
863 if (child_sp.get() == NULL)
864 return 0;
865 return child_sp->GetDataExtractor().Copy(data);
866 }
867 return true;
868 }
869 else /* (items > 1) */
870 {
871 Error error;
872 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
873 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
874
875 AddressType addr_type;
876 lldb::addr_t addr = IsPointerType() ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
877
Enrico Granata9128ee22011-09-06 19:20:51 +0000878 switch (addr_type)
879 {
880 case eAddressTypeFile:
881 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000882 ModuleSP module_sp (GetModule());
883 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000884 {
Enrico Granata9c2efe32012-08-07 01:49:34 +0000885 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +0000886 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +0000887 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000888 ExecutionContext exe_ctx (GetExecutionContextRef());
889 Target* target = exe_ctx.GetTargetPtr();
890 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +0000891 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000892 heap_buf_ptr->SetByteSize(bytes);
893 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
894 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +0000895 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000896 data.SetData(data_sp);
897 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +0000898 }
899 }
900 }
901 }
902 break;
903 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +0000904 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000905 ExecutionContext exe_ctx (GetExecutionContextRef());
906 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +0000907 if (process)
908 {
909 heap_buf_ptr->SetByteSize(bytes);
910 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
911 if (error.Success())
912 {
913 data.SetData(data_sp);
914 return bytes_read;
915 }
916 }
917 }
918 break;
919 case eAddressTypeHost:
920 {
921 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes);
922 data.SetData(data_sp);
923 return bytes;
924 }
925 break;
926 case eAddressTypeInvalid:
927 default:
928 break;
929 }
930 }
931 return 0;
932}
933
934size_t
935ValueObject::GetData (DataExtractor& data)
936{
937 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000938 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytone72dfb32012-02-24 01:59:29 +0000939 Error error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +0000940 if (error.Fail())
941 return 0;
942 data.SetAddressByteSize(m_data.GetAddressByteSize());
943 data.SetByteOrder(m_data.GetByteOrder());
944 return data.GetByteSize();
945}
946
947// will compute strlen(str), but without consuming more than
948// maxlen bytes out of str (this serves the purpose of reading
949// chunks of a string without having to worry about
950// missing NULL terminators in the chunk)
951// of course, if strlen(str) > maxlen, the function will return
952// maxlen_value (which should be != maxlen, because that allows you
953// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
954static uint32_t
955strlen_or_inf (const char* str,
956 uint32_t maxlen,
957 uint32_t maxlen_value)
958{
959 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +0000960 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +0000961 {
Greg Clayton8dd5c172011-10-05 22:19:51 +0000962 while(*str)
963 {
964 len++;str++;
965 if (len > maxlen)
966 return maxlen_value;
967 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000968 }
969 return len;
970}
971
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000972void
Greg Claytoncc4d0142012-02-17 07:49:44 +0000973ValueObject::ReadPointedString (Stream& s,
974 Error& error,
975 uint32_t max_length,
976 bool honor_array,
977 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000978{
Greg Claytoncc4d0142012-02-17 07:49:44 +0000979 ExecutionContext exe_ctx (GetExecutionContextRef());
980 Target* target = exe_ctx.GetTargetPtr();
981
982 if (target && max_length == 0)
983 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000984
985 clang_type_t clang_type = GetClangType();
986 clang_type_t elem_or_pointee_clang_type;
987 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
988 GetClangAST(),
989 &elem_or_pointee_clang_type));
990 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
991 ClangASTContext::IsCharType (elem_or_pointee_clang_type))
992 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000993 if (target == NULL)
994 {
995 s << "<no target to read from>";
996 }
997 else
998 {
999 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1000 AddressType cstr_address_type = eAddressTypeInvalid;
1001
1002 size_t cstr_len = 0;
1003 bool capped_data = false;
1004 if (type_flags.Test (ClangASTContext::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001005 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001006 // We have an array
1007 cstr_len = ClangASTContext::GetArraySize (clang_type);
1008 if (cstr_len > max_length)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001009 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001010 capped_data = true;
1011 cstr_len = max_length;
1012 }
1013 cstr_address = GetAddressOf (true, &cstr_address_type);
1014 }
1015 else
1016 {
1017 // We have a pointer
1018 cstr_address = GetPointerValue (&cstr_address_type);
1019 }
1020 if (cstr_address != 0 && cstr_address != LLDB_INVALID_ADDRESS)
1021 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001022 Address cstr_so_addr (cstr_address);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001023 DataExtractor data;
1024 size_t bytes_read = 0;
1025 if (cstr_len > 0 && honor_array)
1026 {
1027 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1028 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1029 GetPointeeData(data, 0, cstr_len);
1030
1031 if ((bytes_read = data.GetByteSize()) > 0)
1032 {
1033 s << '"';
1034 data.Dump (&s,
1035 0, // Start offset in "data"
1036 item_format,
1037 1, // Size of item (1 byte for a char!)
1038 bytes_read, // How many bytes to print?
1039 UINT32_MAX, // num per line
1040 LLDB_INVALID_ADDRESS,// base address
1041 0, // bitfield bit size
1042 0); // bitfield bit offset
1043 if (capped_data)
1044 s << "...";
1045 s << '"';
1046 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00001047 }
1048 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001049 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001050 cstr_len = max_length;
1051 const size_t k_max_buf_size = 64;
1052
1053 size_t offset = 0;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001054
Greg Claytoncc4d0142012-02-17 07:49:44 +00001055 int cstr_len_displayed = -1;
1056 bool capped_cstr = false;
1057 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1058 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1059 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001060 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001061 const char *cstr = data.PeekCStr(0);
1062 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1063 if (len > k_max_buf_size)
1064 len = k_max_buf_size;
1065 if (cstr && cstr_len_displayed < 0)
1066 s << '"';
1067
1068 if (cstr_len_displayed < 0)
1069 cstr_len_displayed = len;
1070
1071 if (len == 0)
1072 break;
1073 cstr_len_displayed += len;
1074 if (len > bytes_read)
1075 len = bytes_read;
1076 if (len > cstr_len)
1077 len = cstr_len;
1078
1079 data.Dump (&s,
1080 0, // Start offset in "data"
1081 item_format,
1082 1, // Size of item (1 byte for a char!)
1083 len, // How many bytes to print?
1084 UINT32_MAX, // num per line
1085 LLDB_INVALID_ADDRESS,// base address
1086 0, // bitfield bit size
1087 0); // bitfield bit offset
1088
1089 if (len < k_max_buf_size)
1090 break;
1091
1092 if (len >= cstr_len)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001093 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001094 capped_cstr = true;
1095 break;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001096 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001097
1098 cstr_len -= len;
1099 offset += len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001100 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001101
1102 if (cstr_len_displayed >= 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001103 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001104 s << '"';
1105 if (capped_cstr)
1106 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001107 }
1108 }
1109 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001110 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001111 }
1112 else
1113 {
1114 error.SetErrorString("impossible to read a string from this object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001115 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001116 }
1117}
1118
Jim Ingham53c47f12010-09-10 23:12:17 +00001119const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001120ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001121{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001122
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001123 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001124 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001125
1126 if (!m_object_desc_str.empty())
1127 return m_object_desc_str.c_str();
1128
Greg Claytoncc4d0142012-02-17 07:49:44 +00001129 ExecutionContext exe_ctx (GetExecutionContextRef());
1130 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001131 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001132 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001133
Jim Ingham53c47f12010-09-10 23:12:17 +00001134 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001135
Greg Claytonafacd142011-09-02 01:15:17 +00001136 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001137 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1138
Jim Inghama2cf2632010-12-23 02:29:54 +00001139 if (runtime == NULL)
1140 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001141 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Jim Inghama2cf2632010-12-23 02:29:54 +00001142 clang_type_t opaque_qual_type = GetClangType();
1143 if (opaque_qual_type != NULL)
1144 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001145 bool is_signed;
1146 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed)
1147 || ClangASTContext::IsPointerType (opaque_qual_type))
1148 {
Greg Claytonafacd142011-09-02 01:15:17 +00001149 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001150 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001151 }
1152 }
1153
Jim Ingham8d543de2011-03-31 23:01:21 +00001154 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001155 {
1156 m_object_desc_str.append (s.GetData());
1157 }
Sean Callanan672ad942010-10-23 00:18:49 +00001158
1159 if (m_object_desc_str.empty())
1160 return NULL;
1161 else
1162 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001163}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001164
Enrico Granata0c489f52012-03-01 04:24:26 +00001165bool
1166ValueObject::GetValueAsCString (lldb::Format format,
1167 std::string& destination)
1168{
1169 if (ClangASTContext::IsAggregateType (GetClangType()) == false &&
1170 UpdateValueIfNeeded(false))
1171 {
1172 const Value::ContextType context_type = m_value.GetContextType();
1173
1174 switch (context_type)
1175 {
1176 case Value::eContextTypeClangType:
1177 case Value::eContextTypeLLDBType:
1178 case Value::eContextTypeVariable:
1179 {
1180 clang_type_t clang_type = GetClangType ();
1181 if (clang_type)
1182 {
1183 StreamString sstr;
1184 ExecutionContext exe_ctx (GetExecutionContextRef());
1185 ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
1186 clang_type, // The clang type to display
1187 &sstr,
1188 format, // Format to display this type with
1189 m_data, // Data to extract from
1190 0, // Byte offset into "m_data"
1191 GetByteSize(), // Byte size of item in "m_data"
1192 GetBitfieldBitSize(), // Bitfield bit size
1193 GetBitfieldBitOffset(), // Bitfield bit offset
1194 exe_ctx.GetBestExecutionContextScope());
1195 // Don't set the m_error to anything here otherwise
1196 // we won't be able to re-format as anything else. The
1197 // code for ClangASTType::DumpTypeValue() should always
1198 // return something, even if that something contains
1199 // an error messsage. "m_error" is used to detect errors
1200 // when reading the valid object, not for formatting errors.
1201 if (sstr.GetString().empty())
1202 destination.clear();
1203 else
1204 destination.swap(sstr.GetString());
1205 }
1206 }
1207 break;
1208
1209 case Value::eContextTypeRegisterInfo:
1210 {
1211 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1212 if (reg_info)
1213 {
1214 ExecutionContext exe_ctx (GetExecutionContextRef());
1215
1216 StreamString reg_sstr;
1217 m_data.Dump (&reg_sstr,
1218 0,
1219 format,
1220 reg_info->byte_size,
1221 1,
1222 UINT32_MAX,
1223 LLDB_INVALID_ADDRESS,
1224 0,
1225 0,
1226 exe_ctx.GetBestExecutionContextScope());
1227 destination.swap(reg_sstr.GetString());
1228 }
1229 }
1230 break;
1231
1232 default:
1233 break;
1234 }
1235 return !destination.empty();
1236 }
1237 else
1238 return false;
1239}
1240
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001241const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001242ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001243{
Enrico Granata0c489f52012-03-01 04:24:26 +00001244 if (UpdateValueIfNeeded(true) && m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001245 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001246 lldb::Format my_format = GetFormat();
1247 if (m_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001248 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001249 if (m_type_format_sp)
1250 my_format = m_type_format_sp->GetFormat();
1251 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001252 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001253 if (m_is_bitfield_for_scalar)
1254 my_format = eFormatUnsigned;
1255 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001256 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001257 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001258 {
1259 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1260 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001261 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001262 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001263 else
1264 {
1265 clang_type_t clang_type = GetClangType ();
1266 my_format = ClangASTType::GetFormat(clang_type);
1267 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001268 }
1269 }
1270 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001271 if (GetValueAsCString(my_format, m_value_str))
1272 {
1273 if (!m_value_did_change && m_old_value_valid)
1274 {
1275 // The value was gotten successfully, so we consider the
1276 // value as changed if the value string differs
1277 SetValueDidChange (m_old_value_str != m_value_str);
1278 }
1279 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001280 }
1281 if (m_value_str.empty())
1282 return NULL;
1283 return m_value_str.c_str();
1284}
1285
Enrico Granatac3e320a2011-08-02 17:27:39 +00001286// if > 8bytes, 0 is returned. this method should mostly be used
1287// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001288uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001289ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001290{
1291 // If our byte size is zero this is an aggregate type that has children
1292 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
1293 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001294 Scalar scalar;
1295 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001296 {
1297 if (success)
1298 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001299 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001300 }
1301 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001302 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001303
1304 if (success)
1305 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001306 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001307}
1308
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001309// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1310// this call up to date by returning true for your new special cases. We will eventually move
1311// to checking this call result before trying to display special cases
1312bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001313ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1314 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001315{
1316 clang_type_t elem_or_pointee_type;
1317 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
1318
1319 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001320 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001321 {
1322 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001323 (custom_format == eFormatCString ||
1324 custom_format == eFormatCharArray ||
1325 custom_format == eFormatChar ||
1326 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001327 return true;
1328
1329 if (flags.Test(ClangASTContext::eTypeIsArray))
1330 {
Greg Claytonafacd142011-09-02 01:15:17 +00001331 if ((custom_format == eFormatBytes) ||
1332 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001333 return true;
1334
Greg Claytonafacd142011-09-02 01:15:17 +00001335 if ((custom_format == eFormatVectorOfChar) ||
1336 (custom_format == eFormatVectorOfFloat32) ||
1337 (custom_format == eFormatVectorOfFloat64) ||
1338 (custom_format == eFormatVectorOfSInt16) ||
1339 (custom_format == eFormatVectorOfSInt32) ||
1340 (custom_format == eFormatVectorOfSInt64) ||
1341 (custom_format == eFormatVectorOfSInt8) ||
1342 (custom_format == eFormatVectorOfUInt128) ||
1343 (custom_format == eFormatVectorOfUInt16) ||
1344 (custom_format == eFormatVectorOfUInt32) ||
1345 (custom_format == eFormatVectorOfUInt64) ||
1346 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001347 return true;
1348 }
1349 }
1350 return false;
1351}
1352
Enrico Granata9fc19442011-07-06 02:13:41 +00001353bool
1354ValueObject::DumpPrintableRepresentation(Stream& s,
1355 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001356 Format custom_format,
Enrico Granata86cc9822012-03-19 22:58:49 +00001357 PrintableRepresentationSpecialCases special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001358{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001359
1360 clang_type_t elem_or_pointee_type;
1361 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001362
Enrico Granata86cc9822012-03-19 22:58:49 +00001363 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1364 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1365
1366 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001367 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001368 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1369 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001370 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001371 // when being asked to get a printable display an array or pointer type directly,
1372 // try to "do the right thing"
1373
1374 if (IsCStringContainer(true) &&
1375 (custom_format == eFormatCString ||
1376 custom_format == eFormatCharArray ||
1377 custom_format == eFormatChar ||
1378 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001379 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001380 Error error;
1381 ReadPointedString(s,
1382 error,
1383 0,
1384 (custom_format == eFormatVectorOfChar) ||
1385 (custom_format == eFormatCharArray));
1386 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001387 }
1388
Enrico Granata86cc9822012-03-19 22:58:49 +00001389 if (custom_format == eFormatEnum)
1390 return false;
1391
1392 // this only works for arrays, because I have no way to know when
1393 // the pointed memory ends, and no special \0 end of data marker
1394 if (flags.Test(ClangASTContext::eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001395 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001396 if ((custom_format == eFormatBytes) ||
1397 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001398 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001399 uint32_t count = GetNumChildren();
1400
1401 s << '[';
1402 for (uint32_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001403 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001404
1405 if (low)
1406 s << ',';
1407
1408 ValueObjectSP child = GetChildAtIndex(low,true);
1409 if (!child.get())
1410 {
1411 s << "<invalid child>";
1412 continue;
1413 }
1414 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1415 }
1416
1417 s << ']';
1418
1419 return true;
1420 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001421
Enrico Granata86cc9822012-03-19 22:58:49 +00001422 if ((custom_format == eFormatVectorOfChar) ||
1423 (custom_format == eFormatVectorOfFloat32) ||
1424 (custom_format == eFormatVectorOfFloat64) ||
1425 (custom_format == eFormatVectorOfSInt16) ||
1426 (custom_format == eFormatVectorOfSInt32) ||
1427 (custom_format == eFormatVectorOfSInt64) ||
1428 (custom_format == eFormatVectorOfSInt8) ||
1429 (custom_format == eFormatVectorOfUInt128) ||
1430 (custom_format == eFormatVectorOfUInt16) ||
1431 (custom_format == eFormatVectorOfUInt32) ||
1432 (custom_format == eFormatVectorOfUInt64) ||
1433 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1434 {
1435 uint32_t count = GetNumChildren();
1436
1437 Format format = FormatManager::GetSingleItemFormat(custom_format);
1438
1439 s << '[';
1440 for (uint32_t low = 0; low < count; low++)
1441 {
1442
1443 if (low)
1444 s << ',';
1445
1446 ValueObjectSP child = GetChildAtIndex(low,true);
1447 if (!child.get())
1448 {
1449 s << "<invalid child>";
1450 continue;
1451 }
1452 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1453 }
1454
1455 s << ']';
1456
1457 return true;
1458 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001459 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001460
1461 if ((custom_format == eFormatBoolean) ||
1462 (custom_format == eFormatBinary) ||
1463 (custom_format == eFormatChar) ||
1464 (custom_format == eFormatCharPrintable) ||
1465 (custom_format == eFormatComplexFloat) ||
1466 (custom_format == eFormatDecimal) ||
1467 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001468 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001469 (custom_format == eFormatFloat) ||
1470 (custom_format == eFormatOctal) ||
1471 (custom_format == eFormatOSType) ||
1472 (custom_format == eFormatUnicode16) ||
1473 (custom_format == eFormatUnicode32) ||
1474 (custom_format == eFormatUnsigned) ||
1475 (custom_format == eFormatPointer) ||
1476 (custom_format == eFormatComplexInteger) ||
1477 (custom_format == eFormatComplex) ||
1478 (custom_format == eFormatDefault)) // use the [] operator
1479 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001480 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001481 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001482
1483 if (only_special)
1484 return false;
1485
Enrico Granata86cc9822012-03-19 22:58:49 +00001486 bool var_success = false;
1487
1488 {
1489 const char * return_value;
1490 std::string alloc_mem;
1491
1492 if (custom_format != eFormatInvalid)
1493 SetFormat(custom_format);
1494
1495 switch(val_obj_display)
1496 {
1497 case eValueObjectRepresentationStyleValue:
1498 return_value = GetValueAsCString();
1499 break;
1500
1501 case eValueObjectRepresentationStyleSummary:
1502 return_value = GetSummaryAsCString();
1503 break;
1504
1505 case eValueObjectRepresentationStyleLanguageSpecific:
1506 return_value = GetObjectDescription();
1507 break;
1508
1509 case eValueObjectRepresentationStyleLocation:
1510 return_value = GetLocationAsCString();
1511 break;
1512
1513 case eValueObjectRepresentationStyleChildrenCount:
1514 {
1515 alloc_mem.resize(512);
1516 return_value = &alloc_mem[0];
1517 int count = GetNumChildren();
1518 snprintf((char*)return_value, 512, "%d", count);
1519 }
1520 break;
1521
1522 case eValueObjectRepresentationStyleType:
1523 return_value = GetTypeName().AsCString();
1524 break;
1525
1526 default:
1527 break;
1528 }
1529
1530 if (!return_value)
1531 {
1532 if (val_obj_display == eValueObjectRepresentationStyleValue)
1533 return_value = GetSummaryAsCString();
1534 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1535 {
1536 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1537 {
1538 // this thing has no value, and it seems to have no summary
1539 // some combination of unitialized data and other factors can also
1540 // raise this condition, so let's print a nice generic description
1541 {
1542 alloc_mem.resize(684);
1543 return_value = &alloc_mem[0];
1544 snprintf((char*)return_value, 684, "%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1545 }
1546 }
1547 else
1548 return_value = GetValueAsCString();
1549 }
1550 }
1551
1552 if (return_value)
1553 s.PutCString(return_value);
1554 else
1555 {
1556 if (m_error.Fail())
1557 s.Printf("<%s>", m_error.AsCString());
1558 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1559 s.PutCString("<no summary available>");
1560 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1561 s.PutCString("<no value available>");
1562 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1563 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1564 else
1565 s.PutCString("<no printable representation>");
1566 }
1567
1568 // we should only return false here if we could not do *anything*
1569 // even if we have an error message as output, that's a success
1570 // from our callers' perspective, so return true
1571 var_success = true;
1572
1573 if (custom_format != eFormatInvalid)
1574 SetFormat(eFormatDefault);
1575 }
1576
Enrico Granataf4efecd2011-07-12 22:56:10 +00001577 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001578}
1579
Greg Clayton737b9322010-09-13 03:32:57 +00001580addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001581ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001582{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001583 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001584 return LLDB_INVALID_ADDRESS;
1585
Greg Clayton73b472d2010-10-27 03:32:59 +00001586 switch (m_value.GetValueType())
1587 {
1588 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001589 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001590 if (scalar_is_load_address)
1591 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001592 if(address_type)
1593 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001594 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1595 }
1596 break;
1597
1598 case Value::eValueTypeLoadAddress:
1599 case Value::eValueTypeFileAddress:
1600 case Value::eValueTypeHostAddress:
1601 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001602 if(address_type)
1603 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001604 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1605 }
1606 break;
1607 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001608 if (address_type)
1609 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001610 return LLDB_INVALID_ADDRESS;
1611}
1612
1613addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001614ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001615{
Greg Claytonafacd142011-09-02 01:15:17 +00001616 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001617 if(address_type)
1618 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001619
Enrico Granatac3e320a2011-08-02 17:27:39 +00001620 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001621 return address;
1622
Greg Clayton73b472d2010-10-27 03:32:59 +00001623 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001624 {
1625 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001626 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001627 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001628 break;
1629
Enrico Granata9128ee22011-09-06 19:20:51 +00001630 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001631 case Value::eValueTypeLoadAddress:
1632 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001633 {
1634 uint32_t data_offset = 0;
1635 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001636 }
1637 break;
1638 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001639
Enrico Granata9128ee22011-09-06 19:20:51 +00001640 if (address_type)
1641 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001642
Greg Clayton737b9322010-09-13 03:32:57 +00001643 return address;
1644}
1645
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001646bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001647ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001648{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001649 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001650 // Make sure our value is up to date first so that our location and location
1651 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001652 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001653 {
1654 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001655 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001656 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001657
1658 uint32_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001659 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001660
Greg Claytonb1320972010-07-14 00:18:15 +00001661 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001662
Jim Ingham16e0c682011-08-12 23:34:31 +00001663 Value::ValueType value_type = m_value.GetValueType();
1664
1665 if (value_type == Value::eValueTypeScalar)
1666 {
1667 // If the value is already a scalar, then let the scalar change itself:
1668 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1669 }
1670 else if (byte_size <= Scalar::GetMaxByteSize())
1671 {
1672 // If the value fits in a scalar, then make a new scalar and again let the
1673 // scalar code do the conversion, then figure out where to put the new value.
1674 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001675 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1676 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001677 {
Jim Ingham4b536182011-08-09 02:12:22 +00001678 switch (value_type)
1679 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001680 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001681 {
1682 // If it is a load address, then the scalar value is the storage location
1683 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001684 ExecutionContext exe_ctx (GetExecutionContextRef());
1685 Process *process = exe_ctx.GetProcessPtr();
1686 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001687 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001688 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001689 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1690 new_scalar,
1691 byte_size,
1692 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001693 if (!error.Success())
1694 return false;
1695 if (bytes_written != byte_size)
1696 {
1697 error.SetErrorString("unable to write value to memory");
1698 return false;
1699 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001700 }
1701 }
Jim Ingham4b536182011-08-09 02:12:22 +00001702 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001703 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001704 {
1705 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1706 DataExtractor new_data;
1707 new_data.SetByteOrder (m_data.GetByteOrder());
1708
1709 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1710 m_data.SetData(buffer_sp, 0);
1711 bool success = new_scalar.GetData(new_data);
1712 if (success)
1713 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001714 new_data.CopyByteOrderedData (0,
1715 byte_size,
1716 const_cast<uint8_t *>(m_data.GetDataStart()),
1717 byte_size,
1718 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001719 }
1720 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1721
1722 }
Jim Ingham4b536182011-08-09 02:12:22 +00001723 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001724 case Value::eValueTypeFileAddress:
1725 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001726 case Value::eValueTypeVector:
1727 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001728 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001729 }
1730 else
1731 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001732 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001733 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001734 }
1735 else
1736 {
1737 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001738 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001739 return false;
1740 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001741
1742 // If we have reached this point, then we have successfully changed the value.
1743 SetNeedsUpdate();
1744 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001745}
1746
Greg Clayton81e871e2012-02-04 02:27:34 +00001747bool
1748ValueObject::GetDeclaration (Declaration &decl)
1749{
1750 decl.Clear();
1751 return false;
1752}
1753
Greg Clayton84db9102012-03-26 23:03:23 +00001754ConstString
1755ValueObject::GetTypeName()
1756{
1757 return ClangASTType::GetConstTypeName (GetClangAST(), GetClangType());
1758}
1759
1760ConstString
1761ValueObject::GetQualifiedTypeName()
1762{
1763 return ClangASTType::GetConstQualifiedTypeName (GetClangAST(), GetClangType());
1764}
1765
1766
Greg Claytonafacd142011-09-02 01:15:17 +00001767LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001768ValueObject::GetObjectRuntimeLanguage ()
1769{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001770 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1771 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001772}
1773
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001774void
Jim Ingham58b59f92011-04-22 23:53:53 +00001775ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001776{
Jim Ingham58b59f92011-04-22 23:53:53 +00001777 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001778}
1779
1780ValueObjectSP
1781ValueObject::GetSyntheticChild (const ConstString &key) const
1782{
1783 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001784 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001785 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001786 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001787 return synthetic_child_sp;
1788}
1789
1790bool
1791ValueObject::IsPointerType ()
1792{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001793 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001794}
1795
Jim Inghamb7603bb2011-03-18 00:05:18 +00001796bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001797ValueObject::IsArrayType ()
1798{
1799 return ClangASTContext::IsArrayType (GetClangType());
1800}
1801
1802bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001803ValueObject::IsScalarType ()
1804{
1805 return ClangASTContext::IsScalarType (GetClangType());
1806}
1807
1808bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001809ValueObject::IsIntegerType (bool &is_signed)
1810{
1811 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1812}
Greg Clayton73b472d2010-10-27 03:32:59 +00001813
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001814bool
1815ValueObject::IsPointerOrReferenceType ()
1816{
Greg Clayton007d5be2011-05-30 00:49:24 +00001817 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1818}
1819
1820bool
Greg Claytondea8cb42011-06-29 22:09:02 +00001821ValueObject::IsPossibleDynamicType ()
1822{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00001823 ExecutionContext exe_ctx (GetExecutionContextRef());
1824 Process *process = exe_ctx.GetProcessPtr();
1825 if (process)
1826 return process->IsPossibleDynamicValue(*this);
1827 else
Greg Clayton70364252012-08-31 18:56:24 +00001828 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType(), NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00001829}
1830
Greg Claytonafacd142011-09-02 01:15:17 +00001831ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001832ValueObject::GetSyntheticArrayMember (int32_t index, bool can_create)
1833{
1834 if (IsArrayType())
1835 return GetSyntheticArrayMemberFromArray(index, can_create);
1836
1837 if (IsPointerType())
1838 return GetSyntheticArrayMemberFromPointer(index, can_create);
1839
1840 return ValueObjectSP();
1841
1842}
1843
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001844ValueObjectSP
1845ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1846{
1847 ValueObjectSP synthetic_child_sp;
1848 if (IsPointerType ())
1849 {
1850 char index_str[64];
1851 snprintf(index_str, sizeof(index_str), "[%i]", index);
1852 ConstString index_const_str(index_str);
1853 // Check if we have already created a synthetic array member in this
1854 // valid object. If we have we will re-use it.
1855 synthetic_child_sp = GetSyntheticChild (index_const_str);
1856 if (!synthetic_child_sp)
1857 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001858 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001859 // We haven't made a synthetic array member for INDEX yet, so
1860 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001861 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001862
1863 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001864 if (synthetic_child)
1865 {
1866 AddSyntheticChild(index_const_str, synthetic_child);
1867 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001868 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001869 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001870 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001871 }
1872 }
1873 return synthetic_child_sp;
1874}
Jim Ingham22777012010-09-23 02:01:19 +00001875
Greg Claytondaf515f2011-07-09 20:12:33 +00001876// This allows you to create an array member using and index
1877// that doesn't not fall in the normal bounds of the array.
1878// Many times structure can be defined as:
1879// struct Collection
1880// {
1881// uint32_t item_count;
1882// Item item_array[0];
1883// };
1884// The size of the "item_array" is 1, but many times in practice
1885// there are more items in "item_array".
1886
1887ValueObjectSP
1888ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1889{
1890 ValueObjectSP synthetic_child_sp;
1891 if (IsArrayType ())
1892 {
1893 char index_str[64];
1894 snprintf(index_str, sizeof(index_str), "[%i]", index);
1895 ConstString index_const_str(index_str);
1896 // Check if we have already created a synthetic array member in this
1897 // valid object. If we have we will re-use it.
1898 synthetic_child_sp = GetSyntheticChild (index_const_str);
1899 if (!synthetic_child_sp)
1900 {
1901 ValueObject *synthetic_child;
1902 // We haven't made a synthetic array member for INDEX yet, so
1903 // lets make one and cache it for any future reference.
1904 synthetic_child = CreateChildAtIndex(0, true, index);
1905
1906 // Cache the value if we got one back...
1907 if (synthetic_child)
1908 {
1909 AddSyntheticChild(index_const_str, synthetic_child);
1910 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001911 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001912 synthetic_child_sp->m_is_array_item_for_pointer = true;
1913 }
1914 }
1915 }
1916 return synthetic_child_sp;
1917}
1918
Enrico Granata9fc19442011-07-06 02:13:41 +00001919ValueObjectSP
1920ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1921{
1922 ValueObjectSP synthetic_child_sp;
1923 if (IsScalarType ())
1924 {
1925 char index_str[64];
1926 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1927 ConstString index_const_str(index_str);
1928 // Check if we have already created a synthetic array member in this
1929 // valid object. If we have we will re-use it.
1930 synthetic_child_sp = GetSyntheticChild (index_const_str);
1931 if (!synthetic_child_sp)
1932 {
1933 ValueObjectChild *synthetic_child;
1934 // We haven't made a synthetic array member for INDEX yet, so
1935 // lets make one and cache it for any future reference.
1936 synthetic_child = new ValueObjectChild(*this,
1937 GetClangAST(),
1938 GetClangType(),
1939 index_const_str,
1940 GetByteSize(),
1941 0,
1942 to-from+1,
1943 from,
1944 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001945 false,
1946 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00001947
1948 // Cache the value if we got one back...
1949 if (synthetic_child)
1950 {
1951 AddSyntheticChild(index_const_str, synthetic_child);
1952 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001953 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00001954 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1955 }
1956 }
1957 }
1958 return synthetic_child_sp;
1959}
1960
Greg Claytonafacd142011-09-02 01:15:17 +00001961ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001962ValueObject::GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create)
1963{
1964 ValueObjectSP synthetic_child_sp;
1965 if (IsArrayType () || IsPointerType ())
1966 {
1967 char index_str[64];
1968 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1969 ConstString index_const_str(index_str);
1970 // Check if we have already created a synthetic array member in this
1971 // valid object. If we have we will re-use it.
1972 synthetic_child_sp = GetSyntheticChild (index_const_str);
1973 if (!synthetic_child_sp)
1974 {
1975 ValueObjectSynthetic *synthetic_child;
1976
1977 // We haven't made a synthetic array member for INDEX yet, so
1978 // lets make one and cache it for any future reference.
Enrico Granata061858c2012-02-15 02:34:21 +00001979 SyntheticArrayView *view = new SyntheticArrayView(SyntheticChildren::Flags());
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001980 view->AddRange(from,to);
1981 SyntheticChildrenSP view_sp(view);
1982 synthetic_child = new ValueObjectSynthetic(*this, view_sp);
1983
1984 // Cache the value if we got one back...
1985 if (synthetic_child)
1986 {
1987 AddSyntheticChild(index_const_str, synthetic_child);
1988 synthetic_child_sp = synthetic_child->GetSP();
1989 synthetic_child_sp->SetName(ConstString(index_str));
1990 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1991 }
1992 }
1993 }
1994 return synthetic_child_sp;
1995}
1996
Greg Claytonafacd142011-09-02 01:15:17 +00001997ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00001998ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
1999{
2000
2001 ValueObjectSP synthetic_child_sp;
2002
2003 char name_str[64];
2004 snprintf(name_str, sizeof(name_str), "@%i", offset);
2005 ConstString name_const_str(name_str);
2006
2007 // Check if we have already created a synthetic array member in this
2008 // valid object. If we have we will re-use it.
2009 synthetic_child_sp = GetSyntheticChild (name_const_str);
2010
2011 if (synthetic_child_sp.get())
2012 return synthetic_child_sp;
2013
2014 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002015 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002016
2017 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2018 type.GetASTContext(),
2019 type.GetOpaqueQualType(),
2020 name_const_str,
2021 type.GetTypeByteSize(),
2022 offset,
2023 0,
2024 0,
2025 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002026 false,
2027 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002028 if (synthetic_child)
2029 {
2030 AddSyntheticChild(name_const_str, synthetic_child);
2031 synthetic_child_sp = synthetic_child->GetSP();
2032 synthetic_child_sp->SetName(name_const_str);
2033 synthetic_child_sp->m_is_child_at_offset = true;
2034 }
2035 return synthetic_child_sp;
2036}
2037
Enrico Granatad55546b2011-07-22 00:16:08 +00002038// your expression path needs to have a leading . or ->
2039// (unless it somehow "looks like" an array, in which case it has
2040// a leading [ symbol). while the [ is meaningful and should be shown
2041// to the user, . and -> are just parser design, but by no means
2042// added information for the user.. strip them off
2043static const char*
2044SkipLeadingExpressionPathSeparators(const char* expression)
2045{
2046 if (!expression || !expression[0])
2047 return expression;
2048 if (expression[0] == '.')
2049 return expression+1;
2050 if (expression[0] == '-' && expression[1] == '>')
2051 return expression+2;
2052 return expression;
2053}
2054
Greg Claytonafacd142011-09-02 01:15:17 +00002055ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002056ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2057{
2058 ValueObjectSP synthetic_child_sp;
2059 ConstString name_const_string(expression);
2060 // Check if we have already created a synthetic array member in this
2061 // valid object. If we have we will re-use it.
2062 synthetic_child_sp = GetSyntheticChild (name_const_string);
2063 if (!synthetic_child_sp)
2064 {
2065 // We haven't made a synthetic array member for expression yet, so
2066 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002067 synthetic_child_sp = GetValueForExpressionPath(expression,
2068 NULL, NULL, NULL,
2069 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
Enrico Granatad55546b2011-07-22 00:16:08 +00002070
2071 // Cache the value if we got one back...
2072 if (synthetic_child_sp.get())
2073 {
2074 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002075 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002076 synthetic_child_sp->m_is_expression_path_child = true;
2077 }
2078 }
2079 return synthetic_child_sp;
2080}
2081
2082void
Enrico Granata86cc9822012-03-19 22:58:49 +00002083ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002084{
Enrico Granata86cc9822012-03-19 22:58:49 +00002085 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002086 return;
2087
Enrico Granatac5bc4122012-03-27 02:35:13 +00002088 TargetSP target_sp(GetTargetSP());
2089 if (target_sp && (target_sp->GetEnableSyntheticValue() == false || target_sp->GetSuppressSyntheticValue() == true))
2090 {
2091 m_synthetic_value = NULL;
2092 return;
2093 }
2094
Enrico Granatae3e91512012-10-22 18:18:36 +00002095 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2096
Enrico Granata86cc9822012-03-19 22:58:49 +00002097 if (!UpdateFormatsIfNeeded(m_last_format_mgr_dynamic) && m_synthetic_value)
2098 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002099
Enrico Granata0c489f52012-03-01 04:24:26 +00002100 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002101 return;
2102
Enrico Granatae3e91512012-10-22 18:18:36 +00002103 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2104 return;
2105
Enrico Granata86cc9822012-03-19 22:58:49 +00002106 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002107}
2108
Jim Ingham78a685a2011-04-16 00:01:13 +00002109void
Greg Claytonafacd142011-09-02 01:15:17 +00002110ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002111{
Greg Claytonafacd142011-09-02 01:15:17 +00002112 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002113 return;
2114
Jim Ingham58b59f92011-04-22 23:53:53 +00002115 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002116 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002117 ExecutionContext exe_ctx (GetExecutionContextRef());
2118 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002119 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002120 {
2121 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002122 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002123 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002124 }
2125}
2126
Jim Ingham58b59f92011-04-22 23:53:53 +00002127ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002128ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002129{
Greg Claytonafacd142011-09-02 01:15:17 +00002130 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002131 return ValueObjectSP();
2132
2133 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002134 {
Jim Ingham2837b762011-05-04 03:43:18 +00002135 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002136 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002137 if (m_dynamic_value)
2138 return m_dynamic_value->GetSP();
2139 else
2140 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002141}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002142
Jim Ingham60dbabb2011-12-08 19:44:08 +00002143ValueObjectSP
2144ValueObject::GetStaticValue()
2145{
2146 return GetSP();
2147}
2148
Enrico Granata886147f2012-05-08 18:47:08 +00002149lldb::ValueObjectSP
2150ValueObject::GetNonSyntheticValue ()
2151{
2152 return GetSP();
2153}
2154
Enrico Granatad55546b2011-07-22 00:16:08 +00002155ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002156ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002157{
Enrico Granata86cc9822012-03-19 22:58:49 +00002158 if (use_synthetic == false)
2159 return ValueObjectSP();
2160
Enrico Granatad55546b2011-07-22 00:16:08 +00002161 CalculateSyntheticValue(use_synthetic);
2162
2163 if (m_synthetic_value)
2164 return m_synthetic_value->GetSP();
2165 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002166 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002167}
2168
Greg Claytone221f822011-01-21 01:59:00 +00002169bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002170ValueObject::HasSyntheticValue()
2171{
2172 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
2173
Enrico Granata0c489f52012-03-01 04:24:26 +00002174 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002175 return false;
2176
Enrico Granata86cc9822012-03-19 22:58:49 +00002177 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002178
2179 if (m_synthetic_value)
2180 return true;
2181 else
2182 return false;
2183}
2184
2185bool
Greg Claytone221f822011-01-21 01:59:00 +00002186ValueObject::GetBaseClassPath (Stream &s)
2187{
2188 if (IsBaseClass())
2189 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002190 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00002191 clang_type_t clang_type = GetClangType();
2192 std::string cxx_class_name;
2193 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
2194 if (this_had_base_class)
2195 {
2196 if (parent_had_base_class)
2197 s.PutCString("::");
2198 s.PutCString(cxx_class_name.c_str());
2199 }
2200 return parent_had_base_class || this_had_base_class;
2201 }
2202 return false;
2203}
2204
2205
2206ValueObject *
2207ValueObject::GetNonBaseClassParent()
2208{
Jim Ingham78a685a2011-04-16 00:01:13 +00002209 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002210 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002211 if (GetParent()->IsBaseClass())
2212 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002213 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002214 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002215 }
2216 return NULL;
2217}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002218
2219void
Enrico Granata4becb372011-06-29 22:27:15 +00002220ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002221{
Greg Claytone221f822011-01-21 01:59:00 +00002222 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002223
Enrico Granata86cc9822012-03-19 22:58:49 +00002224 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002225 {
Enrico Granata4becb372011-06-29 22:27:15 +00002226 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2227 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2228 // the eHonorPointers mode is meant to produce strings in this latter format
2229 s.PutCString("*(");
2230 }
Greg Claytone221f822011-01-21 01:59:00 +00002231
Enrico Granata4becb372011-06-29 22:27:15 +00002232 ValueObject* parent = GetParent();
2233
2234 if (parent)
2235 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002236
2237 // if we are a deref_of_parent just because we are synthetic array
2238 // members made up to allow ptr[%d] syntax to work in variable
2239 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002240 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002241 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002242
Greg Claytone221f822011-01-21 01:59:00 +00002243 if (!IsBaseClass())
2244 {
2245 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002246 {
Greg Claytone221f822011-01-21 01:59:00 +00002247 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2248 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002249 {
Greg Claytone221f822011-01-21 01:59:00 +00002250 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2251 if (non_base_class_parent_clang_type)
2252 {
2253 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2254
Enrico Granata86cc9822012-03-19 22:58:49 +00002255 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002256 {
2257 s.PutCString("->");
2258 }
Enrico Granata4becb372011-06-29 22:27:15 +00002259 else
2260 {
2261 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2262 {
2263 s.PutCString("->");
2264 }
2265 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2266 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2267 {
2268 s.PutChar('.');
2269 }
Greg Claytone221f822011-01-21 01:59:00 +00002270 }
2271 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002272 }
Greg Claytone221f822011-01-21 01:59:00 +00002273
2274 const char *name = GetName().GetCString();
2275 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002276 {
Greg Claytone221f822011-01-21 01:59:00 +00002277 if (qualify_cxx_base_classes)
2278 {
2279 if (GetBaseClassPath (s))
2280 s.PutCString("::");
2281 }
2282 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002283 }
2284 }
2285 }
2286
Enrico Granata86cc9822012-03-19 22:58:49 +00002287 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002288 {
Greg Claytone221f822011-01-21 01:59:00 +00002289 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002290 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002291}
2292
Greg Claytonafacd142011-09-02 01:15:17 +00002293ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002294ValueObject::GetValueForExpressionPath(const char* expression,
2295 const char** first_unparsed,
2296 ExpressionPathScanEndReason* reason_to_stop,
2297 ExpressionPathEndResultType* final_value_type,
2298 const GetValueForExpressionPathOptions& options,
2299 ExpressionPathAftermath* final_task_on_target)
2300{
2301
2302 const char* dummy_first_unparsed;
2303 ExpressionPathScanEndReason dummy_reason_to_stop;
2304 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002305 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002306
2307 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2308 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2309 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2310 final_value_type ? final_value_type : &dummy_final_value_type,
2311 options,
2312 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2313
Enrico Granata86cc9822012-03-19 22:58:49 +00002314 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002315 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002316
Enrico Granata86cc9822012-03-19 22:58:49 +00002317 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 +00002318 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002319 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002320 {
2321 Error error;
2322 ValueObjectSP final_value = ret_val->Dereference(error);
2323 if (error.Fail() || !final_value.get())
2324 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002325 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002326 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002327 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002328 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002329 return ValueObjectSP();
2330 }
2331 else
2332 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002333 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002334 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002335 return final_value;
2336 }
2337 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002338 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002339 {
2340 Error error;
2341 ValueObjectSP final_value = ret_val->AddressOf(error);
2342 if (error.Fail() || !final_value.get())
2343 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002344 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002345 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002346 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002347 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002348 return ValueObjectSP();
2349 }
2350 else
2351 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002352 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002353 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002354 return final_value;
2355 }
2356 }
2357 }
2358 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2359}
2360
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002361int
2362ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002363 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002364 const char** first_unparsed,
2365 ExpressionPathScanEndReason* reason_to_stop,
2366 ExpressionPathEndResultType* final_value_type,
2367 const GetValueForExpressionPathOptions& options,
2368 ExpressionPathAftermath* final_task_on_target)
2369{
2370 const char* dummy_first_unparsed;
2371 ExpressionPathScanEndReason dummy_reason_to_stop;
2372 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002373 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002374
2375 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2376 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2377 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2378 final_value_type ? final_value_type : &dummy_final_value_type,
2379 options,
2380 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2381
2382 if (!ret_val.get()) // if there are errors, I add nothing to the list
2383 return 0;
2384
Enrico Granata86ea8d82012-03-29 01:34:34 +00002385 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002386 {
2387 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002388 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002389 {
2390 list->Append(ret_val);
2391 return 1;
2392 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002393 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 +00002394 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002395 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002396 {
2397 Error error;
2398 ValueObjectSP final_value = ret_val->Dereference(error);
2399 if (error.Fail() || !final_value.get())
2400 {
Greg Clayton23f59502012-07-17 03:23:13 +00002401 if (reason_to_stop)
2402 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2403 if (final_value_type)
2404 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002405 return 0;
2406 }
2407 else
2408 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002409 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002410 list->Append(final_value);
2411 return 1;
2412 }
2413 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002414 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002415 {
2416 Error error;
2417 ValueObjectSP final_value = ret_val->AddressOf(error);
2418 if (error.Fail() || !final_value.get())
2419 {
Greg Clayton23f59502012-07-17 03:23:13 +00002420 if (reason_to_stop)
2421 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2422 if (final_value_type)
2423 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002424 return 0;
2425 }
2426 else
2427 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002428 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002429 list->Append(final_value);
2430 return 1;
2431 }
2432 }
2433 }
2434 }
2435 else
2436 {
2437 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2438 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2439 ret_val,
2440 list,
2441 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2442 final_value_type ? final_value_type : &dummy_final_value_type,
2443 options,
2444 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2445 }
2446 // in any non-covered case, just do the obviously right thing
2447 list->Append(ret_val);
2448 return 1;
2449}
2450
Greg Claytonafacd142011-09-02 01:15:17 +00002451ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002452ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2453 const char** first_unparsed,
2454 ExpressionPathScanEndReason* reason_to_stop,
2455 ExpressionPathEndResultType* final_result,
2456 const GetValueForExpressionPathOptions& options,
2457 ExpressionPathAftermath* what_next)
2458{
2459 ValueObjectSP root = GetSP();
2460
2461 if (!root.get())
2462 return ValueObjectSP();
2463
2464 *first_unparsed = expression_cstr;
2465
2466 while (true)
2467 {
2468
2469 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2470
Greg Claytonafacd142011-09-02 01:15:17 +00002471 clang_type_t root_clang_type = root->GetClangType();
2472 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002473 Flags root_clang_type_info,pointee_clang_type_info;
2474
2475 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2476 if (pointee_clang_type)
2477 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002478
2479 if (!expression_cstr || *expression_cstr == '\0')
2480 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002481 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002482 return root;
2483 }
2484
2485 switch (*expression_cstr)
2486 {
2487 case '-':
2488 {
2489 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002490 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 +00002491 {
2492 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002493 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2494 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002495 return ValueObjectSP();
2496 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002497 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2498 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002499 options.m_no_fragile_ivar)
2500 {
2501 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002502 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2503 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002504 return ValueObjectSP();
2505 }
2506 if (expression_cstr[1] != '>')
2507 {
2508 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002509 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2510 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002511 return ValueObjectSP();
2512 }
2513 expression_cstr++; // skip the -
2514 }
2515 case '.': // or fallthrough from ->
2516 {
2517 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002518 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 +00002519 {
2520 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002521 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2522 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002523 return ValueObjectSP();
2524 }
2525 expression_cstr++; // skip .
2526 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2527 ConstString child_name;
2528 if (!next_separator) // if no other separator just expand this last layer
2529 {
2530 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002531 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2532
2533 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002534 {
2535 *first_unparsed = '\0';
Enrico Granata86cc9822012-03-19 22:58:49 +00002536 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2537 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002538 return child_valobj_sp;
2539 }
2540 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2541 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002542 if (root->IsSynthetic())
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002543 {
2544 *first_unparsed = expression_cstr;
2545 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2546 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2547 return ValueObjectSP();
2548 }
2549
2550 child_valobj_sp = root->GetSyntheticValue();
Enrico Granata86cc9822012-03-19 22:58:49 +00002551 if (child_valobj_sp.get())
2552 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002553 }
2554
2555 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2556 // so we hit the "else" branch, and return an error
2557 if(child_valobj_sp.get()) // if it worked, just return
2558 {
2559 *first_unparsed = '\0';
Enrico Granata86cc9822012-03-19 22:58:49 +00002560 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2561 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002562 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002563 }
2564 else
2565 {
2566 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002567 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2568 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002569 return ValueObjectSP();
2570 }
2571 }
2572 else // other layers do expand
2573 {
2574 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002575 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2576 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002577 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002578 root = child_valobj_sp;
2579 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002580 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002581 continue;
2582 }
2583 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2584 {
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002585 if (root->IsSynthetic())
2586 {
2587 *first_unparsed = expression_cstr;
2588 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2589 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2590 return ValueObjectSP();
2591 }
2592
Enrico Granata86cc9822012-03-19 22:58:49 +00002593 child_valobj_sp = root->GetSyntheticValue(true);
2594 if (child_valobj_sp)
2595 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002596 }
2597
2598 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2599 // so we hit the "else" branch, and return an error
2600 if(child_valobj_sp.get()) // if it worked, move on
2601 {
2602 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002603 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002604 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002605 continue;
2606 }
2607 else
2608 {
2609 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002610 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2611 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002612 return ValueObjectSP();
2613 }
2614 }
2615 break;
2616 }
2617 case '[':
2618 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002619 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 +00002620 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002621 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002622 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002623 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2624 {
2625 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002626 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2627 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002628 return ValueObjectSP();
2629 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002630 }
2631 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2632 {
2633 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002634 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2635 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002636 return ValueObjectSP();
2637 }
2638 }
2639 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2640 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002641 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002642 {
2643 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002644 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2645 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002646 return ValueObjectSP();
2647 }
2648 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2649 {
2650 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002651 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2652 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002653 return root;
2654 }
2655 }
2656 const char *separator_position = ::strchr(expression_cstr+1,'-');
2657 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2658 if (!close_bracket_position) // if there is no ], this is a syntax error
2659 {
2660 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002661 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2662 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002663 return ValueObjectSP();
2664 }
2665 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2666 {
2667 char *end = NULL;
2668 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2669 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2670 {
2671 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002672 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2673 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002674 return ValueObjectSP();
2675 }
2676 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2677 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002678 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002679 {
2680 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002681 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2682 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002683 return root;
2684 }
2685 else
2686 {
2687 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002688 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2689 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002690 return ValueObjectSP();
2691 }
2692 }
2693 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002694 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002695 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002696 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2697 if (!child_valobj_sp)
2698 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002699 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002700 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2701 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002702 if (child_valobj_sp)
2703 {
2704 root = child_valobj_sp;
2705 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002706 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002707 continue;
2708 }
2709 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002710 {
2711 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002712 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2713 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002714 return ValueObjectSP();
2715 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002716 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002717 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002718 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002719 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 +00002720 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002721 {
2722 Error error;
2723 root = root->Dereference(error);
2724 if (error.Fail() || !root.get())
2725 {
2726 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002727 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2728 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002729 return ValueObjectSP();
2730 }
2731 else
2732 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002733 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002734 continue;
2735 }
2736 }
2737 else
2738 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002739 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Clayton84db9102012-03-26 23:03:23 +00002740 root->GetClangType()) == eLanguageTypeObjC
2741 && ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2742 && root->HasSyntheticValue()
2743 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002744 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002745 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002746 }
2747 else
2748 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002749 if (!root.get())
2750 {
2751 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002752 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2753 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002754 return ValueObjectSP();
2755 }
2756 else
2757 {
2758 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002759 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002760 continue;
2761 }
2762 }
2763 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002764 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002765 {
2766 root = root->GetSyntheticBitFieldChild(index, index, true);
2767 if (!root.get())
2768 {
2769 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002770 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2771 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002772 return ValueObjectSP();
2773 }
2774 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2775 {
2776 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002777 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2778 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002779 return root;
2780 }
2781 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002782 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002783 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002784 if (root->HasSyntheticValue())
2785 root = root->GetSyntheticValue();
2786 else if (!root->IsSynthetic())
2787 {
2788 *first_unparsed = expression_cstr;
2789 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2790 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2791 return ValueObjectSP();
2792 }
2793 // if we are here, then root itself is a synthetic VO.. should be good to go
2794
Enrico Granata27b625e2011-08-09 01:04:56 +00002795 if (!root.get())
2796 {
2797 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002798 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2799 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2800 return ValueObjectSP();
2801 }
2802 root = root->GetChildAtIndex(index, true);
2803 if (!root.get())
2804 {
2805 *first_unparsed = expression_cstr;
2806 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2807 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002808 return ValueObjectSP();
2809 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002810 else
2811 {
2812 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002813 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002814 continue;
2815 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002816 }
2817 else
2818 {
2819 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002820 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2821 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002822 return ValueObjectSP();
2823 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002824 }
2825 else // we have a low and a high index
2826 {
2827 char *end = NULL;
2828 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2829 if (!end || end != separator_position) // if something weird is in our way return an error
2830 {
2831 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002832 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2833 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002834 return ValueObjectSP();
2835 }
2836 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2837 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2838 {
2839 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002840 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2841 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002842 return ValueObjectSP();
2843 }
2844 if (index_lower > index_higher) // swap indices if required
2845 {
2846 unsigned long temp = index_lower;
2847 index_lower = index_higher;
2848 index_higher = temp;
2849 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002850 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002851 {
2852 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2853 if (!root.get())
2854 {
2855 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002856 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2857 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002858 return ValueObjectSP();
2859 }
2860 else
2861 {
2862 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002863 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2864 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002865 return root;
2866 }
2867 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002868 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 +00002869 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002870 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002871 {
2872 Error error;
2873 root = root->Dereference(error);
2874 if (error.Fail() || !root.get())
2875 {
2876 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002877 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2878 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002879 return ValueObjectSP();
2880 }
2881 else
2882 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002883 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002884 continue;
2885 }
2886 }
2887 else
2888 {
2889 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002890 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2891 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002892 return root;
2893 }
2894 }
2895 break;
2896 }
2897 default: // some non-separator is in the way
2898 {
2899 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002900 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2901 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002902 return ValueObjectSP();
2903 break;
2904 }
2905 }
2906 }
2907}
2908
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002909int
2910ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2911 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002912 ValueObjectSP root,
2913 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002914 ExpressionPathScanEndReason* reason_to_stop,
2915 ExpressionPathEndResultType* final_result,
2916 const GetValueForExpressionPathOptions& options,
2917 ExpressionPathAftermath* what_next)
2918{
2919 if (!root.get())
2920 return 0;
2921
2922 *first_unparsed = expression_cstr;
2923
2924 while (true)
2925 {
2926
2927 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2928
Greg Claytonafacd142011-09-02 01:15:17 +00002929 clang_type_t root_clang_type = root->GetClangType();
2930 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002931 Flags root_clang_type_info,pointee_clang_type_info;
2932
2933 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2934 if (pointee_clang_type)
2935 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2936
2937 if (!expression_cstr || *expression_cstr == '\0')
2938 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002939 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002940 list->Append(root);
2941 return 1;
2942 }
2943
2944 switch (*expression_cstr)
2945 {
2946 case '[':
2947 {
2948 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2949 {
2950 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2951 {
2952 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002953 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2954 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002955 return 0;
2956 }
2957 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2958 {
2959 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002960 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2961 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002962 return 0;
2963 }
2964 }
2965 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2966 {
2967 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2968 {
2969 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002970 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2971 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002972 return 0;
2973 }
2974 else // expand this into list
2975 {
2976 int max_index = root->GetNumChildren() - 1;
2977 for (int index = 0; index < max_index; index++)
2978 {
2979 ValueObjectSP child =
2980 root->GetChildAtIndex(index, true);
2981 list->Append(child);
2982 }
2983 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002984 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
2985 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002986 return max_index; // tell me number of items I added to the VOList
2987 }
2988 }
2989 const char *separator_position = ::strchr(expression_cstr+1,'-');
2990 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2991 if (!close_bracket_position) // if there is no ], this is a syntax error
2992 {
2993 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002994 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2995 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002996 return 0;
2997 }
2998 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2999 {
3000 char *end = NULL;
3001 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3002 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3003 {
3004 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003005 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3006 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003007 return 0;
3008 }
3009 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3010 {
3011 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3012 {
3013 int max_index = root->GetNumChildren() - 1;
3014 for (int index = 0; index < max_index; index++)
3015 {
3016 ValueObjectSP child =
3017 root->GetChildAtIndex(index, true);
3018 list->Append(child);
3019 }
3020 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003021 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3022 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003023 return max_index; // tell me number of items I added to the VOList
3024 }
3025 else
3026 {
3027 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003028 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3029 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003030 return 0;
3031 }
3032 }
3033 // from here on we do have a valid index
3034 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3035 {
3036 root = root->GetChildAtIndex(index, true);
3037 if (!root.get())
3038 {
3039 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003040 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3041 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003042 return 0;
3043 }
3044 else
3045 {
3046 list->Append(root);
3047 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003048 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3049 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003050 return 1;
3051 }
3052 }
3053 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
3054 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003055 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 +00003056 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3057 {
3058 Error error;
3059 root = root->Dereference(error);
3060 if (error.Fail() || !root.get())
3061 {
3062 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003063 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3064 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003065 return 0;
3066 }
3067 else
3068 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003069 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003070 continue;
3071 }
3072 }
3073 else
3074 {
3075 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3076 if (!root.get())
3077 {
3078 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003079 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3080 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003081 return 0;
3082 }
3083 else
3084 {
3085 list->Append(root);
3086 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003087 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3088 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003089 return 1;
3090 }
3091 }
3092 }
3093 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3094 {
3095 root = root->GetSyntheticBitFieldChild(index, index, true);
3096 if (!root.get())
3097 {
3098 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003099 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3100 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003101 return 0;
3102 }
3103 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3104 {
3105 list->Append(root);
3106 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003107 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3108 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003109 return 1;
3110 }
3111 }
3112 }
3113 else // we have a low and a high index
3114 {
3115 char *end = NULL;
3116 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3117 if (!end || end != separator_position) // if something weird is in our way return an error
3118 {
3119 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003120 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3121 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003122 return 0;
3123 }
3124 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3125 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3126 {
3127 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003128 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3129 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003130 return 0;
3131 }
3132 if (index_lower > index_higher) // swap indices if required
3133 {
3134 unsigned long temp = index_lower;
3135 index_lower = index_higher;
3136 index_higher = temp;
3137 }
3138 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
3139 {
3140 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3141 if (!root.get())
3142 {
3143 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003144 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3145 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003146 return 0;
3147 }
3148 else
3149 {
3150 list->Append(root);
3151 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003152 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3153 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003154 return 1;
3155 }
3156 }
3157 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 +00003158 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003159 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3160 {
3161 Error error;
3162 root = root->Dereference(error);
3163 if (error.Fail() || !root.get())
3164 {
3165 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003166 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3167 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003168 return 0;
3169 }
3170 else
3171 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003172 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003173 continue;
3174 }
3175 }
3176 else
3177 {
Johnny Chen44805302011-07-19 19:48:13 +00003178 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003179 index <= index_higher; index++)
3180 {
3181 ValueObjectSP child =
3182 root->GetChildAtIndex(index, true);
3183 list->Append(child);
3184 }
3185 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003186 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3187 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003188 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3189 }
3190 }
3191 break;
3192 }
3193 default: // some non-[ separator, or something entirely wrong, is in the way
3194 {
3195 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003196 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3197 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003198 return 0;
3199 break;
3200 }
3201 }
3202 }
3203}
3204
Enrico Granata0c489f52012-03-01 04:24:26 +00003205static void
3206DumpValueObject_Impl (Stream &s,
3207 ValueObject *valobj,
3208 const ValueObject::DumpValueObjectOptions& options,
3209 uint32_t ptr_depth,
3210 uint32_t curr_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003211{
Greg Clayton007d5be2011-05-30 00:49:24 +00003212 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003213 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003214 bool update_success = valobj->UpdateValueIfNeeded (options.m_use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00003215
Enrico Granata0c489f52012-03-01 04:24:26 +00003216 const char *root_valobj_name =
3217 options.m_root_valobj_name.empty() ?
3218 valobj->GetName().AsCString() :
3219 options.m_root_valobj_name.c_str();
3220
3221 if (update_success && options.m_use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00003222 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003223 ValueObject *dynamic_value = valobj->GetDynamicValue(options.m_use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003224 if (dynamic_value)
3225 valobj = dynamic_value;
3226 }
3227
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003228 clang_type_t clang_type = valobj->GetClangType();
3229
Greg Clayton73b472d2010-10-27 03:32:59 +00003230 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003231 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00003232 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
3233 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003234
Enrico Granata0c489f52012-03-01 04:24:26 +00003235 const bool print_valobj = options.m_flat_output == false || has_value;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003236
3237 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003238 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003239 if (options.m_show_location)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003240 {
Jim Ingham6035b672011-03-31 00:19:25 +00003241 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003242 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003243
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003244 s.Indent();
Enrico Granata2b2631c2012-08-09 16:51:25 +00003245
3246 bool show_type = true;
3247 // if we are at the root-level and been asked to hide the root's type, then hide it
3248 if (curr_depth == 0 && options.m_hide_root_type)
3249 show_type = false;
3250 else
3251 // otherwise decide according to the usual rules (asked to show types - always at the root level)
3252 show_type = options.m_show_types || (curr_depth == 0 && !options.m_flat_output);
3253
3254 if (show_type)
Enrico Granatac3e320a2011-08-02 17:27:39 +00003255 {
Greg Clayton84db9102012-03-26 23:03:23 +00003256 const char* typeName = valobj->GetQualifiedTypeName().AsCString("<invalid type>");
3257 //const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
Enrico Granata9910bc82011-08-03 02:18:51 +00003258 s.Printf("(%s", typeName);
3259 // only show dynamic types if the user really wants to see types
Enrico Granata0c489f52012-03-01 04:24:26 +00003260 if (options.m_show_types && options.m_use_dynamic != eNoDynamicValues &&
Enrico Granata9910bc82011-08-03 02:18:51 +00003261 (/*strstr(typeName, "id") == typeName ||*/
Greg Claytonafacd142011-09-02 01:15:17 +00003262 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003263 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003264 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3265 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatac3e320a2011-08-02 17:27:39 +00003266 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003267 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003268 else
3269 {
3270 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
3271 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003272 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003273 else
3274 {
Greg Claytonf0246d12012-10-11 18:07:21 +00003275 ObjCLanguageRuntime::ClassDescriptorSP objc_class_sp (runtime->GetNonKVOClassDescriptor(*valobj));
3276 if (objc_class_sp)
3277 s.Printf(", dynamic type: %s) ", objc_class_sp->GetClassName().GetCString());
Enrico Granatac3e320a2011-08-02 17:27:39 +00003278 else
Greg Claytonf0246d12012-10-11 18:07:21 +00003279 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003280 }
3281 }
3282 }
3283 else
3284 s.Printf(") ");
3285 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003286
Greg Clayton1d3afba2010-10-05 00:00:42 +00003287
Enrico Granata0c489f52012-03-01 04:24:26 +00003288 if (options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003289 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003290 // If we are showing types, also qualify the C++ base classes
Enrico Granata0c489f52012-03-01 04:24:26 +00003291 const bool qualify_cxx_base_classes = options.m_show_types;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003292 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003293 s.PutCString(" =");
3294 }
3295 else
3296 {
3297 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3298 s.Printf ("%s =", name_cstr);
3299 }
3300
Enrico Granata0c489f52012-03-01 04:24:26 +00003301 if (!options.m_scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003302 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003303 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003304 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003305 }
3306
Enrico Granata0c489f52012-03-01 04:24:26 +00003307 std::string summary_str;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003308 std::string value_str;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003309 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003310 const char *sum_cstr = NULL;
Enrico Granata0c489f52012-03-01 04:24:26 +00003311 TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003312
Enrico Granata0c489f52012-03-01 04:24:26 +00003313 if (options.m_omit_summary_depth > 0)
Enrico Granata0c5ef692011-07-16 01:22:04 +00003314 entry = NULL;
3315
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003316 if (err_cstr == NULL)
3317 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003318 if (options.m_format != eFormatDefault && options.m_format != valobj->GetFormat())
Greg Clayton6efba4f2012-01-26 21:08:30 +00003319 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003320 valobj->GetValueAsCString(options.m_format,
3321 value_str);
Greg Clayton6efba4f2012-01-26 21:08:30 +00003322 }
Enrico Granata0c489f52012-03-01 04:24:26 +00003323 else
Greg Clayton6efba4f2012-01-26 21:08:30 +00003324 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003325 val_cstr = valobj->GetValueAsCString();
3326 if (val_cstr)
3327 value_str = val_cstr;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003328 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003329 err_cstr = valobj->GetError().AsCString();
3330 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003331
3332 if (err_cstr)
3333 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003334 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003335 }
3336 else
3337 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003338 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003339 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003340 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003341 if (options.m_omit_summary_depth == 0)
3342 {
3343 if (options.m_summary_sp)
3344 {
3345 valobj->GetSummaryAsCString(entry, summary_str);
3346 sum_cstr = summary_str.c_str();
3347 }
3348 else
3349 sum_cstr = valobj->GetSummaryAsCString();
3350 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003351
Greg Clayton6efba4f2012-01-26 21:08:30 +00003352 // Make sure we have a value and make sure the summary didn't
3353 // specify that the value should not be printed
3354 if (!value_str.empty() && (entry == NULL || entry->DoesPrintValue() || sum_cstr == NULL))
3355 s.Printf(" %s", value_str.c_str());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003356
Enrico Granata9dd75c82011-07-15 23:30:15 +00003357 if (sum_cstr)
Enrico Granata0c489f52012-03-01 04:24:26 +00003358 s.Printf(" %s", sum_cstr);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003359
Enrico Granata0c489f52012-03-01 04:24:26 +00003360 if (options.m_use_objc)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003361 {
Jim Ingham6035b672011-03-31 00:19:25 +00003362 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003363 if (object_desc)
3364 s.Printf(" %s\n", object_desc);
3365 else
Sean Callanan672ad942010-10-23 00:18:49 +00003366 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003367 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003368 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003369 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003370
Enrico Granata0c489f52012-03-01 04:24:26 +00003371 if (curr_depth < options.m_max_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003372 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003373 // We will show children for all concrete types. We won't show
3374 // pointer contents unless a pointer depth has been specified.
3375 // We won't reference contents unless the reference is the
3376 // root object (depth of zero).
3377 bool print_children = true;
3378
3379 // Use a new temporary pointer depth in case we override the
3380 // current pointer depth below...
3381 uint32_t curr_ptr_depth = ptr_depth;
3382
3383 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3384 if (is_ptr || is_ref)
3385 {
3386 // We have a pointer or reference whose value is an address.
3387 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003388 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003389 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003390 print_children = false;
3391
3392 else if (is_ref && curr_depth == 0)
3393 {
3394 // If this is the root object (depth is zero) that we are showing
3395 // and it is a reference, and no pointer depth has been supplied
3396 // print out what it references. Don't do this at deeper depths
3397 // otherwise we can end up with infinite recursion...
3398 curr_ptr_depth = 1;
3399 }
3400
3401 if (curr_ptr_depth == 0)
3402 print_children = false;
3403 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003404
Enrico Granata0a3958e2011-07-02 00:25:22 +00003405 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003406 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003407 ValueObject* synth_valobj;
3408 ValueObjectSP synth_valobj_sp = valobj->GetSyntheticValue (options.m_use_synthetic);
3409 synth_valobj = (synth_valobj_sp ? synth_valobj_sp.get() : valobj);
Enrico Granatac5bc4122012-03-27 02:35:13 +00003410
Enrico Granatac482a192011-08-17 22:13:59 +00003411 uint32_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003412 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003413 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003414 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003415 if (options.m_flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003416 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003417 if (print_valobj)
3418 s.EOL();
3419 }
3420 else
3421 {
3422 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003423 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003424 s.IndentMore();
3425 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003426
Greg Claytoncc4d0142012-02-17 07:49:44 +00003427 uint32_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00003428
Enrico Granata0c489f52012-03-01 04:24:26 +00003429 if (num_children > max_num_children && !options.m_ignore_cap)
Enrico Granata22c55d12011-08-12 02:00:06 +00003430 {
3431 num_children = max_num_children;
3432 print_dotdotdot = true;
3433 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003434
Enrico Granata0c489f52012-03-01 04:24:26 +00003435 ValueObject::DumpValueObjectOptions child_options(options);
3436 child_options.SetFormat().SetSummary().SetRootValueObjectName();
3437 child_options.SetScopeChecked(true)
3438 .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003439 for (uint32_t idx=0; idx<num_children; ++idx)
3440 {
Enrico Granatac482a192011-08-17 22:13:59 +00003441 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003442 if (child_sp.get())
3443 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003444 DumpValueObject_Impl (s,
3445 child_sp.get(),
3446 child_options,
3447 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
3448 curr_depth + 1);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003449 }
3450 }
3451
Enrico Granata0c489f52012-03-01 04:24:26 +00003452 if (!options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003453 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003454 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003455 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003456 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3457 Target *target = exe_ctx.GetTargetPtr();
3458 if (target)
3459 target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003460 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003461 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003462 s.IndentLess();
3463 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003464 }
3465 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003466 else if (has_children)
3467 {
3468 // Aggregate, no children...
3469 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003470 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003471 }
3472 else
3473 {
3474 if (print_valobj)
3475 s.EOL();
3476 }
3477
Greg Clayton1d3afba2010-10-05 00:00:42 +00003478 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003479 else
3480 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003481 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003482 }
3483 }
3484 else
3485 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003486 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003487 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003488 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003489 }
3490 }
3491 }
3492 }
3493}
3494
Enrico Granata0c489f52012-03-01 04:24:26 +00003495void
Greg Claytonf830dbb2012-03-22 18:15:37 +00003496ValueObject::LogValueObject (Log *log,
3497 ValueObject *valobj)
3498{
3499 if (log && valobj)
3500 return LogValueObject (log, valobj, DumpValueObjectOptions::DefaultOptions());
3501}
3502
3503void
3504ValueObject::LogValueObject (Log *log,
3505 ValueObject *valobj,
3506 const DumpValueObjectOptions& options)
3507{
3508 if (log && valobj)
3509 {
3510 StreamString s;
3511 ValueObject::DumpValueObject (s, valobj, options);
3512 if (s.GetSize())
3513 log->PutCString(s.GetData());
3514 }
3515}
3516
3517void
Enrico Granata0c489f52012-03-01 04:24:26 +00003518ValueObject::DumpValueObject (Stream &s,
3519 ValueObject *valobj)
3520{
3521
3522 if (!valobj)
3523 return;
3524
3525 DumpValueObject_Impl(s,
3526 valobj,
3527 DumpValueObjectOptions::DefaultOptions(),
3528 0,
3529 0);
3530}
3531
3532void
3533ValueObject::DumpValueObject (Stream &s,
3534 ValueObject *valobj,
3535 const DumpValueObjectOptions& options)
3536{
3537 DumpValueObject_Impl(s,
3538 valobj,
3539 options,
3540 options.m_max_ptr_depth, // max pointer depth allowed, we will go down from here
3541 0 // current object depth is 0 since we are just starting
3542 );
3543}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003544
3545ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003546ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003547{
3548 ValueObjectSP valobj_sp;
3549
Enrico Granatac3e320a2011-08-02 17:27:39 +00003550 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003551 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003552 ExecutionContext exe_ctx (GetExecutionContextRef());
3553 clang::ASTContext *ast = GetClangAST ();
3554
3555 DataExtractor data;
3556 data.SetByteOrder (m_data.GetByteOrder());
3557 data.SetAddressByteSize(m_data.GetAddressByteSize());
3558
Enrico Granata9f1e2042012-04-24 22:15:37 +00003559 if (IsBitfield())
3560 {
3561 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
3562 m_error = v.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
3563 }
3564 else
3565 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003566
3567 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3568 ast,
3569 GetClangType(),
3570 name,
3571 data,
3572 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003573 }
Jim Ingham6035b672011-03-31 00:19:25 +00003574
3575 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003576 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003577 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003578 }
3579 return valobj_sp;
3580}
3581
Greg Claytonafacd142011-09-02 01:15:17 +00003582ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003583ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003584{
Jim Ingham58b59f92011-04-22 23:53:53 +00003585 if (m_deref_valobj)
3586 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003587
Greg Clayton54979cd2010-12-15 05:08:08 +00003588 const bool is_pointer_type = IsPointerType();
3589 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003590 {
3591 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003592 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003593
3594 std::string child_name_str;
3595 uint32_t child_byte_size = 0;
3596 int32_t child_byte_offset = 0;
3597 uint32_t child_bitfield_bit_size = 0;
3598 uint32_t child_bitfield_bit_offset = 0;
3599 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003600 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003601 const bool transparent_pointers = false;
3602 clang::ASTContext *clang_ast = GetClangAST();
3603 clang_type_t clang_type = GetClangType();
3604 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003605
Greg Claytoncc4d0142012-02-17 07:49:44 +00003606 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003607
3608 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3609 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003610 GetName().GetCString(),
3611 clang_type,
3612 0,
3613 transparent_pointers,
3614 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003615 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003616 child_name_str,
3617 child_byte_size,
3618 child_byte_offset,
3619 child_bitfield_bit_size,
3620 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003621 child_is_base_class,
3622 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003623 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003624 {
3625 ConstString child_name;
3626 if (!child_name_str.empty())
3627 child_name.SetCString (child_name_str.c_str());
3628
Jim Ingham58b59f92011-04-22 23:53:53 +00003629 m_deref_valobj = new ValueObjectChild (*this,
3630 clang_ast,
3631 child_clang_type,
3632 child_name,
3633 child_byte_size,
3634 child_byte_offset,
3635 child_bitfield_bit_size,
3636 child_bitfield_bit_offset,
3637 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003638 child_is_deref_of_parent,
3639 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003640 }
3641 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003642
Jim Ingham58b59f92011-04-22 23:53:53 +00003643 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003644 {
3645 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003646 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003647 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003648 else
3649 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003650 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003651 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003652
3653 if (is_pointer_type)
3654 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3655 else
3656 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003657 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003658 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003659}
3660
Greg Claytonafacd142011-09-02 01:15:17 +00003661ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003662ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003663{
Jim Ingham78a685a2011-04-16 00:01:13 +00003664 if (m_addr_of_valobj_sp)
3665 return m_addr_of_valobj_sp;
3666
Greg Claytone0d378b2011-03-24 21:19:54 +00003667 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003668 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003669 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003670 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003671 if (addr != LLDB_INVALID_ADDRESS)
3672 {
3673 switch (address_type)
3674 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003675 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003676 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003677 {
3678 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003679 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003680 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3681 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003682 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003683
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003684 case eAddressTypeFile:
3685 case eAddressTypeLoad:
3686 case eAddressTypeHost:
3687 {
3688 clang::ASTContext *ast = GetClangAST();
3689 clang_type_t clang_type = GetClangType();
3690 if (ast && clang_type)
3691 {
3692 std::string name (1, '&');
3693 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003694 ExecutionContext exe_ctx (GetExecutionContextRef());
3695 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003696 ast,
3697 ClangASTContext::CreatePointerType (ast, clang_type),
3698 ConstString (name.c_str()),
3699 addr,
3700 eAddressTypeInvalid,
3701 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003702 }
3703 }
3704 break;
3705 }
3706 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003707 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003708}
3709
Greg Clayton9a142cf2012-02-03 05:34:10 +00003710ValueObjectSP
3711ValueObject::Cast (const ClangASTType &clang_ast_type)
3712{
Greg Clayton81e871e2012-02-04 02:27:34 +00003713 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003714}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003715
Greg Claytonafacd142011-09-02 01:15:17 +00003716ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003717ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3718{
Greg Claytonafacd142011-09-02 01:15:17 +00003719 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003720 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003721 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003722
3723 if (ptr_value != LLDB_INVALID_ADDRESS)
3724 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003725 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003726 ExecutionContext exe_ctx (GetExecutionContextRef());
3727 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003728 name,
3729 ptr_addr,
3730 clang_ast_type);
3731 }
3732 return valobj_sp;
3733}
3734
Greg Claytonafacd142011-09-02 01:15:17 +00003735ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003736ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3737{
Greg Claytonafacd142011-09-02 01:15:17 +00003738 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003739 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003740 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003741
3742 if (ptr_value != LLDB_INVALID_ADDRESS)
3743 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003744 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003745 ExecutionContext exe_ctx (GetExecutionContextRef());
3746 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003747 name,
3748 ptr_addr,
3749 type_sp);
3750 }
3751 return valobj_sp;
3752}
3753
Jim Ingham6035b672011-03-31 00:19:25 +00003754ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003755 m_mod_id(),
3756 m_exe_ctx_ref(),
3757 m_needs_update (true),
3758 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003759{
3760}
3761
3762ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003763 m_mod_id(),
3764 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003765 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003766 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003767{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003768 ExecutionContext exe_ctx(exe_scope);
3769 TargetSP target_sp (exe_ctx.GetTargetSP());
3770 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003771 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003772 m_exe_ctx_ref.SetTargetSP (target_sp);
3773 ProcessSP process_sp (exe_ctx.GetProcessSP());
3774 if (!process_sp)
3775 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003776
Greg Claytoncc4d0142012-02-17 07:49:44 +00003777 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003778 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003779 m_mod_id = process_sp->GetModID();
3780 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003781
Greg Claytoncc4d0142012-02-17 07:49:44 +00003782 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003783
Greg Claytoncc4d0142012-02-17 07:49:44 +00003784 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003785 {
3786 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003787 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003788 }
Jim Ingham6035b672011-03-31 00:19:25 +00003789
Greg Claytoncc4d0142012-02-17 07:49:44 +00003790 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003791 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003792 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003793
Greg Claytoncc4d0142012-02-17 07:49:44 +00003794 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3795 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003796 {
3797 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003798 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003799 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003800 if (frame_sp)
3801 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003802 }
3803 }
3804 }
Jim Ingham6035b672011-03-31 00:19:25 +00003805}
3806
3807ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003808 m_mod_id(),
3809 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3810 m_needs_update (true),
3811 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003812{
3813}
3814
3815ValueObject::EvaluationPoint::~EvaluationPoint ()
3816{
3817}
3818
Jim Ingham6035b672011-03-31 00:19:25 +00003819// This function checks the EvaluationPoint against the current process state. If the current
3820// state matches the evaluation point, or the evaluation point is already invalid, then we return
3821// false, meaning "no change". If the current state is different, we update our state, and return
3822// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3823// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003824// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003825
3826bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003827ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003828{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003829
3830 // 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 +00003831 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00003832
Greg Claytoncc4d0142012-02-17 07:49:44 +00003833 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003834 return false;
3835
Jim Ingham6035b672011-03-31 00:19:25 +00003836 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003837 Process *process = exe_ctx.GetProcessPtr();
3838 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003839 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003840
Jim Ingham6035b672011-03-31 00:19:25 +00003841 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003842 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003843
Jim Ingham78a685a2011-04-16 00:01:13 +00003844 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3845 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003846 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003847 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003848
Greg Clayton23f59502012-07-17 03:23:13 +00003849 bool changed = false;
3850 const bool was_valid = m_mod_id.IsValid();
3851 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003852 {
3853 if (m_mod_id == current_mod_id)
3854 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003855 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003856 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003857 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003858 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003859 else
3860 {
3861 m_mod_id = current_mod_id;
3862 m_needs_update = true;
3863 changed = true;
3864 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003865 }
Jim Ingham6035b672011-03-31 00:19:25 +00003866
Jim Ingham73ca05a2011-12-17 01:35:57 +00003867 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3868 // That way we'll be sure to return a valid exe_scope.
3869 // 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 +00003870
Greg Claytoncc4d0142012-02-17 07:49:44 +00003871 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003872 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003873 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3874 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003875 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003876 if (m_exe_ctx_ref.HasFrameRef())
3877 {
3878 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3879 if (!frame_sp)
3880 {
3881 // We used to have a frame, but now it is gone
3882 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003883 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00003884 }
3885 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003886 }
Jim Ingham6035b672011-03-31 00:19:25 +00003887 else
3888 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003889 // We used to have a thread, but now it is gone
3890 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003891 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00003892 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003893
Jim Ingham6035b672011-03-31 00:19:25 +00003894 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003895 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003896}
3897
Jim Ingham61be0902011-05-02 18:13:59 +00003898void
3899ValueObject::EvaluationPoint::SetUpdated ()
3900{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003901 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3902 if (process_sp)
3903 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003904 m_first_update = false;
3905 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003906}
3907
3908
Greg Claytoncc4d0142012-02-17 07:49:44 +00003909//bool
3910//ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3911//{
3912// if (!IsValid())
3913// return false;
3914//
3915// bool needs_update = false;
3916//
3917// // The target has to be non-null, and the
3918// Target *target = exe_scope->CalculateTarget();
3919// if (target != NULL)
3920// {
3921// Target *old_target = m_target_sp.get();
3922// assert (target == old_target);
3923// Process *process = exe_scope->CalculateProcess();
3924// if (process != NULL)
3925// {
3926// // FOR NOW - assume you can't update variable objects across process boundaries.
3927// Process *old_process = m_process_sp.get();
3928// assert (process == old_process);
3929// ProcessModID current_mod_id = process->GetModID();
3930// if (m_mod_id != current_mod_id)
3931// {
3932// needs_update = true;
3933// m_mod_id = current_mod_id;
3934// }
3935// // See if we're switching the thread or stack context. If no thread is given, this is
3936// // being evaluated in a global context.
3937// Thread *thread = exe_scope->CalculateThread();
3938// if (thread != NULL)
3939// {
3940// user_id_t new_thread_index = thread->GetIndexID();
3941// if (new_thread_index != m_thread_id)
3942// {
3943// needs_update = true;
3944// m_thread_id = new_thread_index;
3945// m_stack_id.Clear();
3946// }
3947//
3948// StackFrame *new_frame = exe_scope->CalculateStackFrame();
3949// if (new_frame != NULL)
3950// {
3951// if (new_frame->GetStackID() != m_stack_id)
3952// {
3953// needs_update = true;
3954// m_stack_id = new_frame->GetStackID();
3955// }
3956// }
3957// else
3958// {
3959// m_stack_id.Clear();
3960// needs_update = true;
3961// }
3962// }
3963// else
3964// {
3965// // If this had been given a thread, and now there is none, we should update.
3966// // Otherwise we don't have to do anything.
3967// if (m_thread_id != LLDB_INVALID_UID)
3968// {
3969// m_thread_id = LLDB_INVALID_UID;
3970// m_stack_id.Clear();
3971// needs_update = true;
3972// }
3973// }
3974// }
3975// else
3976// {
3977// // If there is no process, then we don't need to update anything.
3978// // But if we're switching from having a process to not, we should try to update.
3979// if (m_process_sp.get() != NULL)
3980// {
3981// needs_update = true;
3982// m_process_sp.reset();
3983// m_thread_id = LLDB_INVALID_UID;
3984// m_stack_id.Clear();
3985// }
3986// }
3987// }
3988// else
3989// {
3990// // If there's no target, nothing can change so we don't need to update anything.
3991// // But if we're switching from having a target to not, we should try to update.
3992// if (m_target_sp.get() != NULL)
3993// {
3994// needs_update = true;
3995// m_target_sp.reset();
3996// m_process_sp.reset();
3997// m_thread_id = LLDB_INVALID_UID;
3998// m_stack_id.Clear();
3999// }
4000// }
4001// if (!m_needs_update)
4002// m_needs_update = needs_update;
4003//
4004// return needs_update;
4005//}
Enrico Granataf2bbf712011-07-15 02:26:42 +00004006
4007void
Enrico Granata86cc9822012-03-19 22:58:49 +00004008ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004009{
Enrico Granata86cc9822012-03-19 22:58:49 +00004010 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4011 m_value_str.clear();
4012
4013 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4014 m_location_str.clear();
4015
4016 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
4017 {
Enrico Granata86cc9822012-03-19 22:58:49 +00004018 m_summary_str.clear();
4019 }
4020
4021 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4022 m_object_desc_str.clear();
4023
4024 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4025 {
4026 if (m_synthetic_value)
4027 m_synthetic_value = NULL;
4028 }
Johnny Chen44805302011-07-19 19:48:13 +00004029}
Enrico Granata9128ee22011-09-06 19:20:51 +00004030
4031SymbolContextScope *
4032ValueObject::GetSymbolContextScope()
4033{
4034 if (m_parent)
4035 {
4036 if (!m_parent->IsPointerOrReferenceType())
4037 return m_parent->GetSymbolContextScope();
4038 }
4039 return NULL;
4040}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004041
4042lldb::ValueObjectSP
4043ValueObject::CreateValueObjectFromExpression (const char* name,
4044 const char* expression,
4045 const ExecutionContext& exe_ctx)
4046{
4047 lldb::ValueObjectSP retval_sp;
4048 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4049 if (!target_sp)
4050 return retval_sp;
4051 if (!expression || !*expression)
4052 return retval_sp;
4053 target_sp->EvaluateExpression (expression,
4054 exe_ctx.GetFrameSP().get(),
4055 retval_sp);
4056 if (retval_sp && name && *name)
4057 retval_sp->SetName(ConstString(name));
4058 return retval_sp;
4059}
4060
4061lldb::ValueObjectSP
4062ValueObject::CreateValueObjectFromAddress (const char* name,
4063 uint64_t address,
4064 const ExecutionContext& exe_ctx,
4065 ClangASTType type)
4066{
4067 ClangASTType pointer_type(type.GetASTContext(),type.GetPointerType());
4068 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4069 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4070 pointer_type.GetASTContext(),
4071 pointer_type.GetOpaqueQualType(),
4072 ConstString(name),
4073 buffer,
4074 lldb::endian::InlHostByteOrder(),
4075 exe_ctx.GetAddressByteSize()));
4076 if (ptr_result_valobj_sp)
4077 {
4078 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4079 Error err;
4080 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4081 if (ptr_result_valobj_sp && name && *name)
4082 ptr_result_valobj_sp->SetName(ConstString(name));
4083 }
4084 return ptr_result_valobj_sp;
4085}
4086
4087lldb::ValueObjectSP
4088ValueObject::CreateValueObjectFromData (const char* name,
4089 DataExtractor& data,
4090 const ExecutionContext& exe_ctx,
4091 ClangASTType type)
4092{
4093 lldb::ValueObjectSP new_value_sp;
4094 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4095 type.GetASTContext() ,
4096 type.GetOpaqueQualType(),
4097 ConstString(name),
4098 data,
4099 LLDB_INVALID_ADDRESS);
4100 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4101 if (new_value_sp && name && *name)
4102 new_value_sp->SetName(ConstString(name));
4103 return new_value_sp;
4104}