blob: c3560f1089ef666b6155c4177ac569c13725c59d [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 Clayton526e5af2010-11-13 03:52:47 +0000425 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000426 {
427 RegisterInfo *reg_info = m_value.GetRegisterInfo();
428 if (reg_info)
429 {
430 if (reg_info->name)
431 m_location_str = reg_info->name;
432 else if (reg_info->alt_name)
433 m_location_str = reg_info->alt_name;
434 break;
435 }
436 }
437 m_location_str = "scalar";
438 break;
439
440 case Value::eValueTypeLoadAddress:
441 case Value::eValueTypeFileAddress:
442 case Value::eValueTypeHostAddress:
443 {
444 uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2;
445 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
446 m_location_str.swap(sstr.GetString());
447 }
448 break;
449 }
450 }
451 }
452 return m_location_str.c_str();
453}
454
455Value &
456ValueObject::GetValue()
457{
458 return m_value;
459}
460
461const Value &
462ValueObject::GetValue() const
463{
464 return m_value;
465}
466
467bool
Jim Ingham6035b672011-03-31 00:19:25 +0000468ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000469{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000470 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
471 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000472 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000473 Value tmp_value(m_value);
474 scalar = tmp_value.ResolveValue(&exe_ctx, GetClangAST ());
Greg Claytondcad5022011-12-29 01:26:56 +0000475 if (scalar.IsValid())
476 {
477 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
478 if (bitfield_bit_size)
479 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
480 return true;
481 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000482 }
Greg Claytondcad5022011-12-29 01:26:56 +0000483 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000484}
485
486bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000487ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000488{
Greg Clayton288bdf92010-09-02 02:59:18 +0000489 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000490}
491
492
493void
494ValueObject::SetValueIsValid (bool b)
495{
Greg Clayton288bdf92010-09-02 02:59:18 +0000496 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000497}
498
499bool
Jim Ingham6035b672011-03-31 00:19:25 +0000500ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000501{
Jim Ingham6035b672011-03-31 00:19:25 +0000502 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000503 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000504}
505
506void
507ValueObject::SetValueDidChange (bool value_changed)
508{
Greg Clayton288bdf92010-09-02 02:59:18 +0000509 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000510}
511
512ValueObjectSP
513ValueObject::GetChildAtIndex (uint32_t idx, bool can_create)
514{
515 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000516 // We may need to update our value if we are dynamic
517 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000518 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000519 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000520 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000521 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000522 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000523 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000524 // No we haven't created the child at this index, so lets have our
525 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000526 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000527 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000528
Enrico Granata9d60f602012-03-09 03:09:58 +0000529 ValueObject* child = m_children.GetChildAtIndex(idx);
530 if (child != NULL)
531 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000532 }
533 return child_sp;
534}
535
536uint32_t
537ValueObject::GetIndexOfChildWithName (const ConstString &name)
538{
539 bool omit_empty_base_classes = true;
540 return ClangASTContext::GetIndexOfChildWithName (GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +0000541 GetClangType(),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000542 name.GetCString(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000543 omit_empty_base_classes);
544}
545
546ValueObjectSP
547ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
548{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000549 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000550 // classes (which really aren't part of the expression path), so we
551 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000552 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000553
Greg Claytondea8cb42011-06-29 22:09:02 +0000554 // We may need to update our value if we are dynamic
555 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000556 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000557
558 std::vector<uint32_t> child_indexes;
559 clang::ASTContext *clang_ast = GetClangAST();
560 void *clang_type = GetClangType();
561 bool omit_empty_base_classes = true;
562 const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast,
563 clang_type,
564 name.GetCString(),
565 omit_empty_base_classes,
566 child_indexes);
567 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000568 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000569 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
570 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
571
572 child_sp = GetChildAtIndex(*pos, can_create);
573 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000574 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000575 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000576 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000577 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
578 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000579 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000580 else
581 {
582 child_sp.reset();
583 }
584
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000585 }
586 }
587 return child_sp;
588}
589
590
591uint32_t
592ValueObject::GetNumChildren ()
593{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000594 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000595 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000596 {
597 SetNumChildren (CalculateNumChildren());
598 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000599 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000600}
Greg Clayton4a792072012-10-23 01:50:10 +0000601
602bool
603ValueObject::MightHaveChildren()
604{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000605 bool has_children = false;
Greg Clayton4a792072012-10-23 01:50:10 +0000606 clang_type_t clang_type = GetClangType();
607 if (clang_type)
608 {
609 const uint32_t type_info = ClangASTContext::GetTypeInfo (clang_type,
610 GetClangAST(),
611 NULL);
612 if (type_info & (ClangASTContext::eTypeHasChildren |
613 ClangASTContext::eTypeIsPointer |
614 ClangASTContext::eTypeIsReference))
615 has_children = true;
616 }
617 else
618 {
619 has_children = GetNumChildren () > 0;
620 }
621 return has_children;
622}
623
624// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000625void
626ValueObject::SetNumChildren (uint32_t num_children)
627{
Greg Clayton288bdf92010-09-02 02:59:18 +0000628 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000629 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000630}
631
632void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000633ValueObject::SetName (const ConstString &name)
634{
635 m_name = name;
636}
637
Jim Ingham58b59f92011-04-22 23:53:53 +0000638ValueObject *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000639ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index)
640{
Jim Ingham2eec4872011-05-07 00:10:58 +0000641 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000642
Greg Claytondea8cb42011-06-29 22:09:02 +0000643 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000644 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000645 std::string child_name_str;
646 uint32_t child_byte_size = 0;
647 int32_t child_byte_offset = 0;
648 uint32_t child_bitfield_bit_size = 0;
649 uint32_t child_bitfield_bit_offset = 0;
650 bool child_is_base_class = false;
651 bool child_is_deref_of_parent = false;
652
653 const bool transparent_pointers = synthetic_array_member == false;
654 clang::ASTContext *clang_ast = GetClangAST();
655 clang_type_t clang_type = GetClangType();
656 clang_type_t child_clang_type;
657
Greg Claytoncc4d0142012-02-17 07:49:44 +0000658 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000659
660 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
661 clang_ast,
662 GetName().GetCString(),
663 clang_type,
664 idx,
665 transparent_pointers,
666 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +0000667 ignore_array_bounds,
Greg Claytondea8cb42011-06-29 22:09:02 +0000668 child_name_str,
669 child_byte_size,
670 child_byte_offset,
671 child_bitfield_bit_size,
672 child_bitfield_bit_offset,
673 child_is_base_class,
674 child_is_deref_of_parent);
675 if (child_clang_type && child_byte_size)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000676 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000677 if (synthetic_index)
678 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000679
Greg Claytondea8cb42011-06-29 22:09:02 +0000680 ConstString child_name;
681 if (!child_name_str.empty())
682 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000683
Greg Claytondea8cb42011-06-29 22:09:02 +0000684 valobj = new ValueObjectChild (*this,
685 clang_ast,
686 child_clang_type,
687 child_name,
688 child_byte_size,
689 child_byte_offset,
690 child_bitfield_bit_size,
691 child_bitfield_bit_offset,
692 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000693 child_is_deref_of_parent,
694 eAddressTypeInvalid);
695 //if (valobj)
696 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
697 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000698
Jim Ingham58b59f92011-04-22 23:53:53 +0000699 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000700}
701
Enrico Granata0c489f52012-03-01 04:24:26 +0000702bool
703ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
704 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000705{
Enrico Granata0c489f52012-03-01 04:24:26 +0000706 destination.clear();
707
708 // ideally we would like to bail out if passing NULL, but if we do so
709 // we end up not providing the summary for function pointers anymore
710 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
711 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000712
713 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000714
715 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
716 // information that we might care to see in a crash log. might be useful in very specific situations though.
717 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
718 GetTypeName().GetCString(),
719 GetName().GetCString(),
720 summary_ptr->GetDescription().c_str());*/
721
Enrico Granata0c489f52012-03-01 04:24:26 +0000722 if (UpdateValueIfNeeded (false))
723 {
724 if (summary_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000725 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000726 if (HasSyntheticValue())
727 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
728 summary_ptr->FormatObject(this, destination);
Enrico Granata0c489f52012-03-01 04:24:26 +0000729 }
730 else
731 {
732 clang_type_t clang_type = GetClangType();
733
734 // Do some default printout for function pointers
735 if (clang_type)
Enrico Granata4becb372011-06-29 22:27:15 +0000736 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000737 StreamString sstr;
738 clang_type_t elem_or_pointee_clang_type;
739 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
740 GetClangAST(),
741 &elem_or_pointee_clang_type));
742
743 if (ClangASTContext::IsFunctionPointerType (clang_type))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000744 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000745 AddressType func_ptr_address_type = eAddressTypeInvalid;
746 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
747 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000748 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000749 switch (func_ptr_address_type)
Jim Ingham6035b672011-03-31 00:19:25 +0000750 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000751 case eAddressTypeInvalid:
752 case eAddressTypeFile:
753 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000754
Greg Claytoncc4d0142012-02-17 07:49:44 +0000755 case eAddressTypeLoad:
Enrico Granata0c489f52012-03-01 04:24:26 +0000756 {
757 ExecutionContext exe_ctx (GetExecutionContextRef());
758
759 Address so_addr;
760 Target *target = exe_ctx.GetTargetPtr();
761 if (target && target->GetSectionLoadList().IsEmpty() == false)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000762 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000763 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000764 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000765 so_addr.Dump (&sstr,
766 exe_ctx.GetBestExecutionContextScope(),
767 Address::DumpStyleResolvedDescription,
768 Address::DumpStyleSectionNameOffset);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000769 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000770 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000771 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000772 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000773
Greg Claytoncc4d0142012-02-17 07:49:44 +0000774 case eAddressTypeHost:
775 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +0000776 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000777 }
778 if (sstr.GetSize() > 0)
779 {
780 destination.assign (1, '(');
781 destination.append (sstr.GetData(), sstr.GetSize());
782 destination.append (1, ')');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000783 }
784 }
785 }
786 }
787 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000788 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000789 return !destination.empty();
790}
791
792const char *
793ValueObject::GetSummaryAsCString ()
794{
795 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
796 {
797 GetSummaryAsCString(GetSummaryFormat().get(),
798 m_summary_str);
799 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000800 if (m_summary_str.empty())
801 return NULL;
802 return m_summary_str.c_str();
803}
804
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000805bool
806ValueObject::IsCStringContainer(bool check_pointer)
807{
808 clang_type_t elem_or_pointee_clang_type;
809 const Flags type_flags (ClangASTContext::GetTypeInfo (GetClangType(),
810 GetClangAST(),
811 &elem_or_pointee_clang_type));
812 bool is_char_arr_ptr (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
813 ClangASTContext::IsCharType (elem_or_pointee_clang_type));
814 if (!is_char_arr_ptr)
815 return false;
816 if (!check_pointer)
817 return true;
818 if (type_flags.Test(ClangASTContext::eTypeIsArray))
819 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000820 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000821 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000822 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000823 return (cstr_address != LLDB_INVALID_ADDRESS);
824}
825
Enrico Granata9128ee22011-09-06 19:20:51 +0000826size_t
827ValueObject::GetPointeeData (DataExtractor& data,
828 uint32_t item_idx,
829 uint32_t item_count)
830{
831 if (!IsPointerType() && !IsArrayType())
832 return 0;
833
834 if (item_count == 0)
835 return 0;
836
837 uint32_t stride = 0;
838
839 ClangASTType type(GetClangAST(),
840 GetClangType());
841
842 const uint64_t item_type_size = (IsPointerType() ? ClangASTType::GetTypeByteSize(GetClangAST(), type.GetPointeeType()) :
843 ClangASTType::GetTypeByteSize(GetClangAST(), type.GetArrayElementType(stride)));
844
845 const uint64_t bytes = item_count * item_type_size;
846
847 const uint64_t offset = item_idx * item_type_size;
848
849 if (item_idx == 0 && item_count == 1) // simply a deref
850 {
851 if (IsPointerType())
852 {
853 Error error;
854 ValueObjectSP pointee_sp = Dereference(error);
855 if (error.Fail() || pointee_sp.get() == NULL)
856 return 0;
857 return pointee_sp->GetDataExtractor().Copy(data);
858 }
859 else
860 {
861 ValueObjectSP child_sp = GetChildAtIndex(0, true);
862 if (child_sp.get() == NULL)
863 return 0;
864 return child_sp->GetDataExtractor().Copy(data);
865 }
866 return true;
867 }
868 else /* (items > 1) */
869 {
870 Error error;
871 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
872 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
873
874 AddressType addr_type;
875 lldb::addr_t addr = IsPointerType() ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
876
Enrico Granata9128ee22011-09-06 19:20:51 +0000877 switch (addr_type)
878 {
879 case eAddressTypeFile:
880 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000881 ModuleSP module_sp (GetModule());
882 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000883 {
Enrico Granata9c2efe32012-08-07 01:49:34 +0000884 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +0000885 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +0000886 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000887 ExecutionContext exe_ctx (GetExecutionContextRef());
888 Target* target = exe_ctx.GetTargetPtr();
889 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +0000890 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000891 heap_buf_ptr->SetByteSize(bytes);
892 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
893 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +0000894 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000895 data.SetData(data_sp);
896 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +0000897 }
898 }
899 }
900 }
901 break;
902 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +0000903 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000904 ExecutionContext exe_ctx (GetExecutionContextRef());
905 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +0000906 if (process)
907 {
908 heap_buf_ptr->SetByteSize(bytes);
909 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
910 if (error.Success())
911 {
912 data.SetData(data_sp);
913 return bytes_read;
914 }
915 }
916 }
917 break;
918 case eAddressTypeHost:
919 {
920 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes);
921 data.SetData(data_sp);
922 return bytes;
923 }
924 break;
925 case eAddressTypeInvalid:
926 default:
927 break;
928 }
929 }
930 return 0;
931}
932
933size_t
934ValueObject::GetData (DataExtractor& data)
935{
936 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000937 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytone72dfb32012-02-24 01:59:29 +0000938 Error error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +0000939 if (error.Fail())
940 return 0;
941 data.SetAddressByteSize(m_data.GetAddressByteSize());
942 data.SetByteOrder(m_data.GetByteOrder());
943 return data.GetByteSize();
944}
945
946// will compute strlen(str), but without consuming more than
947// maxlen bytes out of str (this serves the purpose of reading
948// chunks of a string without having to worry about
949// missing NULL terminators in the chunk)
950// of course, if strlen(str) > maxlen, the function will return
951// maxlen_value (which should be != maxlen, because that allows you
952// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
953static uint32_t
954strlen_or_inf (const char* str,
955 uint32_t maxlen,
956 uint32_t maxlen_value)
957{
958 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +0000959 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +0000960 {
Greg Clayton8dd5c172011-10-05 22:19:51 +0000961 while(*str)
962 {
963 len++;str++;
964 if (len > maxlen)
965 return maxlen_value;
966 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000967 }
968 return len;
969}
970
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000971void
Greg Claytoncc4d0142012-02-17 07:49:44 +0000972ValueObject::ReadPointedString (Stream& s,
973 Error& error,
974 uint32_t max_length,
975 bool honor_array,
976 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000977{
Greg Claytoncc4d0142012-02-17 07:49:44 +0000978 ExecutionContext exe_ctx (GetExecutionContextRef());
979 Target* target = exe_ctx.GetTargetPtr();
980
981 if (target && max_length == 0)
982 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000983
984 clang_type_t clang_type = GetClangType();
985 clang_type_t elem_or_pointee_clang_type;
986 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
987 GetClangAST(),
988 &elem_or_pointee_clang_type));
989 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
990 ClangASTContext::IsCharType (elem_or_pointee_clang_type))
991 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000992 if (target == NULL)
993 {
994 s << "<no target to read from>";
995 }
996 else
997 {
998 addr_t cstr_address = LLDB_INVALID_ADDRESS;
999 AddressType cstr_address_type = eAddressTypeInvalid;
1000
1001 size_t cstr_len = 0;
1002 bool capped_data = false;
1003 if (type_flags.Test (ClangASTContext::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001004 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001005 // We have an array
1006 cstr_len = ClangASTContext::GetArraySize (clang_type);
1007 if (cstr_len > max_length)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001008 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001009 capped_data = true;
1010 cstr_len = max_length;
1011 }
1012 cstr_address = GetAddressOf (true, &cstr_address_type);
1013 }
1014 else
1015 {
1016 // We have a pointer
1017 cstr_address = GetPointerValue (&cstr_address_type);
1018 }
1019 if (cstr_address != 0 && cstr_address != LLDB_INVALID_ADDRESS)
1020 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001021 Address cstr_so_addr (cstr_address);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001022 DataExtractor data;
1023 size_t bytes_read = 0;
1024 if (cstr_len > 0 && honor_array)
1025 {
1026 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1027 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1028 GetPointeeData(data, 0, cstr_len);
1029
1030 if ((bytes_read = data.GetByteSize()) > 0)
1031 {
1032 s << '"';
1033 data.Dump (&s,
1034 0, // Start offset in "data"
1035 item_format,
1036 1, // Size of item (1 byte for a char!)
1037 bytes_read, // How many bytes to print?
1038 UINT32_MAX, // num per line
1039 LLDB_INVALID_ADDRESS,// base address
1040 0, // bitfield bit size
1041 0); // bitfield bit offset
1042 if (capped_data)
1043 s << "...";
1044 s << '"';
1045 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00001046 }
1047 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001048 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001049 cstr_len = max_length;
1050 const size_t k_max_buf_size = 64;
1051
1052 size_t offset = 0;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001053
Greg Claytoncc4d0142012-02-17 07:49:44 +00001054 int cstr_len_displayed = -1;
1055 bool capped_cstr = false;
1056 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1057 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1058 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001059 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001060 const char *cstr = data.PeekCStr(0);
1061 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1062 if (len > k_max_buf_size)
1063 len = k_max_buf_size;
1064 if (cstr && cstr_len_displayed < 0)
1065 s << '"';
1066
1067 if (cstr_len_displayed < 0)
1068 cstr_len_displayed = len;
1069
1070 if (len == 0)
1071 break;
1072 cstr_len_displayed += len;
1073 if (len > bytes_read)
1074 len = bytes_read;
1075 if (len > cstr_len)
1076 len = cstr_len;
1077
1078 data.Dump (&s,
1079 0, // Start offset in "data"
1080 item_format,
1081 1, // Size of item (1 byte for a char!)
1082 len, // How many bytes to print?
1083 UINT32_MAX, // num per line
1084 LLDB_INVALID_ADDRESS,// base address
1085 0, // bitfield bit size
1086 0); // bitfield bit offset
1087
1088 if (len < k_max_buf_size)
1089 break;
1090
1091 if (len >= cstr_len)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001092 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001093 capped_cstr = true;
1094 break;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001095 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001096
1097 cstr_len -= len;
1098 offset += len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001099 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001100
1101 if (cstr_len_displayed >= 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001102 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001103 s << '"';
1104 if (capped_cstr)
1105 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001106 }
1107 }
1108 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001109 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001110 }
1111 else
1112 {
1113 error.SetErrorString("impossible to read a string from this object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001114 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001115 }
1116}
1117
Jim Ingham53c47f12010-09-10 23:12:17 +00001118const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001119ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001120{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001121
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001122 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001123 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001124
1125 if (!m_object_desc_str.empty())
1126 return m_object_desc_str.c_str();
1127
Greg Claytoncc4d0142012-02-17 07:49:44 +00001128 ExecutionContext exe_ctx (GetExecutionContextRef());
1129 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001130 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001131 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001132
Jim Ingham53c47f12010-09-10 23:12:17 +00001133 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001134
Greg Claytonafacd142011-09-02 01:15:17 +00001135 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001136 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1137
Jim Inghama2cf2632010-12-23 02:29:54 +00001138 if (runtime == NULL)
1139 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001140 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Jim Inghama2cf2632010-12-23 02:29:54 +00001141 clang_type_t opaque_qual_type = GetClangType();
1142 if (opaque_qual_type != NULL)
1143 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001144 bool is_signed;
1145 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed)
1146 || ClangASTContext::IsPointerType (opaque_qual_type))
1147 {
Greg Claytonafacd142011-09-02 01:15:17 +00001148 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001149 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001150 }
1151 }
1152
Jim Ingham8d543de2011-03-31 23:01:21 +00001153 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001154 {
1155 m_object_desc_str.append (s.GetData());
1156 }
Sean Callanan672ad942010-10-23 00:18:49 +00001157
1158 if (m_object_desc_str.empty())
1159 return NULL;
1160 else
1161 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001162}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001163
Enrico Granata0c489f52012-03-01 04:24:26 +00001164bool
1165ValueObject::GetValueAsCString (lldb::Format format,
1166 std::string& destination)
1167{
1168 if (ClangASTContext::IsAggregateType (GetClangType()) == false &&
1169 UpdateValueIfNeeded(false))
1170 {
1171 const Value::ContextType context_type = m_value.GetContextType();
1172
1173 switch (context_type)
1174 {
1175 case Value::eContextTypeClangType:
1176 case Value::eContextTypeLLDBType:
1177 case Value::eContextTypeVariable:
1178 {
1179 clang_type_t clang_type = GetClangType ();
1180 if (clang_type)
1181 {
1182 StreamString sstr;
1183 ExecutionContext exe_ctx (GetExecutionContextRef());
1184 ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
1185 clang_type, // The clang type to display
1186 &sstr,
1187 format, // Format to display this type with
1188 m_data, // Data to extract from
1189 0, // Byte offset into "m_data"
1190 GetByteSize(), // Byte size of item in "m_data"
1191 GetBitfieldBitSize(), // Bitfield bit size
1192 GetBitfieldBitOffset(), // Bitfield bit offset
1193 exe_ctx.GetBestExecutionContextScope());
1194 // Don't set the m_error to anything here otherwise
1195 // we won't be able to re-format as anything else. The
1196 // code for ClangASTType::DumpTypeValue() should always
1197 // return something, even if that something contains
1198 // an error messsage. "m_error" is used to detect errors
1199 // when reading the valid object, not for formatting errors.
1200 if (sstr.GetString().empty())
1201 destination.clear();
1202 else
1203 destination.swap(sstr.GetString());
1204 }
1205 }
1206 break;
1207
1208 case Value::eContextTypeRegisterInfo:
1209 {
1210 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1211 if (reg_info)
1212 {
1213 ExecutionContext exe_ctx (GetExecutionContextRef());
1214
1215 StreamString reg_sstr;
1216 m_data.Dump (&reg_sstr,
1217 0,
1218 format,
1219 reg_info->byte_size,
1220 1,
1221 UINT32_MAX,
1222 LLDB_INVALID_ADDRESS,
1223 0,
1224 0,
1225 exe_ctx.GetBestExecutionContextScope());
1226 destination.swap(reg_sstr.GetString());
1227 }
1228 }
1229 break;
1230
1231 default:
1232 break;
1233 }
1234 return !destination.empty();
1235 }
1236 else
1237 return false;
1238}
1239
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001240const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001241ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001242{
Enrico Granata0c489f52012-03-01 04:24:26 +00001243 if (UpdateValueIfNeeded(true) && m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001244 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001245 lldb::Format my_format = GetFormat();
1246 if (m_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001247 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001248 if (m_type_format_sp)
1249 my_format = m_type_format_sp->GetFormat();
1250 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001251 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001252 if (m_is_bitfield_for_scalar)
1253 my_format = eFormatUnsigned;
1254 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001255 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001256 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001257 {
1258 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1259 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001260 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001261 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001262 else
1263 {
1264 clang_type_t clang_type = GetClangType ();
1265 my_format = ClangASTType::GetFormat(clang_type);
1266 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001267 }
1268 }
1269 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001270 if (GetValueAsCString(my_format, m_value_str))
1271 {
1272 if (!m_value_did_change && m_old_value_valid)
1273 {
1274 // The value was gotten successfully, so we consider the
1275 // value as changed if the value string differs
1276 SetValueDidChange (m_old_value_str != m_value_str);
1277 }
1278 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001279 }
1280 if (m_value_str.empty())
1281 return NULL;
1282 return m_value_str.c_str();
1283}
1284
Enrico Granatac3e320a2011-08-02 17:27:39 +00001285// if > 8bytes, 0 is returned. this method should mostly be used
1286// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001287uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001288ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001289{
1290 // If our byte size is zero this is an aggregate type that has children
1291 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
1292 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001293 Scalar scalar;
1294 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001295 {
1296 if (success)
1297 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001298 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001299 }
1300 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001301 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001302
1303 if (success)
1304 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001305 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001306}
1307
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001308// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1309// this call up to date by returning true for your new special cases. We will eventually move
1310// to checking this call result before trying to display special cases
1311bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001312ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1313 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001314{
1315 clang_type_t elem_or_pointee_type;
1316 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
1317
1318 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001319 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001320 {
1321 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001322 (custom_format == eFormatCString ||
1323 custom_format == eFormatCharArray ||
1324 custom_format == eFormatChar ||
1325 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001326 return true;
1327
1328 if (flags.Test(ClangASTContext::eTypeIsArray))
1329 {
Greg Claytonafacd142011-09-02 01:15:17 +00001330 if ((custom_format == eFormatBytes) ||
1331 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001332 return true;
1333
Greg Claytonafacd142011-09-02 01:15:17 +00001334 if ((custom_format == eFormatVectorOfChar) ||
1335 (custom_format == eFormatVectorOfFloat32) ||
1336 (custom_format == eFormatVectorOfFloat64) ||
1337 (custom_format == eFormatVectorOfSInt16) ||
1338 (custom_format == eFormatVectorOfSInt32) ||
1339 (custom_format == eFormatVectorOfSInt64) ||
1340 (custom_format == eFormatVectorOfSInt8) ||
1341 (custom_format == eFormatVectorOfUInt128) ||
1342 (custom_format == eFormatVectorOfUInt16) ||
1343 (custom_format == eFormatVectorOfUInt32) ||
1344 (custom_format == eFormatVectorOfUInt64) ||
1345 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001346 return true;
1347 }
1348 }
1349 return false;
1350}
1351
Enrico Granata9fc19442011-07-06 02:13:41 +00001352bool
1353ValueObject::DumpPrintableRepresentation(Stream& s,
1354 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001355 Format custom_format,
Enrico Granata86cc9822012-03-19 22:58:49 +00001356 PrintableRepresentationSpecialCases special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001357{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001358
1359 clang_type_t elem_or_pointee_type;
1360 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001361
Enrico Granata86cc9822012-03-19 22:58:49 +00001362 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1363 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1364
1365 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001366 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001367 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1368 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001369 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001370 // when being asked to get a printable display an array or pointer type directly,
1371 // try to "do the right thing"
1372
1373 if (IsCStringContainer(true) &&
1374 (custom_format == eFormatCString ||
1375 custom_format == eFormatCharArray ||
1376 custom_format == eFormatChar ||
1377 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001378 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001379 Error error;
1380 ReadPointedString(s,
1381 error,
1382 0,
1383 (custom_format == eFormatVectorOfChar) ||
1384 (custom_format == eFormatCharArray));
1385 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001386 }
1387
Enrico Granata86cc9822012-03-19 22:58:49 +00001388 if (custom_format == eFormatEnum)
1389 return false;
1390
1391 // this only works for arrays, because I have no way to know when
1392 // the pointed memory ends, and no special \0 end of data marker
1393 if (flags.Test(ClangASTContext::eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001394 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001395 if ((custom_format == eFormatBytes) ||
1396 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001397 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001398 uint32_t count = GetNumChildren();
1399
1400 s << '[';
1401 for (uint32_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001402 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001403
1404 if (low)
1405 s << ',';
1406
1407 ValueObjectSP child = GetChildAtIndex(low,true);
1408 if (!child.get())
1409 {
1410 s << "<invalid child>";
1411 continue;
1412 }
1413 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1414 }
1415
1416 s << ']';
1417
1418 return true;
1419 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001420
Enrico Granata86cc9822012-03-19 22:58:49 +00001421 if ((custom_format == eFormatVectorOfChar) ||
1422 (custom_format == eFormatVectorOfFloat32) ||
1423 (custom_format == eFormatVectorOfFloat64) ||
1424 (custom_format == eFormatVectorOfSInt16) ||
1425 (custom_format == eFormatVectorOfSInt32) ||
1426 (custom_format == eFormatVectorOfSInt64) ||
1427 (custom_format == eFormatVectorOfSInt8) ||
1428 (custom_format == eFormatVectorOfUInt128) ||
1429 (custom_format == eFormatVectorOfUInt16) ||
1430 (custom_format == eFormatVectorOfUInt32) ||
1431 (custom_format == eFormatVectorOfUInt64) ||
1432 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1433 {
1434 uint32_t count = GetNumChildren();
1435
1436 Format format = FormatManager::GetSingleItemFormat(custom_format);
1437
1438 s << '[';
1439 for (uint32_t low = 0; low < count; low++)
1440 {
1441
1442 if (low)
1443 s << ',';
1444
1445 ValueObjectSP child = GetChildAtIndex(low,true);
1446 if (!child.get())
1447 {
1448 s << "<invalid child>";
1449 continue;
1450 }
1451 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1452 }
1453
1454 s << ']';
1455
1456 return true;
1457 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001458 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001459
1460 if ((custom_format == eFormatBoolean) ||
1461 (custom_format == eFormatBinary) ||
1462 (custom_format == eFormatChar) ||
1463 (custom_format == eFormatCharPrintable) ||
1464 (custom_format == eFormatComplexFloat) ||
1465 (custom_format == eFormatDecimal) ||
1466 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001467 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001468 (custom_format == eFormatFloat) ||
1469 (custom_format == eFormatOctal) ||
1470 (custom_format == eFormatOSType) ||
1471 (custom_format == eFormatUnicode16) ||
1472 (custom_format == eFormatUnicode32) ||
1473 (custom_format == eFormatUnsigned) ||
1474 (custom_format == eFormatPointer) ||
1475 (custom_format == eFormatComplexInteger) ||
1476 (custom_format == eFormatComplex) ||
1477 (custom_format == eFormatDefault)) // use the [] operator
1478 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001479 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001480 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001481
1482 if (only_special)
1483 return false;
1484
Enrico Granata86cc9822012-03-19 22:58:49 +00001485 bool var_success = false;
1486
1487 {
1488 const char * return_value;
1489 std::string alloc_mem;
1490
1491 if (custom_format != eFormatInvalid)
1492 SetFormat(custom_format);
1493
1494 switch(val_obj_display)
1495 {
1496 case eValueObjectRepresentationStyleValue:
1497 return_value = GetValueAsCString();
1498 break;
1499
1500 case eValueObjectRepresentationStyleSummary:
1501 return_value = GetSummaryAsCString();
1502 break;
1503
1504 case eValueObjectRepresentationStyleLanguageSpecific:
1505 return_value = GetObjectDescription();
1506 break;
1507
1508 case eValueObjectRepresentationStyleLocation:
1509 return_value = GetLocationAsCString();
1510 break;
1511
1512 case eValueObjectRepresentationStyleChildrenCount:
1513 {
1514 alloc_mem.resize(512);
1515 return_value = &alloc_mem[0];
1516 int count = GetNumChildren();
1517 snprintf((char*)return_value, 512, "%d", count);
1518 }
1519 break;
1520
1521 case eValueObjectRepresentationStyleType:
1522 return_value = GetTypeName().AsCString();
1523 break;
1524
1525 default:
1526 break;
1527 }
1528
1529 if (!return_value)
1530 {
1531 if (val_obj_display == eValueObjectRepresentationStyleValue)
1532 return_value = GetSummaryAsCString();
1533 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1534 {
1535 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1536 {
1537 // this thing has no value, and it seems to have no summary
1538 // some combination of unitialized data and other factors can also
1539 // raise this condition, so let's print a nice generic description
1540 {
1541 alloc_mem.resize(684);
1542 return_value = &alloc_mem[0];
1543 snprintf((char*)return_value, 684, "%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1544 }
1545 }
1546 else
1547 return_value = GetValueAsCString();
1548 }
1549 }
1550
1551 if (return_value)
1552 s.PutCString(return_value);
1553 else
1554 {
1555 if (m_error.Fail())
1556 s.Printf("<%s>", m_error.AsCString());
1557 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1558 s.PutCString("<no summary available>");
1559 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1560 s.PutCString("<no value available>");
1561 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1562 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1563 else
1564 s.PutCString("<no printable representation>");
1565 }
1566
1567 // we should only return false here if we could not do *anything*
1568 // even if we have an error message as output, that's a success
1569 // from our callers' perspective, so return true
1570 var_success = true;
1571
1572 if (custom_format != eFormatInvalid)
1573 SetFormat(eFormatDefault);
1574 }
1575
Enrico Granataf4efecd2011-07-12 22:56:10 +00001576 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001577}
1578
Greg Clayton737b9322010-09-13 03:32:57 +00001579addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001580ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001581{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001582 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001583 return LLDB_INVALID_ADDRESS;
1584
Greg Clayton73b472d2010-10-27 03:32:59 +00001585 switch (m_value.GetValueType())
1586 {
1587 case Value::eValueTypeScalar:
1588 if (scalar_is_load_address)
1589 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001590 if(address_type)
1591 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001592 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1593 }
1594 break;
1595
1596 case Value::eValueTypeLoadAddress:
1597 case Value::eValueTypeFileAddress:
1598 case Value::eValueTypeHostAddress:
1599 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001600 if(address_type)
1601 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001602 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1603 }
1604 break;
1605 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001606 if (address_type)
1607 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001608 return LLDB_INVALID_ADDRESS;
1609}
1610
1611addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001612ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001613{
Greg Claytonafacd142011-09-02 01:15:17 +00001614 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001615 if(address_type)
1616 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001617
Enrico Granatac3e320a2011-08-02 17:27:39 +00001618 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001619 return address;
1620
Greg Clayton73b472d2010-10-27 03:32:59 +00001621 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001622 {
1623 case Value::eValueTypeScalar:
Enrico Granata9128ee22011-09-06 19:20:51 +00001624 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001625 break;
1626
Enrico Granata9128ee22011-09-06 19:20:51 +00001627 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001628 case Value::eValueTypeLoadAddress:
1629 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001630 {
1631 uint32_t data_offset = 0;
1632 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001633 }
1634 break;
1635 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001636
Enrico Granata9128ee22011-09-06 19:20:51 +00001637 if (address_type)
1638 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001639
Greg Clayton737b9322010-09-13 03:32:57 +00001640 return address;
1641}
1642
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001643bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001644ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001645{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001646 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001647 // Make sure our value is up to date first so that our location and location
1648 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001649 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001650 {
1651 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001652 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001653 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001654
1655 uint32_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001656 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001657
Greg Claytonb1320972010-07-14 00:18:15 +00001658 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001659
Jim Ingham16e0c682011-08-12 23:34:31 +00001660 Value::ValueType value_type = m_value.GetValueType();
1661
1662 if (value_type == Value::eValueTypeScalar)
1663 {
1664 // If the value is already a scalar, then let the scalar change itself:
1665 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1666 }
1667 else if (byte_size <= Scalar::GetMaxByteSize())
1668 {
1669 // If the value fits in a scalar, then make a new scalar and again let the
1670 // scalar code do the conversion, then figure out where to put the new value.
1671 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001672 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1673 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001674 {
Jim Ingham4b536182011-08-09 02:12:22 +00001675 switch (value_type)
1676 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001677 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001678 {
1679 // If it is a load address, then the scalar value is the storage location
1680 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001681 ExecutionContext exe_ctx (GetExecutionContextRef());
1682 Process *process = exe_ctx.GetProcessPtr();
1683 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001684 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001685 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001686 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1687 new_scalar,
1688 byte_size,
1689 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001690 if (!error.Success())
1691 return false;
1692 if (bytes_written != byte_size)
1693 {
1694 error.SetErrorString("unable to write value to memory");
1695 return false;
1696 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001697 }
1698 }
Jim Ingham4b536182011-08-09 02:12:22 +00001699 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001700 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001701 {
1702 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1703 DataExtractor new_data;
1704 new_data.SetByteOrder (m_data.GetByteOrder());
1705
1706 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1707 m_data.SetData(buffer_sp, 0);
1708 bool success = new_scalar.GetData(new_data);
1709 if (success)
1710 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001711 new_data.CopyByteOrderedData (0,
1712 byte_size,
1713 const_cast<uint8_t *>(m_data.GetDataStart()),
1714 byte_size,
1715 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001716 }
1717 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1718
1719 }
Jim Ingham4b536182011-08-09 02:12:22 +00001720 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001721 case Value::eValueTypeFileAddress:
1722 case Value::eValueTypeScalar:
Jim Ingham16e0c682011-08-12 23:34:31 +00001723 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001724 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001725 }
1726 else
1727 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001728 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001729 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001730 }
1731 else
1732 {
1733 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001734 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001735 return false;
1736 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001737
1738 // If we have reached this point, then we have successfully changed the value.
1739 SetNeedsUpdate();
1740 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001741}
1742
Greg Clayton81e871e2012-02-04 02:27:34 +00001743bool
1744ValueObject::GetDeclaration (Declaration &decl)
1745{
1746 decl.Clear();
1747 return false;
1748}
1749
Greg Clayton84db9102012-03-26 23:03:23 +00001750ConstString
1751ValueObject::GetTypeName()
1752{
1753 return ClangASTType::GetConstTypeName (GetClangAST(), GetClangType());
1754}
1755
1756ConstString
1757ValueObject::GetQualifiedTypeName()
1758{
1759 return ClangASTType::GetConstQualifiedTypeName (GetClangAST(), GetClangType());
1760}
1761
1762
Greg Claytonafacd142011-09-02 01:15:17 +00001763LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001764ValueObject::GetObjectRuntimeLanguage ()
1765{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001766 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1767 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001768}
1769
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001770void
Jim Ingham58b59f92011-04-22 23:53:53 +00001771ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001772{
Jim Ingham58b59f92011-04-22 23:53:53 +00001773 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001774}
1775
1776ValueObjectSP
1777ValueObject::GetSyntheticChild (const ConstString &key) const
1778{
1779 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001780 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001781 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001782 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001783 return synthetic_child_sp;
1784}
1785
1786bool
1787ValueObject::IsPointerType ()
1788{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001789 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001790}
1791
Jim Inghamb7603bb2011-03-18 00:05:18 +00001792bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001793ValueObject::IsArrayType ()
1794{
1795 return ClangASTContext::IsArrayType (GetClangType());
1796}
1797
1798bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001799ValueObject::IsScalarType ()
1800{
1801 return ClangASTContext::IsScalarType (GetClangType());
1802}
1803
1804bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001805ValueObject::IsIntegerType (bool &is_signed)
1806{
1807 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1808}
Greg Clayton73b472d2010-10-27 03:32:59 +00001809
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001810bool
1811ValueObject::IsPointerOrReferenceType ()
1812{
Greg Clayton007d5be2011-05-30 00:49:24 +00001813 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1814}
1815
1816bool
Greg Claytondea8cb42011-06-29 22:09:02 +00001817ValueObject::IsPossibleDynamicType ()
1818{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00001819 ExecutionContext exe_ctx (GetExecutionContextRef());
1820 Process *process = exe_ctx.GetProcessPtr();
1821 if (process)
1822 return process->IsPossibleDynamicValue(*this);
1823 else
Greg Clayton70364252012-08-31 18:56:24 +00001824 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType(), NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00001825}
1826
Greg Claytonafacd142011-09-02 01:15:17 +00001827ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001828ValueObject::GetSyntheticArrayMember (int32_t index, bool can_create)
1829{
1830 if (IsArrayType())
1831 return GetSyntheticArrayMemberFromArray(index, can_create);
1832
1833 if (IsPointerType())
1834 return GetSyntheticArrayMemberFromPointer(index, can_create);
1835
1836 return ValueObjectSP();
1837
1838}
1839
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001840ValueObjectSP
1841ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1842{
1843 ValueObjectSP synthetic_child_sp;
1844 if (IsPointerType ())
1845 {
1846 char index_str[64];
1847 snprintf(index_str, sizeof(index_str), "[%i]", index);
1848 ConstString index_const_str(index_str);
1849 // Check if we have already created a synthetic array member in this
1850 // valid object. If we have we will re-use it.
1851 synthetic_child_sp = GetSyntheticChild (index_const_str);
1852 if (!synthetic_child_sp)
1853 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001854 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001855 // We haven't made a synthetic array member for INDEX yet, so
1856 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001857 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001858
1859 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001860 if (synthetic_child)
1861 {
1862 AddSyntheticChild(index_const_str, synthetic_child);
1863 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001864 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001865 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001866 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001867 }
1868 }
1869 return synthetic_child_sp;
1870}
Jim Ingham22777012010-09-23 02:01:19 +00001871
Greg Claytondaf515f2011-07-09 20:12:33 +00001872// This allows you to create an array member using and index
1873// that doesn't not fall in the normal bounds of the array.
1874// Many times structure can be defined as:
1875// struct Collection
1876// {
1877// uint32_t item_count;
1878// Item item_array[0];
1879// };
1880// The size of the "item_array" is 1, but many times in practice
1881// there are more items in "item_array".
1882
1883ValueObjectSP
1884ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1885{
1886 ValueObjectSP synthetic_child_sp;
1887 if (IsArrayType ())
1888 {
1889 char index_str[64];
1890 snprintf(index_str, sizeof(index_str), "[%i]", index);
1891 ConstString index_const_str(index_str);
1892 // Check if we have already created a synthetic array member in this
1893 // valid object. If we have we will re-use it.
1894 synthetic_child_sp = GetSyntheticChild (index_const_str);
1895 if (!synthetic_child_sp)
1896 {
1897 ValueObject *synthetic_child;
1898 // We haven't made a synthetic array member for INDEX yet, so
1899 // lets make one and cache it for any future reference.
1900 synthetic_child = CreateChildAtIndex(0, true, index);
1901
1902 // Cache the value if we got one back...
1903 if (synthetic_child)
1904 {
1905 AddSyntheticChild(index_const_str, synthetic_child);
1906 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001907 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001908 synthetic_child_sp->m_is_array_item_for_pointer = true;
1909 }
1910 }
1911 }
1912 return synthetic_child_sp;
1913}
1914
Enrico Granata9fc19442011-07-06 02:13:41 +00001915ValueObjectSP
1916ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1917{
1918 ValueObjectSP synthetic_child_sp;
1919 if (IsScalarType ())
1920 {
1921 char index_str[64];
1922 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1923 ConstString index_const_str(index_str);
1924 // Check if we have already created a synthetic array member in this
1925 // valid object. If we have we will re-use it.
1926 synthetic_child_sp = GetSyntheticChild (index_const_str);
1927 if (!synthetic_child_sp)
1928 {
1929 ValueObjectChild *synthetic_child;
1930 // We haven't made a synthetic array member for INDEX yet, so
1931 // lets make one and cache it for any future reference.
1932 synthetic_child = new ValueObjectChild(*this,
1933 GetClangAST(),
1934 GetClangType(),
1935 index_const_str,
1936 GetByteSize(),
1937 0,
1938 to-from+1,
1939 from,
1940 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001941 false,
1942 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00001943
1944 // Cache the value if we got one back...
1945 if (synthetic_child)
1946 {
1947 AddSyntheticChild(index_const_str, synthetic_child);
1948 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001949 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00001950 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1951 }
1952 }
1953 }
1954 return synthetic_child_sp;
1955}
1956
Greg Claytonafacd142011-09-02 01:15:17 +00001957ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001958ValueObject::GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create)
1959{
1960 ValueObjectSP synthetic_child_sp;
1961 if (IsArrayType () || IsPointerType ())
1962 {
1963 char index_str[64];
1964 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1965 ConstString index_const_str(index_str);
1966 // Check if we have already created a synthetic array member in this
1967 // valid object. If we have we will re-use it.
1968 synthetic_child_sp = GetSyntheticChild (index_const_str);
1969 if (!synthetic_child_sp)
1970 {
1971 ValueObjectSynthetic *synthetic_child;
1972
1973 // We haven't made a synthetic array member for INDEX yet, so
1974 // lets make one and cache it for any future reference.
Enrico Granata061858c2012-02-15 02:34:21 +00001975 SyntheticArrayView *view = new SyntheticArrayView(SyntheticChildren::Flags());
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001976 view->AddRange(from,to);
1977 SyntheticChildrenSP view_sp(view);
1978 synthetic_child = new ValueObjectSynthetic(*this, view_sp);
1979
1980 // Cache the value if we got one back...
1981 if (synthetic_child)
1982 {
1983 AddSyntheticChild(index_const_str, synthetic_child);
1984 synthetic_child_sp = synthetic_child->GetSP();
1985 synthetic_child_sp->SetName(ConstString(index_str));
1986 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1987 }
1988 }
1989 }
1990 return synthetic_child_sp;
1991}
1992
Greg Claytonafacd142011-09-02 01:15:17 +00001993ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00001994ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
1995{
1996
1997 ValueObjectSP synthetic_child_sp;
1998
1999 char name_str[64];
2000 snprintf(name_str, sizeof(name_str), "@%i", offset);
2001 ConstString name_const_str(name_str);
2002
2003 // Check if we have already created a synthetic array member in this
2004 // valid object. If we have we will re-use it.
2005 synthetic_child_sp = GetSyntheticChild (name_const_str);
2006
2007 if (synthetic_child_sp.get())
2008 return synthetic_child_sp;
2009
2010 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002011 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002012
2013 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2014 type.GetASTContext(),
2015 type.GetOpaqueQualType(),
2016 name_const_str,
2017 type.GetTypeByteSize(),
2018 offset,
2019 0,
2020 0,
2021 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002022 false,
2023 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002024 if (synthetic_child)
2025 {
2026 AddSyntheticChild(name_const_str, synthetic_child);
2027 synthetic_child_sp = synthetic_child->GetSP();
2028 synthetic_child_sp->SetName(name_const_str);
2029 synthetic_child_sp->m_is_child_at_offset = true;
2030 }
2031 return synthetic_child_sp;
2032}
2033
Enrico Granatad55546b2011-07-22 00:16:08 +00002034// your expression path needs to have a leading . or ->
2035// (unless it somehow "looks like" an array, in which case it has
2036// a leading [ symbol). while the [ is meaningful and should be shown
2037// to the user, . and -> are just parser design, but by no means
2038// added information for the user.. strip them off
2039static const char*
2040SkipLeadingExpressionPathSeparators(const char* expression)
2041{
2042 if (!expression || !expression[0])
2043 return expression;
2044 if (expression[0] == '.')
2045 return expression+1;
2046 if (expression[0] == '-' && expression[1] == '>')
2047 return expression+2;
2048 return expression;
2049}
2050
Greg Claytonafacd142011-09-02 01:15:17 +00002051ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002052ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2053{
2054 ValueObjectSP synthetic_child_sp;
2055 ConstString name_const_string(expression);
2056 // Check if we have already created a synthetic array member in this
2057 // valid object. If we have we will re-use it.
2058 synthetic_child_sp = GetSyntheticChild (name_const_string);
2059 if (!synthetic_child_sp)
2060 {
2061 // We haven't made a synthetic array member for expression yet, so
2062 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002063 synthetic_child_sp = GetValueForExpressionPath(expression,
2064 NULL, NULL, NULL,
2065 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
Enrico Granatad55546b2011-07-22 00:16:08 +00002066
2067 // Cache the value if we got one back...
2068 if (synthetic_child_sp.get())
2069 {
2070 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002071 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002072 synthetic_child_sp->m_is_expression_path_child = true;
2073 }
2074 }
2075 return synthetic_child_sp;
2076}
2077
2078void
Enrico Granata86cc9822012-03-19 22:58:49 +00002079ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002080{
Enrico Granata86cc9822012-03-19 22:58:49 +00002081 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002082 return;
2083
Enrico Granatac5bc4122012-03-27 02:35:13 +00002084 TargetSP target_sp(GetTargetSP());
2085 if (target_sp && (target_sp->GetEnableSyntheticValue() == false || target_sp->GetSuppressSyntheticValue() == true))
2086 {
2087 m_synthetic_value = NULL;
2088 return;
2089 }
2090
Enrico Granatae3e91512012-10-22 18:18:36 +00002091 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2092
Enrico Granata86cc9822012-03-19 22:58:49 +00002093 if (!UpdateFormatsIfNeeded(m_last_format_mgr_dynamic) && m_synthetic_value)
2094 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002095
Enrico Granata0c489f52012-03-01 04:24:26 +00002096 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002097 return;
2098
Enrico Granatae3e91512012-10-22 18:18:36 +00002099 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2100 return;
2101
Enrico Granata86cc9822012-03-19 22:58:49 +00002102 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002103}
2104
Jim Ingham78a685a2011-04-16 00:01:13 +00002105void
Greg Claytonafacd142011-09-02 01:15:17 +00002106ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002107{
Greg Claytonafacd142011-09-02 01:15:17 +00002108 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002109 return;
2110
Jim Ingham58b59f92011-04-22 23:53:53 +00002111 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002112 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002113 ExecutionContext exe_ctx (GetExecutionContextRef());
2114 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002115 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002116 {
2117 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002118 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002119 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002120 }
2121}
2122
Jim Ingham58b59f92011-04-22 23:53:53 +00002123ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002124ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002125{
Greg Claytonafacd142011-09-02 01:15:17 +00002126 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002127 return ValueObjectSP();
2128
2129 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002130 {
Jim Ingham2837b762011-05-04 03:43:18 +00002131 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002132 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002133 if (m_dynamic_value)
2134 return m_dynamic_value->GetSP();
2135 else
2136 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002137}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002138
Jim Ingham60dbabb2011-12-08 19:44:08 +00002139ValueObjectSP
2140ValueObject::GetStaticValue()
2141{
2142 return GetSP();
2143}
2144
Enrico Granata886147f2012-05-08 18:47:08 +00002145lldb::ValueObjectSP
2146ValueObject::GetNonSyntheticValue ()
2147{
2148 return GetSP();
2149}
2150
Enrico Granatad55546b2011-07-22 00:16:08 +00002151ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002152ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002153{
Enrico Granata86cc9822012-03-19 22:58:49 +00002154 if (use_synthetic == false)
2155 return ValueObjectSP();
2156
Enrico Granatad55546b2011-07-22 00:16:08 +00002157 CalculateSyntheticValue(use_synthetic);
2158
2159 if (m_synthetic_value)
2160 return m_synthetic_value->GetSP();
2161 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002162 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002163}
2164
Greg Claytone221f822011-01-21 01:59:00 +00002165bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002166ValueObject::HasSyntheticValue()
2167{
2168 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
2169
Enrico Granata0c489f52012-03-01 04:24:26 +00002170 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002171 return false;
2172
Enrico Granata86cc9822012-03-19 22:58:49 +00002173 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002174
2175 if (m_synthetic_value)
2176 return true;
2177 else
2178 return false;
2179}
2180
2181bool
Greg Claytone221f822011-01-21 01:59:00 +00002182ValueObject::GetBaseClassPath (Stream &s)
2183{
2184 if (IsBaseClass())
2185 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002186 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00002187 clang_type_t clang_type = GetClangType();
2188 std::string cxx_class_name;
2189 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
2190 if (this_had_base_class)
2191 {
2192 if (parent_had_base_class)
2193 s.PutCString("::");
2194 s.PutCString(cxx_class_name.c_str());
2195 }
2196 return parent_had_base_class || this_had_base_class;
2197 }
2198 return false;
2199}
2200
2201
2202ValueObject *
2203ValueObject::GetNonBaseClassParent()
2204{
Jim Ingham78a685a2011-04-16 00:01:13 +00002205 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002206 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002207 if (GetParent()->IsBaseClass())
2208 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002209 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002210 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002211 }
2212 return NULL;
2213}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002214
2215void
Enrico Granata4becb372011-06-29 22:27:15 +00002216ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002217{
Greg Claytone221f822011-01-21 01:59:00 +00002218 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002219
Enrico Granata86cc9822012-03-19 22:58:49 +00002220 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002221 {
Enrico Granata4becb372011-06-29 22:27:15 +00002222 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2223 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2224 // the eHonorPointers mode is meant to produce strings in this latter format
2225 s.PutCString("*(");
2226 }
Greg Claytone221f822011-01-21 01:59:00 +00002227
Enrico Granata4becb372011-06-29 22:27:15 +00002228 ValueObject* parent = GetParent();
2229
2230 if (parent)
2231 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002232
2233 // if we are a deref_of_parent just because we are synthetic array
2234 // members made up to allow ptr[%d] syntax to work in variable
2235 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002236 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002237 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002238
Greg Claytone221f822011-01-21 01:59:00 +00002239 if (!IsBaseClass())
2240 {
2241 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002242 {
Greg Claytone221f822011-01-21 01:59:00 +00002243 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2244 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002245 {
Greg Claytone221f822011-01-21 01:59:00 +00002246 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2247 if (non_base_class_parent_clang_type)
2248 {
2249 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2250
Enrico Granata86cc9822012-03-19 22:58:49 +00002251 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002252 {
2253 s.PutCString("->");
2254 }
Enrico Granata4becb372011-06-29 22:27:15 +00002255 else
2256 {
2257 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2258 {
2259 s.PutCString("->");
2260 }
2261 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2262 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2263 {
2264 s.PutChar('.');
2265 }
Greg Claytone221f822011-01-21 01:59:00 +00002266 }
2267 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002268 }
Greg Claytone221f822011-01-21 01:59:00 +00002269
2270 const char *name = GetName().GetCString();
2271 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002272 {
Greg Claytone221f822011-01-21 01:59:00 +00002273 if (qualify_cxx_base_classes)
2274 {
2275 if (GetBaseClassPath (s))
2276 s.PutCString("::");
2277 }
2278 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002279 }
2280 }
2281 }
2282
Enrico Granata86cc9822012-03-19 22:58:49 +00002283 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002284 {
Greg Claytone221f822011-01-21 01:59:00 +00002285 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002286 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002287}
2288
Greg Claytonafacd142011-09-02 01:15:17 +00002289ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002290ValueObject::GetValueForExpressionPath(const char* expression,
2291 const char** first_unparsed,
2292 ExpressionPathScanEndReason* reason_to_stop,
2293 ExpressionPathEndResultType* final_value_type,
2294 const GetValueForExpressionPathOptions& options,
2295 ExpressionPathAftermath* final_task_on_target)
2296{
2297
2298 const char* dummy_first_unparsed;
2299 ExpressionPathScanEndReason dummy_reason_to_stop;
2300 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002301 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002302
2303 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2304 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2305 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2306 final_value_type ? final_value_type : &dummy_final_value_type,
2307 options,
2308 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2309
Enrico Granata86cc9822012-03-19 22:58:49 +00002310 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002311 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002312
Enrico Granata86cc9822012-03-19 22:58:49 +00002313 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 +00002314 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002315 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002316 {
2317 Error error;
2318 ValueObjectSP final_value = ret_val->Dereference(error);
2319 if (error.Fail() || !final_value.get())
2320 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002321 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002322 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002323 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002324 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002325 return ValueObjectSP();
2326 }
2327 else
2328 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002329 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002330 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002331 return final_value;
2332 }
2333 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002334 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002335 {
2336 Error error;
2337 ValueObjectSP final_value = ret_val->AddressOf(error);
2338 if (error.Fail() || !final_value.get())
2339 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002340 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002341 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002342 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002343 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002344 return ValueObjectSP();
2345 }
2346 else
2347 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002348 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002349 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002350 return final_value;
2351 }
2352 }
2353 }
2354 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2355}
2356
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002357int
2358ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002359 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002360 const char** first_unparsed,
2361 ExpressionPathScanEndReason* reason_to_stop,
2362 ExpressionPathEndResultType* final_value_type,
2363 const GetValueForExpressionPathOptions& options,
2364 ExpressionPathAftermath* final_task_on_target)
2365{
2366 const char* dummy_first_unparsed;
2367 ExpressionPathScanEndReason dummy_reason_to_stop;
2368 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002369 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002370
2371 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2372 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2373 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2374 final_value_type ? final_value_type : &dummy_final_value_type,
2375 options,
2376 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2377
2378 if (!ret_val.get()) // if there are errors, I add nothing to the list
2379 return 0;
2380
Enrico Granata86ea8d82012-03-29 01:34:34 +00002381 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002382 {
2383 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002384 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002385 {
2386 list->Append(ret_val);
2387 return 1;
2388 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002389 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 +00002390 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002391 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002392 {
2393 Error error;
2394 ValueObjectSP final_value = ret_val->Dereference(error);
2395 if (error.Fail() || !final_value.get())
2396 {
Greg Clayton23f59502012-07-17 03:23:13 +00002397 if (reason_to_stop)
2398 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2399 if (final_value_type)
2400 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002401 return 0;
2402 }
2403 else
2404 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002405 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002406 list->Append(final_value);
2407 return 1;
2408 }
2409 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002410 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002411 {
2412 Error error;
2413 ValueObjectSP final_value = ret_val->AddressOf(error);
2414 if (error.Fail() || !final_value.get())
2415 {
Greg Clayton23f59502012-07-17 03:23:13 +00002416 if (reason_to_stop)
2417 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2418 if (final_value_type)
2419 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002420 return 0;
2421 }
2422 else
2423 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002424 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002425 list->Append(final_value);
2426 return 1;
2427 }
2428 }
2429 }
2430 }
2431 else
2432 {
2433 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2434 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2435 ret_val,
2436 list,
2437 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2438 final_value_type ? final_value_type : &dummy_final_value_type,
2439 options,
2440 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2441 }
2442 // in any non-covered case, just do the obviously right thing
2443 list->Append(ret_val);
2444 return 1;
2445}
2446
Greg Claytonafacd142011-09-02 01:15:17 +00002447ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002448ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2449 const char** first_unparsed,
2450 ExpressionPathScanEndReason* reason_to_stop,
2451 ExpressionPathEndResultType* final_result,
2452 const GetValueForExpressionPathOptions& options,
2453 ExpressionPathAftermath* what_next)
2454{
2455 ValueObjectSP root = GetSP();
2456
2457 if (!root.get())
2458 return ValueObjectSP();
2459
2460 *first_unparsed = expression_cstr;
2461
2462 while (true)
2463 {
2464
2465 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2466
Greg Claytonafacd142011-09-02 01:15:17 +00002467 clang_type_t root_clang_type = root->GetClangType();
2468 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002469 Flags root_clang_type_info,pointee_clang_type_info;
2470
2471 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2472 if (pointee_clang_type)
2473 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002474
2475 if (!expression_cstr || *expression_cstr == '\0')
2476 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002477 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002478 return root;
2479 }
2480
2481 switch (*expression_cstr)
2482 {
2483 case '-':
2484 {
2485 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002486 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 +00002487 {
2488 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002489 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2490 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002491 return ValueObjectSP();
2492 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002493 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2494 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002495 options.m_no_fragile_ivar)
2496 {
2497 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002498 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2499 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002500 return ValueObjectSP();
2501 }
2502 if (expression_cstr[1] != '>')
2503 {
2504 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002505 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2506 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002507 return ValueObjectSP();
2508 }
2509 expression_cstr++; // skip the -
2510 }
2511 case '.': // or fallthrough from ->
2512 {
2513 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002514 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 +00002515 {
2516 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002517 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2518 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002519 return ValueObjectSP();
2520 }
2521 expression_cstr++; // skip .
2522 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2523 ConstString child_name;
2524 if (!next_separator) // if no other separator just expand this last layer
2525 {
2526 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002527 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2528
2529 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002530 {
2531 *first_unparsed = '\0';
Enrico Granata86cc9822012-03-19 22:58:49 +00002532 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2533 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002534 return child_valobj_sp;
2535 }
2536 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2537 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002538 if (root->IsSynthetic())
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002539 {
2540 *first_unparsed = expression_cstr;
2541 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2542 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2543 return ValueObjectSP();
2544 }
2545
2546 child_valobj_sp = root->GetSyntheticValue();
Enrico Granata86cc9822012-03-19 22:58:49 +00002547 if (child_valobj_sp.get())
2548 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002549 }
2550
2551 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2552 // so we hit the "else" branch, and return an error
2553 if(child_valobj_sp.get()) // if it worked, just return
2554 {
2555 *first_unparsed = '\0';
Enrico Granata86cc9822012-03-19 22:58:49 +00002556 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2557 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002558 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002559 }
2560 else
2561 {
2562 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002563 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2564 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002565 return ValueObjectSP();
2566 }
2567 }
2568 else // other layers do expand
2569 {
2570 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002571 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2572 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002573 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002574 root = child_valobj_sp;
2575 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002576 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002577 continue;
2578 }
2579 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2580 {
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002581 if (root->IsSynthetic())
2582 {
2583 *first_unparsed = expression_cstr;
2584 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2585 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2586 return ValueObjectSP();
2587 }
2588
Enrico Granata86cc9822012-03-19 22:58:49 +00002589 child_valobj_sp = root->GetSyntheticValue(true);
2590 if (child_valobj_sp)
2591 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002592 }
2593
2594 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2595 // so we hit the "else" branch, and return an error
2596 if(child_valobj_sp.get()) // if it worked, move on
2597 {
2598 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002599 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002600 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002601 continue;
2602 }
2603 else
2604 {
2605 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002606 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2607 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002608 return ValueObjectSP();
2609 }
2610 }
2611 break;
2612 }
2613 case '[':
2614 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002615 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 +00002616 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002617 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002618 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002619 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2620 {
2621 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002622 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2623 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002624 return ValueObjectSP();
2625 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002626 }
2627 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2628 {
2629 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002630 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2631 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002632 return ValueObjectSP();
2633 }
2634 }
2635 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2636 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002637 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002638 {
2639 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002640 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2641 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002642 return ValueObjectSP();
2643 }
2644 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2645 {
2646 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002647 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2648 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002649 return root;
2650 }
2651 }
2652 const char *separator_position = ::strchr(expression_cstr+1,'-');
2653 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2654 if (!close_bracket_position) // if there is no ], this is a syntax error
2655 {
2656 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002657 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2658 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002659 return ValueObjectSP();
2660 }
2661 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2662 {
2663 char *end = NULL;
2664 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2665 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2666 {
2667 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002668 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2669 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002670 return ValueObjectSP();
2671 }
2672 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2673 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002674 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002675 {
2676 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002677 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2678 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002679 return root;
2680 }
2681 else
2682 {
2683 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002684 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2685 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002686 return ValueObjectSP();
2687 }
2688 }
2689 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002690 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002691 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002692 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2693 if (!child_valobj_sp)
2694 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002695 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002696 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2697 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002698 if (child_valobj_sp)
2699 {
2700 root = child_valobj_sp;
2701 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002702 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002703 continue;
2704 }
2705 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002706 {
2707 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002708 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2709 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002710 return ValueObjectSP();
2711 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002712 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002713 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002714 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002715 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 +00002716 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002717 {
2718 Error error;
2719 root = root->Dereference(error);
2720 if (error.Fail() || !root.get())
2721 {
2722 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002723 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2724 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002725 return ValueObjectSP();
2726 }
2727 else
2728 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002729 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002730 continue;
2731 }
2732 }
2733 else
2734 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002735 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Clayton84db9102012-03-26 23:03:23 +00002736 root->GetClangType()) == eLanguageTypeObjC
2737 && ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2738 && root->HasSyntheticValue()
2739 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002740 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002741 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002742 }
2743 else
2744 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002745 if (!root.get())
2746 {
2747 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002748 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2749 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002750 return ValueObjectSP();
2751 }
2752 else
2753 {
2754 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002755 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002756 continue;
2757 }
2758 }
2759 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002760 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002761 {
2762 root = root->GetSyntheticBitFieldChild(index, index, true);
2763 if (!root.get())
2764 {
2765 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002766 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2767 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002768 return ValueObjectSP();
2769 }
2770 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2771 {
2772 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002773 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2774 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002775 return root;
2776 }
2777 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002778 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002779 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002780 if (root->HasSyntheticValue())
2781 root = root->GetSyntheticValue();
2782 else if (!root->IsSynthetic())
2783 {
2784 *first_unparsed = expression_cstr;
2785 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2786 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2787 return ValueObjectSP();
2788 }
2789 // if we are here, then root itself is a synthetic VO.. should be good to go
2790
Enrico Granata27b625e2011-08-09 01:04:56 +00002791 if (!root.get())
2792 {
2793 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002794 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2795 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2796 return ValueObjectSP();
2797 }
2798 root = root->GetChildAtIndex(index, true);
2799 if (!root.get())
2800 {
2801 *first_unparsed = expression_cstr;
2802 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2803 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002804 return ValueObjectSP();
2805 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002806 else
2807 {
2808 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002809 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002810 continue;
2811 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002812 }
2813 else
2814 {
2815 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002816 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2817 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002818 return ValueObjectSP();
2819 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002820 }
2821 else // we have a low and a high index
2822 {
2823 char *end = NULL;
2824 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2825 if (!end || end != separator_position) // if something weird is in our way return an error
2826 {
2827 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002828 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2829 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002830 return ValueObjectSP();
2831 }
2832 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2833 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2834 {
2835 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002836 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2837 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002838 return ValueObjectSP();
2839 }
2840 if (index_lower > index_higher) // swap indices if required
2841 {
2842 unsigned long temp = index_lower;
2843 index_lower = index_higher;
2844 index_higher = temp;
2845 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002846 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002847 {
2848 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2849 if (!root.get())
2850 {
2851 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002852 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2853 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002854 return ValueObjectSP();
2855 }
2856 else
2857 {
2858 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002859 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2860 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002861 return root;
2862 }
2863 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002864 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 +00002865 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002866 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002867 {
2868 Error error;
2869 root = root->Dereference(error);
2870 if (error.Fail() || !root.get())
2871 {
2872 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002873 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2874 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002875 return ValueObjectSP();
2876 }
2877 else
2878 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002879 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002880 continue;
2881 }
2882 }
2883 else
2884 {
2885 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002886 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2887 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002888 return root;
2889 }
2890 }
2891 break;
2892 }
2893 default: // some non-separator is in the way
2894 {
2895 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002896 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2897 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002898 return ValueObjectSP();
2899 break;
2900 }
2901 }
2902 }
2903}
2904
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002905int
2906ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2907 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002908 ValueObjectSP root,
2909 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002910 ExpressionPathScanEndReason* reason_to_stop,
2911 ExpressionPathEndResultType* final_result,
2912 const GetValueForExpressionPathOptions& options,
2913 ExpressionPathAftermath* what_next)
2914{
2915 if (!root.get())
2916 return 0;
2917
2918 *first_unparsed = expression_cstr;
2919
2920 while (true)
2921 {
2922
2923 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2924
Greg Claytonafacd142011-09-02 01:15:17 +00002925 clang_type_t root_clang_type = root->GetClangType();
2926 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002927 Flags root_clang_type_info,pointee_clang_type_info;
2928
2929 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2930 if (pointee_clang_type)
2931 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2932
2933 if (!expression_cstr || *expression_cstr == '\0')
2934 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002935 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002936 list->Append(root);
2937 return 1;
2938 }
2939
2940 switch (*expression_cstr)
2941 {
2942 case '[':
2943 {
2944 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2945 {
2946 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2947 {
2948 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002949 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2950 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002951 return 0;
2952 }
2953 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2954 {
2955 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002956 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2957 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002958 return 0;
2959 }
2960 }
2961 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2962 {
2963 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2964 {
2965 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002966 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2967 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002968 return 0;
2969 }
2970 else // expand this into list
2971 {
2972 int max_index = root->GetNumChildren() - 1;
2973 for (int index = 0; index < max_index; index++)
2974 {
2975 ValueObjectSP child =
2976 root->GetChildAtIndex(index, true);
2977 list->Append(child);
2978 }
2979 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002980 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
2981 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002982 return max_index; // tell me number of items I added to the VOList
2983 }
2984 }
2985 const char *separator_position = ::strchr(expression_cstr+1,'-');
2986 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2987 if (!close_bracket_position) // if there is no ], this is a syntax error
2988 {
2989 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002990 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2991 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002992 return 0;
2993 }
2994 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2995 {
2996 char *end = NULL;
2997 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2998 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2999 {
3000 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003001 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3002 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003003 return 0;
3004 }
3005 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3006 {
3007 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3008 {
3009 int max_index = root->GetNumChildren() - 1;
3010 for (int index = 0; index < max_index; index++)
3011 {
3012 ValueObjectSP child =
3013 root->GetChildAtIndex(index, true);
3014 list->Append(child);
3015 }
3016 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003017 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3018 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003019 return max_index; // tell me number of items I added to the VOList
3020 }
3021 else
3022 {
3023 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003024 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3025 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003026 return 0;
3027 }
3028 }
3029 // from here on we do have a valid index
3030 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3031 {
3032 root = root->GetChildAtIndex(index, true);
3033 if (!root.get())
3034 {
3035 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003036 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3037 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003038 return 0;
3039 }
3040 else
3041 {
3042 list->Append(root);
3043 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003044 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3045 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003046 return 1;
3047 }
3048 }
3049 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
3050 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003051 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 +00003052 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3053 {
3054 Error error;
3055 root = root->Dereference(error);
3056 if (error.Fail() || !root.get())
3057 {
3058 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003059 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3060 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003061 return 0;
3062 }
3063 else
3064 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003065 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003066 continue;
3067 }
3068 }
3069 else
3070 {
3071 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3072 if (!root.get())
3073 {
3074 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003075 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3076 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003077 return 0;
3078 }
3079 else
3080 {
3081 list->Append(root);
3082 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003083 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3084 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003085 return 1;
3086 }
3087 }
3088 }
3089 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3090 {
3091 root = root->GetSyntheticBitFieldChild(index, index, true);
3092 if (!root.get())
3093 {
3094 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003095 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3096 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003097 return 0;
3098 }
3099 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3100 {
3101 list->Append(root);
3102 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003103 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3104 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003105 return 1;
3106 }
3107 }
3108 }
3109 else // we have a low and a high index
3110 {
3111 char *end = NULL;
3112 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3113 if (!end || end != separator_position) // if something weird is in our way return an error
3114 {
3115 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003116 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3117 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003118 return 0;
3119 }
3120 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3121 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3122 {
3123 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003124 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3125 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003126 return 0;
3127 }
3128 if (index_lower > index_higher) // swap indices if required
3129 {
3130 unsigned long temp = index_lower;
3131 index_lower = index_higher;
3132 index_higher = temp;
3133 }
3134 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
3135 {
3136 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3137 if (!root.get())
3138 {
3139 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003140 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3141 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003142 return 0;
3143 }
3144 else
3145 {
3146 list->Append(root);
3147 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003148 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3149 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003150 return 1;
3151 }
3152 }
3153 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 +00003154 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003155 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3156 {
3157 Error error;
3158 root = root->Dereference(error);
3159 if (error.Fail() || !root.get())
3160 {
3161 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003162 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3163 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003164 return 0;
3165 }
3166 else
3167 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003168 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003169 continue;
3170 }
3171 }
3172 else
3173 {
Johnny Chen44805302011-07-19 19:48:13 +00003174 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003175 index <= index_higher; index++)
3176 {
3177 ValueObjectSP child =
3178 root->GetChildAtIndex(index, true);
3179 list->Append(child);
3180 }
3181 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003182 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3183 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003184 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3185 }
3186 }
3187 break;
3188 }
3189 default: // some non-[ separator, or something entirely wrong, is in the way
3190 {
3191 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003192 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3193 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003194 return 0;
3195 break;
3196 }
3197 }
3198 }
3199}
3200
Enrico Granata0c489f52012-03-01 04:24:26 +00003201static void
3202DumpValueObject_Impl (Stream &s,
3203 ValueObject *valobj,
3204 const ValueObject::DumpValueObjectOptions& options,
3205 uint32_t ptr_depth,
3206 uint32_t curr_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003207{
Greg Clayton007d5be2011-05-30 00:49:24 +00003208 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003209 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003210 bool update_success = valobj->UpdateValueIfNeeded (options.m_use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00003211
Enrico Granata0c489f52012-03-01 04:24:26 +00003212 const char *root_valobj_name =
3213 options.m_root_valobj_name.empty() ?
3214 valobj->GetName().AsCString() :
3215 options.m_root_valobj_name.c_str();
3216
3217 if (update_success && options.m_use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00003218 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003219 ValueObject *dynamic_value = valobj->GetDynamicValue(options.m_use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003220 if (dynamic_value)
3221 valobj = dynamic_value;
3222 }
3223
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003224 clang_type_t clang_type = valobj->GetClangType();
3225
Greg Clayton73b472d2010-10-27 03:32:59 +00003226 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003227 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00003228 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
3229 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003230
Enrico Granata0c489f52012-03-01 04:24:26 +00003231 const bool print_valobj = options.m_flat_output == false || has_value;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003232
3233 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003234 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003235 if (options.m_show_location)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003236 {
Jim Ingham6035b672011-03-31 00:19:25 +00003237 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003238 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003239
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003240 s.Indent();
Enrico Granata2b2631c2012-08-09 16:51:25 +00003241
3242 bool show_type = true;
3243 // if we are at the root-level and been asked to hide the root's type, then hide it
3244 if (curr_depth == 0 && options.m_hide_root_type)
3245 show_type = false;
3246 else
3247 // otherwise decide according to the usual rules (asked to show types - always at the root level)
3248 show_type = options.m_show_types || (curr_depth == 0 && !options.m_flat_output);
3249
3250 if (show_type)
Enrico Granatac3e320a2011-08-02 17:27:39 +00003251 {
Greg Clayton84db9102012-03-26 23:03:23 +00003252 const char* typeName = valobj->GetQualifiedTypeName().AsCString("<invalid type>");
3253 //const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
Enrico Granata9910bc82011-08-03 02:18:51 +00003254 s.Printf("(%s", typeName);
3255 // only show dynamic types if the user really wants to see types
Enrico Granata0c489f52012-03-01 04:24:26 +00003256 if (options.m_show_types && options.m_use_dynamic != eNoDynamicValues &&
Enrico Granata9910bc82011-08-03 02:18:51 +00003257 (/*strstr(typeName, "id") == typeName ||*/
Greg Claytonafacd142011-09-02 01:15:17 +00003258 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003259 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003260 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3261 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatac3e320a2011-08-02 17:27:39 +00003262 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003263 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003264 else
3265 {
3266 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
3267 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003268 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003269 else
3270 {
Greg Claytonf0246d12012-10-11 18:07:21 +00003271 ObjCLanguageRuntime::ClassDescriptorSP objc_class_sp (runtime->GetNonKVOClassDescriptor(*valobj));
3272 if (objc_class_sp)
3273 s.Printf(", dynamic type: %s) ", objc_class_sp->GetClassName().GetCString());
Enrico Granatac3e320a2011-08-02 17:27:39 +00003274 else
Greg Claytonf0246d12012-10-11 18:07:21 +00003275 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003276 }
3277 }
3278 }
3279 else
3280 s.Printf(") ");
3281 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003282
Greg Clayton1d3afba2010-10-05 00:00:42 +00003283
Enrico Granata0c489f52012-03-01 04:24:26 +00003284 if (options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003285 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003286 // If we are showing types, also qualify the C++ base classes
Enrico Granata0c489f52012-03-01 04:24:26 +00003287 const bool qualify_cxx_base_classes = options.m_show_types;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003288 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003289 s.PutCString(" =");
3290 }
3291 else
3292 {
3293 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3294 s.Printf ("%s =", name_cstr);
3295 }
3296
Enrico Granata0c489f52012-03-01 04:24:26 +00003297 if (!options.m_scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003298 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003299 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003300 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003301 }
3302
Enrico Granata0c489f52012-03-01 04:24:26 +00003303 std::string summary_str;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003304 std::string value_str;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003305 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003306 const char *sum_cstr = NULL;
Enrico Granata0c489f52012-03-01 04:24:26 +00003307 TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003308
Enrico Granata0c489f52012-03-01 04:24:26 +00003309 if (options.m_omit_summary_depth > 0)
Enrico Granata0c5ef692011-07-16 01:22:04 +00003310 entry = NULL;
3311
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003312 if (err_cstr == NULL)
3313 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003314 if (options.m_format != eFormatDefault && options.m_format != valobj->GetFormat())
Greg Clayton6efba4f2012-01-26 21:08:30 +00003315 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003316 valobj->GetValueAsCString(options.m_format,
3317 value_str);
Greg Clayton6efba4f2012-01-26 21:08:30 +00003318 }
Enrico Granata0c489f52012-03-01 04:24:26 +00003319 else
Greg Clayton6efba4f2012-01-26 21:08:30 +00003320 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003321 val_cstr = valobj->GetValueAsCString();
3322 if (val_cstr)
3323 value_str = val_cstr;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003324 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003325 err_cstr = valobj->GetError().AsCString();
3326 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003327
3328 if (err_cstr)
3329 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003330 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003331 }
3332 else
3333 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003334 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003335 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003336 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003337 if (options.m_omit_summary_depth == 0)
3338 {
3339 if (options.m_summary_sp)
3340 {
3341 valobj->GetSummaryAsCString(entry, summary_str);
3342 sum_cstr = summary_str.c_str();
3343 }
3344 else
3345 sum_cstr = valobj->GetSummaryAsCString();
3346 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003347
Greg Clayton6efba4f2012-01-26 21:08:30 +00003348 // Make sure we have a value and make sure the summary didn't
3349 // specify that the value should not be printed
3350 if (!value_str.empty() && (entry == NULL || entry->DoesPrintValue() || sum_cstr == NULL))
3351 s.Printf(" %s", value_str.c_str());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003352
Enrico Granata9dd75c82011-07-15 23:30:15 +00003353 if (sum_cstr)
Enrico Granata0c489f52012-03-01 04:24:26 +00003354 s.Printf(" %s", sum_cstr);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003355
Enrico Granata0c489f52012-03-01 04:24:26 +00003356 if (options.m_use_objc)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003357 {
Jim Ingham6035b672011-03-31 00:19:25 +00003358 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003359 if (object_desc)
3360 s.Printf(" %s\n", object_desc);
3361 else
Sean Callanan672ad942010-10-23 00:18:49 +00003362 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003363 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003364 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003365 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003366
Enrico Granata0c489f52012-03-01 04:24:26 +00003367 if (curr_depth < options.m_max_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003368 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003369 // We will show children for all concrete types. We won't show
3370 // pointer contents unless a pointer depth has been specified.
3371 // We won't reference contents unless the reference is the
3372 // root object (depth of zero).
3373 bool print_children = true;
3374
3375 // Use a new temporary pointer depth in case we override the
3376 // current pointer depth below...
3377 uint32_t curr_ptr_depth = ptr_depth;
3378
3379 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3380 if (is_ptr || is_ref)
3381 {
3382 // We have a pointer or reference whose value is an address.
3383 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003384 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003385 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003386 print_children = false;
3387
3388 else if (is_ref && curr_depth == 0)
3389 {
3390 // If this is the root object (depth is zero) that we are showing
3391 // and it is a reference, and no pointer depth has been supplied
3392 // print out what it references. Don't do this at deeper depths
3393 // otherwise we can end up with infinite recursion...
3394 curr_ptr_depth = 1;
3395 }
3396
3397 if (curr_ptr_depth == 0)
3398 print_children = false;
3399 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003400
Enrico Granata0a3958e2011-07-02 00:25:22 +00003401 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003402 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003403 ValueObject* synth_valobj;
3404 ValueObjectSP synth_valobj_sp = valobj->GetSyntheticValue (options.m_use_synthetic);
3405 synth_valobj = (synth_valobj_sp ? synth_valobj_sp.get() : valobj);
Enrico Granatac5bc4122012-03-27 02:35:13 +00003406
Enrico Granatac482a192011-08-17 22:13:59 +00003407 uint32_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003408 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003409 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003410 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003411 if (options.m_flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003412 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003413 if (print_valobj)
3414 s.EOL();
3415 }
3416 else
3417 {
3418 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003419 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003420 s.IndentMore();
3421 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003422
Greg Claytoncc4d0142012-02-17 07:49:44 +00003423 uint32_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00003424
Enrico Granata0c489f52012-03-01 04:24:26 +00003425 if (num_children > max_num_children && !options.m_ignore_cap)
Enrico Granata22c55d12011-08-12 02:00:06 +00003426 {
3427 num_children = max_num_children;
3428 print_dotdotdot = true;
3429 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003430
Enrico Granata0c489f52012-03-01 04:24:26 +00003431 ValueObject::DumpValueObjectOptions child_options(options);
3432 child_options.SetFormat().SetSummary().SetRootValueObjectName();
3433 child_options.SetScopeChecked(true)
3434 .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003435 for (uint32_t idx=0; idx<num_children; ++idx)
3436 {
Enrico Granatac482a192011-08-17 22:13:59 +00003437 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003438 if (child_sp.get())
3439 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003440 DumpValueObject_Impl (s,
3441 child_sp.get(),
3442 child_options,
3443 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
3444 curr_depth + 1);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003445 }
3446 }
3447
Enrico Granata0c489f52012-03-01 04:24:26 +00003448 if (!options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003449 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003450 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003451 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003452 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3453 Target *target = exe_ctx.GetTargetPtr();
3454 if (target)
3455 target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003456 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003457 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003458 s.IndentLess();
3459 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003460 }
3461 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003462 else if (has_children)
3463 {
3464 // Aggregate, no children...
3465 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003466 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003467 }
3468 else
3469 {
3470 if (print_valobj)
3471 s.EOL();
3472 }
3473
Greg Clayton1d3afba2010-10-05 00:00:42 +00003474 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003475 else
3476 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003477 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003478 }
3479 }
3480 else
3481 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003482 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003483 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003484 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003485 }
3486 }
3487 }
3488 }
3489}
3490
Enrico Granata0c489f52012-03-01 04:24:26 +00003491void
Greg Claytonf830dbb2012-03-22 18:15:37 +00003492ValueObject::LogValueObject (Log *log,
3493 ValueObject *valobj)
3494{
3495 if (log && valobj)
3496 return LogValueObject (log, valobj, DumpValueObjectOptions::DefaultOptions());
3497}
3498
3499void
3500ValueObject::LogValueObject (Log *log,
3501 ValueObject *valobj,
3502 const DumpValueObjectOptions& options)
3503{
3504 if (log && valobj)
3505 {
3506 StreamString s;
3507 ValueObject::DumpValueObject (s, valobj, options);
3508 if (s.GetSize())
3509 log->PutCString(s.GetData());
3510 }
3511}
3512
3513void
Enrico Granata0c489f52012-03-01 04:24:26 +00003514ValueObject::DumpValueObject (Stream &s,
3515 ValueObject *valobj)
3516{
3517
3518 if (!valobj)
3519 return;
3520
3521 DumpValueObject_Impl(s,
3522 valobj,
3523 DumpValueObjectOptions::DefaultOptions(),
3524 0,
3525 0);
3526}
3527
3528void
3529ValueObject::DumpValueObject (Stream &s,
3530 ValueObject *valobj,
3531 const DumpValueObjectOptions& options)
3532{
3533 DumpValueObject_Impl(s,
3534 valobj,
3535 options,
3536 options.m_max_ptr_depth, // max pointer depth allowed, we will go down from here
3537 0 // current object depth is 0 since we are just starting
3538 );
3539}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003540
3541ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003542ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003543{
3544 ValueObjectSP valobj_sp;
3545
Enrico Granatac3e320a2011-08-02 17:27:39 +00003546 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003547 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003548 ExecutionContext exe_ctx (GetExecutionContextRef());
3549 clang::ASTContext *ast = GetClangAST ();
3550
3551 DataExtractor data;
3552 data.SetByteOrder (m_data.GetByteOrder());
3553 data.SetAddressByteSize(m_data.GetAddressByteSize());
3554
Enrico Granata9f1e2042012-04-24 22:15:37 +00003555 if (IsBitfield())
3556 {
3557 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
3558 m_error = v.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
3559 }
3560 else
3561 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003562
3563 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3564 ast,
3565 GetClangType(),
3566 name,
3567 data,
3568 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003569 }
Jim Ingham6035b672011-03-31 00:19:25 +00003570
3571 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003572 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003573 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003574 }
3575 return valobj_sp;
3576}
3577
Greg Claytonafacd142011-09-02 01:15:17 +00003578ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003579ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003580{
Jim Ingham58b59f92011-04-22 23:53:53 +00003581 if (m_deref_valobj)
3582 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003583
Greg Clayton54979cd2010-12-15 05:08:08 +00003584 const bool is_pointer_type = IsPointerType();
3585 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003586 {
3587 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003588 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003589
3590 std::string child_name_str;
3591 uint32_t child_byte_size = 0;
3592 int32_t child_byte_offset = 0;
3593 uint32_t child_bitfield_bit_size = 0;
3594 uint32_t child_bitfield_bit_offset = 0;
3595 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003596 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003597 const bool transparent_pointers = false;
3598 clang::ASTContext *clang_ast = GetClangAST();
3599 clang_type_t clang_type = GetClangType();
3600 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003601
Greg Claytoncc4d0142012-02-17 07:49:44 +00003602 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003603
3604 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3605 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003606 GetName().GetCString(),
3607 clang_type,
3608 0,
3609 transparent_pointers,
3610 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003611 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003612 child_name_str,
3613 child_byte_size,
3614 child_byte_offset,
3615 child_bitfield_bit_size,
3616 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003617 child_is_base_class,
3618 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003619 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003620 {
3621 ConstString child_name;
3622 if (!child_name_str.empty())
3623 child_name.SetCString (child_name_str.c_str());
3624
Jim Ingham58b59f92011-04-22 23:53:53 +00003625 m_deref_valobj = new ValueObjectChild (*this,
3626 clang_ast,
3627 child_clang_type,
3628 child_name,
3629 child_byte_size,
3630 child_byte_offset,
3631 child_bitfield_bit_size,
3632 child_bitfield_bit_offset,
3633 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003634 child_is_deref_of_parent,
3635 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003636 }
3637 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003638
Jim Ingham58b59f92011-04-22 23:53:53 +00003639 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003640 {
3641 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003642 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003643 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003644 else
3645 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003646 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003647 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003648
3649 if (is_pointer_type)
3650 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3651 else
3652 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003653 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003654 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003655}
3656
Greg Claytonafacd142011-09-02 01:15:17 +00003657ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003658ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003659{
Jim Ingham78a685a2011-04-16 00:01:13 +00003660 if (m_addr_of_valobj_sp)
3661 return m_addr_of_valobj_sp;
3662
Greg Claytone0d378b2011-03-24 21:19:54 +00003663 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003664 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003665 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003666 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003667 if (addr != LLDB_INVALID_ADDRESS)
3668 {
3669 switch (address_type)
3670 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003671 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003672 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003673 {
3674 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003675 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003676 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3677 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003678 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003679
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003680 case eAddressTypeFile:
3681 case eAddressTypeLoad:
3682 case eAddressTypeHost:
3683 {
3684 clang::ASTContext *ast = GetClangAST();
3685 clang_type_t clang_type = GetClangType();
3686 if (ast && clang_type)
3687 {
3688 std::string name (1, '&');
3689 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003690 ExecutionContext exe_ctx (GetExecutionContextRef());
3691 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003692 ast,
3693 ClangASTContext::CreatePointerType (ast, clang_type),
3694 ConstString (name.c_str()),
3695 addr,
3696 eAddressTypeInvalid,
3697 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003698 }
3699 }
3700 break;
3701 }
3702 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003703 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003704}
3705
Greg Clayton9a142cf2012-02-03 05:34:10 +00003706ValueObjectSP
3707ValueObject::Cast (const ClangASTType &clang_ast_type)
3708{
Greg Clayton81e871e2012-02-04 02:27:34 +00003709 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003710}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003711
Greg Claytonafacd142011-09-02 01:15:17 +00003712ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003713ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3714{
Greg Claytonafacd142011-09-02 01:15:17 +00003715 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003716 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003717 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003718
3719 if (ptr_value != LLDB_INVALID_ADDRESS)
3720 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003721 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003722 ExecutionContext exe_ctx (GetExecutionContextRef());
3723 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003724 name,
3725 ptr_addr,
3726 clang_ast_type);
3727 }
3728 return valobj_sp;
3729}
3730
Greg Claytonafacd142011-09-02 01:15:17 +00003731ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003732ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3733{
Greg Claytonafacd142011-09-02 01:15:17 +00003734 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003735 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003736 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003737
3738 if (ptr_value != LLDB_INVALID_ADDRESS)
3739 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003740 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003741 ExecutionContext exe_ctx (GetExecutionContextRef());
3742 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003743 name,
3744 ptr_addr,
3745 type_sp);
3746 }
3747 return valobj_sp;
3748}
3749
Jim Ingham6035b672011-03-31 00:19:25 +00003750ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003751 m_mod_id(),
3752 m_exe_ctx_ref(),
3753 m_needs_update (true),
3754 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003755{
3756}
3757
3758ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003759 m_mod_id(),
3760 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003761 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003762 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003763{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003764 ExecutionContext exe_ctx(exe_scope);
3765 TargetSP target_sp (exe_ctx.GetTargetSP());
3766 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003767 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003768 m_exe_ctx_ref.SetTargetSP (target_sp);
3769 ProcessSP process_sp (exe_ctx.GetProcessSP());
3770 if (!process_sp)
3771 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003772
Greg Claytoncc4d0142012-02-17 07:49:44 +00003773 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003774 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003775 m_mod_id = process_sp->GetModID();
3776 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003777
Greg Claytoncc4d0142012-02-17 07:49:44 +00003778 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003779
Greg Claytoncc4d0142012-02-17 07:49:44 +00003780 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003781 {
3782 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003783 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003784 }
Jim Ingham6035b672011-03-31 00:19:25 +00003785
Greg Claytoncc4d0142012-02-17 07:49:44 +00003786 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003787 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003788 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003789
Greg Claytoncc4d0142012-02-17 07:49:44 +00003790 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3791 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003792 {
3793 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003794 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003795 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003796 if (frame_sp)
3797 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003798 }
3799 }
3800 }
Jim Ingham6035b672011-03-31 00:19:25 +00003801}
3802
3803ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003804 m_mod_id(),
3805 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3806 m_needs_update (true),
3807 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003808{
3809}
3810
3811ValueObject::EvaluationPoint::~EvaluationPoint ()
3812{
3813}
3814
Jim Ingham6035b672011-03-31 00:19:25 +00003815// This function checks the EvaluationPoint against the current process state. If the current
3816// state matches the evaluation point, or the evaluation point is already invalid, then we return
3817// false, meaning "no change". If the current state is different, we update our state, and return
3818// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3819// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003820// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003821
3822bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003823ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003824{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003825
3826 // 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 +00003827 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00003828
Greg Claytoncc4d0142012-02-17 07:49:44 +00003829 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003830 return false;
3831
Jim Ingham6035b672011-03-31 00:19:25 +00003832 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003833 Process *process = exe_ctx.GetProcessPtr();
3834 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003835 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003836
Jim Ingham6035b672011-03-31 00:19:25 +00003837 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003838 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003839
Jim Ingham78a685a2011-04-16 00:01:13 +00003840 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3841 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003842 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003843 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003844
Greg Clayton23f59502012-07-17 03:23:13 +00003845 bool changed = false;
3846 const bool was_valid = m_mod_id.IsValid();
3847 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003848 {
3849 if (m_mod_id == current_mod_id)
3850 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003851 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003852 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003853 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003854 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003855 else
3856 {
3857 m_mod_id = current_mod_id;
3858 m_needs_update = true;
3859 changed = true;
3860 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003861 }
Jim Ingham6035b672011-03-31 00:19:25 +00003862
Jim Ingham73ca05a2011-12-17 01:35:57 +00003863 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3864 // That way we'll be sure to return a valid exe_scope.
3865 // 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 +00003866
Greg Claytoncc4d0142012-02-17 07:49:44 +00003867 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003868 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003869 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3870 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003871 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003872 if (m_exe_ctx_ref.HasFrameRef())
3873 {
3874 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3875 if (!frame_sp)
3876 {
3877 // We used to have a frame, but now it is gone
3878 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003879 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00003880 }
3881 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003882 }
Jim Ingham6035b672011-03-31 00:19:25 +00003883 else
3884 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003885 // We used to have a thread, but now it is gone
3886 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003887 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00003888 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003889
Jim Ingham6035b672011-03-31 00:19:25 +00003890 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003891 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003892}
3893
Jim Ingham61be0902011-05-02 18:13:59 +00003894void
3895ValueObject::EvaluationPoint::SetUpdated ()
3896{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003897 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3898 if (process_sp)
3899 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003900 m_first_update = false;
3901 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003902}
3903
3904
Greg Claytoncc4d0142012-02-17 07:49:44 +00003905//bool
3906//ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3907//{
3908// if (!IsValid())
3909// return false;
3910//
3911// bool needs_update = false;
3912//
3913// // The target has to be non-null, and the
3914// Target *target = exe_scope->CalculateTarget();
3915// if (target != NULL)
3916// {
3917// Target *old_target = m_target_sp.get();
3918// assert (target == old_target);
3919// Process *process = exe_scope->CalculateProcess();
3920// if (process != NULL)
3921// {
3922// // FOR NOW - assume you can't update variable objects across process boundaries.
3923// Process *old_process = m_process_sp.get();
3924// assert (process == old_process);
3925// ProcessModID current_mod_id = process->GetModID();
3926// if (m_mod_id != current_mod_id)
3927// {
3928// needs_update = true;
3929// m_mod_id = current_mod_id;
3930// }
3931// // See if we're switching the thread or stack context. If no thread is given, this is
3932// // being evaluated in a global context.
3933// Thread *thread = exe_scope->CalculateThread();
3934// if (thread != NULL)
3935// {
3936// user_id_t new_thread_index = thread->GetIndexID();
3937// if (new_thread_index != m_thread_id)
3938// {
3939// needs_update = true;
3940// m_thread_id = new_thread_index;
3941// m_stack_id.Clear();
3942// }
3943//
3944// StackFrame *new_frame = exe_scope->CalculateStackFrame();
3945// if (new_frame != NULL)
3946// {
3947// if (new_frame->GetStackID() != m_stack_id)
3948// {
3949// needs_update = true;
3950// m_stack_id = new_frame->GetStackID();
3951// }
3952// }
3953// else
3954// {
3955// m_stack_id.Clear();
3956// needs_update = true;
3957// }
3958// }
3959// else
3960// {
3961// // If this had been given a thread, and now there is none, we should update.
3962// // Otherwise we don't have to do anything.
3963// if (m_thread_id != LLDB_INVALID_UID)
3964// {
3965// m_thread_id = LLDB_INVALID_UID;
3966// m_stack_id.Clear();
3967// needs_update = true;
3968// }
3969// }
3970// }
3971// else
3972// {
3973// // If there is no process, then we don't need to update anything.
3974// // But if we're switching from having a process to not, we should try to update.
3975// if (m_process_sp.get() != NULL)
3976// {
3977// needs_update = true;
3978// m_process_sp.reset();
3979// m_thread_id = LLDB_INVALID_UID;
3980// m_stack_id.Clear();
3981// }
3982// }
3983// }
3984// else
3985// {
3986// // If there's no target, nothing can change so we don't need to update anything.
3987// // But if we're switching from having a target to not, we should try to update.
3988// if (m_target_sp.get() != NULL)
3989// {
3990// needs_update = true;
3991// m_target_sp.reset();
3992// m_process_sp.reset();
3993// m_thread_id = LLDB_INVALID_UID;
3994// m_stack_id.Clear();
3995// }
3996// }
3997// if (!m_needs_update)
3998// m_needs_update = needs_update;
3999//
4000// return needs_update;
4001//}
Enrico Granataf2bbf712011-07-15 02:26:42 +00004002
4003void
Enrico Granata86cc9822012-03-19 22:58:49 +00004004ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004005{
Enrico Granata86cc9822012-03-19 22:58:49 +00004006 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4007 m_value_str.clear();
4008
4009 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4010 m_location_str.clear();
4011
4012 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
4013 {
Enrico Granata86cc9822012-03-19 22:58:49 +00004014 m_summary_str.clear();
4015 }
4016
4017 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4018 m_object_desc_str.clear();
4019
4020 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4021 {
4022 if (m_synthetic_value)
4023 m_synthetic_value = NULL;
4024 }
Johnny Chen44805302011-07-19 19:48:13 +00004025}
Enrico Granata9128ee22011-09-06 19:20:51 +00004026
4027SymbolContextScope *
4028ValueObject::GetSymbolContextScope()
4029{
4030 if (m_parent)
4031 {
4032 if (!m_parent->IsPointerOrReferenceType())
4033 return m_parent->GetSymbolContextScope();
4034 }
4035 return NULL;
4036}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004037
4038lldb::ValueObjectSP
4039ValueObject::CreateValueObjectFromExpression (const char* name,
4040 const char* expression,
4041 const ExecutionContext& exe_ctx)
4042{
4043 lldb::ValueObjectSP retval_sp;
4044 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4045 if (!target_sp)
4046 return retval_sp;
4047 if (!expression || !*expression)
4048 return retval_sp;
4049 target_sp->EvaluateExpression (expression,
4050 exe_ctx.GetFrameSP().get(),
4051 retval_sp);
4052 if (retval_sp && name && *name)
4053 retval_sp->SetName(ConstString(name));
4054 return retval_sp;
4055}
4056
4057lldb::ValueObjectSP
4058ValueObject::CreateValueObjectFromAddress (const char* name,
4059 uint64_t address,
4060 const ExecutionContext& exe_ctx,
4061 ClangASTType type)
4062{
4063 ClangASTType pointer_type(type.GetASTContext(),type.GetPointerType());
4064 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4065 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4066 pointer_type.GetASTContext(),
4067 pointer_type.GetOpaqueQualType(),
4068 ConstString(name),
4069 buffer,
4070 lldb::endian::InlHostByteOrder(),
4071 exe_ctx.GetAddressByteSize()));
4072 if (ptr_result_valobj_sp)
4073 {
4074 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4075 Error err;
4076 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4077 if (ptr_result_valobj_sp && name && *name)
4078 ptr_result_valobj_sp->SetName(ConstString(name));
4079 }
4080 return ptr_result_valobj_sp;
4081}
4082
4083lldb::ValueObjectSP
4084ValueObject::CreateValueObjectFromData (const char* name,
4085 DataExtractor& data,
4086 const ExecutionContext& exe_ctx,
4087 ClangASTType type)
4088{
4089 lldb::ValueObjectSP new_value_sp;
4090 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4091 type.GetASTContext() ,
4092 type.GetOpaqueQualType(),
4093 ConstString(name),
4094 data,
4095 LLDB_INVALID_ADDRESS);
4096 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4097 if (new_value_sp && name && *name)
4098 new_value_sp->SetName(ConstString(name));
4099 return new_value_sp;
4100}