blob: dcc9e0e8265e50b609bf7a32061919709c5d5ad0 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- ValueObject.cpp -----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "lldb/Core/ValueObject.h"
13
14// C Includes
Greg Claytonf5e56de2010-09-14 23:36:40 +000015#include <stdlib.h>
16
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017// C++ Includes
18// Other libraries and framework includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "llvm/Support/raw_ostream.h"
Jim Ingham5a369122010-09-28 01:25:32 +000020#include "clang/AST/Type.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021
22// Project includes
23#include "lldb/Core/DataBufferHeap.h"
Enrico Granata4becb372011-06-29 22:27:15 +000024#include "lldb/Core/Debugger.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000025#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000026#include "lldb/Core/Module.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Core/StreamString.h"
Enrico Granata21fd13f2012-10-27 02:05:48 +000028#include "lldb/Core/ValueObjectCast.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Core/ValueObjectChild.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000030#include "lldb/Core/ValueObjectConstResult.h"
Jim Ingham78a685a2011-04-16 00:01:13 +000031#include "lldb/Core/ValueObjectDynamicValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032#include "lldb/Core/ValueObjectList.h"
Greg Claytonb2dcc362011-05-05 23:32:56 +000033#include "lldb/Core/ValueObjectMemory.h"
Enrico Granatad55546b2011-07-22 00:16:08 +000034#include "lldb/Core/ValueObjectSyntheticFilter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035
Enrico Granata5548cb52013-01-28 23:47:25 +000036#include "lldb/DataFormatters/DataVisualization.h"
37
Greg Clayton7fb56d02011-02-01 01:31:41 +000038#include "lldb/Host/Endian.h"
39
Enrico Granata61a80ba2011-08-12 16:42:31 +000040#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granataf2bbf712011-07-15 02:26:42 +000041#include "lldb/Interpreter/ScriptInterpreterPython.h"
42
Greg Claytone1a916a2010-07-21 22:12:05 +000043#include "lldb/Symbol/ClangASTType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000044#include "lldb/Symbol/ClangASTContext.h"
45#include "lldb/Symbol/Type.h"
46
Jim Ingham53c47f12010-09-10 23:12:17 +000047#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000048#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000049#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000050#include "lldb/Target/Process.h"
51#include "lldb/Target/RegisterContext.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000052#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054
55using namespace lldb;
56using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000057using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058
Greg Claytonafacd142011-09-02 01:15:17 +000059static user_id_t g_value_obj_uid = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060
61//----------------------------------------------------------------------
62// ValueObject constructor
63//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000064ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000066 m_parent (&parent),
Enrico Granata4873e522013-04-11 22:48:58 +000067 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +000068 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000069 m_name (),
70 m_data (),
71 m_value (),
72 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000073 m_value_str (),
74 m_old_value_str (),
75 m_location_str (),
76 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000077 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +000078 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000079 m_children (),
80 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000081 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000082 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000083 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000084 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000085 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +000086 m_type_summary_sp(),
87 m_type_format_sp(),
88 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +000089 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +000090 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
Greg Clayton288bdf92010-09-02 02:59:18 +000091 m_value_is_valid (false),
92 m_value_did_change (false),
93 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000094 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +000095 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +000096 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +000097 m_is_bitfield_for_scalar(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),
Enrico Granata4873e522013-04-11 22:48:58 +0000112 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000113 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000114 m_name (),
115 m_data (),
116 m_value (),
117 m_error (),
118 m_value_str (),
119 m_old_value_str (),
120 m_location_str (),
121 m_summary_str (),
122 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000123 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000124 m_children (),
125 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000126 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000127 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000128 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000129 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000130 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +0000131 m_type_summary_sp(),
132 m_type_format_sp(),
133 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000134 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000135 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Jim Ingham6035b672011-03-31 00:19:25 +0000136 m_value_is_valid (false),
137 m_value_did_change (false),
138 m_children_count_valid (false),
139 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000140 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000141 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000142 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000143 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000144 m_is_getting_summary(false),
145 m_did_calculate_complete_objc_class_type(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000146{
Jim Ingham58b59f92011-04-22 23:53:53 +0000147 m_manager = new ValueObjectManager();
148 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000149}
150
151//----------------------------------------------------------------------
152// Destructor
153//----------------------------------------------------------------------
154ValueObject::~ValueObject ()
155{
156}
157
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000158bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000159ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000160{
Enrico Granata4becb372011-06-29 22:27:15 +0000161
Enrico Granata9128ee22011-09-06 19:20:51 +0000162 bool did_change_formats = false;
163
Enrico Granata0a3958e2011-07-02 00:25:22 +0000164 if (update_format)
Enrico Granata5548cb52013-01-28 23:47:25 +0000165 did_change_formats = UpdateFormatsIfNeeded();
Enrico Granata4becb372011-06-29 22:27:15 +0000166
Greg Claytonb71f3842010-10-05 03:13:51 +0000167 // If this is a constant value, then our success is predicated on whether
168 // we have an error or not
169 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000170 {
171 // if you were asked to update your formatters, but did not get a chance to do it
172 // clear your own values (this serves the purpose of faking a stop-id for frozen
173 // objects (which are regarded as constant, but could have changes behind their backs
174 // because of the frozen-pointer depth limit)
175 // TODO: decouple summary from value and then remove this code and only force-clear the summary
176 if (update_format && !did_change_formats)
Enrico Granata86cc9822012-03-19 22:58:49 +0000177 ClearUserVisibleData(eClearUserVisibleDataItemsSummary);
Greg Claytonb71f3842010-10-05 03:13:51 +0000178 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000179 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000180
Jim Ingham6035b672011-03-31 00:19:25 +0000181 bool first_update = m_update_point.IsFirstEvaluation();
182
183 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000184 {
Jim Ingham6035b672011-03-31 00:19:25 +0000185 m_update_point.SetUpdated();
186
187 // Save the old value using swap to avoid a string copy which
188 // also will clear our m_value_str
189 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000190 {
Jim Ingham6035b672011-03-31 00:19:25 +0000191 m_old_value_valid = false;
192 }
193 else
194 {
195 m_old_value_valid = true;
196 m_old_value_str.swap (m_value_str);
Enrico Granata86cc9822012-03-19 22:58:49 +0000197 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham6035b672011-03-31 00:19:25 +0000198 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000199
Enrico Granataf2bbf712011-07-15 02:26:42 +0000200 ClearUserVisibleData();
201
Greg Claytonefbc7d22012-03-09 04:23:44 +0000202 if (IsInScope())
Jim Ingham6035b672011-03-31 00:19:25 +0000203 {
Greg Claytonefbc7d22012-03-09 04:23:44 +0000204 const bool value_was_valid = GetValueIsValid();
205 SetValueDidChange (false);
206
207 m_error.Clear();
208
209 // Call the pure virtual function to update the value
210 bool success = UpdateValue ();
211
212 SetValueIsValid (success);
213
214 if (first_update)
215 SetValueDidChange (false);
216 else if (!m_value_did_change && success == false)
217 {
218 // The value wasn't gotten successfully, so we mark this
219 // as changed if the value used to be valid and now isn't
220 SetValueDidChange (value_was_valid);
221 }
222 }
223 else
224 {
225 m_error.SetErrorString("out of scope");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000226 }
227 }
228 return m_error.Success();
229}
230
Enrico Granata9128ee22011-09-06 19:20:51 +0000231bool
Enrico Granata5548cb52013-01-28 23:47:25 +0000232ValueObject::UpdateFormatsIfNeeded()
Enrico Granata4becb372011-06-29 22:27:15 +0000233{
Greg Clayton5160ce52013-03-27 23:08:40 +0000234 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000235 if (log)
Enrico Granatad2284832012-10-17 22:23:56 +0000236 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
Enrico Granata6f3533f2011-07-29 19:53:35 +0000237 GetName().GetCString(),
Enrico Granatad2284832012-10-17 22:23:56 +0000238 this,
Enrico Granata4becb372011-06-29 22:27:15 +0000239 m_last_format_mgr_revision,
Enrico Granata85933ed2011-08-18 16:38:26 +0000240 DataVisualization::GetCurrentRevision());
Enrico Granata9128ee22011-09-06 19:20:51 +0000241
242 bool any_change = false;
243
Enrico Granata5548cb52013-01-28 23:47:25 +0000244 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()))
Enrico Granata4becb372011-06-29 22:27:15 +0000245 {
Enrico Granata78d06382011-09-09 23:33:14 +0000246 SetValueFormat(DataVisualization::ValueFormats::GetFormat (*this, eNoDynamicValues));
Enrico Granata5548cb52013-01-28 23:47:25 +0000247 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000248#ifndef LLDB_DISABLE_PYTHON
Enrico Granata5548cb52013-01-28 23:47:25 +0000249 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000250#endif
Enrico Granata1490c6f2011-07-19 02:34:21 +0000251
Enrico Granata85933ed2011-08-18 16:38:26 +0000252 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
Enrico Granata855cd902011-09-06 22:59:55 +0000253
254 any_change = true;
Enrico Granata4becb372011-06-29 22:27:15 +0000255 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000256
257 return any_change;
258
Enrico Granata4becb372011-06-29 22:27:15 +0000259}
260
Jim Ingham16e0c682011-08-12 23:34:31 +0000261void
262ValueObject::SetNeedsUpdate ()
263{
264 m_update_point.SetNeedsUpdate();
265 // We have to clear the value string here so ConstResult children will notice if their values are
266 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000267 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000268}
269
Enrico Granata13ac0e22012-10-17 19:03:34 +0000270void
Enrico Granatae3e91512012-10-22 18:18:36 +0000271ValueObject::ClearDynamicTypeInformation ()
Enrico Granata13ac0e22012-10-17 19:03:34 +0000272{
273 m_did_calculate_complete_objc_class_type = false;
Enrico Granatae3e91512012-10-22 18:18:36 +0000274 m_last_format_mgr_revision = 0;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000275 m_override_type = ClangASTType();
Enrico Granatae3e91512012-10-22 18:18:36 +0000276 SetValueFormat(lldb::TypeFormatImplSP());
277 SetSummaryFormat(lldb::TypeSummaryImplSP());
278 SetSyntheticChildren(lldb::SyntheticChildrenSP());
Enrico Granata13ac0e22012-10-17 19:03:34 +0000279}
280
Sean Callanan72772842012-02-22 23:57:45 +0000281ClangASTType
282ValueObject::MaybeCalculateCompleteType ()
283{
284 ClangASTType ret(GetClangASTImpl(), GetClangTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000285
Sean Callanan72772842012-02-22 23:57:45 +0000286 if (m_did_calculate_complete_objc_class_type)
287 {
288 if (m_override_type.IsValid())
289 return m_override_type;
290 else
291 return ret;
292 }
293
294 clang_type_t ast_type(GetClangTypeImpl());
295 clang_type_t class_type;
296 bool is_pointer_type;
297
298 if (ClangASTContext::IsObjCObjectPointerType(ast_type, &class_type))
299 {
300 is_pointer_type = true;
301 }
302 else if (ClangASTContext::IsObjCClassType(ast_type))
303 {
304 is_pointer_type = false;
305 class_type = ast_type;
306 }
307 else
308 {
309 return ret;
310 }
311
312 m_did_calculate_complete_objc_class_type = true;
313
314 if (!class_type)
315 return ret;
316
317 std::string class_name;
318
319 if (!ClangASTContext::GetObjCClassName(class_type, class_name))
320 return ret;
321
322 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
323
324 if (!process_sp)
325 return ret;
326
327 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
328
329 if (!objc_language_runtime)
330 return ret;
331
332 ConstString class_name_cs(class_name.c_str());
333
334 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name_cs);
335
336 if (!complete_objc_class_type_sp)
337 return ret;
338
339 ClangASTType complete_class(complete_objc_class_type_sp->GetClangAST(),
340 complete_objc_class_type_sp->GetClangFullType());
341
342 if (!ClangASTContext::GetCompleteType(complete_class.GetASTContext(),
343 complete_class.GetOpaqueQualType()))
344 return ret;
345
346 if (is_pointer_type)
347 {
348 clang_type_t pointer_type = ClangASTContext::CreatePointerType(complete_class.GetASTContext(),
349 complete_class.GetOpaqueQualType());
350
351 m_override_type = ClangASTType(complete_class.GetASTContext(),
352 pointer_type);
353 }
354 else
355 {
356 m_override_type = complete_class;
357 }
358
Sean Callanan356e17c2012-03-30 02:04:38 +0000359 if (m_override_type.IsValid())
360 return m_override_type;
361 else
362 return ret;
Sean Callanan72772842012-02-22 23:57:45 +0000363}
364
365clang::ASTContext *
366ValueObject::GetClangAST ()
367{
368 ClangASTType type = MaybeCalculateCompleteType();
369
370 return type.GetASTContext();
371}
372
373lldb::clang_type_t
374ValueObject::GetClangType ()
375{
376 ClangASTType type = MaybeCalculateCompleteType();
377
378 return type.GetOpaqueQualType();
379}
380
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000381DataExtractor &
382ValueObject::GetDataExtractor ()
383{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000384 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000385 return m_data;
386}
387
388const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000389ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000390{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000391 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000392 return m_error;
393}
394
395const ConstString &
396ValueObject::GetName() const
397{
398 return m_name;
399}
400
401const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000402ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000403{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000404 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000405 {
406 if (m_location_str.empty())
407 {
408 StreamString sstr;
409
410 switch (m_value.GetValueType())
411 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000412 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +0000413 case Value::eValueTypeVector:
Greg Clayton526e5af2010-11-13 03:52:47 +0000414 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000415 {
416 RegisterInfo *reg_info = m_value.GetRegisterInfo();
417 if (reg_info)
418 {
419 if (reg_info->name)
420 m_location_str = reg_info->name;
421 else if (reg_info->alt_name)
422 m_location_str = reg_info->alt_name;
Greg Clayton0665a0f2012-10-30 18:18:43 +0000423
424 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000425 }
426 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000427 break;
428
429 case Value::eValueTypeLoadAddress:
430 case Value::eValueTypeFileAddress:
431 case Value::eValueTypeHostAddress:
432 {
433 uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2;
434 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
435 m_location_str.swap(sstr.GetString());
436 }
437 break;
438 }
439 }
440 }
441 return m_location_str.c_str();
442}
443
444Value &
445ValueObject::GetValue()
446{
447 return m_value;
448}
449
450const Value &
451ValueObject::GetValue() const
452{
453 return m_value;
454}
455
456bool
Jim Ingham6035b672011-03-31 00:19:25 +0000457ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000458{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000459 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
460 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000461 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000462 Value tmp_value(m_value);
463 scalar = tmp_value.ResolveValue(&exe_ctx, GetClangAST ());
Greg Claytondcad5022011-12-29 01:26:56 +0000464 if (scalar.IsValid())
465 {
466 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
467 if (bitfield_bit_size)
468 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
469 return true;
470 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000471 }
Greg Claytondcad5022011-12-29 01:26:56 +0000472 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000473}
474
475bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000476ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000477{
Greg Clayton288bdf92010-09-02 02:59:18 +0000478 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000479}
480
481
482void
483ValueObject::SetValueIsValid (bool b)
484{
Greg Clayton288bdf92010-09-02 02:59:18 +0000485 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000486}
487
488bool
Jim Ingham6035b672011-03-31 00:19:25 +0000489ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000490{
Jim Ingham6035b672011-03-31 00:19:25 +0000491 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000492 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000493}
494
495void
496ValueObject::SetValueDidChange (bool value_changed)
497{
Greg Clayton288bdf92010-09-02 02:59:18 +0000498 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000499}
500
501ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000502ValueObject::GetChildAtIndex (size_t idx, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000503{
504 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000505 // We may need to update our value if we are dynamic
506 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000507 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000508 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000509 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000510 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000511 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000512 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000513 // No we haven't created the child at this index, so lets have our
514 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000515 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000516 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000517
Enrico Granata9d60f602012-03-09 03:09:58 +0000518 ValueObject* child = m_children.GetChildAtIndex(idx);
519 if (child != NULL)
520 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000521 }
522 return child_sp;
523}
524
Enrico Granata3309d882013-01-12 01:00:22 +0000525ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000526ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
527 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000528{
529 if (idxs.size() == 0)
530 return GetSP();
531 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000532 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000533 {
534 root = root->GetChildAtIndex(idx, true);
535 if (!root)
536 {
537 if (index_of_error)
538 *index_of_error = idx;
539 return root;
540 }
541 }
542 return root;
543}
544
545ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000546ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
547 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000548{
549 if (idxs.size() == 0)
550 return GetSP();
551 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000552 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000553 {
554 root = root->GetChildAtIndex(idx.first, idx.second);
555 if (!root)
556 {
557 if (index_of_error)
558 *index_of_error = idx.first;
559 return root;
560 }
561 }
562 return root;
563}
564
565lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000566ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
567 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000568{
569 if (idxs.size() == 0)
570 return GetSP();
571 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000572 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000573 {
574 root = root->GetChildAtIndex(idx, true);
575 if (!root)
576 {
577 if (index_of_error)
578 *index_of_error = idx;
579 return root;
580 }
581 }
582 return root;
583}
584
585lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000586ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
587 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000588{
589 if (idxs.size() == 0)
590 return GetSP();
591 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000592 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000593 {
594 root = root->GetChildAtIndex(idx.first, idx.second);
595 if (!root)
596 {
597 if (index_of_error)
598 *index_of_error = idx.first;
599 return root;
600 }
601 }
602 return root;
603}
604
Greg Claytonc7bece562013-01-25 18:06:21 +0000605size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000606ValueObject::GetIndexOfChildWithName (const ConstString &name)
607{
608 bool omit_empty_base_classes = true;
609 return ClangASTContext::GetIndexOfChildWithName (GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +0000610 GetClangType(),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000611 name.GetCString(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000612 omit_empty_base_classes);
613}
614
615ValueObjectSP
616ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
617{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000618 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000619 // classes (which really aren't part of the expression path), so we
620 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000621 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000622
Greg Claytondea8cb42011-06-29 22:09:02 +0000623 // We may need to update our value if we are dynamic
624 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000625 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000626
627 std::vector<uint32_t> child_indexes;
628 clang::ASTContext *clang_ast = GetClangAST();
629 void *clang_type = GetClangType();
630 bool omit_empty_base_classes = true;
631 const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast,
632 clang_type,
633 name.GetCString(),
634 omit_empty_base_classes,
635 child_indexes);
636 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000637 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000638 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
639 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
640
641 child_sp = GetChildAtIndex(*pos, can_create);
642 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000643 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000644 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000645 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000646 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
647 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000648 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000649 else
650 {
651 child_sp.reset();
652 }
653
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000654 }
655 }
656 return child_sp;
657}
658
659
Greg Claytonc7bece562013-01-25 18:06:21 +0000660size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000661ValueObject::GetNumChildren ()
662{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000663 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000664 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000665 {
666 SetNumChildren (CalculateNumChildren());
667 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000668 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000669}
Greg Clayton4a792072012-10-23 01:50:10 +0000670
671bool
672ValueObject::MightHaveChildren()
673{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000674 bool has_children = false;
Greg Clayton2452ab72013-02-08 22:02:02 +0000675 const uint32_t type_info = GetTypeInfo();
676 if (type_info)
Greg Clayton4a792072012-10-23 01:50:10 +0000677 {
Greg Clayton4a792072012-10-23 01:50:10 +0000678 if (type_info & (ClangASTContext::eTypeHasChildren |
679 ClangASTContext::eTypeIsPointer |
680 ClangASTContext::eTypeIsReference))
681 has_children = true;
682 }
683 else
684 {
685 has_children = GetNumChildren () > 0;
686 }
687 return has_children;
688}
689
690// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000691void
Greg Claytonc7bece562013-01-25 18:06:21 +0000692ValueObject::SetNumChildren (size_t num_children)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000693{
Greg Clayton288bdf92010-09-02 02:59:18 +0000694 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000695 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000696}
697
698void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000699ValueObject::SetName (const ConstString &name)
700{
701 m_name = name;
702}
703
Jim Ingham58b59f92011-04-22 23:53:53 +0000704ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000705ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000706{
Jim Ingham2eec4872011-05-07 00:10:58 +0000707 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000708
Greg Claytondea8cb42011-06-29 22:09:02 +0000709 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000710 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000711 std::string child_name_str;
712 uint32_t child_byte_size = 0;
713 int32_t child_byte_offset = 0;
714 uint32_t child_bitfield_bit_size = 0;
715 uint32_t child_bitfield_bit_offset = 0;
716 bool child_is_base_class = false;
717 bool child_is_deref_of_parent = false;
718
719 const bool transparent_pointers = synthetic_array_member == false;
720 clang::ASTContext *clang_ast = GetClangAST();
721 clang_type_t clang_type = GetClangType();
722 clang_type_t child_clang_type;
723
Greg Claytoncc4d0142012-02-17 07:49:44 +0000724 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000725
726 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
727 clang_ast,
728 GetName().GetCString(),
729 clang_type,
730 idx,
731 transparent_pointers,
732 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +0000733 ignore_array_bounds,
Greg Claytondea8cb42011-06-29 22:09:02 +0000734 child_name_str,
735 child_byte_size,
736 child_byte_offset,
737 child_bitfield_bit_size,
738 child_bitfield_bit_offset,
739 child_is_base_class,
740 child_is_deref_of_parent);
Greg Clayton4ef877f2012-12-06 02:33:54 +0000741 if (child_clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000742 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000743 if (synthetic_index)
744 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000745
Greg Claytondea8cb42011-06-29 22:09:02 +0000746 ConstString child_name;
747 if (!child_name_str.empty())
748 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000749
Greg Claytondea8cb42011-06-29 22:09:02 +0000750 valobj = new ValueObjectChild (*this,
751 clang_ast,
752 child_clang_type,
753 child_name,
754 child_byte_size,
755 child_byte_offset,
756 child_bitfield_bit_size,
757 child_bitfield_bit_offset,
758 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000759 child_is_deref_of_parent,
760 eAddressTypeInvalid);
761 //if (valobj)
762 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
763 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000764
Jim Ingham58b59f92011-04-22 23:53:53 +0000765 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000766}
767
Enrico Granata0c489f52012-03-01 04:24:26 +0000768bool
769ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
770 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000771{
Enrico Granata0c489f52012-03-01 04:24:26 +0000772 destination.clear();
773
774 // ideally we would like to bail out if passing NULL, but if we do so
775 // we end up not providing the summary for function pointers anymore
776 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
777 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000778
779 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000780
781 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
782 // information that we might care to see in a crash log. might be useful in very specific situations though.
783 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
784 GetTypeName().GetCString(),
785 GetName().GetCString(),
786 summary_ptr->GetDescription().c_str());*/
787
Enrico Granata0c489f52012-03-01 04:24:26 +0000788 if (UpdateValueIfNeeded (false))
789 {
790 if (summary_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000791 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000792 if (HasSyntheticValue())
793 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
794 summary_ptr->FormatObject(this, destination);
Enrico Granata0c489f52012-03-01 04:24:26 +0000795 }
796 else
797 {
798 clang_type_t clang_type = GetClangType();
799
800 // Do some default printout for function pointers
801 if (clang_type)
Enrico Granata4becb372011-06-29 22:27:15 +0000802 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000803 StreamString sstr;
804 clang_type_t elem_or_pointee_clang_type;
805 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
806 GetClangAST(),
807 &elem_or_pointee_clang_type));
808
809 if (ClangASTContext::IsFunctionPointerType (clang_type))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000810 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000811 AddressType func_ptr_address_type = eAddressTypeInvalid;
812 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
813 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000814 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000815 switch (func_ptr_address_type)
Jim Ingham6035b672011-03-31 00:19:25 +0000816 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000817 case eAddressTypeInvalid:
818 case eAddressTypeFile:
819 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000820
Greg Claytoncc4d0142012-02-17 07:49:44 +0000821 case eAddressTypeLoad:
Enrico Granata0c489f52012-03-01 04:24:26 +0000822 {
823 ExecutionContext exe_ctx (GetExecutionContextRef());
824
825 Address so_addr;
826 Target *target = exe_ctx.GetTargetPtr();
827 if (target && target->GetSectionLoadList().IsEmpty() == false)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000828 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000829 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000830 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000831 so_addr.Dump (&sstr,
832 exe_ctx.GetBestExecutionContextScope(),
833 Address::DumpStyleResolvedDescription,
834 Address::DumpStyleSectionNameOffset);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000835 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000836 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000837 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000838 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000839
Greg Claytoncc4d0142012-02-17 07:49:44 +0000840 case eAddressTypeHost:
841 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +0000842 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000843 }
844 if (sstr.GetSize() > 0)
845 {
846 destination.assign (1, '(');
847 destination.append (sstr.GetData(), sstr.GetSize());
848 destination.append (1, ')');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000849 }
850 }
851 }
852 }
853 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000854 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000855 return !destination.empty();
856}
857
858const char *
859ValueObject::GetSummaryAsCString ()
860{
861 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
862 {
863 GetSummaryAsCString(GetSummaryFormat().get(),
864 m_summary_str);
865 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000866 if (m_summary_str.empty())
867 return NULL;
868 return m_summary_str.c_str();
869}
870
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000871bool
872ValueObject::IsCStringContainer(bool check_pointer)
873{
874 clang_type_t elem_or_pointee_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +0000875 const Flags type_flags (GetTypeInfo (&elem_or_pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000876 bool is_char_arr_ptr (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
Greg Clayton2452ab72013-02-08 22:02:02 +0000877 ClangASTContext::IsCharType (elem_or_pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000878 if (!is_char_arr_ptr)
879 return false;
880 if (!check_pointer)
881 return true;
882 if (type_flags.Test(ClangASTContext::eTypeIsArray))
883 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000884 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000885 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000886 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000887 return (cstr_address != LLDB_INVALID_ADDRESS);
888}
889
Enrico Granata9128ee22011-09-06 19:20:51 +0000890size_t
891ValueObject::GetPointeeData (DataExtractor& data,
892 uint32_t item_idx,
893 uint32_t item_count)
894{
Greg Clayton2452ab72013-02-08 22:02:02 +0000895 clang_type_t pointee_or_element_clang_type;
896 const uint32_t type_info = GetTypeInfo (&pointee_or_element_clang_type);
897 const bool is_pointer_type = type_info & ClangASTContext::eTypeIsPointer;
898 const bool is_array_type = type_info & ClangASTContext::eTypeIsArray;
899 if (!(is_pointer_type || is_array_type))
Enrico Granata9128ee22011-09-06 19:20:51 +0000900 return 0;
901
902 if (item_count == 0)
903 return 0;
904
Greg Clayton2452ab72013-02-08 22:02:02 +0000905 clang::ASTContext *ast = GetClangAST();
906 ClangASTType pointee_or_element_type(ast, pointee_or_element_clang_type);
Enrico Granata9128ee22011-09-06 19:20:51 +0000907
Greg Clayton2452ab72013-02-08 22:02:02 +0000908 const uint64_t item_type_size = pointee_or_element_type.GetClangTypeByteSize();
Enrico Granata9128ee22011-09-06 19:20:51 +0000909
910 const uint64_t bytes = item_count * item_type_size;
911
912 const uint64_t offset = item_idx * item_type_size;
913
914 if (item_idx == 0 && item_count == 1) // simply a deref
915 {
Greg Clayton2452ab72013-02-08 22:02:02 +0000916 if (is_pointer_type)
Enrico Granata9128ee22011-09-06 19:20:51 +0000917 {
918 Error error;
919 ValueObjectSP pointee_sp = Dereference(error);
920 if (error.Fail() || pointee_sp.get() == NULL)
921 return 0;
922 return pointee_sp->GetDataExtractor().Copy(data);
923 }
924 else
925 {
926 ValueObjectSP child_sp = GetChildAtIndex(0, true);
927 if (child_sp.get() == NULL)
928 return 0;
929 return child_sp->GetDataExtractor().Copy(data);
930 }
931 return true;
932 }
933 else /* (items > 1) */
934 {
935 Error error;
936 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
937 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
938
939 AddressType addr_type;
Greg Clayton2452ab72013-02-08 22:02:02 +0000940 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +0000941
Enrico Granata9128ee22011-09-06 19:20:51 +0000942 switch (addr_type)
943 {
944 case eAddressTypeFile:
945 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000946 ModuleSP module_sp (GetModule());
947 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000948 {
Enrico Granata9c2efe32012-08-07 01:49:34 +0000949 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +0000950 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +0000951 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000952 ExecutionContext exe_ctx (GetExecutionContextRef());
953 Target* target = exe_ctx.GetTargetPtr();
954 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +0000955 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000956 heap_buf_ptr->SetByteSize(bytes);
957 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
958 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +0000959 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000960 data.SetData(data_sp);
961 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +0000962 }
963 }
964 }
965 }
966 break;
967 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +0000968 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000969 ExecutionContext exe_ctx (GetExecutionContextRef());
970 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +0000971 if (process)
972 {
973 heap_buf_ptr->SetByteSize(bytes);
974 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
975 if (error.Success())
976 {
977 data.SetData(data_sp);
978 return bytes_read;
979 }
980 }
981 }
982 break;
983 case eAddressTypeHost:
984 {
Greg Clayton2452ab72013-02-08 22:02:02 +0000985 ClangASTType valobj_type(ast, GetClangType());
986 uint64_t max_bytes = valobj_type.GetClangTypeByteSize();
987 if (max_bytes > offset)
988 {
989 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
990 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
991 data.SetData(data_sp);
992 return bytes_read;
993 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000994 }
995 break;
996 case eAddressTypeInvalid:
Enrico Granata9128ee22011-09-06 19:20:51 +0000997 break;
998 }
999 }
1000 return 0;
1001}
1002
Greg Claytonfaac1112013-03-14 18:31:44 +00001003uint64_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001004ValueObject::GetData (DataExtractor& data)
1005{
1006 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001007 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytone72dfb32012-02-24 01:59:29 +00001008 Error error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001009 if (error.Fail())
1010 return 0;
1011 data.SetAddressByteSize(m_data.GetAddressByteSize());
1012 data.SetByteOrder(m_data.GetByteOrder());
1013 return data.GetByteSize();
1014}
1015
1016// will compute strlen(str), but without consuming more than
1017// maxlen bytes out of str (this serves the purpose of reading
1018// chunks of a string without having to worry about
1019// missing NULL terminators in the chunk)
1020// of course, if strlen(str) > maxlen, the function will return
1021// maxlen_value (which should be != maxlen, because that allows you
1022// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1023static uint32_t
1024strlen_or_inf (const char* str,
1025 uint32_t maxlen,
1026 uint32_t maxlen_value)
1027{
1028 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +00001029 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +00001030 {
Greg Clayton8dd5c172011-10-05 22:19:51 +00001031 while(*str)
1032 {
1033 len++;str++;
Greg Clayton2452ab72013-02-08 22:02:02 +00001034 if (len >= maxlen)
Greg Clayton8dd5c172011-10-05 22:19:51 +00001035 return maxlen_value;
1036 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001037 }
1038 return len;
1039}
1040
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001041size_t
Greg Claytoncc4d0142012-02-17 07:49:44 +00001042ValueObject::ReadPointedString (Stream& s,
1043 Error& error,
1044 uint32_t max_length,
1045 bool honor_array,
1046 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001047{
Greg Claytoncc4d0142012-02-17 07:49:44 +00001048 ExecutionContext exe_ctx (GetExecutionContextRef());
1049 Target* target = exe_ctx.GetTargetPtr();
1050
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001051 if (!target)
1052 {
1053 s << "<no target to read from>";
1054 error.SetErrorString("no target to read from");
1055 return 0;
1056 }
1057
1058 if (max_length == 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001059 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001060
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001061 size_t bytes_read = 0;
1062 size_t total_bytes_read = 0;
1063
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001064 clang_type_t clang_type = GetClangType();
1065 clang_type_t elem_or_pointee_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001066 const Flags type_flags (GetTypeInfo (&elem_or_pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001067 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
1068 ClangASTContext::IsCharType (elem_or_pointee_clang_type))
1069 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001070 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1071 AddressType cstr_address_type = eAddressTypeInvalid;
1072
1073 size_t cstr_len = 0;
1074 bool capped_data = false;
1075 if (type_flags.Test (ClangASTContext::eTypeIsArray))
Greg Claytoncc4d0142012-02-17 07:49:44 +00001076 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001077 // We have an array
1078 cstr_len = ClangASTContext::GetArraySize (clang_type);
1079 if (cstr_len > max_length)
1080 {
1081 capped_data = true;
1082 cstr_len = max_length;
1083 }
1084 cstr_address = GetAddressOf (true, &cstr_address_type);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001085 }
1086 else
1087 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001088 // We have a pointer
1089 cstr_address = GetPointerValue (&cstr_address_type);
1090 }
1091
1092 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1093 {
1094 s << "<invalid address>";
1095 error.SetErrorString("invalid address");
1096 return 0;
1097 }
1098
1099 Address cstr_so_addr (cstr_address);
1100 DataExtractor data;
1101 if (cstr_len > 0 && honor_array)
1102 {
1103 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1104 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1105 GetPointeeData(data, 0, cstr_len);
1106
1107 if ((bytes_read = data.GetByteSize()) > 0)
1108 {
1109 total_bytes_read = bytes_read;
1110 s << '"';
1111 data.Dump (&s,
1112 0, // Start offset in "data"
1113 item_format,
1114 1, // Size of item (1 byte for a char!)
1115 bytes_read, // How many bytes to print?
1116 UINT32_MAX, // num per line
1117 LLDB_INVALID_ADDRESS,// base address
1118 0, // bitfield bit size
1119 0); // bitfield bit offset
1120 if (capped_data)
1121 s << "...";
1122 s << '"';
1123 }
1124 }
1125 else
1126 {
1127 cstr_len = max_length;
1128 const size_t k_max_buf_size = 64;
1129
1130 size_t offset = 0;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001131
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001132 int cstr_len_displayed = -1;
1133 bool capped_cstr = false;
1134 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1135 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1136 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001137 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001138 total_bytes_read += bytes_read;
1139 const char *cstr = data.PeekCStr(0);
1140 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1141 if (len > k_max_buf_size)
1142 len = k_max_buf_size;
1143 if (cstr && cstr_len_displayed < 0)
1144 s << '"';
1145
1146 if (cstr_len_displayed < 0)
1147 cstr_len_displayed = len;
1148
1149 if (len == 0)
1150 break;
1151 cstr_len_displayed += len;
1152 if (len > bytes_read)
1153 len = bytes_read;
1154 if (len > cstr_len)
1155 len = cstr_len;
1156
1157 data.Dump (&s,
1158 0, // Start offset in "data"
1159 item_format,
1160 1, // Size of item (1 byte for a char!)
1161 len, // How many bytes to print?
1162 UINT32_MAX, // num per line
1163 LLDB_INVALID_ADDRESS,// base address
1164 0, // bitfield bit size
1165 0); // bitfield bit offset
1166
1167 if (len < k_max_buf_size)
1168 break;
1169
1170 if (len >= cstr_len)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001171 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001172 capped_cstr = true;
1173 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001174 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001175
1176 cstr_len -= len;
1177 offset += len;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001178 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001179
1180 if (cstr_len_displayed >= 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001181 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001182 s << '"';
1183 if (capped_cstr)
1184 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001185 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001186 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001187 }
1188 else
1189 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001190 error.SetErrorString("not a string object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001191 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001192 }
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001193 return total_bytes_read;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001194}
1195
Jim Ingham53c47f12010-09-10 23:12:17 +00001196const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001197ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001198{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001199
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001200 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001201 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001202
1203 if (!m_object_desc_str.empty())
1204 return m_object_desc_str.c_str();
1205
Greg Claytoncc4d0142012-02-17 07:49:44 +00001206 ExecutionContext exe_ctx (GetExecutionContextRef());
1207 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001208 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001209 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001210
Jim Ingham53c47f12010-09-10 23:12:17 +00001211 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001212
Greg Claytonafacd142011-09-02 01:15:17 +00001213 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001214 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1215
Jim Inghama2cf2632010-12-23 02:29:54 +00001216 if (runtime == NULL)
1217 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001218 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Jim Inghama2cf2632010-12-23 02:29:54 +00001219 clang_type_t opaque_qual_type = GetClangType();
1220 if (opaque_qual_type != NULL)
1221 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001222 bool is_signed;
1223 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed)
1224 || ClangASTContext::IsPointerType (opaque_qual_type))
1225 {
Greg Claytonafacd142011-09-02 01:15:17 +00001226 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001227 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001228 }
1229 }
1230
Jim Ingham8d543de2011-03-31 23:01:21 +00001231 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001232 {
1233 m_object_desc_str.append (s.GetData());
1234 }
Sean Callanan672ad942010-10-23 00:18:49 +00001235
1236 if (m_object_desc_str.empty())
1237 return NULL;
1238 else
1239 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001240}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001241
Enrico Granata0c489f52012-03-01 04:24:26 +00001242bool
1243ValueObject::GetValueAsCString (lldb::Format format,
1244 std::string& destination)
1245{
1246 if (ClangASTContext::IsAggregateType (GetClangType()) == false &&
1247 UpdateValueIfNeeded(false))
1248 {
1249 const Value::ContextType context_type = m_value.GetContextType();
1250
1251 switch (context_type)
1252 {
1253 case Value::eContextTypeClangType:
1254 case Value::eContextTypeLLDBType:
1255 case Value::eContextTypeVariable:
1256 {
1257 clang_type_t clang_type = GetClangType ();
1258 if (clang_type)
1259 {
Enrico Granata852cce72013-03-23 01:12:38 +00001260 // put custom bytes to display in this DataExtractor to override the default value logic
1261 lldb_private::DataExtractor special_format_data;
1262 clang::ASTContext* ast = GetClangAST();
Enrico Granata123c39c2013-03-23 01:44:23 +00001263 if (format == eFormatCString)
Enrico Granata852cce72013-03-23 01:12:38 +00001264 {
Enrico Granata9d71afe2013-03-23 01:44:59 +00001265 Flags type_flags(ClangASTContext::GetTypeInfo(clang_type, ast, NULL));
Enrico Granata123c39c2013-03-23 01:44:23 +00001266 if (type_flags.Test(ClangASTContext::eTypeIsPointer) && !type_flags.Test(ClangASTContext::eTypeIsObjC))
Enrico Granata852cce72013-03-23 01:12:38 +00001267 {
1268 // if we are dumping a pointer as a c-string, get the pointee data as a string
1269 TargetSP target_sp(GetTargetSP());
1270 if (target_sp)
1271 {
1272 size_t max_len = target_sp->GetMaximumSizeOfStringSummary();
1273 Error error;
1274 DataBufferSP buffer_sp(new DataBufferHeap(max_len+1,0));
1275 Address address(GetPointerValue());
1276 if (target_sp->ReadCStringFromMemory(address, (char*)buffer_sp->GetBytes(), max_len, error) && error.Success())
1277 special_format_data.SetData(buffer_sp);
1278 }
1279 }
1280 }
1281
Enrico Granata0c489f52012-03-01 04:24:26 +00001282 StreamString sstr;
1283 ExecutionContext exe_ctx (GetExecutionContextRef());
Enrico Granata852cce72013-03-23 01:12:38 +00001284 ClangASTType::DumpTypeValue (ast, // The clang AST
1285 clang_type, // The clang type to display
1286 &sstr, // The stream to use for display
1287 format, // Format to display this type with
1288 special_format_data.GetByteSize() ?
1289 special_format_data: m_data, // Data to extract from
1290 0, // Byte offset into "m_data"
1291 GetByteSize(), // Byte size of item in "m_data"
1292 GetBitfieldBitSize(), // Bitfield bit size
1293 GetBitfieldBitOffset(), // Bitfield bit offset
Enrico Granata0c489f52012-03-01 04:24:26 +00001294 exe_ctx.GetBestExecutionContextScope());
1295 // Don't set the m_error to anything here otherwise
1296 // we won't be able to re-format as anything else. The
1297 // code for ClangASTType::DumpTypeValue() should always
1298 // return something, even if that something contains
1299 // an error messsage. "m_error" is used to detect errors
1300 // when reading the valid object, not for formatting errors.
1301 if (sstr.GetString().empty())
1302 destination.clear();
1303 else
1304 destination.swap(sstr.GetString());
1305 }
1306 }
1307 break;
1308
1309 case Value::eContextTypeRegisterInfo:
1310 {
1311 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1312 if (reg_info)
1313 {
1314 ExecutionContext exe_ctx (GetExecutionContextRef());
1315
1316 StreamString reg_sstr;
1317 m_data.Dump (&reg_sstr,
1318 0,
1319 format,
1320 reg_info->byte_size,
1321 1,
1322 UINT32_MAX,
1323 LLDB_INVALID_ADDRESS,
1324 0,
1325 0,
1326 exe_ctx.GetBestExecutionContextScope());
1327 destination.swap(reg_sstr.GetString());
1328 }
1329 }
1330 break;
1331
1332 default:
1333 break;
1334 }
1335 return !destination.empty();
1336 }
1337 else
1338 return false;
1339}
1340
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001341const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001342ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001343{
Enrico Granata0c489f52012-03-01 04:24:26 +00001344 if (UpdateValueIfNeeded(true) && m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001345 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001346 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001347 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001348 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001349 if (m_type_format_sp)
1350 my_format = m_type_format_sp->GetFormat();
1351 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001352 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001353 if (m_is_bitfield_for_scalar)
1354 my_format = eFormatUnsigned;
1355 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001356 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001357 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001358 {
1359 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1360 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001361 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001362 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001363 else
1364 {
1365 clang_type_t clang_type = GetClangType ();
1366 my_format = ClangASTType::GetFormat(clang_type);
1367 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001368 }
1369 }
1370 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001371 if (GetValueAsCString(my_format, m_value_str))
1372 {
1373 if (!m_value_did_change && m_old_value_valid)
1374 {
1375 // The value was gotten successfully, so we consider the
1376 // value as changed if the value string differs
1377 SetValueDidChange (m_old_value_str != m_value_str);
1378 }
1379 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001380 }
1381 if (m_value_str.empty())
1382 return NULL;
1383 return m_value_str.c_str();
1384}
1385
Enrico Granatac3e320a2011-08-02 17:27:39 +00001386// if > 8bytes, 0 is returned. this method should mostly be used
1387// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001388uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001389ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001390{
1391 // If our byte size is zero this is an aggregate type that has children
1392 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
1393 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001394 Scalar scalar;
1395 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001396 {
1397 if (success)
1398 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001399 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001400 }
1401 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001402 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001403
1404 if (success)
1405 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001406 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001407}
1408
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001409// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1410// this call up to date by returning true for your new special cases. We will eventually move
1411// to checking this call result before trying to display special cases
1412bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001413ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1414 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001415{
1416 clang_type_t elem_or_pointee_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001417 Flags flags(GetTypeInfo(&elem_or_pointee_type));
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001418
1419 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001420 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001421 {
1422 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001423 (custom_format == eFormatCString ||
1424 custom_format == eFormatCharArray ||
1425 custom_format == eFormatChar ||
1426 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001427 return true;
1428
1429 if (flags.Test(ClangASTContext::eTypeIsArray))
1430 {
Greg Claytonafacd142011-09-02 01:15:17 +00001431 if ((custom_format == eFormatBytes) ||
1432 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001433 return true;
1434
Greg Claytonafacd142011-09-02 01:15:17 +00001435 if ((custom_format == eFormatVectorOfChar) ||
1436 (custom_format == eFormatVectorOfFloat32) ||
1437 (custom_format == eFormatVectorOfFloat64) ||
1438 (custom_format == eFormatVectorOfSInt16) ||
1439 (custom_format == eFormatVectorOfSInt32) ||
1440 (custom_format == eFormatVectorOfSInt64) ||
1441 (custom_format == eFormatVectorOfSInt8) ||
1442 (custom_format == eFormatVectorOfUInt128) ||
1443 (custom_format == eFormatVectorOfUInt16) ||
1444 (custom_format == eFormatVectorOfUInt32) ||
1445 (custom_format == eFormatVectorOfUInt64) ||
1446 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001447 return true;
1448 }
1449 }
1450 return false;
1451}
1452
Enrico Granata9fc19442011-07-06 02:13:41 +00001453bool
1454ValueObject::DumpPrintableRepresentation(Stream& s,
1455 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001456 Format custom_format,
Enrico Granata86cc9822012-03-19 22:58:49 +00001457 PrintableRepresentationSpecialCases special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001458{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001459
1460 clang_type_t elem_or_pointee_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001461 Flags flags(GetTypeInfo(&elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001462
Enrico Granata86cc9822012-03-19 22:58:49 +00001463 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1464 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1465
1466 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001467 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001468 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1469 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001470 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001471 // when being asked to get a printable display an array or pointer type directly,
1472 // try to "do the right thing"
1473
1474 if (IsCStringContainer(true) &&
1475 (custom_format == eFormatCString ||
1476 custom_format == eFormatCharArray ||
1477 custom_format == eFormatChar ||
1478 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001479 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001480 Error error;
1481 ReadPointedString(s,
1482 error,
1483 0,
1484 (custom_format == eFormatVectorOfChar) ||
1485 (custom_format == eFormatCharArray));
1486 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001487 }
1488
Enrico Granata86cc9822012-03-19 22:58:49 +00001489 if (custom_format == eFormatEnum)
1490 return false;
1491
1492 // this only works for arrays, because I have no way to know when
1493 // the pointed memory ends, and no special \0 end of data marker
1494 if (flags.Test(ClangASTContext::eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001495 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001496 if ((custom_format == eFormatBytes) ||
1497 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001498 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001499 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001500
1501 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001502 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001503 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001504
1505 if (low)
1506 s << ',';
1507
1508 ValueObjectSP child = GetChildAtIndex(low,true);
1509 if (!child.get())
1510 {
1511 s << "<invalid child>";
1512 continue;
1513 }
1514 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1515 }
1516
1517 s << ']';
1518
1519 return true;
1520 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001521
Enrico Granata86cc9822012-03-19 22:58:49 +00001522 if ((custom_format == eFormatVectorOfChar) ||
1523 (custom_format == eFormatVectorOfFloat32) ||
1524 (custom_format == eFormatVectorOfFloat64) ||
1525 (custom_format == eFormatVectorOfSInt16) ||
1526 (custom_format == eFormatVectorOfSInt32) ||
1527 (custom_format == eFormatVectorOfSInt64) ||
1528 (custom_format == eFormatVectorOfSInt8) ||
1529 (custom_format == eFormatVectorOfUInt128) ||
1530 (custom_format == eFormatVectorOfUInt16) ||
1531 (custom_format == eFormatVectorOfUInt32) ||
1532 (custom_format == eFormatVectorOfUInt64) ||
1533 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1534 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001535 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001536
1537 Format format = FormatManager::GetSingleItemFormat(custom_format);
1538
1539 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001540 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001541 {
1542
1543 if (low)
1544 s << ',';
1545
1546 ValueObjectSP child = GetChildAtIndex(low,true);
1547 if (!child.get())
1548 {
1549 s << "<invalid child>";
1550 continue;
1551 }
1552 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1553 }
1554
1555 s << ']';
1556
1557 return true;
1558 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001559 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001560
1561 if ((custom_format == eFormatBoolean) ||
1562 (custom_format == eFormatBinary) ||
1563 (custom_format == eFormatChar) ||
1564 (custom_format == eFormatCharPrintable) ||
1565 (custom_format == eFormatComplexFloat) ||
1566 (custom_format == eFormatDecimal) ||
1567 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001568 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001569 (custom_format == eFormatFloat) ||
1570 (custom_format == eFormatOctal) ||
1571 (custom_format == eFormatOSType) ||
1572 (custom_format == eFormatUnicode16) ||
1573 (custom_format == eFormatUnicode32) ||
1574 (custom_format == eFormatUnsigned) ||
1575 (custom_format == eFormatPointer) ||
1576 (custom_format == eFormatComplexInteger) ||
1577 (custom_format == eFormatComplex) ||
1578 (custom_format == eFormatDefault)) // use the [] operator
1579 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001580 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001581 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001582
1583 if (only_special)
1584 return false;
1585
Enrico Granata86cc9822012-03-19 22:58:49 +00001586 bool var_success = false;
1587
1588 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001589 const char *cstr = NULL;
1590 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001591
1592 if (custom_format != eFormatInvalid)
1593 SetFormat(custom_format);
1594
1595 switch(val_obj_display)
1596 {
1597 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001598 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001599 break;
1600
1601 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001602 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001603 break;
1604
1605 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001606 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001607 break;
1608
1609 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001610 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001611 break;
1612
1613 case eValueObjectRepresentationStyleChildrenCount:
Greg Claytonc7bece562013-01-25 18:06:21 +00001614 strm.Printf("%zu", GetNumChildren());
1615 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001616 break;
1617
1618 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001619 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001620 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001621 }
1622
Greg Claytonc7bece562013-01-25 18:06:21 +00001623 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001624 {
1625 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001626 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001627 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1628 {
1629 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1630 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001631 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1632 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001633 }
1634 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001635 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001636 }
1637 }
1638
Greg Claytonc7bece562013-01-25 18:06:21 +00001639 if (cstr)
1640 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001641 else
1642 {
1643 if (m_error.Fail())
1644 s.Printf("<%s>", m_error.AsCString());
1645 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1646 s.PutCString("<no summary available>");
1647 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1648 s.PutCString("<no value available>");
1649 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1650 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1651 else
1652 s.PutCString("<no printable representation>");
1653 }
1654
1655 // we should only return false here if we could not do *anything*
1656 // even if we have an error message as output, that's a success
1657 // from our callers' perspective, so return true
1658 var_success = true;
1659
1660 if (custom_format != eFormatInvalid)
1661 SetFormat(eFormatDefault);
1662 }
1663
Enrico Granataf4efecd2011-07-12 22:56:10 +00001664 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001665}
1666
Greg Clayton737b9322010-09-13 03:32:57 +00001667addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001668ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001669{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001670 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001671 return LLDB_INVALID_ADDRESS;
1672
Greg Clayton73b472d2010-10-27 03:32:59 +00001673 switch (m_value.GetValueType())
1674 {
1675 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001676 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001677 if (scalar_is_load_address)
1678 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001679 if(address_type)
1680 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001681 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1682 }
1683 break;
1684
1685 case Value::eValueTypeLoadAddress:
1686 case Value::eValueTypeFileAddress:
1687 case Value::eValueTypeHostAddress:
1688 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001689 if(address_type)
1690 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001691 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1692 }
1693 break;
1694 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001695 if (address_type)
1696 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001697 return LLDB_INVALID_ADDRESS;
1698}
1699
1700addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001701ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001702{
Greg Claytonafacd142011-09-02 01:15:17 +00001703 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001704 if(address_type)
1705 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001706
Enrico Granatac3e320a2011-08-02 17:27:39 +00001707 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001708 return address;
1709
Greg Clayton73b472d2010-10-27 03:32:59 +00001710 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001711 {
1712 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001713 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001714 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001715 break;
1716
Enrico Granata9128ee22011-09-06 19:20:51 +00001717 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001718 case Value::eValueTypeLoadAddress:
1719 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001720 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001721 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001722 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001723 }
1724 break;
1725 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001726
Enrico Granata9128ee22011-09-06 19:20:51 +00001727 if (address_type)
1728 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001729
Greg Clayton737b9322010-09-13 03:32:57 +00001730 return address;
1731}
1732
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001733bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001734ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001735{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001736 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001737 // Make sure our value is up to date first so that our location and location
1738 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001739 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001740 {
1741 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001742 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001743 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001744
Greg Claytonfaac1112013-03-14 18:31:44 +00001745 uint64_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001746 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001747
Greg Claytonb1320972010-07-14 00:18:15 +00001748 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001749
Jim Ingham16e0c682011-08-12 23:34:31 +00001750 Value::ValueType value_type = m_value.GetValueType();
1751
1752 if (value_type == Value::eValueTypeScalar)
1753 {
1754 // If the value is already a scalar, then let the scalar change itself:
1755 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1756 }
1757 else if (byte_size <= Scalar::GetMaxByteSize())
1758 {
1759 // If the value fits in a scalar, then make a new scalar and again let the
1760 // scalar code do the conversion, then figure out where to put the new value.
1761 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001762 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1763 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001764 {
Jim Ingham4b536182011-08-09 02:12:22 +00001765 switch (value_type)
1766 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001767 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001768 {
1769 // If it is a load address, then the scalar value is the storage location
1770 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001771 ExecutionContext exe_ctx (GetExecutionContextRef());
1772 Process *process = exe_ctx.GetProcessPtr();
1773 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001774 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001775 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001776 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1777 new_scalar,
1778 byte_size,
1779 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001780 if (!error.Success())
1781 return false;
1782 if (bytes_written != byte_size)
1783 {
1784 error.SetErrorString("unable to write value to memory");
1785 return false;
1786 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001787 }
1788 }
Jim Ingham4b536182011-08-09 02:12:22 +00001789 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001790 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001791 {
1792 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1793 DataExtractor new_data;
1794 new_data.SetByteOrder (m_data.GetByteOrder());
1795
1796 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1797 m_data.SetData(buffer_sp, 0);
1798 bool success = new_scalar.GetData(new_data);
1799 if (success)
1800 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001801 new_data.CopyByteOrderedData (0,
1802 byte_size,
1803 const_cast<uint8_t *>(m_data.GetDataStart()),
1804 byte_size,
1805 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001806 }
1807 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1808
1809 }
Jim Ingham4b536182011-08-09 02:12:22 +00001810 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001811 case Value::eValueTypeFileAddress:
1812 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001813 case Value::eValueTypeVector:
1814 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001815 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001816 }
1817 else
1818 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001819 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001820 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001821 }
1822 else
1823 {
1824 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001825 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001826 return false;
1827 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001828
1829 // If we have reached this point, then we have successfully changed the value.
1830 SetNeedsUpdate();
1831 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001832}
1833
Greg Clayton81e871e2012-02-04 02:27:34 +00001834bool
1835ValueObject::GetDeclaration (Declaration &decl)
1836{
1837 decl.Clear();
1838 return false;
1839}
1840
Greg Clayton84db9102012-03-26 23:03:23 +00001841ConstString
1842ValueObject::GetTypeName()
1843{
1844 return ClangASTType::GetConstTypeName (GetClangAST(), GetClangType());
1845}
1846
1847ConstString
1848ValueObject::GetQualifiedTypeName()
1849{
1850 return ClangASTType::GetConstQualifiedTypeName (GetClangAST(), GetClangType());
1851}
1852
1853
Greg Claytonafacd142011-09-02 01:15:17 +00001854LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001855ValueObject::GetObjectRuntimeLanguage ()
1856{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001857 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1858 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001859}
1860
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001861void
Jim Ingham58b59f92011-04-22 23:53:53 +00001862ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001863{
Jim Ingham58b59f92011-04-22 23:53:53 +00001864 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001865}
1866
1867ValueObjectSP
1868ValueObject::GetSyntheticChild (const ConstString &key) const
1869{
1870 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001871 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001872 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001873 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001874 return synthetic_child_sp;
1875}
1876
Greg Clayton2452ab72013-02-08 22:02:02 +00001877uint32_t
1878ValueObject::GetTypeInfo (clang_type_t *pointee_or_element_clang_type)
1879{
1880 return ClangASTContext::GetTypeInfo (GetClangType(), GetClangAST(), pointee_or_element_clang_type);
1881}
1882
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001883bool
1884ValueObject::IsPointerType ()
1885{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001886 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001887}
1888
Jim Inghamb7603bb2011-03-18 00:05:18 +00001889bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001890ValueObject::IsArrayType ()
1891{
Greg Clayton4ef877f2012-12-06 02:33:54 +00001892 return ClangASTContext::IsArrayType (GetClangType(), NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00001893}
1894
1895bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001896ValueObject::IsScalarType ()
1897{
1898 return ClangASTContext::IsScalarType (GetClangType());
1899}
1900
1901bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001902ValueObject::IsIntegerType (bool &is_signed)
1903{
1904 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1905}
Greg Clayton73b472d2010-10-27 03:32:59 +00001906
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001907bool
1908ValueObject::IsPointerOrReferenceType ()
1909{
Greg Clayton007d5be2011-05-30 00:49:24 +00001910 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1911}
1912
1913bool
Greg Claytondea8cb42011-06-29 22:09:02 +00001914ValueObject::IsPossibleDynamicType ()
1915{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00001916 ExecutionContext exe_ctx (GetExecutionContextRef());
1917 Process *process = exe_ctx.GetProcessPtr();
1918 if (process)
1919 return process->IsPossibleDynamicValue(*this);
1920 else
Greg Clayton70364252012-08-31 18:56:24 +00001921 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType(), NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00001922}
1923
Enrico Granata9e7b3882012-12-13 23:50:33 +00001924bool
1925ValueObject::IsObjCNil ()
1926{
Enrico Granata7277d202013-03-15 23:33:15 +00001927 const uint32_t mask = ClangASTContext::eTypeIsObjC | ClangASTContext::eTypeIsPointer;
1928 bool isObjCpointer = ( ((ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), NULL)) & mask) == mask);
1929 if (!isObjCpointer)
1930 return false;
Enrico Granata9e7b3882012-12-13 23:50:33 +00001931 bool canReadValue = true;
1932 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
Enrico Granata7277d202013-03-15 23:33:15 +00001933 return canReadValue && isZero;
Enrico Granata9e7b3882012-12-13 23:50:33 +00001934}
1935
Greg Claytonafacd142011-09-02 01:15:17 +00001936ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00001937ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001938{
Greg Clayton2452ab72013-02-08 22:02:02 +00001939 const uint32_t type_info = GetTypeInfo ();
1940 if (type_info & ClangASTContext::eTypeIsArray)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001941 return GetSyntheticArrayMemberFromArray(index, can_create);
1942
Greg Clayton2452ab72013-02-08 22:02:02 +00001943 if (type_info & ClangASTContext::eTypeIsPointer)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001944 return GetSyntheticArrayMemberFromPointer(index, can_create);
1945
1946 return ValueObjectSP();
1947
1948}
1949
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001950ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00001951ValueObject::GetSyntheticArrayMemberFromPointer (size_t index, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001952{
1953 ValueObjectSP synthetic_child_sp;
1954 if (IsPointerType ())
1955 {
1956 char index_str[64];
Greg Claytonc7bece562013-01-25 18:06:21 +00001957 snprintf(index_str, sizeof(index_str), "[%zu]", index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001958 ConstString index_const_str(index_str);
1959 // Check if we have already created a synthetic array member in this
1960 // valid object. If we have we will re-use it.
1961 synthetic_child_sp = GetSyntheticChild (index_const_str);
1962 if (!synthetic_child_sp)
1963 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001964 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001965 // We haven't made a synthetic array member for INDEX yet, so
1966 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001967 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001968
1969 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001970 if (synthetic_child)
1971 {
1972 AddSyntheticChild(index_const_str, synthetic_child);
1973 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001974 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001975 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001976 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001977 }
1978 }
1979 return synthetic_child_sp;
1980}
Jim Ingham22777012010-09-23 02:01:19 +00001981
Greg Claytondaf515f2011-07-09 20:12:33 +00001982// This allows you to create an array member using and index
1983// that doesn't not fall in the normal bounds of the array.
1984// Many times structure can be defined as:
1985// struct Collection
1986// {
1987// uint32_t item_count;
1988// Item item_array[0];
1989// };
1990// The size of the "item_array" is 1, but many times in practice
1991// there are more items in "item_array".
1992
1993ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00001994ValueObject::GetSyntheticArrayMemberFromArray (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00001995{
1996 ValueObjectSP synthetic_child_sp;
1997 if (IsArrayType ())
1998 {
1999 char index_str[64];
Greg Claytonc7bece562013-01-25 18:06:21 +00002000 snprintf(index_str, sizeof(index_str), "[%zu]", index);
Greg Claytondaf515f2011-07-09 20:12:33 +00002001 ConstString index_const_str(index_str);
2002 // Check if we have already created a synthetic array member in this
2003 // valid object. If we have we will re-use it.
2004 synthetic_child_sp = GetSyntheticChild (index_const_str);
2005 if (!synthetic_child_sp)
2006 {
2007 ValueObject *synthetic_child;
2008 // We haven't made a synthetic array member for INDEX yet, so
2009 // lets make one and cache it for any future reference.
2010 synthetic_child = CreateChildAtIndex(0, true, index);
2011
2012 // Cache the value if we got one back...
2013 if (synthetic_child)
2014 {
2015 AddSyntheticChild(index_const_str, synthetic_child);
2016 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002017 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00002018 synthetic_child_sp->m_is_array_item_for_pointer = true;
2019 }
2020 }
2021 }
2022 return synthetic_child_sp;
2023}
2024
Enrico Granata9fc19442011-07-06 02:13:41 +00002025ValueObjectSP
2026ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2027{
2028 ValueObjectSP synthetic_child_sp;
2029 if (IsScalarType ())
2030 {
2031 char index_str[64];
2032 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2033 ConstString index_const_str(index_str);
2034 // Check if we have already created a synthetic array member in this
2035 // valid object. If we have we will re-use it.
2036 synthetic_child_sp = GetSyntheticChild (index_const_str);
2037 if (!synthetic_child_sp)
2038 {
2039 ValueObjectChild *synthetic_child;
2040 // We haven't made a synthetic array member for INDEX yet, so
2041 // lets make one and cache it for any future reference.
2042 synthetic_child = new ValueObjectChild(*this,
2043 GetClangAST(),
2044 GetClangType(),
2045 index_const_str,
2046 GetByteSize(),
2047 0,
2048 to-from+1,
2049 from,
2050 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002051 false,
2052 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002053
2054 // Cache the value if we got one back...
2055 if (synthetic_child)
2056 {
2057 AddSyntheticChild(index_const_str, synthetic_child);
2058 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002059 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002060 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2061 }
2062 }
2063 }
2064 return synthetic_child_sp;
2065}
2066
Greg Claytonafacd142011-09-02 01:15:17 +00002067ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00002068ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
2069{
2070
2071 ValueObjectSP synthetic_child_sp;
2072
2073 char name_str[64];
2074 snprintf(name_str, sizeof(name_str), "@%i", offset);
2075 ConstString name_const_str(name_str);
2076
2077 // Check if we have already created a synthetic array member in this
2078 // valid object. If we have we will re-use it.
2079 synthetic_child_sp = GetSyntheticChild (name_const_str);
2080
2081 if (synthetic_child_sp.get())
2082 return synthetic_child_sp;
2083
2084 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002085 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002086
2087 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2088 type.GetASTContext(),
2089 type.GetOpaqueQualType(),
2090 name_const_str,
2091 type.GetTypeByteSize(),
2092 offset,
2093 0,
2094 0,
2095 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002096 false,
2097 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002098 if (synthetic_child)
2099 {
2100 AddSyntheticChild(name_const_str, synthetic_child);
2101 synthetic_child_sp = synthetic_child->GetSP();
2102 synthetic_child_sp->SetName(name_const_str);
2103 synthetic_child_sp->m_is_child_at_offset = true;
2104 }
2105 return synthetic_child_sp;
2106}
2107
Enrico Granatad55546b2011-07-22 00:16:08 +00002108// your expression path needs to have a leading . or ->
2109// (unless it somehow "looks like" an array, in which case it has
2110// a leading [ symbol). while the [ is meaningful and should be shown
2111// to the user, . and -> are just parser design, but by no means
2112// added information for the user.. strip them off
2113static const char*
2114SkipLeadingExpressionPathSeparators(const char* expression)
2115{
2116 if (!expression || !expression[0])
2117 return expression;
2118 if (expression[0] == '.')
2119 return expression+1;
2120 if (expression[0] == '-' && expression[1] == '>')
2121 return expression+2;
2122 return expression;
2123}
2124
Greg Claytonafacd142011-09-02 01:15:17 +00002125ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002126ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2127{
2128 ValueObjectSP synthetic_child_sp;
2129 ConstString name_const_string(expression);
2130 // Check if we have already created a synthetic array member in this
2131 // valid object. If we have we will re-use it.
2132 synthetic_child_sp = GetSyntheticChild (name_const_string);
2133 if (!synthetic_child_sp)
2134 {
2135 // We haven't made a synthetic array member for expression yet, so
2136 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002137 synthetic_child_sp = GetValueForExpressionPath(expression,
2138 NULL, NULL, NULL,
2139 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
Enrico Granatad55546b2011-07-22 00:16:08 +00002140
2141 // Cache the value if we got one back...
2142 if (synthetic_child_sp.get())
2143 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002144 // FIXME: this causes a "real" child to end up with its name changed to the contents of expression
Enrico Granatad55546b2011-07-22 00:16:08 +00002145 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002146 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002147 }
2148 }
2149 return synthetic_child_sp;
2150}
2151
2152void
Enrico Granata86cc9822012-03-19 22:58:49 +00002153ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002154{
Enrico Granata86cc9822012-03-19 22:58:49 +00002155 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002156 return;
2157
Enrico Granatac5bc4122012-03-27 02:35:13 +00002158 TargetSP target_sp(GetTargetSP());
2159 if (target_sp && (target_sp->GetEnableSyntheticValue() == false || target_sp->GetSuppressSyntheticValue() == true))
2160 {
2161 m_synthetic_value = NULL;
2162 return;
2163 }
2164
Enrico Granatae3e91512012-10-22 18:18:36 +00002165 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2166
Enrico Granata5548cb52013-01-28 23:47:25 +00002167 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002168 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002169
Enrico Granata0c489f52012-03-01 04:24:26 +00002170 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002171 return;
2172
Enrico Granatae3e91512012-10-22 18:18:36 +00002173 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2174 return;
2175
Enrico Granata86cc9822012-03-19 22:58:49 +00002176 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002177}
2178
Jim Ingham78a685a2011-04-16 00:01:13 +00002179void
Greg Claytonafacd142011-09-02 01:15:17 +00002180ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002181{
Greg Claytonafacd142011-09-02 01:15:17 +00002182 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002183 return;
2184
Jim Ingham58b59f92011-04-22 23:53:53 +00002185 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002186 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002187 ExecutionContext exe_ctx (GetExecutionContextRef());
2188 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002189 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002190 {
2191 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002192 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002193 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002194 }
2195}
2196
Jim Ingham58b59f92011-04-22 23:53:53 +00002197ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002198ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002199{
Greg Claytonafacd142011-09-02 01:15:17 +00002200 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002201 return ValueObjectSP();
2202
2203 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002204 {
Jim Ingham2837b762011-05-04 03:43:18 +00002205 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002206 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002207 if (m_dynamic_value)
2208 return m_dynamic_value->GetSP();
2209 else
2210 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002211}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002212
Jim Ingham60dbabb2011-12-08 19:44:08 +00002213ValueObjectSP
2214ValueObject::GetStaticValue()
2215{
2216 return GetSP();
2217}
2218
Enrico Granata886147f2012-05-08 18:47:08 +00002219lldb::ValueObjectSP
2220ValueObject::GetNonSyntheticValue ()
2221{
2222 return GetSP();
2223}
2224
Enrico Granatad55546b2011-07-22 00:16:08 +00002225ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002226ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002227{
Enrico Granata86cc9822012-03-19 22:58:49 +00002228 if (use_synthetic == false)
2229 return ValueObjectSP();
2230
Enrico Granatad55546b2011-07-22 00:16:08 +00002231 CalculateSyntheticValue(use_synthetic);
2232
2233 if (m_synthetic_value)
2234 return m_synthetic_value->GetSP();
2235 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002236 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002237}
2238
Greg Claytone221f822011-01-21 01:59:00 +00002239bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002240ValueObject::HasSyntheticValue()
2241{
Enrico Granata5548cb52013-01-28 23:47:25 +00002242 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002243
Enrico Granata0c489f52012-03-01 04:24:26 +00002244 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002245 return false;
2246
Enrico Granata86cc9822012-03-19 22:58:49 +00002247 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002248
2249 if (m_synthetic_value)
2250 return true;
2251 else
2252 return false;
2253}
2254
2255bool
Greg Claytone221f822011-01-21 01:59:00 +00002256ValueObject::GetBaseClassPath (Stream &s)
2257{
2258 if (IsBaseClass())
2259 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002260 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00002261 clang_type_t clang_type = GetClangType();
2262 std::string cxx_class_name;
2263 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
2264 if (this_had_base_class)
2265 {
2266 if (parent_had_base_class)
2267 s.PutCString("::");
2268 s.PutCString(cxx_class_name.c_str());
2269 }
2270 return parent_had_base_class || this_had_base_class;
2271 }
2272 return false;
2273}
2274
2275
2276ValueObject *
2277ValueObject::GetNonBaseClassParent()
2278{
Jim Ingham78a685a2011-04-16 00:01:13 +00002279 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002280 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002281 if (GetParent()->IsBaseClass())
2282 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002283 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002284 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002285 }
2286 return NULL;
2287}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002288
2289void
Enrico Granata4becb372011-06-29 22:27:15 +00002290ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002291{
Greg Claytone221f822011-01-21 01:59:00 +00002292 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002293
Enrico Granata86cc9822012-03-19 22:58:49 +00002294 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002295 {
Enrico Granata4becb372011-06-29 22:27:15 +00002296 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2297 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2298 // the eHonorPointers mode is meant to produce strings in this latter format
2299 s.PutCString("*(");
2300 }
Greg Claytone221f822011-01-21 01:59:00 +00002301
Enrico Granata4becb372011-06-29 22:27:15 +00002302 ValueObject* parent = GetParent();
2303
2304 if (parent)
2305 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002306
2307 // if we are a deref_of_parent just because we are synthetic array
2308 // members made up to allow ptr[%d] syntax to work in variable
2309 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002310 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002311 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002312
Greg Claytone221f822011-01-21 01:59:00 +00002313 if (!IsBaseClass())
2314 {
2315 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002316 {
Greg Claytone221f822011-01-21 01:59:00 +00002317 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2318 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002319 {
Greg Claytone221f822011-01-21 01:59:00 +00002320 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2321 if (non_base_class_parent_clang_type)
2322 {
2323 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2324
Enrico Granata86cc9822012-03-19 22:58:49 +00002325 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002326 {
2327 s.PutCString("->");
2328 }
Enrico Granata4becb372011-06-29 22:27:15 +00002329 else
2330 {
2331 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2332 {
2333 s.PutCString("->");
2334 }
2335 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2336 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2337 {
2338 s.PutChar('.');
2339 }
Greg Claytone221f822011-01-21 01:59:00 +00002340 }
2341 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002342 }
Greg Claytone221f822011-01-21 01:59:00 +00002343
2344 const char *name = GetName().GetCString();
2345 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002346 {
Greg Claytone221f822011-01-21 01:59:00 +00002347 if (qualify_cxx_base_classes)
2348 {
2349 if (GetBaseClassPath (s))
2350 s.PutCString("::");
2351 }
2352 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002353 }
2354 }
2355 }
2356
Enrico Granata86cc9822012-03-19 22:58:49 +00002357 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002358 {
Greg Claytone221f822011-01-21 01:59:00 +00002359 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002360 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002361}
2362
Greg Claytonafacd142011-09-02 01:15:17 +00002363ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002364ValueObject::GetValueForExpressionPath(const char* expression,
2365 const char** first_unparsed,
2366 ExpressionPathScanEndReason* reason_to_stop,
2367 ExpressionPathEndResultType* final_value_type,
2368 const GetValueForExpressionPathOptions& options,
2369 ExpressionPathAftermath* final_task_on_target)
2370{
2371
2372 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002373 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2374 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002375 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002376
2377 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2378 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2379 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2380 final_value_type ? final_value_type : &dummy_final_value_type,
2381 options,
2382 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2383
Enrico Granata86cc9822012-03-19 22:58:49 +00002384 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002385 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002386
Enrico Granata86cc9822012-03-19 22:58:49 +00002387 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 +00002388 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002389 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002390 {
2391 Error error;
2392 ValueObjectSP final_value = ret_val->Dereference(error);
2393 if (error.Fail() || !final_value.get())
2394 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002395 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002396 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002397 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002398 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002399 return ValueObjectSP();
2400 }
2401 else
2402 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002403 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002404 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002405 return final_value;
2406 }
2407 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002408 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002409 {
2410 Error error;
2411 ValueObjectSP final_value = ret_val->AddressOf(error);
2412 if (error.Fail() || !final_value.get())
2413 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002414 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002415 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002416 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002417 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002418 return ValueObjectSP();
2419 }
2420 else
2421 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002422 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002423 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002424 return final_value;
2425 }
2426 }
2427 }
2428 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2429}
2430
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002431int
2432ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002433 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002434 const char** first_unparsed,
2435 ExpressionPathScanEndReason* reason_to_stop,
2436 ExpressionPathEndResultType* final_value_type,
2437 const GetValueForExpressionPathOptions& options,
2438 ExpressionPathAftermath* final_task_on_target)
2439{
2440 const char* dummy_first_unparsed;
2441 ExpressionPathScanEndReason dummy_reason_to_stop;
2442 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002443 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002444
2445 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2446 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2447 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2448 final_value_type ? final_value_type : &dummy_final_value_type,
2449 options,
2450 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2451
2452 if (!ret_val.get()) // if there are errors, I add nothing to the list
2453 return 0;
2454
Enrico Granata86ea8d82012-03-29 01:34:34 +00002455 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002456 {
2457 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002458 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002459 {
2460 list->Append(ret_val);
2461 return 1;
2462 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002463 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 +00002464 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002465 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002466 {
2467 Error error;
2468 ValueObjectSP final_value = ret_val->Dereference(error);
2469 if (error.Fail() || !final_value.get())
2470 {
Greg Clayton23f59502012-07-17 03:23:13 +00002471 if (reason_to_stop)
2472 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2473 if (final_value_type)
2474 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002475 return 0;
2476 }
2477 else
2478 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002479 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002480 list->Append(final_value);
2481 return 1;
2482 }
2483 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002484 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002485 {
2486 Error error;
2487 ValueObjectSP final_value = ret_val->AddressOf(error);
2488 if (error.Fail() || !final_value.get())
2489 {
Greg Clayton23f59502012-07-17 03:23:13 +00002490 if (reason_to_stop)
2491 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2492 if (final_value_type)
2493 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002494 return 0;
2495 }
2496 else
2497 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002498 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002499 list->Append(final_value);
2500 return 1;
2501 }
2502 }
2503 }
2504 }
2505 else
2506 {
2507 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2508 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2509 ret_val,
2510 list,
2511 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2512 final_value_type ? final_value_type : &dummy_final_value_type,
2513 options,
2514 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2515 }
2516 // in any non-covered case, just do the obviously right thing
2517 list->Append(ret_val);
2518 return 1;
2519}
2520
Greg Claytonafacd142011-09-02 01:15:17 +00002521ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002522ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2523 const char** first_unparsed,
2524 ExpressionPathScanEndReason* reason_to_stop,
2525 ExpressionPathEndResultType* final_result,
2526 const GetValueForExpressionPathOptions& options,
2527 ExpressionPathAftermath* what_next)
2528{
2529 ValueObjectSP root = GetSP();
2530
2531 if (!root.get())
2532 return ValueObjectSP();
2533
2534 *first_unparsed = expression_cstr;
2535
2536 while (true)
2537 {
2538
2539 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2540
Greg Claytonafacd142011-09-02 01:15:17 +00002541 clang_type_t root_clang_type = root->GetClangType();
2542 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002543 Flags root_clang_type_info,pointee_clang_type_info;
2544
2545 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2546 if (pointee_clang_type)
2547 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002548
2549 if (!expression_cstr || *expression_cstr == '\0')
2550 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002551 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002552 return root;
2553 }
2554
2555 switch (*expression_cstr)
2556 {
2557 case '-':
2558 {
2559 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002560 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 +00002561 {
2562 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002563 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2564 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002565 return ValueObjectSP();
2566 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002567 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2568 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002569 options.m_no_fragile_ivar)
2570 {
2571 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002572 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2573 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002574 return ValueObjectSP();
2575 }
2576 if (expression_cstr[1] != '>')
2577 {
2578 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002579 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2580 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002581 return ValueObjectSP();
2582 }
2583 expression_cstr++; // skip the -
2584 }
2585 case '.': // or fallthrough from ->
2586 {
2587 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002588 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 +00002589 {
2590 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002591 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2592 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002593 return ValueObjectSP();
2594 }
2595 expression_cstr++; // skip .
2596 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2597 ConstString child_name;
2598 if (!next_separator) // if no other separator just expand this last layer
2599 {
2600 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002601 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2602
2603 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002604 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002605 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002606 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2607 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002608 return child_valobj_sp;
2609 }
2610 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2611 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002612 if (root->IsSynthetic())
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002613 {
2614 *first_unparsed = expression_cstr;
2615 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2616 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2617 return ValueObjectSP();
2618 }
2619
2620 child_valobj_sp = root->GetSyntheticValue();
Enrico Granata86cc9822012-03-19 22:58:49 +00002621 if (child_valobj_sp.get())
2622 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002623 }
2624
2625 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2626 // so we hit the "else" branch, and return an error
2627 if(child_valobj_sp.get()) // if it worked, just return
2628 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002629 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002630 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2631 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002632 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002633 }
2634 else
2635 {
2636 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002637 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2638 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002639 return ValueObjectSP();
2640 }
2641 }
2642 else // other layers do expand
2643 {
2644 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002645 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2646 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002647 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002648 root = child_valobj_sp;
2649 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002650 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002651 continue;
2652 }
2653 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2654 {
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002655 if (root->IsSynthetic())
2656 {
2657 *first_unparsed = expression_cstr;
2658 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2659 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2660 return ValueObjectSP();
2661 }
2662
Enrico Granata86cc9822012-03-19 22:58:49 +00002663 child_valobj_sp = root->GetSyntheticValue(true);
2664 if (child_valobj_sp)
2665 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002666 }
2667
2668 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2669 // so we hit the "else" branch, and return an error
2670 if(child_valobj_sp.get()) // if it worked, move on
2671 {
2672 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002673 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002674 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002675 continue;
2676 }
2677 else
2678 {
2679 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002680 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2681 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002682 return ValueObjectSP();
2683 }
2684 }
2685 break;
2686 }
2687 case '[':
2688 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002689 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 +00002690 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002691 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002692 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002693 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2694 {
2695 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002696 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2697 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002698 return ValueObjectSP();
2699 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002700 }
2701 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2702 {
2703 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002704 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2705 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002706 return ValueObjectSP();
2707 }
2708 }
2709 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2710 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002711 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002712 {
2713 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002714 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2715 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002716 return ValueObjectSP();
2717 }
2718 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2719 {
2720 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002721 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2722 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002723 return root;
2724 }
2725 }
2726 const char *separator_position = ::strchr(expression_cstr+1,'-');
2727 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2728 if (!close_bracket_position) // if there is no ], this is a syntax error
2729 {
2730 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002731 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2732 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002733 return ValueObjectSP();
2734 }
2735 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2736 {
2737 char *end = NULL;
2738 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2739 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2740 {
2741 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002742 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2743 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002744 return ValueObjectSP();
2745 }
2746 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2747 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002748 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002749 {
2750 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002751 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2752 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002753 return root;
2754 }
2755 else
2756 {
2757 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002758 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2759 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002760 return ValueObjectSP();
2761 }
2762 }
2763 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002764 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002765 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002766 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2767 if (!child_valobj_sp)
2768 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002769 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002770 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2771 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002772 if (child_valobj_sp)
2773 {
2774 root = child_valobj_sp;
2775 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002776 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002777 continue;
2778 }
2779 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002780 {
2781 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002782 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2783 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002784 return ValueObjectSP();
2785 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002786 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002787 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002788 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002789 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 +00002790 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002791 {
2792 Error error;
2793 root = root->Dereference(error);
2794 if (error.Fail() || !root.get())
2795 {
2796 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002797 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2798 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002799 return ValueObjectSP();
2800 }
2801 else
2802 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002803 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002804 continue;
2805 }
2806 }
2807 else
2808 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002809 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Clayton84db9102012-03-26 23:03:23 +00002810 root->GetClangType()) == eLanguageTypeObjC
2811 && ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2812 && root->HasSyntheticValue()
2813 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002814 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002815 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002816 }
2817 else
2818 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002819 if (!root.get())
2820 {
2821 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002822 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2823 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002824 return ValueObjectSP();
2825 }
2826 else
2827 {
2828 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002829 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002830 continue;
2831 }
2832 }
2833 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002834 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002835 {
2836 root = root->GetSyntheticBitFieldChild(index, index, true);
2837 if (!root.get())
2838 {
2839 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002840 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2841 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002842 return ValueObjectSP();
2843 }
2844 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2845 {
2846 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002847 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2848 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002849 return root;
2850 }
2851 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002852 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002853 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002854 if (root->HasSyntheticValue())
2855 root = root->GetSyntheticValue();
2856 else if (!root->IsSynthetic())
2857 {
2858 *first_unparsed = expression_cstr;
2859 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2860 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2861 return ValueObjectSP();
2862 }
2863 // if we are here, then root itself is a synthetic VO.. should be good to go
2864
Enrico Granata27b625e2011-08-09 01:04:56 +00002865 if (!root.get())
2866 {
2867 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002868 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2869 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2870 return ValueObjectSP();
2871 }
2872 root = root->GetChildAtIndex(index, true);
2873 if (!root.get())
2874 {
2875 *first_unparsed = expression_cstr;
2876 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2877 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002878 return ValueObjectSP();
2879 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002880 else
2881 {
2882 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002883 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002884 continue;
2885 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002886 }
2887 else
2888 {
2889 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002890 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2891 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002892 return ValueObjectSP();
2893 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002894 }
2895 else // we have a low and a high index
2896 {
2897 char *end = NULL;
2898 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2899 if (!end || end != separator_position) // if something weird is in our way return an error
2900 {
2901 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002902 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2903 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002904 return ValueObjectSP();
2905 }
2906 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2907 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2908 {
2909 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002910 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2911 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002912 return ValueObjectSP();
2913 }
2914 if (index_lower > index_higher) // swap indices if required
2915 {
2916 unsigned long temp = index_lower;
2917 index_lower = index_higher;
2918 index_higher = temp;
2919 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002920 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002921 {
2922 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2923 if (!root.get())
2924 {
2925 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002926 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2927 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002928 return ValueObjectSP();
2929 }
2930 else
2931 {
2932 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002933 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2934 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002935 return root;
2936 }
2937 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002938 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 +00002939 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002940 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002941 {
2942 Error error;
2943 root = root->Dereference(error);
2944 if (error.Fail() || !root.get())
2945 {
2946 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002947 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2948 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002949 return ValueObjectSP();
2950 }
2951 else
2952 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002953 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002954 continue;
2955 }
2956 }
2957 else
2958 {
2959 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002960 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2961 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002962 return root;
2963 }
2964 }
2965 break;
2966 }
2967 default: // some non-separator is in the way
2968 {
2969 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002970 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2971 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002972 return ValueObjectSP();
2973 break;
2974 }
2975 }
2976 }
2977}
2978
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002979int
2980ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2981 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002982 ValueObjectSP root,
2983 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002984 ExpressionPathScanEndReason* reason_to_stop,
2985 ExpressionPathEndResultType* final_result,
2986 const GetValueForExpressionPathOptions& options,
2987 ExpressionPathAftermath* what_next)
2988{
2989 if (!root.get())
2990 return 0;
2991
2992 *first_unparsed = expression_cstr;
2993
2994 while (true)
2995 {
2996
2997 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2998
Greg Claytonafacd142011-09-02 01:15:17 +00002999 clang_type_t root_clang_type = root->GetClangType();
3000 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003001 Flags root_clang_type_info,pointee_clang_type_info;
3002
3003 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
3004 if (pointee_clang_type)
3005 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
3006
3007 if (!expression_cstr || *expression_cstr == '\0')
3008 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003009 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003010 list->Append(root);
3011 return 1;
3012 }
3013
3014 switch (*expression_cstr)
3015 {
3016 case '[':
3017 {
3018 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
3019 {
3020 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
3021 {
3022 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003023 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3024 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003025 return 0;
3026 }
3027 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3028 {
3029 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003030 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3031 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003032 return 0;
3033 }
3034 }
3035 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3036 {
3037 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3038 {
3039 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003040 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3041 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003042 return 0;
3043 }
3044 else // expand this into list
3045 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003046 const size_t max_index = root->GetNumChildren() - 1;
3047 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003048 {
3049 ValueObjectSP child =
3050 root->GetChildAtIndex(index, true);
3051 list->Append(child);
3052 }
3053 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003054 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3055 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003056 return max_index; // tell me number of items I added to the VOList
3057 }
3058 }
3059 const char *separator_position = ::strchr(expression_cstr+1,'-');
3060 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3061 if (!close_bracket_position) // if there is no ], this is a syntax error
3062 {
3063 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003064 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3065 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003066 return 0;
3067 }
3068 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3069 {
3070 char *end = NULL;
3071 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3072 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3073 {
3074 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003075 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3076 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003077 return 0;
3078 }
3079 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3080 {
3081 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3082 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003083 const size_t max_index = root->GetNumChildren() - 1;
3084 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003085 {
3086 ValueObjectSP child =
3087 root->GetChildAtIndex(index, true);
3088 list->Append(child);
3089 }
3090 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003091 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3092 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003093 return max_index; // tell me number of items I added to the VOList
3094 }
3095 else
3096 {
3097 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003098 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3099 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003100 return 0;
3101 }
3102 }
3103 // from here on we do have a valid index
3104 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
3105 {
3106 root = root->GetChildAtIndex(index, true);
3107 if (!root.get())
3108 {
3109 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003110 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3111 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003112 return 0;
3113 }
3114 else
3115 {
3116 list->Append(root);
3117 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003118 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3119 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003120 return 1;
3121 }
3122 }
3123 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
3124 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003125 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 +00003126 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3127 {
3128 Error error;
3129 root = root->Dereference(error);
3130 if (error.Fail() || !root.get())
3131 {
3132 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003133 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3134 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003135 return 0;
3136 }
3137 else
3138 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003139 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003140 continue;
3141 }
3142 }
3143 else
3144 {
3145 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3146 if (!root.get())
3147 {
3148 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003149 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3150 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003151 return 0;
3152 }
3153 else
3154 {
3155 list->Append(root);
3156 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003157 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3158 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003159 return 1;
3160 }
3161 }
3162 }
3163 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3164 {
3165 root = root->GetSyntheticBitFieldChild(index, index, true);
3166 if (!root.get())
3167 {
3168 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003169 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3170 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003171 return 0;
3172 }
3173 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3174 {
3175 list->Append(root);
3176 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003177 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3178 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003179 return 1;
3180 }
3181 }
3182 }
3183 else // we have a low and a high index
3184 {
3185 char *end = NULL;
3186 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3187 if (!end || end != separator_position) // if something weird is in our way return an error
3188 {
3189 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003190 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3191 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003192 return 0;
3193 }
3194 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3195 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3196 {
3197 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003198 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3199 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003200 return 0;
3201 }
3202 if (index_lower > index_higher) // swap indices if required
3203 {
3204 unsigned long temp = index_lower;
3205 index_lower = index_higher;
3206 index_higher = temp;
3207 }
3208 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
3209 {
3210 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3211 if (!root.get())
3212 {
3213 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003214 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3215 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003216 return 0;
3217 }
3218 else
3219 {
3220 list->Append(root);
3221 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003222 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3223 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003224 return 1;
3225 }
3226 }
3227 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 +00003228 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003229 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3230 {
3231 Error error;
3232 root = root->Dereference(error);
3233 if (error.Fail() || !root.get())
3234 {
3235 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003236 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3237 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003238 return 0;
3239 }
3240 else
3241 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003242 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003243 continue;
3244 }
3245 }
3246 else
3247 {
Johnny Chen44805302011-07-19 19:48:13 +00003248 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003249 index <= index_higher; index++)
3250 {
3251 ValueObjectSP child =
3252 root->GetChildAtIndex(index, true);
3253 list->Append(child);
3254 }
3255 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003256 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3257 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003258 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3259 }
3260 }
3261 break;
3262 }
3263 default: // some non-[ separator, or something entirely wrong, is in the way
3264 {
3265 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003266 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3267 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003268 return 0;
3269 break;
3270 }
3271 }
3272 }
3273}
3274
Enrico Granata0c489f52012-03-01 04:24:26 +00003275static void
3276DumpValueObject_Impl (Stream &s,
3277 ValueObject *valobj,
3278 const ValueObject::DumpValueObjectOptions& options,
3279 uint32_t ptr_depth,
3280 uint32_t curr_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003281{
Greg Clayton007d5be2011-05-30 00:49:24 +00003282 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003283 {
Enrico Granata5548cb52013-01-28 23:47:25 +00003284 bool update_success = valobj->UpdateValueIfNeeded (true);
Greg Clayton007d5be2011-05-30 00:49:24 +00003285
Enrico Granata0c489f52012-03-01 04:24:26 +00003286 const char *root_valobj_name =
3287 options.m_root_valobj_name.empty() ?
3288 valobj->GetName().AsCString() :
3289 options.m_root_valobj_name.c_str();
3290
3291 if (update_success && options.m_use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00003292 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003293 ValueObject *dynamic_value = valobj->GetDynamicValue(options.m_use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003294 if (dynamic_value)
3295 valobj = dynamic_value;
3296 }
3297
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003298 clang_type_t clang_type = valobj->GetClangType();
3299
Greg Clayton73b472d2010-10-27 03:32:59 +00003300 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003301 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00003302 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
3303 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003304
Enrico Granata0c489f52012-03-01 04:24:26 +00003305 const bool print_valobj = options.m_flat_output == false || has_value;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003306
3307 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003308 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003309 if (options.m_show_location)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003310 {
Jim Ingham6035b672011-03-31 00:19:25 +00003311 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003312 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003313
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003314 s.Indent();
Enrico Granata2b2631c2012-08-09 16:51:25 +00003315
3316 bool show_type = true;
3317 // if we are at the root-level and been asked to hide the root's type, then hide it
3318 if (curr_depth == 0 && options.m_hide_root_type)
3319 show_type = false;
3320 else
3321 // otherwise decide according to the usual rules (asked to show types - always at the root level)
3322 show_type = options.m_show_types || (curr_depth == 0 && !options.m_flat_output);
3323
3324 if (show_type)
Enrico Granataf7b1a342013-01-23 01:17:27 +00003325 s.Printf("(%s) ", valobj->GetQualifiedTypeName().AsCString("<invalid type>"));
Greg Clayton1d3afba2010-10-05 00:00:42 +00003326
Enrico Granata0c489f52012-03-01 04:24:26 +00003327 if (options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003328 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003329 // If we are showing types, also qualify the C++ base classes
Enrico Granata0c489f52012-03-01 04:24:26 +00003330 const bool qualify_cxx_base_classes = options.m_show_types;
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003331 if (!options.m_hide_name)
3332 {
3333 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
3334 s.PutCString(" =");
3335 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003336 }
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003337 else if (!options.m_hide_name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003338 {
3339 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3340 s.Printf ("%s =", name_cstr);
3341 }
3342
Enrico Granata0c489f52012-03-01 04:24:26 +00003343 if (!options.m_scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003344 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003345 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003346 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003347 }
3348
Enrico Granata0c489f52012-03-01 04:24:26 +00003349 std::string summary_str;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003350 std::string value_str;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003351 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003352 const char *sum_cstr = NULL;
Enrico Granata0c489f52012-03-01 04:24:26 +00003353 TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003354
Enrico Granata0c489f52012-03-01 04:24:26 +00003355 if (options.m_omit_summary_depth > 0)
Enrico Granata0c5ef692011-07-16 01:22:04 +00003356 entry = NULL;
3357
Enrico Granata9e7b3882012-12-13 23:50:33 +00003358 bool is_nil = valobj->IsObjCNil();
3359
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003360 if (err_cstr == NULL)
3361 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003362 if (options.m_format != eFormatDefault && options.m_format != valobj->GetFormat())
Greg Clayton6efba4f2012-01-26 21:08:30 +00003363 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003364 valobj->GetValueAsCString(options.m_format,
3365 value_str);
Greg Clayton6efba4f2012-01-26 21:08:30 +00003366 }
Enrico Granata0c489f52012-03-01 04:24:26 +00003367 else
Greg Clayton6efba4f2012-01-26 21:08:30 +00003368 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003369 val_cstr = valobj->GetValueAsCString();
3370 if (val_cstr)
3371 value_str = val_cstr;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003372 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003373 err_cstr = valobj->GetError().AsCString();
3374 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003375
3376 if (err_cstr)
3377 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003378 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003379 }
3380 else
3381 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003382 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003383 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003384 {
Enrico Granata9e7b3882012-12-13 23:50:33 +00003385 if (is_nil)
3386 sum_cstr = "nil";
3387 else if (options.m_omit_summary_depth == 0)
Enrico Granata0c489f52012-03-01 04:24:26 +00003388 {
3389 if (options.m_summary_sp)
3390 {
3391 valobj->GetSummaryAsCString(entry, summary_str);
3392 sum_cstr = summary_str.c_str();
3393 }
3394 else
3395 sum_cstr = valobj->GetSummaryAsCString();
3396 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003397
Greg Clayton6efba4f2012-01-26 21:08:30 +00003398 // Make sure we have a value and make sure the summary didn't
Enrico Granata9e7b3882012-12-13 23:50:33 +00003399 // specify that the value should not be printed - and do not print
3400 // the value if this thing is nil
Enrico Granatac2a58d72013-03-25 19:46:48 +00003401 // (but show the value if the user passes a format explicitly)
3402 if (!is_nil && !value_str.empty() && (entry == NULL || (entry->DoesPrintValue() || options.m_format != eFormatDefault) || sum_cstr == NULL) && !options.m_hide_value)
Greg Clayton6efba4f2012-01-26 21:08:30 +00003403 s.Printf(" %s", value_str.c_str());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003404
Enrico Granata9dd75c82011-07-15 23:30:15 +00003405 if (sum_cstr)
Enrico Granata0c489f52012-03-01 04:24:26 +00003406 s.Printf(" %s", sum_cstr);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003407
Enrico Granata9e7b3882012-12-13 23:50:33 +00003408 // let's avoid the overly verbose no description error for a nil thing
3409 if (options.m_use_objc && !is_nil)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003410 {
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003411 if (!options.m_hide_value || !options.m_hide_name)
3412 s.Printf(" ");
Jim Ingham6035b672011-03-31 00:19:25 +00003413 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003414 if (object_desc)
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003415 s.Printf("%s\n", object_desc);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003416 else
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003417 s.Printf ("[no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003418 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003419 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003420 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003421
Enrico Granata0c489f52012-03-01 04:24:26 +00003422 if (curr_depth < options.m_max_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003423 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003424 // We will show children for all concrete types. We won't show
3425 // pointer contents unless a pointer depth has been specified.
3426 // We won't reference contents unless the reference is the
3427 // root object (depth of zero).
3428 bool print_children = true;
3429
3430 // Use a new temporary pointer depth in case we override the
3431 // current pointer depth below...
3432 uint32_t curr_ptr_depth = ptr_depth;
3433
3434 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3435 if (is_ptr || is_ref)
3436 {
3437 // We have a pointer or reference whose value is an address.
3438 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003439 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003440 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003441 print_children = false;
3442
3443 else if (is_ref && curr_depth == 0)
3444 {
3445 // If this is the root object (depth is zero) that we are showing
3446 // and it is a reference, and no pointer depth has been supplied
3447 // print out what it references. Don't do this at deeper depths
3448 // otherwise we can end up with infinite recursion...
3449 curr_ptr_depth = 1;
3450 }
3451
3452 if (curr_ptr_depth == 0)
3453 print_children = false;
3454 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003455
Enrico Granata0a3958e2011-07-02 00:25:22 +00003456 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003457 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003458 ValueObject* synth_valobj;
3459 ValueObjectSP synth_valobj_sp = valobj->GetSyntheticValue (options.m_use_synthetic);
3460 synth_valobj = (synth_valobj_sp ? synth_valobj_sp.get() : valobj);
Enrico Granatac5bc4122012-03-27 02:35:13 +00003461
Greg Claytonc7bece562013-01-25 18:06:21 +00003462 size_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003463 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003464 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003465 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003466 if (options.m_flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003467 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003468 if (print_valobj)
3469 s.EOL();
3470 }
3471 else
3472 {
3473 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003474 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003475 s.IndentMore();
3476 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003477
Greg Claytonc7bece562013-01-25 18:06:21 +00003478 const size_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00003479
Enrico Granata0c489f52012-03-01 04:24:26 +00003480 if (num_children > max_num_children && !options.m_ignore_cap)
Enrico Granata22c55d12011-08-12 02:00:06 +00003481 {
3482 num_children = max_num_children;
3483 print_dotdotdot = true;
3484 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003485
Enrico Granata0c489f52012-03-01 04:24:26 +00003486 ValueObject::DumpValueObjectOptions child_options(options);
Enrico Granatac953a6a2012-12-11 02:17:22 +00003487 child_options.SetFormat(options.m_format).SetSummary().SetRootValueObjectName();
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003488 child_options.SetScopeChecked(true).SetHideName(options.m_hide_name).SetHideValue(options.m_hide_value)
Enrico Granata0c489f52012-03-01 04:24:26 +00003489 .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0);
Greg Claytonc7bece562013-01-25 18:06:21 +00003490 for (size_t idx=0; idx<num_children; ++idx)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003491 {
Enrico Granatac482a192011-08-17 22:13:59 +00003492 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003493 if (child_sp.get())
3494 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003495 DumpValueObject_Impl (s,
3496 child_sp.get(),
3497 child_options,
3498 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
3499 curr_depth + 1);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003500 }
3501 }
3502
Enrico Granata0c489f52012-03-01 04:24:26 +00003503 if (!options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003504 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003505 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003506 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003507 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3508 Target *target = exe_ctx.GetTargetPtr();
3509 if (target)
3510 target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003511 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003512 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003513 s.IndentLess();
3514 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003515 }
3516 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003517 else if (has_children)
3518 {
3519 // Aggregate, no children...
3520 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003521 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003522 }
3523 else
3524 {
3525 if (print_valobj)
3526 s.EOL();
3527 }
3528
Greg Clayton1d3afba2010-10-05 00:00:42 +00003529 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003530 else
3531 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003532 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003533 }
3534 }
3535 else
3536 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003537 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003538 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003539 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003540 }
3541 }
3542 }
3543 }
3544}
3545
Enrico Granata0c489f52012-03-01 04:24:26 +00003546void
Greg Claytonf830dbb2012-03-22 18:15:37 +00003547ValueObject::LogValueObject (Log *log,
3548 ValueObject *valobj)
3549{
3550 if (log && valobj)
3551 return LogValueObject (log, valobj, DumpValueObjectOptions::DefaultOptions());
3552}
3553
3554void
3555ValueObject::LogValueObject (Log *log,
3556 ValueObject *valobj,
3557 const DumpValueObjectOptions& options)
3558{
3559 if (log && valobj)
3560 {
3561 StreamString s;
3562 ValueObject::DumpValueObject (s, valobj, options);
3563 if (s.GetSize())
3564 log->PutCString(s.GetData());
3565 }
3566}
3567
3568void
Enrico Granata0c489f52012-03-01 04:24:26 +00003569ValueObject::DumpValueObject (Stream &s,
3570 ValueObject *valobj)
3571{
3572
3573 if (!valobj)
3574 return;
3575
3576 DumpValueObject_Impl(s,
3577 valobj,
3578 DumpValueObjectOptions::DefaultOptions(),
3579 0,
3580 0);
3581}
3582
3583void
3584ValueObject::DumpValueObject (Stream &s,
3585 ValueObject *valobj,
3586 const DumpValueObjectOptions& options)
3587{
3588 DumpValueObject_Impl(s,
3589 valobj,
3590 options,
3591 options.m_max_ptr_depth, // max pointer depth allowed, we will go down from here
3592 0 // current object depth is 0 since we are just starting
3593 );
3594}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003595
3596ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003597ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003598{
3599 ValueObjectSP valobj_sp;
3600
Enrico Granatac3e320a2011-08-02 17:27:39 +00003601 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003602 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003603 ExecutionContext exe_ctx (GetExecutionContextRef());
3604 clang::ASTContext *ast = GetClangAST ();
3605
3606 DataExtractor data;
3607 data.SetByteOrder (m_data.GetByteOrder());
3608 data.SetAddressByteSize(m_data.GetAddressByteSize());
3609
Enrico Granata9f1e2042012-04-24 22:15:37 +00003610 if (IsBitfield())
3611 {
3612 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
3613 m_error = v.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
3614 }
3615 else
3616 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003617
3618 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3619 ast,
3620 GetClangType(),
3621 name,
3622 data,
3623 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003624 }
Jim Ingham6035b672011-03-31 00:19:25 +00003625
3626 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003627 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003628 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003629 }
3630 return valobj_sp;
3631}
3632
Greg Claytonafacd142011-09-02 01:15:17 +00003633ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003634ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003635{
Jim Ingham58b59f92011-04-22 23:53:53 +00003636 if (m_deref_valobj)
3637 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003638
Greg Clayton54979cd2010-12-15 05:08:08 +00003639 const bool is_pointer_type = IsPointerType();
3640 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003641 {
3642 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003643 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003644
3645 std::string child_name_str;
3646 uint32_t child_byte_size = 0;
3647 int32_t child_byte_offset = 0;
3648 uint32_t child_bitfield_bit_size = 0;
3649 uint32_t child_bitfield_bit_offset = 0;
3650 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003651 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003652 const bool transparent_pointers = false;
3653 clang::ASTContext *clang_ast = GetClangAST();
3654 clang_type_t clang_type = GetClangType();
3655 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003656
Greg Claytoncc4d0142012-02-17 07:49:44 +00003657 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003658
3659 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3660 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003661 GetName().GetCString(),
3662 clang_type,
3663 0,
3664 transparent_pointers,
3665 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003666 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003667 child_name_str,
3668 child_byte_size,
3669 child_byte_offset,
3670 child_bitfield_bit_size,
3671 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003672 child_is_base_class,
3673 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003674 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003675 {
3676 ConstString child_name;
3677 if (!child_name_str.empty())
3678 child_name.SetCString (child_name_str.c_str());
3679
Jim Ingham58b59f92011-04-22 23:53:53 +00003680 m_deref_valobj = new ValueObjectChild (*this,
3681 clang_ast,
3682 child_clang_type,
3683 child_name,
3684 child_byte_size,
3685 child_byte_offset,
3686 child_bitfield_bit_size,
3687 child_bitfield_bit_offset,
3688 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003689 child_is_deref_of_parent,
3690 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003691 }
3692 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003693
Jim Ingham58b59f92011-04-22 23:53:53 +00003694 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003695 {
3696 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003697 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003698 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003699 else
3700 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003701 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003702 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003703
3704 if (is_pointer_type)
3705 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3706 else
3707 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003708 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003709 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003710}
3711
Greg Claytonafacd142011-09-02 01:15:17 +00003712ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003713ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003714{
Jim Ingham78a685a2011-04-16 00:01:13 +00003715 if (m_addr_of_valobj_sp)
3716 return m_addr_of_valobj_sp;
3717
Greg Claytone0d378b2011-03-24 21:19:54 +00003718 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003719 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003720 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003721 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003722 if (addr != LLDB_INVALID_ADDRESS)
3723 {
3724 switch (address_type)
3725 {
3726 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003727 {
3728 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003729 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003730 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3731 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003732 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003733
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003734 case eAddressTypeFile:
3735 case eAddressTypeLoad:
3736 case eAddressTypeHost:
3737 {
3738 clang::ASTContext *ast = GetClangAST();
3739 clang_type_t clang_type = GetClangType();
3740 if (ast && clang_type)
3741 {
3742 std::string name (1, '&');
3743 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003744 ExecutionContext exe_ctx (GetExecutionContextRef());
3745 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003746 ast,
3747 ClangASTContext::CreatePointerType (ast, clang_type),
3748 ConstString (name.c_str()),
3749 addr,
3750 eAddressTypeInvalid,
3751 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003752 }
3753 }
3754 break;
3755 }
3756 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003757 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003758}
3759
Greg Clayton9a142cf2012-02-03 05:34:10 +00003760ValueObjectSP
3761ValueObject::Cast (const ClangASTType &clang_ast_type)
3762{
Greg Clayton81e871e2012-02-04 02:27:34 +00003763 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003764}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003765
Greg Claytonafacd142011-09-02 01:15:17 +00003766ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003767ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3768{
Greg Claytonafacd142011-09-02 01:15:17 +00003769 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003770 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003771 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003772
3773 if (ptr_value != LLDB_INVALID_ADDRESS)
3774 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003775 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003776 ExecutionContext exe_ctx (GetExecutionContextRef());
3777 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003778 name,
3779 ptr_addr,
3780 clang_ast_type);
3781 }
3782 return valobj_sp;
3783}
3784
Greg Claytonafacd142011-09-02 01:15:17 +00003785ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003786ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3787{
Greg Claytonafacd142011-09-02 01:15:17 +00003788 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003789 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003790 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003791
3792 if (ptr_value != LLDB_INVALID_ADDRESS)
3793 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003794 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003795 ExecutionContext exe_ctx (GetExecutionContextRef());
3796 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003797 name,
3798 ptr_addr,
3799 type_sp);
3800 }
3801 return valobj_sp;
3802}
3803
Jim Ingham6035b672011-03-31 00:19:25 +00003804ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003805 m_mod_id(),
3806 m_exe_ctx_ref(),
3807 m_needs_update (true),
3808 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003809{
3810}
3811
3812ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003813 m_mod_id(),
3814 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003815 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003816 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003817{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003818 ExecutionContext exe_ctx(exe_scope);
3819 TargetSP target_sp (exe_ctx.GetTargetSP());
3820 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003821 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003822 m_exe_ctx_ref.SetTargetSP (target_sp);
3823 ProcessSP process_sp (exe_ctx.GetProcessSP());
3824 if (!process_sp)
3825 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003826
Greg Claytoncc4d0142012-02-17 07:49:44 +00003827 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003828 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003829 m_mod_id = process_sp->GetModID();
3830 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003831
Greg Claytoncc4d0142012-02-17 07:49:44 +00003832 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003833
Greg Claytoncc4d0142012-02-17 07:49:44 +00003834 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003835 {
3836 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003837 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003838 }
Jim Ingham6035b672011-03-31 00:19:25 +00003839
Greg Claytoncc4d0142012-02-17 07:49:44 +00003840 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003841 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003842 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003843
Greg Claytoncc4d0142012-02-17 07:49:44 +00003844 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3845 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003846 {
3847 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003848 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003849 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003850 if (frame_sp)
3851 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003852 }
3853 }
3854 }
Jim Ingham6035b672011-03-31 00:19:25 +00003855}
3856
3857ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003858 m_mod_id(),
3859 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3860 m_needs_update (true),
3861 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003862{
3863}
3864
3865ValueObject::EvaluationPoint::~EvaluationPoint ()
3866{
3867}
3868
Jim Ingham6035b672011-03-31 00:19:25 +00003869// This function checks the EvaluationPoint against the current process state. If the current
3870// state matches the evaluation point, or the evaluation point is already invalid, then we return
3871// false, meaning "no change". If the current state is different, we update our state, and return
3872// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3873// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003874// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003875
3876bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003877ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003878{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003879
3880 // 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 +00003881 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00003882
Greg Claytoncc4d0142012-02-17 07:49:44 +00003883 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003884 return false;
3885
Jim Ingham6035b672011-03-31 00:19:25 +00003886 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003887 Process *process = exe_ctx.GetProcessPtr();
3888 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003889 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003890
Jim Ingham6035b672011-03-31 00:19:25 +00003891 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003892 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003893
Jim Ingham78a685a2011-04-16 00:01:13 +00003894 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3895 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003896 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003897 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003898
Greg Clayton23f59502012-07-17 03:23:13 +00003899 bool changed = false;
3900 const bool was_valid = m_mod_id.IsValid();
3901 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003902 {
3903 if (m_mod_id == current_mod_id)
3904 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003905 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003906 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003907 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003908 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003909 else
3910 {
3911 m_mod_id = current_mod_id;
3912 m_needs_update = true;
3913 changed = true;
3914 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003915 }
Jim Ingham6035b672011-03-31 00:19:25 +00003916
Jim Ingham73ca05a2011-12-17 01:35:57 +00003917 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3918 // That way we'll be sure to return a valid exe_scope.
3919 // 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 +00003920
Greg Claytoncc4d0142012-02-17 07:49:44 +00003921 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003922 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003923 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3924 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003925 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003926 if (m_exe_ctx_ref.HasFrameRef())
3927 {
3928 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3929 if (!frame_sp)
3930 {
3931 // We used to have a frame, but now it is gone
3932 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003933 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00003934 }
3935 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003936 }
Jim Ingham6035b672011-03-31 00:19:25 +00003937 else
3938 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003939 // We used to have a thread, but now it is gone
3940 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003941 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00003942 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003943
Jim Ingham6035b672011-03-31 00:19:25 +00003944 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003945 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003946}
3947
Jim Ingham61be0902011-05-02 18:13:59 +00003948void
3949ValueObject::EvaluationPoint::SetUpdated ()
3950{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003951 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3952 if (process_sp)
3953 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003954 m_first_update = false;
3955 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003956}
3957
3958
Greg Claytoncc4d0142012-02-17 07:49:44 +00003959//bool
3960//ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3961//{
3962// if (!IsValid())
3963// return false;
3964//
3965// bool needs_update = false;
3966//
3967// // The target has to be non-null, and the
3968// Target *target = exe_scope->CalculateTarget();
3969// if (target != NULL)
3970// {
3971// Target *old_target = m_target_sp.get();
3972// assert (target == old_target);
3973// Process *process = exe_scope->CalculateProcess();
3974// if (process != NULL)
3975// {
3976// // FOR NOW - assume you can't update variable objects across process boundaries.
3977// Process *old_process = m_process_sp.get();
3978// assert (process == old_process);
3979// ProcessModID current_mod_id = process->GetModID();
3980// if (m_mod_id != current_mod_id)
3981// {
3982// needs_update = true;
3983// m_mod_id = current_mod_id;
3984// }
3985// // See if we're switching the thread or stack context. If no thread is given, this is
3986// // being evaluated in a global context.
3987// Thread *thread = exe_scope->CalculateThread();
3988// if (thread != NULL)
3989// {
3990// user_id_t new_thread_index = thread->GetIndexID();
3991// if (new_thread_index != m_thread_id)
3992// {
3993// needs_update = true;
3994// m_thread_id = new_thread_index;
3995// m_stack_id.Clear();
3996// }
3997//
3998// StackFrame *new_frame = exe_scope->CalculateStackFrame();
3999// if (new_frame != NULL)
4000// {
4001// if (new_frame->GetStackID() != m_stack_id)
4002// {
4003// needs_update = true;
4004// m_stack_id = new_frame->GetStackID();
4005// }
4006// }
4007// else
4008// {
4009// m_stack_id.Clear();
4010// needs_update = true;
4011// }
4012// }
4013// else
4014// {
4015// // If this had been given a thread, and now there is none, we should update.
4016// // Otherwise we don't have to do anything.
4017// if (m_thread_id != LLDB_INVALID_UID)
4018// {
4019// m_thread_id = LLDB_INVALID_UID;
4020// m_stack_id.Clear();
4021// needs_update = true;
4022// }
4023// }
4024// }
4025// else
4026// {
4027// // If there is no process, then we don't need to update anything.
4028// // But if we're switching from having a process to not, we should try to update.
4029// if (m_process_sp.get() != NULL)
4030// {
4031// needs_update = true;
4032// m_process_sp.reset();
4033// m_thread_id = LLDB_INVALID_UID;
4034// m_stack_id.Clear();
4035// }
4036// }
4037// }
4038// else
4039// {
4040// // If there's no target, nothing can change so we don't need to update anything.
4041// // But if we're switching from having a target to not, we should try to update.
4042// if (m_target_sp.get() != NULL)
4043// {
4044// needs_update = true;
4045// m_target_sp.reset();
4046// m_process_sp.reset();
4047// m_thread_id = LLDB_INVALID_UID;
4048// m_stack_id.Clear();
4049// }
4050// }
4051// if (!m_needs_update)
4052// m_needs_update = needs_update;
4053//
4054// return needs_update;
4055//}
Enrico Granataf2bbf712011-07-15 02:26:42 +00004056
4057void
Enrico Granata86cc9822012-03-19 22:58:49 +00004058ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004059{
Enrico Granata86cc9822012-03-19 22:58:49 +00004060 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4061 m_value_str.clear();
4062
4063 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4064 m_location_str.clear();
4065
4066 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
4067 {
Enrico Granata86cc9822012-03-19 22:58:49 +00004068 m_summary_str.clear();
4069 }
4070
4071 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4072 m_object_desc_str.clear();
4073
4074 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4075 {
4076 if (m_synthetic_value)
4077 m_synthetic_value = NULL;
4078 }
Johnny Chen44805302011-07-19 19:48:13 +00004079}
Enrico Granata9128ee22011-09-06 19:20:51 +00004080
4081SymbolContextScope *
4082ValueObject::GetSymbolContextScope()
4083{
4084 if (m_parent)
4085 {
4086 if (!m_parent->IsPointerOrReferenceType())
4087 return m_parent->GetSymbolContextScope();
4088 }
4089 return NULL;
4090}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004091
4092lldb::ValueObjectSP
4093ValueObject::CreateValueObjectFromExpression (const char* name,
4094 const char* expression,
4095 const ExecutionContext& exe_ctx)
4096{
4097 lldb::ValueObjectSP retval_sp;
4098 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4099 if (!target_sp)
4100 return retval_sp;
4101 if (!expression || !*expression)
4102 return retval_sp;
4103 target_sp->EvaluateExpression (expression,
4104 exe_ctx.GetFrameSP().get(),
4105 retval_sp);
4106 if (retval_sp && name && *name)
4107 retval_sp->SetName(ConstString(name));
4108 return retval_sp;
4109}
4110
4111lldb::ValueObjectSP
4112ValueObject::CreateValueObjectFromAddress (const char* name,
4113 uint64_t address,
4114 const ExecutionContext& exe_ctx,
4115 ClangASTType type)
4116{
4117 ClangASTType pointer_type(type.GetASTContext(),type.GetPointerType());
4118 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4119 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4120 pointer_type.GetASTContext(),
4121 pointer_type.GetOpaqueQualType(),
4122 ConstString(name),
4123 buffer,
4124 lldb::endian::InlHostByteOrder(),
4125 exe_ctx.GetAddressByteSize()));
4126 if (ptr_result_valobj_sp)
4127 {
4128 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4129 Error err;
4130 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4131 if (ptr_result_valobj_sp && name && *name)
4132 ptr_result_valobj_sp->SetName(ConstString(name));
4133 }
4134 return ptr_result_valobj_sp;
4135}
4136
4137lldb::ValueObjectSP
4138ValueObject::CreateValueObjectFromData (const char* name,
4139 DataExtractor& data,
4140 const ExecutionContext& exe_ctx,
4141 ClangASTType type)
4142{
4143 lldb::ValueObjectSP new_value_sp;
4144 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4145 type.GetASTContext() ,
4146 type.GetOpaqueQualType(),
4147 ConstString(name),
4148 data,
4149 LLDB_INVALID_ADDRESS);
4150 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4151 if (new_value_sp && name && *name)
4152 new_value_sp->SetName(ConstString(name));
4153 return new_value_sp;
4154}
Enrico Granata4873e522013-04-11 22:48:58 +00004155
4156ModuleSP
4157ValueObject::GetModule ()
4158{
4159 ValueObject* root(GetRoot());
4160 if (root != this)
4161 return root->GetModule();
4162 return lldb::ModuleSP();
4163}
4164
4165ValueObject*
4166ValueObject::GetRoot ()
4167{
4168 if (m_root)
4169 return m_root;
4170 ValueObject* parent = m_parent;
4171 if (!parent)
4172 return (m_root = this);
4173 while (parent->m_parent)
4174 {
4175 if (parent->m_root)
4176 return (m_root = parent->m_root);
4177 parent = parent->m_parent;
4178 }
4179 return (m_root = parent);
4180}
4181
4182AddressType
4183ValueObject::GetAddressTypeOfChildren()
4184{
4185 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
4186 {
4187 ValueObject* root(GetRoot());
4188 if (root != this)
4189 return root->GetAddressTypeOfChildren();
4190 }
4191 return m_address_type_of_ptr_or_ref_children;
4192}
4193
4194lldb::DynamicValueType
4195ValueObject::GetDynamicValueType ()
4196{
4197 ValueObject* with_dv_info = this;
4198 while (with_dv_info)
4199 {
4200 if (with_dv_info->HasDynamicValueTypeInfo())
4201 return with_dv_info->GetDynamicValueTypeImpl();
4202 with_dv_info = with_dv_info->m_parent;
4203 }
4204 return lldb::eNoDynamicValues;
4205}
4206lldb::Format
4207ValueObject::GetFormat () const
4208{
4209 const ValueObject* with_fmt_info = this;
4210 while (with_fmt_info)
4211 {
4212 if (with_fmt_info->m_format != lldb::eFormatDefault)
4213 return with_fmt_info->m_format;
4214 with_fmt_info = with_fmt_info->m_parent;
4215 }
4216 return m_format;
4217}