blob: 0edc8be5ef0415cab551be8c8007d2dc6c2ecd21 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- ValueObject.cpp -----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Core/ValueObject.h"
11
12// C Includes
Greg Claytonf5e56de2010-09-14 23:36:40 +000013#include <stdlib.h>
14
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015// C++ Includes
16// Other libraries and framework includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "llvm/Support/raw_ostream.h"
Jim Ingham5a369122010-09-28 01:25:32 +000018#include "clang/AST/Type.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019
20// Project includes
21#include "lldb/Core/DataBufferHeap.h"
Enrico Granata0a976142011-08-22 22:03:47 +000022#include "lldb/Core/DataVisualization.h"
Enrico Granata4becb372011-06-29 22:27:15 +000023#include "lldb/Core/Debugger.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000024#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000025#include "lldb/Core/Module.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026#include "lldb/Core/StreamString.h"
27#include "lldb/Core/ValueObjectChild.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000028#include "lldb/Core/ValueObjectConstResult.h"
Jim Ingham78a685a2011-04-16 00:01:13 +000029#include "lldb/Core/ValueObjectDynamicValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030#include "lldb/Core/ValueObjectList.h"
Greg Claytonb2dcc362011-05-05 23:32:56 +000031#include "lldb/Core/ValueObjectMemory.h"
Enrico Granatad55546b2011-07-22 00:16:08 +000032#include "lldb/Core/ValueObjectSyntheticFilter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033
Greg Clayton7fb56d02011-02-01 01:31:41 +000034#include "lldb/Host/Endian.h"
35
Enrico Granata61a80ba2011-08-12 16:42:31 +000036#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granataf2bbf712011-07-15 02:26:42 +000037#include "lldb/Interpreter/ScriptInterpreterPython.h"
38
Greg Claytone1a916a2010-07-21 22:12:05 +000039#include "lldb/Symbol/ClangASTType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000040#include "lldb/Symbol/ClangASTContext.h"
41#include "lldb/Symbol/Type.h"
42
Jim Ingham53c47f12010-09-10 23:12:17 +000043#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000044#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000045#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046#include "lldb/Target/Process.h"
47#include "lldb/Target/RegisterContext.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000048#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000050
Enrico Granataf4efecd2011-07-12 22:56:10 +000051#include "lldb/Utility/RefCounter.h"
52
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053using namespace lldb;
54using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000055using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056
Greg Claytonafacd142011-09-02 01:15:17 +000057static user_id_t g_value_obj_uid = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058
59//----------------------------------------------------------------------
60// ValueObject constructor
61//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000062ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000064 m_parent (&parent),
Stephen Wilson71c21d12011-04-11 19:41:40 +000065 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066 m_name (),
67 m_data (),
68 m_value (),
69 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000070 m_value_str (),
71 m_old_value_str (),
72 m_location_str (),
73 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000074 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +000075 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000076 m_children (),
77 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000078 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000079 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000080 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000081 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000082 m_last_format_mgr_revision(0),
Enrico Granatad8b5fce2011-08-02 23:12:24 +000083 m_last_format_mgr_dynamic(parent.m_last_format_mgr_dynamic),
Enrico Granata0c489f52012-03-01 04:24:26 +000084 m_type_summary_sp(),
85 m_type_format_sp(),
86 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +000087 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +000088 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
Greg Clayton288bdf92010-09-02 02:59:18 +000089 m_value_is_valid (false),
90 m_value_did_change (false),
91 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000092 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +000093 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +000094 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +000095 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +000096 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +000097 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +000098 m_is_getting_summary(false),
99 m_did_calculate_complete_objc_class_type(false)
Jim Ingham6035b672011-03-31 00:19:25 +0000100{
Jim Ingham58b59f92011-04-22 23:53:53 +0000101 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000102}
103
104//----------------------------------------------------------------------
105// ValueObject constructor
106//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000107ValueObject::ValueObject (ExecutionContextScope *exe_scope,
108 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000109 UserID (++g_value_obj_uid), // Unique identifier for every value object
110 m_parent (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000111 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000112 m_name (),
113 m_data (),
114 m_value (),
115 m_error (),
116 m_value_str (),
117 m_old_value_str (),
118 m_location_str (),
119 m_summary_str (),
120 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000121 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000122 m_children (),
123 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000124 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000125 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000126 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000127 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000128 m_last_format_mgr_revision(0),
Greg Claytonafacd142011-09-02 01:15:17 +0000129 m_last_format_mgr_dynamic(eNoDynamicValues),
Enrico Granata0c489f52012-03-01 04:24:26 +0000130 m_type_summary_sp(),
131 m_type_format_sp(),
132 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000133 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000134 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Jim Ingham6035b672011-03-31 00:19:25 +0000135 m_value_is_valid (false),
136 m_value_did_change (false),
137 m_children_count_valid (false),
138 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000139 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000140 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000141 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +0000142 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000143 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000144 m_is_getting_summary(false),
145 m_did_calculate_complete_objc_class_type(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000146{
Jim Ingham58b59f92011-04-22 23:53:53 +0000147 m_manager = new ValueObjectManager();
148 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000149}
150
151//----------------------------------------------------------------------
152// Destructor
153//----------------------------------------------------------------------
154ValueObject::~ValueObject ()
155{
156}
157
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000158bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000159ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000160{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000161 return UpdateValueIfNeeded(m_last_format_mgr_dynamic, update_format);
162}
163
164bool
Greg Claytonafacd142011-09-02 01:15:17 +0000165ValueObject::UpdateValueIfNeeded (DynamicValueType use_dynamic, bool update_format)
Enrico Granatac3e320a2011-08-02 17:27:39 +0000166{
Enrico Granata4becb372011-06-29 22:27:15 +0000167
Enrico Granata9128ee22011-09-06 19:20:51 +0000168 bool did_change_formats = false;
169
Enrico Granata0a3958e2011-07-02 00:25:22 +0000170 if (update_format)
Enrico Granata9128ee22011-09-06 19:20:51 +0000171 did_change_formats = UpdateFormatsIfNeeded(use_dynamic);
Enrico Granata4becb372011-06-29 22:27:15 +0000172
Greg Claytonb71f3842010-10-05 03:13:51 +0000173 // If this is a constant value, then our success is predicated on whether
174 // we have an error or not
175 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000176 {
177 // if you were asked to update your formatters, but did not get a chance to do it
178 // clear your own values (this serves the purpose of faking a stop-id for frozen
179 // objects (which are regarded as constant, but could have changes behind their backs
180 // because of the frozen-pointer depth limit)
181 // TODO: decouple summary from value and then remove this code and only force-clear the summary
182 if (update_format && !did_change_formats)
Enrico Granata86cc9822012-03-19 22:58:49 +0000183 ClearUserVisibleData(eClearUserVisibleDataItemsSummary);
Greg Claytonb71f3842010-10-05 03:13:51 +0000184 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000185 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000186
Jim Ingham6035b672011-03-31 00:19:25 +0000187 bool first_update = m_update_point.IsFirstEvaluation();
188
189 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000190 {
Jim Ingham6035b672011-03-31 00:19:25 +0000191 m_update_point.SetUpdated();
192
193 // Save the old value using swap to avoid a string copy which
194 // also will clear our m_value_str
195 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000196 {
Jim Ingham6035b672011-03-31 00:19:25 +0000197 m_old_value_valid = false;
198 }
199 else
200 {
201 m_old_value_valid = true;
202 m_old_value_str.swap (m_value_str);
Enrico Granata86cc9822012-03-19 22:58:49 +0000203 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham6035b672011-03-31 00:19:25 +0000204 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000205
Enrico Granataf2bbf712011-07-15 02:26:42 +0000206 ClearUserVisibleData();
207
Greg Claytonefbc7d22012-03-09 04:23:44 +0000208 if (IsInScope())
Jim Ingham6035b672011-03-31 00:19:25 +0000209 {
Greg Claytonefbc7d22012-03-09 04:23:44 +0000210 const bool value_was_valid = GetValueIsValid();
211 SetValueDidChange (false);
212
213 m_error.Clear();
214
215 // Call the pure virtual function to update the value
216 bool success = UpdateValue ();
217
218 SetValueIsValid (success);
219
220 if (first_update)
221 SetValueDidChange (false);
222 else if (!m_value_did_change && success == false)
223 {
224 // The value wasn't gotten successfully, so we mark this
225 // as changed if the value used to be valid and now isn't
226 SetValueDidChange (value_was_valid);
227 }
228 }
229 else
230 {
231 m_error.SetErrorString("out of scope");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000232 }
233 }
234 return m_error.Success();
235}
236
Enrico Granata9128ee22011-09-06 19:20:51 +0000237bool
Greg Claytonafacd142011-09-02 01:15:17 +0000238ValueObject::UpdateFormatsIfNeeded(DynamicValueType use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000239{
Enrico Granata6f3533f2011-07-29 19:53:35 +0000240 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
241 if (log)
Enrico Granatad2284832012-10-17 22:23:56 +0000242 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
Enrico Granata6f3533f2011-07-29 19:53:35 +0000243 GetName().GetCString(),
Enrico Granatad2284832012-10-17 22:23:56 +0000244 this,
Enrico Granata4becb372011-06-29 22:27:15 +0000245 m_last_format_mgr_revision,
Enrico Granata85933ed2011-08-18 16:38:26 +0000246 DataVisualization::GetCurrentRevision());
Enrico Granata9128ee22011-09-06 19:20:51 +0000247
248 bool any_change = false;
249
Enrico Granata85933ed2011-08-18 16:38:26 +0000250 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()) ||
Enrico Granatac3e320a2011-08-02 17:27:39 +0000251 m_last_format_mgr_dynamic != use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000252 {
Enrico Granata78d06382011-09-09 23:33:14 +0000253 SetValueFormat(DataVisualization::ValueFormats::GetFormat (*this, eNoDynamicValues));
254 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, use_dynamic));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000255#ifndef LLDB_DISABLE_PYTHON
Enrico Granata78d06382011-09-09 23:33:14 +0000256 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, use_dynamic));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000257#endif
Enrico Granata1490c6f2011-07-19 02:34:21 +0000258
Enrico Granata85933ed2011-08-18 16:38:26 +0000259 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
Enrico Granatac3e320a2011-08-02 17:27:39 +0000260 m_last_format_mgr_dynamic = use_dynamic;
Enrico Granata855cd902011-09-06 22:59:55 +0000261
262 any_change = true;
Enrico Granata4becb372011-06-29 22:27:15 +0000263 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000264
265 return any_change;
266
Enrico Granata4becb372011-06-29 22:27:15 +0000267}
268
Jim Ingham16e0c682011-08-12 23:34:31 +0000269void
270ValueObject::SetNeedsUpdate ()
271{
272 m_update_point.SetNeedsUpdate();
273 // We have to clear the value string here so ConstResult children will notice if their values are
274 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000275 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000276}
277
Enrico Granata13ac0e22012-10-17 19:03:34 +0000278void
279ValueObject::ResetCompleteTypeInfo ()
280{
281 m_did_calculate_complete_objc_class_type = false;
282 m_override_type = ClangASTType();
283}
284
Sean Callanan72772842012-02-22 23:57:45 +0000285ClangASTType
286ValueObject::MaybeCalculateCompleteType ()
287{
288 ClangASTType ret(GetClangASTImpl(), GetClangTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000289
Sean Callanan72772842012-02-22 23:57:45 +0000290 if (m_did_calculate_complete_objc_class_type)
291 {
292 if (m_override_type.IsValid())
293 return m_override_type;
294 else
295 return ret;
296 }
297
298 clang_type_t ast_type(GetClangTypeImpl());
299 clang_type_t class_type;
300 bool is_pointer_type;
301
302 if (ClangASTContext::IsObjCObjectPointerType(ast_type, &class_type))
303 {
304 is_pointer_type = true;
305 }
306 else if (ClangASTContext::IsObjCClassType(ast_type))
307 {
308 is_pointer_type = false;
309 class_type = ast_type;
310 }
311 else
312 {
313 return ret;
314 }
315
316 m_did_calculate_complete_objc_class_type = true;
317
318 if (!class_type)
319 return ret;
320
321 std::string class_name;
322
323 if (!ClangASTContext::GetObjCClassName(class_type, class_name))
324 return ret;
325
326 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
327
328 if (!process_sp)
329 return ret;
330
331 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
332
333 if (!objc_language_runtime)
334 return ret;
335
336 ConstString class_name_cs(class_name.c_str());
337
338 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name_cs);
339
340 if (!complete_objc_class_type_sp)
341 return ret;
342
343 ClangASTType complete_class(complete_objc_class_type_sp->GetClangAST(),
344 complete_objc_class_type_sp->GetClangFullType());
345
346 if (!ClangASTContext::GetCompleteType(complete_class.GetASTContext(),
347 complete_class.GetOpaqueQualType()))
348 return ret;
349
350 if (is_pointer_type)
351 {
352 clang_type_t pointer_type = ClangASTContext::CreatePointerType(complete_class.GetASTContext(),
353 complete_class.GetOpaqueQualType());
354
355 m_override_type = ClangASTType(complete_class.GetASTContext(),
356 pointer_type);
357 }
358 else
359 {
360 m_override_type = complete_class;
361 }
362
Sean Callanan356e17c2012-03-30 02:04:38 +0000363 if (m_override_type.IsValid())
364 return m_override_type;
365 else
366 return ret;
Sean Callanan72772842012-02-22 23:57:45 +0000367}
368
369clang::ASTContext *
370ValueObject::GetClangAST ()
371{
372 ClangASTType type = MaybeCalculateCompleteType();
373
374 return type.GetASTContext();
375}
376
377lldb::clang_type_t
378ValueObject::GetClangType ()
379{
380 ClangASTType type = MaybeCalculateCompleteType();
381
382 return type.GetOpaqueQualType();
383}
384
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000385DataExtractor &
386ValueObject::GetDataExtractor ()
387{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000388 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000389 return m_data;
390}
391
392const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000393ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000394{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000395 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000396 return m_error;
397}
398
399const ConstString &
400ValueObject::GetName() const
401{
402 return m_name;
403}
404
405const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000406ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000407{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000408 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000409 {
410 if (m_location_str.empty())
411 {
412 StreamString sstr;
413
414 switch (m_value.GetValueType())
415 {
416 default:
417 break;
418
419 case Value::eValueTypeScalar:
Greg Clayton526e5af2010-11-13 03:52:47 +0000420 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000421 {
422 RegisterInfo *reg_info = m_value.GetRegisterInfo();
423 if (reg_info)
424 {
425 if (reg_info->name)
426 m_location_str = reg_info->name;
427 else if (reg_info->alt_name)
428 m_location_str = reg_info->alt_name;
429 break;
430 }
431 }
432 m_location_str = "scalar";
433 break;
434
435 case Value::eValueTypeLoadAddress:
436 case Value::eValueTypeFileAddress:
437 case Value::eValueTypeHostAddress:
438 {
439 uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2;
440 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
441 m_location_str.swap(sstr.GetString());
442 }
443 break;
444 }
445 }
446 }
447 return m_location_str.c_str();
448}
449
450Value &
451ValueObject::GetValue()
452{
453 return m_value;
454}
455
456const Value &
457ValueObject::GetValue() const
458{
459 return m_value;
460}
461
462bool
Jim Ingham6035b672011-03-31 00:19:25 +0000463ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000464{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000465 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
466 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000467 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000468 Value tmp_value(m_value);
469 scalar = tmp_value.ResolveValue(&exe_ctx, GetClangAST ());
Greg Claytondcad5022011-12-29 01:26:56 +0000470 if (scalar.IsValid())
471 {
472 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
473 if (bitfield_bit_size)
474 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
475 return true;
476 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000477 }
Greg Claytondcad5022011-12-29 01:26:56 +0000478 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000479}
480
481bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000482ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000483{
Greg Clayton288bdf92010-09-02 02:59:18 +0000484 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000485}
486
487
488void
489ValueObject::SetValueIsValid (bool b)
490{
Greg Clayton288bdf92010-09-02 02:59:18 +0000491 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000492}
493
494bool
Jim Ingham6035b672011-03-31 00:19:25 +0000495ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000496{
Jim Ingham6035b672011-03-31 00:19:25 +0000497 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000498 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000499}
500
501void
502ValueObject::SetValueDidChange (bool value_changed)
503{
Greg Clayton288bdf92010-09-02 02:59:18 +0000504 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000505}
506
507ValueObjectSP
508ValueObject::GetChildAtIndex (uint32_t idx, bool can_create)
509{
510 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000511 // We may need to update our value if we are dynamic
512 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000513 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000514 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000515 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000516 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000517 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000518 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000519 // No we haven't created the child at this index, so lets have our
520 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000521 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000522 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000523
Enrico Granata9d60f602012-03-09 03:09:58 +0000524 ValueObject* child = m_children.GetChildAtIndex(idx);
525 if (child != NULL)
526 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000527 }
528 return child_sp;
529}
530
531uint32_t
532ValueObject::GetIndexOfChildWithName (const ConstString &name)
533{
534 bool omit_empty_base_classes = true;
535 return ClangASTContext::GetIndexOfChildWithName (GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +0000536 GetClangType(),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000537 name.GetCString(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000538 omit_empty_base_classes);
539}
540
541ValueObjectSP
542ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
543{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000544 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000545 // classes (which really aren't part of the expression path), so we
546 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000547 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000548
Greg Claytondea8cb42011-06-29 22:09:02 +0000549 // We may need to update our value if we are dynamic
550 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000551 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000552
553 std::vector<uint32_t> child_indexes;
554 clang::ASTContext *clang_ast = GetClangAST();
555 void *clang_type = GetClangType();
556 bool omit_empty_base_classes = true;
557 const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast,
558 clang_type,
559 name.GetCString(),
560 omit_empty_base_classes,
561 child_indexes);
562 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000563 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000564 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
565 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
566
567 child_sp = GetChildAtIndex(*pos, can_create);
568 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000569 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000570 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000571 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000572 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
573 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000574 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000575 else
576 {
577 child_sp.reset();
578 }
579
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000580 }
581 }
582 return child_sp;
583}
584
585
586uint32_t
587ValueObject::GetNumChildren ()
588{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000589 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000590 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000591 {
592 SetNumChildren (CalculateNumChildren());
593 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000594 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000595}
596void
597ValueObject::SetNumChildren (uint32_t num_children)
598{
Greg Clayton288bdf92010-09-02 02:59:18 +0000599 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000600 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000601}
602
603void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000604ValueObject::SetName (const ConstString &name)
605{
606 m_name = name;
607}
608
Jim Ingham58b59f92011-04-22 23:53:53 +0000609ValueObject *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000610ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index)
611{
Jim Ingham2eec4872011-05-07 00:10:58 +0000612 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000613
Greg Claytondea8cb42011-06-29 22:09:02 +0000614 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000615 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000616 std::string child_name_str;
617 uint32_t child_byte_size = 0;
618 int32_t child_byte_offset = 0;
619 uint32_t child_bitfield_bit_size = 0;
620 uint32_t child_bitfield_bit_offset = 0;
621 bool child_is_base_class = false;
622 bool child_is_deref_of_parent = false;
623
624 const bool transparent_pointers = synthetic_array_member == false;
625 clang::ASTContext *clang_ast = GetClangAST();
626 clang_type_t clang_type = GetClangType();
627 clang_type_t child_clang_type;
628
Greg Claytoncc4d0142012-02-17 07:49:44 +0000629 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000630
631 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
632 clang_ast,
633 GetName().GetCString(),
634 clang_type,
635 idx,
636 transparent_pointers,
637 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +0000638 ignore_array_bounds,
Greg Claytondea8cb42011-06-29 22:09:02 +0000639 child_name_str,
640 child_byte_size,
641 child_byte_offset,
642 child_bitfield_bit_size,
643 child_bitfield_bit_offset,
644 child_is_base_class,
645 child_is_deref_of_parent);
646 if (child_clang_type && child_byte_size)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000647 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000648 if (synthetic_index)
649 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000650
Greg Claytondea8cb42011-06-29 22:09:02 +0000651 ConstString child_name;
652 if (!child_name_str.empty())
653 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000654
Greg Claytondea8cb42011-06-29 22:09:02 +0000655 valobj = new ValueObjectChild (*this,
656 clang_ast,
657 child_clang_type,
658 child_name,
659 child_byte_size,
660 child_byte_offset,
661 child_bitfield_bit_size,
662 child_bitfield_bit_offset,
663 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000664 child_is_deref_of_parent,
665 eAddressTypeInvalid);
666 //if (valobj)
667 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
668 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000669
Jim Ingham58b59f92011-04-22 23:53:53 +0000670 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000671}
672
Enrico Granata0c489f52012-03-01 04:24:26 +0000673bool
674ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
675 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000676{
Enrico Granata0c489f52012-03-01 04:24:26 +0000677 destination.clear();
678
679 // ideally we would like to bail out if passing NULL, but if we do so
680 // we end up not providing the summary for function pointers anymore
681 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
682 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000683
684 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000685
686 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
687 // information that we might care to see in a crash log. might be useful in very specific situations though.
688 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
689 GetTypeName().GetCString(),
690 GetName().GetCString(),
691 summary_ptr->GetDescription().c_str());*/
692
Enrico Granata0c489f52012-03-01 04:24:26 +0000693 if (UpdateValueIfNeeded (false))
694 {
695 if (summary_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000696 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000697 if (HasSyntheticValue())
698 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
699 summary_ptr->FormatObject(this, destination);
Enrico Granata0c489f52012-03-01 04:24:26 +0000700 }
701 else
702 {
703 clang_type_t clang_type = GetClangType();
704
705 // Do some default printout for function pointers
706 if (clang_type)
Enrico Granata4becb372011-06-29 22:27:15 +0000707 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000708 StreamString sstr;
709 clang_type_t elem_or_pointee_clang_type;
710 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
711 GetClangAST(),
712 &elem_or_pointee_clang_type));
713
714 if (ClangASTContext::IsFunctionPointerType (clang_type))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000715 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000716 AddressType func_ptr_address_type = eAddressTypeInvalid;
717 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
718 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000719 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000720 switch (func_ptr_address_type)
Jim Ingham6035b672011-03-31 00:19:25 +0000721 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000722 case eAddressTypeInvalid:
723 case eAddressTypeFile:
724 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000725
Greg Claytoncc4d0142012-02-17 07:49:44 +0000726 case eAddressTypeLoad:
Enrico Granata0c489f52012-03-01 04:24:26 +0000727 {
728 ExecutionContext exe_ctx (GetExecutionContextRef());
729
730 Address so_addr;
731 Target *target = exe_ctx.GetTargetPtr();
732 if (target && target->GetSectionLoadList().IsEmpty() == false)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000733 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000734 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000735 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000736 so_addr.Dump (&sstr,
737 exe_ctx.GetBestExecutionContextScope(),
738 Address::DumpStyleResolvedDescription,
739 Address::DumpStyleSectionNameOffset);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000740 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000741 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000742 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000743 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000744
Greg Claytoncc4d0142012-02-17 07:49:44 +0000745 case eAddressTypeHost:
746 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +0000747 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000748 }
749 if (sstr.GetSize() > 0)
750 {
751 destination.assign (1, '(');
752 destination.append (sstr.GetData(), sstr.GetSize());
753 destination.append (1, ')');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000754 }
755 }
756 }
757 }
758 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000759 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000760 return !destination.empty();
761}
762
763const char *
764ValueObject::GetSummaryAsCString ()
765{
766 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
767 {
768 GetSummaryAsCString(GetSummaryFormat().get(),
769 m_summary_str);
770 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000771 if (m_summary_str.empty())
772 return NULL;
773 return m_summary_str.c_str();
774}
775
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000776bool
777ValueObject::IsCStringContainer(bool check_pointer)
778{
779 clang_type_t elem_or_pointee_clang_type;
780 const Flags type_flags (ClangASTContext::GetTypeInfo (GetClangType(),
781 GetClangAST(),
782 &elem_or_pointee_clang_type));
783 bool is_char_arr_ptr (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
784 ClangASTContext::IsCharType (elem_or_pointee_clang_type));
785 if (!is_char_arr_ptr)
786 return false;
787 if (!check_pointer)
788 return true;
789 if (type_flags.Test(ClangASTContext::eTypeIsArray))
790 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000791 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000792 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000793 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000794 return (cstr_address != LLDB_INVALID_ADDRESS);
795}
796
Enrico Granata9128ee22011-09-06 19:20:51 +0000797size_t
798ValueObject::GetPointeeData (DataExtractor& data,
799 uint32_t item_idx,
800 uint32_t item_count)
801{
802 if (!IsPointerType() && !IsArrayType())
803 return 0;
804
805 if (item_count == 0)
806 return 0;
807
808 uint32_t stride = 0;
809
810 ClangASTType type(GetClangAST(),
811 GetClangType());
812
813 const uint64_t item_type_size = (IsPointerType() ? ClangASTType::GetTypeByteSize(GetClangAST(), type.GetPointeeType()) :
814 ClangASTType::GetTypeByteSize(GetClangAST(), type.GetArrayElementType(stride)));
815
816 const uint64_t bytes = item_count * item_type_size;
817
818 const uint64_t offset = item_idx * item_type_size;
819
820 if (item_idx == 0 && item_count == 1) // simply a deref
821 {
822 if (IsPointerType())
823 {
824 Error error;
825 ValueObjectSP pointee_sp = Dereference(error);
826 if (error.Fail() || pointee_sp.get() == NULL)
827 return 0;
828 return pointee_sp->GetDataExtractor().Copy(data);
829 }
830 else
831 {
832 ValueObjectSP child_sp = GetChildAtIndex(0, true);
833 if (child_sp.get() == NULL)
834 return 0;
835 return child_sp->GetDataExtractor().Copy(data);
836 }
837 return true;
838 }
839 else /* (items > 1) */
840 {
841 Error error;
842 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
843 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
844
845 AddressType addr_type;
846 lldb::addr_t addr = IsPointerType() ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
847
Enrico Granata9128ee22011-09-06 19:20:51 +0000848 switch (addr_type)
849 {
850 case eAddressTypeFile:
851 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000852 ModuleSP module_sp (GetModule());
853 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000854 {
Enrico Granata9c2efe32012-08-07 01:49:34 +0000855 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +0000856 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +0000857 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000858 ExecutionContext exe_ctx (GetExecutionContextRef());
859 Target* target = exe_ctx.GetTargetPtr();
860 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +0000861 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000862 heap_buf_ptr->SetByteSize(bytes);
863 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
864 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +0000865 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000866 data.SetData(data_sp);
867 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +0000868 }
869 }
870 }
871 }
872 break;
873 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +0000874 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000875 ExecutionContext exe_ctx (GetExecutionContextRef());
876 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +0000877 if (process)
878 {
879 heap_buf_ptr->SetByteSize(bytes);
880 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
881 if (error.Success())
882 {
883 data.SetData(data_sp);
884 return bytes_read;
885 }
886 }
887 }
888 break;
889 case eAddressTypeHost:
890 {
891 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes);
892 data.SetData(data_sp);
893 return bytes;
894 }
895 break;
896 case eAddressTypeInvalid:
897 default:
898 break;
899 }
900 }
901 return 0;
902}
903
904size_t
905ValueObject::GetData (DataExtractor& data)
906{
907 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000908 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytone72dfb32012-02-24 01:59:29 +0000909 Error error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +0000910 if (error.Fail())
911 return 0;
912 data.SetAddressByteSize(m_data.GetAddressByteSize());
913 data.SetByteOrder(m_data.GetByteOrder());
914 return data.GetByteSize();
915}
916
917// will compute strlen(str), but without consuming more than
918// maxlen bytes out of str (this serves the purpose of reading
919// chunks of a string without having to worry about
920// missing NULL terminators in the chunk)
921// of course, if strlen(str) > maxlen, the function will return
922// maxlen_value (which should be != maxlen, because that allows you
923// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
924static uint32_t
925strlen_or_inf (const char* str,
926 uint32_t maxlen,
927 uint32_t maxlen_value)
928{
929 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +0000930 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +0000931 {
Greg Clayton8dd5c172011-10-05 22:19:51 +0000932 while(*str)
933 {
934 len++;str++;
935 if (len > maxlen)
936 return maxlen_value;
937 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000938 }
939 return len;
940}
941
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000942void
Greg Claytoncc4d0142012-02-17 07:49:44 +0000943ValueObject::ReadPointedString (Stream& s,
944 Error& error,
945 uint32_t max_length,
946 bool honor_array,
947 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000948{
Greg Claytoncc4d0142012-02-17 07:49:44 +0000949 ExecutionContext exe_ctx (GetExecutionContextRef());
950 Target* target = exe_ctx.GetTargetPtr();
951
952 if (target && max_length == 0)
953 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000954
955 clang_type_t clang_type = GetClangType();
956 clang_type_t elem_or_pointee_clang_type;
957 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
958 GetClangAST(),
959 &elem_or_pointee_clang_type));
960 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
961 ClangASTContext::IsCharType (elem_or_pointee_clang_type))
962 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000963 if (target == NULL)
964 {
965 s << "<no target to read from>";
966 }
967 else
968 {
969 addr_t cstr_address = LLDB_INVALID_ADDRESS;
970 AddressType cstr_address_type = eAddressTypeInvalid;
971
972 size_t cstr_len = 0;
973 bool capped_data = false;
974 if (type_flags.Test (ClangASTContext::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000975 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000976 // We have an array
977 cstr_len = ClangASTContext::GetArraySize (clang_type);
978 if (cstr_len > max_length)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000979 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000980 capped_data = true;
981 cstr_len = max_length;
982 }
983 cstr_address = GetAddressOf (true, &cstr_address_type);
984 }
985 else
986 {
987 // We have a pointer
988 cstr_address = GetPointerValue (&cstr_address_type);
989 }
990 if (cstr_address != 0 && cstr_address != LLDB_INVALID_ADDRESS)
991 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000992 Address cstr_so_addr (cstr_address);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000993 DataExtractor data;
994 size_t bytes_read = 0;
995 if (cstr_len > 0 && honor_array)
996 {
997 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
998 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
999 GetPointeeData(data, 0, cstr_len);
1000
1001 if ((bytes_read = data.GetByteSize()) > 0)
1002 {
1003 s << '"';
1004 data.Dump (&s,
1005 0, // Start offset in "data"
1006 item_format,
1007 1, // Size of item (1 byte for a char!)
1008 bytes_read, // How many bytes to print?
1009 UINT32_MAX, // num per line
1010 LLDB_INVALID_ADDRESS,// base address
1011 0, // bitfield bit size
1012 0); // bitfield bit offset
1013 if (capped_data)
1014 s << "...";
1015 s << '"';
1016 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00001017 }
1018 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001019 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001020 cstr_len = max_length;
1021 const size_t k_max_buf_size = 64;
1022
1023 size_t offset = 0;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001024
Greg Claytoncc4d0142012-02-17 07:49:44 +00001025 int cstr_len_displayed = -1;
1026 bool capped_cstr = false;
1027 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1028 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1029 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001030 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001031 const char *cstr = data.PeekCStr(0);
1032 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1033 if (len > k_max_buf_size)
1034 len = k_max_buf_size;
1035 if (cstr && cstr_len_displayed < 0)
1036 s << '"';
1037
1038 if (cstr_len_displayed < 0)
1039 cstr_len_displayed = len;
1040
1041 if (len == 0)
1042 break;
1043 cstr_len_displayed += len;
1044 if (len > bytes_read)
1045 len = bytes_read;
1046 if (len > cstr_len)
1047 len = cstr_len;
1048
1049 data.Dump (&s,
1050 0, // Start offset in "data"
1051 item_format,
1052 1, // Size of item (1 byte for a char!)
1053 len, // How many bytes to print?
1054 UINT32_MAX, // num per line
1055 LLDB_INVALID_ADDRESS,// base address
1056 0, // bitfield bit size
1057 0); // bitfield bit offset
1058
1059 if (len < k_max_buf_size)
1060 break;
1061
1062 if (len >= cstr_len)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001063 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001064 capped_cstr = true;
1065 break;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001066 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001067
1068 cstr_len -= len;
1069 offset += len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001070 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001071
1072 if (cstr_len_displayed >= 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001073 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001074 s << '"';
1075 if (capped_cstr)
1076 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001077 }
1078 }
1079 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001080 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001081 }
1082 else
1083 {
1084 error.SetErrorString("impossible to read a string from this object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001085 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001086 }
1087}
1088
Jim Ingham53c47f12010-09-10 23:12:17 +00001089const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001090ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001091{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001092
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001093 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001094 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001095
1096 if (!m_object_desc_str.empty())
1097 return m_object_desc_str.c_str();
1098
Greg Claytoncc4d0142012-02-17 07:49:44 +00001099 ExecutionContext exe_ctx (GetExecutionContextRef());
1100 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001101 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001102 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001103
Jim Ingham53c47f12010-09-10 23:12:17 +00001104 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001105
Greg Claytonafacd142011-09-02 01:15:17 +00001106 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001107 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1108
Jim Inghama2cf2632010-12-23 02:29:54 +00001109 if (runtime == NULL)
1110 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001111 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Jim Inghama2cf2632010-12-23 02:29:54 +00001112 clang_type_t opaque_qual_type = GetClangType();
1113 if (opaque_qual_type != NULL)
1114 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001115 bool is_signed;
1116 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed)
1117 || ClangASTContext::IsPointerType (opaque_qual_type))
1118 {
Greg Claytonafacd142011-09-02 01:15:17 +00001119 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001120 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001121 }
1122 }
1123
Jim Ingham8d543de2011-03-31 23:01:21 +00001124 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001125 {
1126 m_object_desc_str.append (s.GetData());
1127 }
Sean Callanan672ad942010-10-23 00:18:49 +00001128
1129 if (m_object_desc_str.empty())
1130 return NULL;
1131 else
1132 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001133}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001134
Enrico Granata0c489f52012-03-01 04:24:26 +00001135bool
1136ValueObject::GetValueAsCString (lldb::Format format,
1137 std::string& destination)
1138{
1139 if (ClangASTContext::IsAggregateType (GetClangType()) == false &&
1140 UpdateValueIfNeeded(false))
1141 {
1142 const Value::ContextType context_type = m_value.GetContextType();
1143
1144 switch (context_type)
1145 {
1146 case Value::eContextTypeClangType:
1147 case Value::eContextTypeLLDBType:
1148 case Value::eContextTypeVariable:
1149 {
1150 clang_type_t clang_type = GetClangType ();
1151 if (clang_type)
1152 {
1153 StreamString sstr;
1154 ExecutionContext exe_ctx (GetExecutionContextRef());
1155 ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
1156 clang_type, // The clang type to display
1157 &sstr,
1158 format, // Format to display this type with
1159 m_data, // Data to extract from
1160 0, // Byte offset into "m_data"
1161 GetByteSize(), // Byte size of item in "m_data"
1162 GetBitfieldBitSize(), // Bitfield bit size
1163 GetBitfieldBitOffset(), // Bitfield bit offset
1164 exe_ctx.GetBestExecutionContextScope());
1165 // Don't set the m_error to anything here otherwise
1166 // we won't be able to re-format as anything else. The
1167 // code for ClangASTType::DumpTypeValue() should always
1168 // return something, even if that something contains
1169 // an error messsage. "m_error" is used to detect errors
1170 // when reading the valid object, not for formatting errors.
1171 if (sstr.GetString().empty())
1172 destination.clear();
1173 else
1174 destination.swap(sstr.GetString());
1175 }
1176 }
1177 break;
1178
1179 case Value::eContextTypeRegisterInfo:
1180 {
1181 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1182 if (reg_info)
1183 {
1184 ExecutionContext exe_ctx (GetExecutionContextRef());
1185
1186 StreamString reg_sstr;
1187 m_data.Dump (&reg_sstr,
1188 0,
1189 format,
1190 reg_info->byte_size,
1191 1,
1192 UINT32_MAX,
1193 LLDB_INVALID_ADDRESS,
1194 0,
1195 0,
1196 exe_ctx.GetBestExecutionContextScope());
1197 destination.swap(reg_sstr.GetString());
1198 }
1199 }
1200 break;
1201
1202 default:
1203 break;
1204 }
1205 return !destination.empty();
1206 }
1207 else
1208 return false;
1209}
1210
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001211const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001212ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001213{
Enrico Granata0c489f52012-03-01 04:24:26 +00001214 if (UpdateValueIfNeeded(true) && m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001215 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001216 lldb::Format my_format = GetFormat();
1217 if (m_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001218 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001219 if (m_type_format_sp)
1220 my_format = m_type_format_sp->GetFormat();
1221 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001222 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001223 if (m_is_bitfield_for_scalar)
1224 my_format = eFormatUnsigned;
1225 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001226 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001227 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001228 {
1229 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1230 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001231 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001232 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001233 else
1234 {
1235 clang_type_t clang_type = GetClangType ();
1236 my_format = ClangASTType::GetFormat(clang_type);
1237 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001238 }
1239 }
1240 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001241 if (GetValueAsCString(my_format, m_value_str))
1242 {
1243 if (!m_value_did_change && m_old_value_valid)
1244 {
1245 // The value was gotten successfully, so we consider the
1246 // value as changed if the value string differs
1247 SetValueDidChange (m_old_value_str != m_value_str);
1248 }
1249 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001250 }
1251 if (m_value_str.empty())
1252 return NULL;
1253 return m_value_str.c_str();
1254}
1255
Enrico Granatac3e320a2011-08-02 17:27:39 +00001256// if > 8bytes, 0 is returned. this method should mostly be used
1257// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001258uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001259ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001260{
1261 // If our byte size is zero this is an aggregate type that has children
1262 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
1263 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001264 Scalar scalar;
1265 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001266 {
1267 if (success)
1268 *success = true;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001269 return scalar.GetRawBits64(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001270 }
1271 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001272 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001273
1274 if (success)
1275 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001276 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001277}
1278
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001279// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1280// this call up to date by returning true for your new special cases. We will eventually move
1281// to checking this call result before trying to display special cases
1282bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001283ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1284 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001285{
1286 clang_type_t elem_or_pointee_type;
1287 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
1288
1289 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001290 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001291 {
1292 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001293 (custom_format == eFormatCString ||
1294 custom_format == eFormatCharArray ||
1295 custom_format == eFormatChar ||
1296 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001297 return true;
1298
1299 if (flags.Test(ClangASTContext::eTypeIsArray))
1300 {
Greg Claytonafacd142011-09-02 01:15:17 +00001301 if ((custom_format == eFormatBytes) ||
1302 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001303 return true;
1304
Greg Claytonafacd142011-09-02 01:15:17 +00001305 if ((custom_format == eFormatVectorOfChar) ||
1306 (custom_format == eFormatVectorOfFloat32) ||
1307 (custom_format == eFormatVectorOfFloat64) ||
1308 (custom_format == eFormatVectorOfSInt16) ||
1309 (custom_format == eFormatVectorOfSInt32) ||
1310 (custom_format == eFormatVectorOfSInt64) ||
1311 (custom_format == eFormatVectorOfSInt8) ||
1312 (custom_format == eFormatVectorOfUInt128) ||
1313 (custom_format == eFormatVectorOfUInt16) ||
1314 (custom_format == eFormatVectorOfUInt32) ||
1315 (custom_format == eFormatVectorOfUInt64) ||
1316 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001317 return true;
1318 }
1319 }
1320 return false;
1321}
1322
Enrico Granata9fc19442011-07-06 02:13:41 +00001323bool
1324ValueObject::DumpPrintableRepresentation(Stream& s,
1325 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001326 Format custom_format,
Enrico Granata86cc9822012-03-19 22:58:49 +00001327 PrintableRepresentationSpecialCases special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001328{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001329
1330 clang_type_t elem_or_pointee_type;
1331 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001332
Enrico Granata86cc9822012-03-19 22:58:49 +00001333 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1334 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1335
1336 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001337 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001338 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1339 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001340 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001341 // when being asked to get a printable display an array or pointer type directly,
1342 // try to "do the right thing"
1343
1344 if (IsCStringContainer(true) &&
1345 (custom_format == eFormatCString ||
1346 custom_format == eFormatCharArray ||
1347 custom_format == eFormatChar ||
1348 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001349 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001350 Error error;
1351 ReadPointedString(s,
1352 error,
1353 0,
1354 (custom_format == eFormatVectorOfChar) ||
1355 (custom_format == eFormatCharArray));
1356 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001357 }
1358
Enrico Granata86cc9822012-03-19 22:58:49 +00001359 if (custom_format == eFormatEnum)
1360 return false;
1361
1362 // this only works for arrays, because I have no way to know when
1363 // the pointed memory ends, and no special \0 end of data marker
1364 if (flags.Test(ClangASTContext::eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001365 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001366 if ((custom_format == eFormatBytes) ||
1367 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001368 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001369 uint32_t count = GetNumChildren();
1370
1371 s << '[';
1372 for (uint32_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001373 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001374
1375 if (low)
1376 s << ',';
1377
1378 ValueObjectSP child = GetChildAtIndex(low,true);
1379 if (!child.get())
1380 {
1381 s << "<invalid child>";
1382 continue;
1383 }
1384 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1385 }
1386
1387 s << ']';
1388
1389 return true;
1390 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001391
Enrico Granata86cc9822012-03-19 22:58:49 +00001392 if ((custom_format == eFormatVectorOfChar) ||
1393 (custom_format == eFormatVectorOfFloat32) ||
1394 (custom_format == eFormatVectorOfFloat64) ||
1395 (custom_format == eFormatVectorOfSInt16) ||
1396 (custom_format == eFormatVectorOfSInt32) ||
1397 (custom_format == eFormatVectorOfSInt64) ||
1398 (custom_format == eFormatVectorOfSInt8) ||
1399 (custom_format == eFormatVectorOfUInt128) ||
1400 (custom_format == eFormatVectorOfUInt16) ||
1401 (custom_format == eFormatVectorOfUInt32) ||
1402 (custom_format == eFormatVectorOfUInt64) ||
1403 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1404 {
1405 uint32_t count = GetNumChildren();
1406
1407 Format format = FormatManager::GetSingleItemFormat(custom_format);
1408
1409 s << '[';
1410 for (uint32_t low = 0; low < count; low++)
1411 {
1412
1413 if (low)
1414 s << ',';
1415
1416 ValueObjectSP child = GetChildAtIndex(low,true);
1417 if (!child.get())
1418 {
1419 s << "<invalid child>";
1420 continue;
1421 }
1422 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1423 }
1424
1425 s << ']';
1426
1427 return true;
1428 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001429 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001430
1431 if ((custom_format == eFormatBoolean) ||
1432 (custom_format == eFormatBinary) ||
1433 (custom_format == eFormatChar) ||
1434 (custom_format == eFormatCharPrintable) ||
1435 (custom_format == eFormatComplexFloat) ||
1436 (custom_format == eFormatDecimal) ||
1437 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001438 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001439 (custom_format == eFormatFloat) ||
1440 (custom_format == eFormatOctal) ||
1441 (custom_format == eFormatOSType) ||
1442 (custom_format == eFormatUnicode16) ||
1443 (custom_format == eFormatUnicode32) ||
1444 (custom_format == eFormatUnsigned) ||
1445 (custom_format == eFormatPointer) ||
1446 (custom_format == eFormatComplexInteger) ||
1447 (custom_format == eFormatComplex) ||
1448 (custom_format == eFormatDefault)) // use the [] operator
1449 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001450 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001451 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001452
1453 if (only_special)
1454 return false;
1455
Enrico Granata86cc9822012-03-19 22:58:49 +00001456 bool var_success = false;
1457
1458 {
1459 const char * return_value;
1460 std::string alloc_mem;
1461
1462 if (custom_format != eFormatInvalid)
1463 SetFormat(custom_format);
1464
1465 switch(val_obj_display)
1466 {
1467 case eValueObjectRepresentationStyleValue:
1468 return_value = GetValueAsCString();
1469 break;
1470
1471 case eValueObjectRepresentationStyleSummary:
1472 return_value = GetSummaryAsCString();
1473 break;
1474
1475 case eValueObjectRepresentationStyleLanguageSpecific:
1476 return_value = GetObjectDescription();
1477 break;
1478
1479 case eValueObjectRepresentationStyleLocation:
1480 return_value = GetLocationAsCString();
1481 break;
1482
1483 case eValueObjectRepresentationStyleChildrenCount:
1484 {
1485 alloc_mem.resize(512);
1486 return_value = &alloc_mem[0];
1487 int count = GetNumChildren();
1488 snprintf((char*)return_value, 512, "%d", count);
1489 }
1490 break;
1491
1492 case eValueObjectRepresentationStyleType:
1493 return_value = GetTypeName().AsCString();
1494 break;
1495
1496 default:
1497 break;
1498 }
1499
1500 if (!return_value)
1501 {
1502 if (val_obj_display == eValueObjectRepresentationStyleValue)
1503 return_value = GetSummaryAsCString();
1504 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1505 {
1506 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1507 {
1508 // this thing has no value, and it seems to have no summary
1509 // some combination of unitialized data and other factors can also
1510 // raise this condition, so let's print a nice generic description
1511 {
1512 alloc_mem.resize(684);
1513 return_value = &alloc_mem[0];
1514 snprintf((char*)return_value, 684, "%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1515 }
1516 }
1517 else
1518 return_value = GetValueAsCString();
1519 }
1520 }
1521
1522 if (return_value)
1523 s.PutCString(return_value);
1524 else
1525 {
1526 if (m_error.Fail())
1527 s.Printf("<%s>", m_error.AsCString());
1528 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1529 s.PutCString("<no summary available>");
1530 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1531 s.PutCString("<no value available>");
1532 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1533 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1534 else
1535 s.PutCString("<no printable representation>");
1536 }
1537
1538 // we should only return false here if we could not do *anything*
1539 // even if we have an error message as output, that's a success
1540 // from our callers' perspective, so return true
1541 var_success = true;
1542
1543 if (custom_format != eFormatInvalid)
1544 SetFormat(eFormatDefault);
1545 }
1546
Enrico Granataf4efecd2011-07-12 22:56:10 +00001547 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001548}
1549
Greg Clayton737b9322010-09-13 03:32:57 +00001550addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001551ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001552{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001553 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001554 return LLDB_INVALID_ADDRESS;
1555
Greg Clayton73b472d2010-10-27 03:32:59 +00001556 switch (m_value.GetValueType())
1557 {
1558 case Value::eValueTypeScalar:
1559 if (scalar_is_load_address)
1560 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001561 if(address_type)
1562 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001563 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1564 }
1565 break;
1566
1567 case Value::eValueTypeLoadAddress:
1568 case Value::eValueTypeFileAddress:
1569 case Value::eValueTypeHostAddress:
1570 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001571 if(address_type)
1572 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001573 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1574 }
1575 break;
1576 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001577 if (address_type)
1578 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001579 return LLDB_INVALID_ADDRESS;
1580}
1581
1582addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001583ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001584{
Greg Claytonafacd142011-09-02 01:15:17 +00001585 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001586 if(address_type)
1587 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001588
Enrico Granatac3e320a2011-08-02 17:27:39 +00001589 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001590 return address;
1591
Greg Clayton73b472d2010-10-27 03:32:59 +00001592 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001593 {
1594 case Value::eValueTypeScalar:
Enrico Granata9128ee22011-09-06 19:20:51 +00001595 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001596 break;
1597
Enrico Granata9128ee22011-09-06 19:20:51 +00001598 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001599 case Value::eValueTypeLoadAddress:
1600 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001601 {
1602 uint32_t data_offset = 0;
1603 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001604 }
1605 break;
1606 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001607
Enrico Granata9128ee22011-09-06 19:20:51 +00001608 if (address_type)
1609 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001610
Greg Clayton737b9322010-09-13 03:32:57 +00001611 return address;
1612}
1613
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001614bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001615ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001616{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001617 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001618 // Make sure our value is up to date first so that our location and location
1619 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001620 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001621 {
1622 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001623 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001624 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001625
1626 uint32_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001627 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001628
Greg Claytonb1320972010-07-14 00:18:15 +00001629 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001630
Jim Ingham16e0c682011-08-12 23:34:31 +00001631 Value::ValueType value_type = m_value.GetValueType();
1632
1633 if (value_type == Value::eValueTypeScalar)
1634 {
1635 // If the value is already a scalar, then let the scalar change itself:
1636 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1637 }
1638 else if (byte_size <= Scalar::GetMaxByteSize())
1639 {
1640 // If the value fits in a scalar, then make a new scalar and again let the
1641 // scalar code do the conversion, then figure out where to put the new value.
1642 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001643 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1644 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001645 {
Jim Ingham4b536182011-08-09 02:12:22 +00001646 switch (value_type)
1647 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001648 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001649 {
1650 // If it is a load address, then the scalar value is the storage location
1651 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001652 ExecutionContext exe_ctx (GetExecutionContextRef());
1653 Process *process = exe_ctx.GetProcessPtr();
1654 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001655 {
Greg Claytonafacd142011-09-02 01:15:17 +00001656 addr_t target_addr = m_value.GetScalar().GetRawBits64(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001657 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1658 new_scalar,
1659 byte_size,
1660 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001661 if (!error.Success())
1662 return false;
1663 if (bytes_written != byte_size)
1664 {
1665 error.SetErrorString("unable to write value to memory");
1666 return false;
1667 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001668 }
1669 }
Jim Ingham4b536182011-08-09 02:12:22 +00001670 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001671 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001672 {
1673 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1674 DataExtractor new_data;
1675 new_data.SetByteOrder (m_data.GetByteOrder());
1676
1677 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1678 m_data.SetData(buffer_sp, 0);
1679 bool success = new_scalar.GetData(new_data);
1680 if (success)
1681 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001682 new_data.CopyByteOrderedData (0,
1683 byte_size,
1684 const_cast<uint8_t *>(m_data.GetDataStart()),
1685 byte_size,
1686 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001687 }
1688 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1689
1690 }
Jim Ingham4b536182011-08-09 02:12:22 +00001691 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001692 case Value::eValueTypeFileAddress:
1693 case Value::eValueTypeScalar:
Jim Ingham16e0c682011-08-12 23:34:31 +00001694 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001695 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001696 }
1697 else
1698 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001699 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001700 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001701 }
1702 else
1703 {
1704 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001705 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001706 return false;
1707 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001708
1709 // If we have reached this point, then we have successfully changed the value.
1710 SetNeedsUpdate();
1711 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001712}
1713
Greg Clayton81e871e2012-02-04 02:27:34 +00001714bool
1715ValueObject::GetDeclaration (Declaration &decl)
1716{
1717 decl.Clear();
1718 return false;
1719}
1720
Greg Clayton84db9102012-03-26 23:03:23 +00001721ConstString
1722ValueObject::GetTypeName()
1723{
1724 return ClangASTType::GetConstTypeName (GetClangAST(), GetClangType());
1725}
1726
1727ConstString
1728ValueObject::GetQualifiedTypeName()
1729{
1730 return ClangASTType::GetConstQualifiedTypeName (GetClangAST(), GetClangType());
1731}
1732
1733
Greg Claytonafacd142011-09-02 01:15:17 +00001734LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001735ValueObject::GetObjectRuntimeLanguage ()
1736{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001737 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1738 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001739}
1740
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001741void
Jim Ingham58b59f92011-04-22 23:53:53 +00001742ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001743{
Jim Ingham58b59f92011-04-22 23:53:53 +00001744 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001745}
1746
1747ValueObjectSP
1748ValueObject::GetSyntheticChild (const ConstString &key) const
1749{
1750 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001751 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001752 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001753 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001754 return synthetic_child_sp;
1755}
1756
1757bool
1758ValueObject::IsPointerType ()
1759{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001760 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001761}
1762
Jim Inghamb7603bb2011-03-18 00:05:18 +00001763bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001764ValueObject::IsArrayType ()
1765{
1766 return ClangASTContext::IsArrayType (GetClangType());
1767}
1768
1769bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001770ValueObject::IsScalarType ()
1771{
1772 return ClangASTContext::IsScalarType (GetClangType());
1773}
1774
1775bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001776ValueObject::IsIntegerType (bool &is_signed)
1777{
1778 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1779}
Greg Clayton73b472d2010-10-27 03:32:59 +00001780
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001781bool
1782ValueObject::IsPointerOrReferenceType ()
1783{
Greg Clayton007d5be2011-05-30 00:49:24 +00001784 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1785}
1786
1787bool
Greg Claytondea8cb42011-06-29 22:09:02 +00001788ValueObject::IsPossibleDynamicType ()
1789{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00001790 ExecutionContext exe_ctx (GetExecutionContextRef());
1791 Process *process = exe_ctx.GetProcessPtr();
1792 if (process)
1793 return process->IsPossibleDynamicValue(*this);
1794 else
Greg Clayton70364252012-08-31 18:56:24 +00001795 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType(), NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00001796}
1797
Greg Claytonafacd142011-09-02 01:15:17 +00001798ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001799ValueObject::GetSyntheticArrayMember (int32_t index, bool can_create)
1800{
1801 if (IsArrayType())
1802 return GetSyntheticArrayMemberFromArray(index, can_create);
1803
1804 if (IsPointerType())
1805 return GetSyntheticArrayMemberFromPointer(index, can_create);
1806
1807 return ValueObjectSP();
1808
1809}
1810
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001811ValueObjectSP
1812ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1813{
1814 ValueObjectSP synthetic_child_sp;
1815 if (IsPointerType ())
1816 {
1817 char index_str[64];
1818 snprintf(index_str, sizeof(index_str), "[%i]", index);
1819 ConstString index_const_str(index_str);
1820 // Check if we have already created a synthetic array member in this
1821 // valid object. If we have we will re-use it.
1822 synthetic_child_sp = GetSyntheticChild (index_const_str);
1823 if (!synthetic_child_sp)
1824 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001825 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001826 // We haven't made a synthetic array member for INDEX yet, so
1827 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001828 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001829
1830 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001831 if (synthetic_child)
1832 {
1833 AddSyntheticChild(index_const_str, synthetic_child);
1834 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001835 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001836 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001837 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001838 }
1839 }
1840 return synthetic_child_sp;
1841}
Jim Ingham22777012010-09-23 02:01:19 +00001842
Greg Claytondaf515f2011-07-09 20:12:33 +00001843// This allows you to create an array member using and index
1844// that doesn't not fall in the normal bounds of the array.
1845// Many times structure can be defined as:
1846// struct Collection
1847// {
1848// uint32_t item_count;
1849// Item item_array[0];
1850// };
1851// The size of the "item_array" is 1, but many times in practice
1852// there are more items in "item_array".
1853
1854ValueObjectSP
1855ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1856{
1857 ValueObjectSP synthetic_child_sp;
1858 if (IsArrayType ())
1859 {
1860 char index_str[64];
1861 snprintf(index_str, sizeof(index_str), "[%i]", index);
1862 ConstString index_const_str(index_str);
1863 // Check if we have already created a synthetic array member in this
1864 // valid object. If we have we will re-use it.
1865 synthetic_child_sp = GetSyntheticChild (index_const_str);
1866 if (!synthetic_child_sp)
1867 {
1868 ValueObject *synthetic_child;
1869 // We haven't made a synthetic array member for INDEX yet, so
1870 // lets make one and cache it for any future reference.
1871 synthetic_child = CreateChildAtIndex(0, true, index);
1872
1873 // Cache the value if we got one back...
1874 if (synthetic_child)
1875 {
1876 AddSyntheticChild(index_const_str, synthetic_child);
1877 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001878 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001879 synthetic_child_sp->m_is_array_item_for_pointer = true;
1880 }
1881 }
1882 }
1883 return synthetic_child_sp;
1884}
1885
Enrico Granata9fc19442011-07-06 02:13:41 +00001886ValueObjectSP
1887ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1888{
1889 ValueObjectSP synthetic_child_sp;
1890 if (IsScalarType ())
1891 {
1892 char index_str[64];
1893 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1894 ConstString index_const_str(index_str);
1895 // Check if we have already created a synthetic array member in this
1896 // valid object. If we have we will re-use it.
1897 synthetic_child_sp = GetSyntheticChild (index_const_str);
1898 if (!synthetic_child_sp)
1899 {
1900 ValueObjectChild *synthetic_child;
1901 // We haven't made a synthetic array member for INDEX yet, so
1902 // lets make one and cache it for any future reference.
1903 synthetic_child = new ValueObjectChild(*this,
1904 GetClangAST(),
1905 GetClangType(),
1906 index_const_str,
1907 GetByteSize(),
1908 0,
1909 to-from+1,
1910 from,
1911 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001912 false,
1913 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00001914
1915 // Cache the value if we got one back...
1916 if (synthetic_child)
1917 {
1918 AddSyntheticChild(index_const_str, synthetic_child);
1919 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001920 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00001921 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1922 }
1923 }
1924 }
1925 return synthetic_child_sp;
1926}
1927
Greg Claytonafacd142011-09-02 01:15:17 +00001928ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001929ValueObject::GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create)
1930{
1931 ValueObjectSP synthetic_child_sp;
1932 if (IsArrayType () || IsPointerType ())
1933 {
1934 char index_str[64];
1935 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1936 ConstString index_const_str(index_str);
1937 // Check if we have already created a synthetic array member in this
1938 // valid object. If we have we will re-use it.
1939 synthetic_child_sp = GetSyntheticChild (index_const_str);
1940 if (!synthetic_child_sp)
1941 {
1942 ValueObjectSynthetic *synthetic_child;
1943
1944 // We haven't made a synthetic array member for INDEX yet, so
1945 // lets make one and cache it for any future reference.
Enrico Granata061858c2012-02-15 02:34:21 +00001946 SyntheticArrayView *view = new SyntheticArrayView(SyntheticChildren::Flags());
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001947 view->AddRange(from,to);
1948 SyntheticChildrenSP view_sp(view);
1949 synthetic_child = new ValueObjectSynthetic(*this, view_sp);
1950
1951 // Cache the value if we got one back...
1952 if (synthetic_child)
1953 {
1954 AddSyntheticChild(index_const_str, synthetic_child);
1955 synthetic_child_sp = synthetic_child->GetSP();
1956 synthetic_child_sp->SetName(ConstString(index_str));
1957 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1958 }
1959 }
1960 }
1961 return synthetic_child_sp;
1962}
1963
Greg Claytonafacd142011-09-02 01:15:17 +00001964ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00001965ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
1966{
1967
1968 ValueObjectSP synthetic_child_sp;
1969
1970 char name_str[64];
1971 snprintf(name_str, sizeof(name_str), "@%i", offset);
1972 ConstString name_const_str(name_str);
1973
1974 // Check if we have already created a synthetic array member in this
1975 // valid object. If we have we will re-use it.
1976 synthetic_child_sp = GetSyntheticChild (name_const_str);
1977
1978 if (synthetic_child_sp.get())
1979 return synthetic_child_sp;
1980
1981 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00001982 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001983
1984 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
1985 type.GetASTContext(),
1986 type.GetOpaqueQualType(),
1987 name_const_str,
1988 type.GetTypeByteSize(),
1989 offset,
1990 0,
1991 0,
1992 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001993 false,
1994 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001995 if (synthetic_child)
1996 {
1997 AddSyntheticChild(name_const_str, synthetic_child);
1998 synthetic_child_sp = synthetic_child->GetSP();
1999 synthetic_child_sp->SetName(name_const_str);
2000 synthetic_child_sp->m_is_child_at_offset = true;
2001 }
2002 return synthetic_child_sp;
2003}
2004
Enrico Granatad55546b2011-07-22 00:16:08 +00002005// your expression path needs to have a leading . or ->
2006// (unless it somehow "looks like" an array, in which case it has
2007// a leading [ symbol). while the [ is meaningful and should be shown
2008// to the user, . and -> are just parser design, but by no means
2009// added information for the user.. strip them off
2010static const char*
2011SkipLeadingExpressionPathSeparators(const char* expression)
2012{
2013 if (!expression || !expression[0])
2014 return expression;
2015 if (expression[0] == '.')
2016 return expression+1;
2017 if (expression[0] == '-' && expression[1] == '>')
2018 return expression+2;
2019 return expression;
2020}
2021
Greg Claytonafacd142011-09-02 01:15:17 +00002022ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002023ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2024{
2025 ValueObjectSP synthetic_child_sp;
2026 ConstString name_const_string(expression);
2027 // Check if we have already created a synthetic array member in this
2028 // valid object. If we have we will re-use it.
2029 synthetic_child_sp = GetSyntheticChild (name_const_string);
2030 if (!synthetic_child_sp)
2031 {
2032 // We haven't made a synthetic array member for expression yet, so
2033 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002034 synthetic_child_sp = GetValueForExpressionPath(expression,
2035 NULL, NULL, NULL,
2036 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
Enrico Granatad55546b2011-07-22 00:16:08 +00002037
2038 // Cache the value if we got one back...
2039 if (synthetic_child_sp.get())
2040 {
2041 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002042 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002043 synthetic_child_sp->m_is_expression_path_child = true;
2044 }
2045 }
2046 return synthetic_child_sp;
2047}
2048
2049void
Enrico Granata86cc9822012-03-19 22:58:49 +00002050ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002051{
Enrico Granata86cc9822012-03-19 22:58:49 +00002052 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002053 return;
2054
Enrico Granatac5bc4122012-03-27 02:35:13 +00002055 TargetSP target_sp(GetTargetSP());
2056 if (target_sp && (target_sp->GetEnableSyntheticValue() == false || target_sp->GetSuppressSyntheticValue() == true))
2057 {
2058 m_synthetic_value = NULL;
2059 return;
2060 }
2061
Enrico Granata86cc9822012-03-19 22:58:49 +00002062 if (!UpdateFormatsIfNeeded(m_last_format_mgr_dynamic) && m_synthetic_value)
2063 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002064
Enrico Granata0c489f52012-03-01 04:24:26 +00002065 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002066 return;
2067
Enrico Granata86cc9822012-03-19 22:58:49 +00002068 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002069}
2070
Jim Ingham78a685a2011-04-16 00:01:13 +00002071void
Greg Claytonafacd142011-09-02 01:15:17 +00002072ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002073{
Greg Claytonafacd142011-09-02 01:15:17 +00002074 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002075 return;
2076
Jim Ingham58b59f92011-04-22 23:53:53 +00002077 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002078 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002079 ExecutionContext exe_ctx (GetExecutionContextRef());
2080 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002081 if (process && process->IsPossibleDynamicValue(*this))
2082 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002083 }
2084}
2085
Jim Ingham58b59f92011-04-22 23:53:53 +00002086ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002087ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002088{
Greg Claytonafacd142011-09-02 01:15:17 +00002089 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002090 return ValueObjectSP();
2091
2092 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002093 {
Jim Ingham2837b762011-05-04 03:43:18 +00002094 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002095 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002096 if (m_dynamic_value)
2097 return m_dynamic_value->GetSP();
2098 else
2099 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002100}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002101
Jim Ingham60dbabb2011-12-08 19:44:08 +00002102ValueObjectSP
2103ValueObject::GetStaticValue()
2104{
2105 return GetSP();
2106}
2107
Enrico Granata886147f2012-05-08 18:47:08 +00002108lldb::ValueObjectSP
2109ValueObject::GetNonSyntheticValue ()
2110{
2111 return GetSP();
2112}
2113
Enrico Granatad55546b2011-07-22 00:16:08 +00002114ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002115ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002116{
Enrico Granata86cc9822012-03-19 22:58:49 +00002117 if (use_synthetic == false)
2118 return ValueObjectSP();
2119
Enrico Granatad55546b2011-07-22 00:16:08 +00002120 CalculateSyntheticValue(use_synthetic);
2121
2122 if (m_synthetic_value)
2123 return m_synthetic_value->GetSP();
2124 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002125 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002126}
2127
Greg Claytone221f822011-01-21 01:59:00 +00002128bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002129ValueObject::HasSyntheticValue()
2130{
2131 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
2132
Enrico Granata0c489f52012-03-01 04:24:26 +00002133 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002134 return false;
2135
Enrico Granata86cc9822012-03-19 22:58:49 +00002136 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002137
2138 if (m_synthetic_value)
2139 return true;
2140 else
2141 return false;
2142}
2143
2144bool
Greg Claytone221f822011-01-21 01:59:00 +00002145ValueObject::GetBaseClassPath (Stream &s)
2146{
2147 if (IsBaseClass())
2148 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002149 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00002150 clang_type_t clang_type = GetClangType();
2151 std::string cxx_class_name;
2152 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
2153 if (this_had_base_class)
2154 {
2155 if (parent_had_base_class)
2156 s.PutCString("::");
2157 s.PutCString(cxx_class_name.c_str());
2158 }
2159 return parent_had_base_class || this_had_base_class;
2160 }
2161 return false;
2162}
2163
2164
2165ValueObject *
2166ValueObject::GetNonBaseClassParent()
2167{
Jim Ingham78a685a2011-04-16 00:01:13 +00002168 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002169 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002170 if (GetParent()->IsBaseClass())
2171 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002172 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002173 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002174 }
2175 return NULL;
2176}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002177
2178void
Enrico Granata4becb372011-06-29 22:27:15 +00002179ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002180{
Greg Claytone221f822011-01-21 01:59:00 +00002181 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002182
Enrico Granata86cc9822012-03-19 22:58:49 +00002183 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002184 {
Enrico Granata4becb372011-06-29 22:27:15 +00002185 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2186 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2187 // the eHonorPointers mode is meant to produce strings in this latter format
2188 s.PutCString("*(");
2189 }
Greg Claytone221f822011-01-21 01:59:00 +00002190
Enrico Granata4becb372011-06-29 22:27:15 +00002191 ValueObject* parent = GetParent();
2192
2193 if (parent)
2194 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002195
2196 // if we are a deref_of_parent just because we are synthetic array
2197 // members made up to allow ptr[%d] syntax to work in variable
2198 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002199 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002200 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002201
Greg Claytone221f822011-01-21 01:59:00 +00002202 if (!IsBaseClass())
2203 {
2204 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002205 {
Greg Claytone221f822011-01-21 01:59:00 +00002206 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2207 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002208 {
Greg Claytone221f822011-01-21 01:59:00 +00002209 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2210 if (non_base_class_parent_clang_type)
2211 {
2212 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2213
Enrico Granata86cc9822012-03-19 22:58:49 +00002214 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002215 {
2216 s.PutCString("->");
2217 }
Enrico Granata4becb372011-06-29 22:27:15 +00002218 else
2219 {
2220 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2221 {
2222 s.PutCString("->");
2223 }
2224 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2225 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2226 {
2227 s.PutChar('.');
2228 }
Greg Claytone221f822011-01-21 01:59:00 +00002229 }
2230 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002231 }
Greg Claytone221f822011-01-21 01:59:00 +00002232
2233 const char *name = GetName().GetCString();
2234 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002235 {
Greg Claytone221f822011-01-21 01:59:00 +00002236 if (qualify_cxx_base_classes)
2237 {
2238 if (GetBaseClassPath (s))
2239 s.PutCString("::");
2240 }
2241 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002242 }
2243 }
2244 }
2245
Enrico Granata86cc9822012-03-19 22:58:49 +00002246 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002247 {
Greg Claytone221f822011-01-21 01:59:00 +00002248 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002249 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002250}
2251
Greg Claytonafacd142011-09-02 01:15:17 +00002252ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002253ValueObject::GetValueForExpressionPath(const char* expression,
2254 const char** first_unparsed,
2255 ExpressionPathScanEndReason* reason_to_stop,
2256 ExpressionPathEndResultType* final_value_type,
2257 const GetValueForExpressionPathOptions& options,
2258 ExpressionPathAftermath* final_task_on_target)
2259{
2260
2261 const char* dummy_first_unparsed;
2262 ExpressionPathScanEndReason dummy_reason_to_stop;
2263 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002264 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002265
2266 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2267 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2268 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2269 final_value_type ? final_value_type : &dummy_final_value_type,
2270 options,
2271 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2272
Enrico Granata86cc9822012-03-19 22:58:49 +00002273 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002274 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002275
Enrico Granata86cc9822012-03-19 22:58:49 +00002276 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 +00002277 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002278 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002279 {
2280 Error error;
2281 ValueObjectSP final_value = ret_val->Dereference(error);
2282 if (error.Fail() || !final_value.get())
2283 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002284 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002285 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002286 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002287 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002288 return ValueObjectSP();
2289 }
2290 else
2291 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002292 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002293 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002294 return final_value;
2295 }
2296 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002297 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002298 {
2299 Error error;
2300 ValueObjectSP final_value = ret_val->AddressOf(error);
2301 if (error.Fail() || !final_value.get())
2302 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002303 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002304 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002305 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002306 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002307 return ValueObjectSP();
2308 }
2309 else
2310 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002311 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002312 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002313 return final_value;
2314 }
2315 }
2316 }
2317 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2318}
2319
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002320int
2321ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002322 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002323 const char** first_unparsed,
2324 ExpressionPathScanEndReason* reason_to_stop,
2325 ExpressionPathEndResultType* final_value_type,
2326 const GetValueForExpressionPathOptions& options,
2327 ExpressionPathAftermath* final_task_on_target)
2328{
2329 const char* dummy_first_unparsed;
2330 ExpressionPathScanEndReason dummy_reason_to_stop;
2331 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002332 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002333
2334 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2335 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2336 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2337 final_value_type ? final_value_type : &dummy_final_value_type,
2338 options,
2339 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2340
2341 if (!ret_val.get()) // if there are errors, I add nothing to the list
2342 return 0;
2343
Enrico Granata86ea8d82012-03-29 01:34:34 +00002344 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002345 {
2346 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002347 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002348 {
2349 list->Append(ret_val);
2350 return 1;
2351 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002352 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 +00002353 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002354 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002355 {
2356 Error error;
2357 ValueObjectSP final_value = ret_val->Dereference(error);
2358 if (error.Fail() || !final_value.get())
2359 {
Greg Clayton23f59502012-07-17 03:23:13 +00002360 if (reason_to_stop)
2361 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2362 if (final_value_type)
2363 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002364 return 0;
2365 }
2366 else
2367 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002368 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002369 list->Append(final_value);
2370 return 1;
2371 }
2372 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002373 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002374 {
2375 Error error;
2376 ValueObjectSP final_value = ret_val->AddressOf(error);
2377 if (error.Fail() || !final_value.get())
2378 {
Greg Clayton23f59502012-07-17 03:23:13 +00002379 if (reason_to_stop)
2380 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2381 if (final_value_type)
2382 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002383 return 0;
2384 }
2385 else
2386 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002387 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002388 list->Append(final_value);
2389 return 1;
2390 }
2391 }
2392 }
2393 }
2394 else
2395 {
2396 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2397 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2398 ret_val,
2399 list,
2400 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2401 final_value_type ? final_value_type : &dummy_final_value_type,
2402 options,
2403 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2404 }
2405 // in any non-covered case, just do the obviously right thing
2406 list->Append(ret_val);
2407 return 1;
2408}
2409
Greg Claytonafacd142011-09-02 01:15:17 +00002410ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002411ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2412 const char** first_unparsed,
2413 ExpressionPathScanEndReason* reason_to_stop,
2414 ExpressionPathEndResultType* final_result,
2415 const GetValueForExpressionPathOptions& options,
2416 ExpressionPathAftermath* what_next)
2417{
2418 ValueObjectSP root = GetSP();
2419
2420 if (!root.get())
2421 return ValueObjectSP();
2422
2423 *first_unparsed = expression_cstr;
2424
2425 while (true)
2426 {
2427
2428 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2429
Greg Claytonafacd142011-09-02 01:15:17 +00002430 clang_type_t root_clang_type = root->GetClangType();
2431 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002432 Flags root_clang_type_info,pointee_clang_type_info;
2433
2434 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2435 if (pointee_clang_type)
2436 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002437
2438 if (!expression_cstr || *expression_cstr == '\0')
2439 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002440 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002441 return root;
2442 }
2443
2444 switch (*expression_cstr)
2445 {
2446 case '-':
2447 {
2448 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002449 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 +00002450 {
2451 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002452 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2453 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002454 return ValueObjectSP();
2455 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002456 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2457 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002458 options.m_no_fragile_ivar)
2459 {
2460 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002461 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2462 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002463 return ValueObjectSP();
2464 }
2465 if (expression_cstr[1] != '>')
2466 {
2467 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002468 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2469 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002470 return ValueObjectSP();
2471 }
2472 expression_cstr++; // skip the -
2473 }
2474 case '.': // or fallthrough from ->
2475 {
2476 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002477 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 +00002478 {
2479 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002480 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2481 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002482 return ValueObjectSP();
2483 }
2484 expression_cstr++; // skip .
2485 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2486 ConstString child_name;
2487 if (!next_separator) // if no other separator just expand this last layer
2488 {
2489 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002490 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2491
2492 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002493 {
2494 *first_unparsed = '\0';
Enrico Granata86cc9822012-03-19 22:58:49 +00002495 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2496 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002497 return child_valobj_sp;
2498 }
2499 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2500 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002501 if (root->IsSynthetic())
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002502 {
2503 *first_unparsed = expression_cstr;
2504 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2505 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2506 return ValueObjectSP();
2507 }
2508
2509 child_valobj_sp = root->GetSyntheticValue();
Enrico Granata86cc9822012-03-19 22:58:49 +00002510 if (child_valobj_sp.get())
2511 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002512 }
2513
2514 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2515 // so we hit the "else" branch, and return an error
2516 if(child_valobj_sp.get()) // if it worked, just return
2517 {
2518 *first_unparsed = '\0';
Enrico Granata86cc9822012-03-19 22:58:49 +00002519 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2520 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002521 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002522 }
2523 else
2524 {
2525 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002526 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2527 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002528 return ValueObjectSP();
2529 }
2530 }
2531 else // other layers do expand
2532 {
2533 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002534 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2535 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002536 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002537 root = child_valobj_sp;
2538 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002539 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002540 continue;
2541 }
2542 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2543 {
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002544 if (root->IsSynthetic())
2545 {
2546 *first_unparsed = expression_cstr;
2547 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2548 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2549 return ValueObjectSP();
2550 }
2551
Enrico Granata86cc9822012-03-19 22:58:49 +00002552 child_valobj_sp = root->GetSyntheticValue(true);
2553 if (child_valobj_sp)
2554 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002555 }
2556
2557 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2558 // so we hit the "else" branch, and return an error
2559 if(child_valobj_sp.get()) // if it worked, move on
2560 {
2561 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002562 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002563 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002564 continue;
2565 }
2566 else
2567 {
2568 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002569 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2570 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002571 return ValueObjectSP();
2572 }
2573 }
2574 break;
2575 }
2576 case '[':
2577 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002578 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 +00002579 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002580 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002581 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002582 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2583 {
2584 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002585 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2586 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002587 return ValueObjectSP();
2588 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002589 }
2590 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2591 {
2592 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002593 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2594 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002595 return ValueObjectSP();
2596 }
2597 }
2598 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2599 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002600 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002601 {
2602 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002603 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2604 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002605 return ValueObjectSP();
2606 }
2607 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2608 {
2609 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002610 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2611 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002612 return root;
2613 }
2614 }
2615 const char *separator_position = ::strchr(expression_cstr+1,'-');
2616 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2617 if (!close_bracket_position) // if there is no ], this is a syntax error
2618 {
2619 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002620 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2621 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002622 return ValueObjectSP();
2623 }
2624 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2625 {
2626 char *end = NULL;
2627 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2628 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2629 {
2630 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002631 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2632 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002633 return ValueObjectSP();
2634 }
2635 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2636 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002637 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002638 {
2639 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002640 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2641 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002642 return root;
2643 }
2644 else
2645 {
2646 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002647 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2648 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002649 return ValueObjectSP();
2650 }
2651 }
2652 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002653 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002654 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002655 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2656 if (!child_valobj_sp)
2657 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002658 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002659 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2660 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002661 if (child_valobj_sp)
2662 {
2663 root = child_valobj_sp;
2664 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002665 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002666 continue;
2667 }
2668 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002669 {
2670 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002671 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2672 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002673 return ValueObjectSP();
2674 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002675 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002676 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002677 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002678 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 +00002679 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002680 {
2681 Error error;
2682 root = root->Dereference(error);
2683 if (error.Fail() || !root.get())
2684 {
2685 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002686 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2687 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002688 return ValueObjectSP();
2689 }
2690 else
2691 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002692 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002693 continue;
2694 }
2695 }
2696 else
2697 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002698 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Clayton84db9102012-03-26 23:03:23 +00002699 root->GetClangType()) == eLanguageTypeObjC
2700 && ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2701 && root->HasSyntheticValue()
2702 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002703 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002704 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002705 }
2706 else
2707 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002708 if (!root.get())
2709 {
2710 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002711 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2712 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002713 return ValueObjectSP();
2714 }
2715 else
2716 {
2717 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002718 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002719 continue;
2720 }
2721 }
2722 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002723 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002724 {
2725 root = root->GetSyntheticBitFieldChild(index, index, true);
2726 if (!root.get())
2727 {
2728 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002729 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2730 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002731 return ValueObjectSP();
2732 }
2733 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2734 {
2735 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002736 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2737 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002738 return root;
2739 }
2740 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002741 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002742 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002743 if (root->HasSyntheticValue())
2744 root = root->GetSyntheticValue();
2745 else if (!root->IsSynthetic())
2746 {
2747 *first_unparsed = expression_cstr;
2748 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2749 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2750 return ValueObjectSP();
2751 }
2752 // if we are here, then root itself is a synthetic VO.. should be good to go
2753
Enrico Granata27b625e2011-08-09 01:04:56 +00002754 if (!root.get())
2755 {
2756 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002757 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2758 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2759 return ValueObjectSP();
2760 }
2761 root = root->GetChildAtIndex(index, true);
2762 if (!root.get())
2763 {
2764 *first_unparsed = expression_cstr;
2765 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2766 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002767 return ValueObjectSP();
2768 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002769 else
2770 {
2771 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002772 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002773 continue;
2774 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002775 }
2776 else
2777 {
2778 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002779 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2780 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002781 return ValueObjectSP();
2782 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002783 }
2784 else // we have a low and a high index
2785 {
2786 char *end = NULL;
2787 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2788 if (!end || end != separator_position) // if something weird is in our way return an error
2789 {
2790 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002791 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2792 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002793 return ValueObjectSP();
2794 }
2795 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2796 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2797 {
2798 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002799 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2800 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002801 return ValueObjectSP();
2802 }
2803 if (index_lower > index_higher) // swap indices if required
2804 {
2805 unsigned long temp = index_lower;
2806 index_lower = index_higher;
2807 index_higher = temp;
2808 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002809 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002810 {
2811 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2812 if (!root.get())
2813 {
2814 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002815 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2816 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002817 return ValueObjectSP();
2818 }
2819 else
2820 {
2821 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002822 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2823 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002824 return root;
2825 }
2826 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002827 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 +00002828 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002829 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002830 {
2831 Error error;
2832 root = root->Dereference(error);
2833 if (error.Fail() || !root.get())
2834 {
2835 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002836 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2837 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002838 return ValueObjectSP();
2839 }
2840 else
2841 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002842 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002843 continue;
2844 }
2845 }
2846 else
2847 {
2848 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002849 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2850 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002851 return root;
2852 }
2853 }
2854 break;
2855 }
2856 default: // some non-separator is in the way
2857 {
2858 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002859 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2860 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002861 return ValueObjectSP();
2862 break;
2863 }
2864 }
2865 }
2866}
2867
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002868int
2869ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2870 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002871 ValueObjectSP root,
2872 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002873 ExpressionPathScanEndReason* reason_to_stop,
2874 ExpressionPathEndResultType* final_result,
2875 const GetValueForExpressionPathOptions& options,
2876 ExpressionPathAftermath* what_next)
2877{
2878 if (!root.get())
2879 return 0;
2880
2881 *first_unparsed = expression_cstr;
2882
2883 while (true)
2884 {
2885
2886 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2887
Greg Claytonafacd142011-09-02 01:15:17 +00002888 clang_type_t root_clang_type = root->GetClangType();
2889 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002890 Flags root_clang_type_info,pointee_clang_type_info;
2891
2892 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2893 if (pointee_clang_type)
2894 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2895
2896 if (!expression_cstr || *expression_cstr == '\0')
2897 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002898 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002899 list->Append(root);
2900 return 1;
2901 }
2902
2903 switch (*expression_cstr)
2904 {
2905 case '[':
2906 {
2907 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2908 {
2909 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2910 {
2911 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002912 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2913 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002914 return 0;
2915 }
2916 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2917 {
2918 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002919 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2920 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002921 return 0;
2922 }
2923 }
2924 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2925 {
2926 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2927 {
2928 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002929 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2930 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002931 return 0;
2932 }
2933 else // expand this into list
2934 {
2935 int max_index = root->GetNumChildren() - 1;
2936 for (int index = 0; index < max_index; index++)
2937 {
2938 ValueObjectSP child =
2939 root->GetChildAtIndex(index, true);
2940 list->Append(child);
2941 }
2942 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002943 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
2944 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002945 return max_index; // tell me number of items I added to the VOList
2946 }
2947 }
2948 const char *separator_position = ::strchr(expression_cstr+1,'-');
2949 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2950 if (!close_bracket_position) // if there is no ], this is a syntax error
2951 {
2952 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002953 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2954 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002955 return 0;
2956 }
2957 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2958 {
2959 char *end = NULL;
2960 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2961 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2962 {
2963 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002964 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2965 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002966 return 0;
2967 }
2968 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2969 {
2970 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2971 {
2972 int max_index = root->GetNumChildren() - 1;
2973 for (int index = 0; index < max_index; index++)
2974 {
2975 ValueObjectSP child =
2976 root->GetChildAtIndex(index, true);
2977 list->Append(child);
2978 }
2979 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002980 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
2981 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002982 return max_index; // tell me number of items I added to the VOList
2983 }
2984 else
2985 {
2986 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002987 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2988 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002989 return 0;
2990 }
2991 }
2992 // from here on we do have a valid index
2993 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2994 {
2995 root = root->GetChildAtIndex(index, true);
2996 if (!root.get())
2997 {
2998 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002999 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3000 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003001 return 0;
3002 }
3003 else
3004 {
3005 list->Append(root);
3006 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003007 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3008 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003009 return 1;
3010 }
3011 }
3012 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
3013 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003014 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 +00003015 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3016 {
3017 Error error;
3018 root = root->Dereference(error);
3019 if (error.Fail() || !root.get())
3020 {
3021 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003022 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3023 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003024 return 0;
3025 }
3026 else
3027 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003028 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003029 continue;
3030 }
3031 }
3032 else
3033 {
3034 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3035 if (!root.get())
3036 {
3037 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003038 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3039 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003040 return 0;
3041 }
3042 else
3043 {
3044 list->Append(root);
3045 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003046 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3047 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003048 return 1;
3049 }
3050 }
3051 }
3052 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3053 {
3054 root = root->GetSyntheticBitFieldChild(index, index, true);
3055 if (!root.get())
3056 {
3057 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003058 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3059 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003060 return 0;
3061 }
3062 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3063 {
3064 list->Append(root);
3065 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003066 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3067 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003068 return 1;
3069 }
3070 }
3071 }
3072 else // we have a low and a high index
3073 {
3074 char *end = NULL;
3075 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3076 if (!end || end != separator_position) // if something weird is in our way return an error
3077 {
3078 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003079 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3080 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003081 return 0;
3082 }
3083 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3084 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3085 {
3086 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003087 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3088 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003089 return 0;
3090 }
3091 if (index_lower > index_higher) // swap indices if required
3092 {
3093 unsigned long temp = index_lower;
3094 index_lower = index_higher;
3095 index_higher = temp;
3096 }
3097 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
3098 {
3099 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3100 if (!root.get())
3101 {
3102 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003103 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3104 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003105 return 0;
3106 }
3107 else
3108 {
3109 list->Append(root);
3110 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003111 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3112 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003113 return 1;
3114 }
3115 }
3116 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 +00003117 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003118 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3119 {
3120 Error error;
3121 root = root->Dereference(error);
3122 if (error.Fail() || !root.get())
3123 {
3124 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003125 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3126 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003127 return 0;
3128 }
3129 else
3130 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003131 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003132 continue;
3133 }
3134 }
3135 else
3136 {
Johnny Chen44805302011-07-19 19:48:13 +00003137 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003138 index <= index_higher; index++)
3139 {
3140 ValueObjectSP child =
3141 root->GetChildAtIndex(index, true);
3142 list->Append(child);
3143 }
3144 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003145 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3146 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003147 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3148 }
3149 }
3150 break;
3151 }
3152 default: // some non-[ separator, or something entirely wrong, is in the way
3153 {
3154 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003155 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3156 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003157 return 0;
3158 break;
3159 }
3160 }
3161 }
3162}
3163
Enrico Granata0c489f52012-03-01 04:24:26 +00003164static void
3165DumpValueObject_Impl (Stream &s,
3166 ValueObject *valobj,
3167 const ValueObject::DumpValueObjectOptions& options,
3168 uint32_t ptr_depth,
3169 uint32_t curr_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003170{
Greg Clayton007d5be2011-05-30 00:49:24 +00003171 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003172 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003173 bool update_success = valobj->UpdateValueIfNeeded (options.m_use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00003174
Enrico Granata0c489f52012-03-01 04:24:26 +00003175 const char *root_valobj_name =
3176 options.m_root_valobj_name.empty() ?
3177 valobj->GetName().AsCString() :
3178 options.m_root_valobj_name.c_str();
3179
3180 if (update_success && options.m_use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00003181 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003182 ValueObject *dynamic_value = valobj->GetDynamicValue(options.m_use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003183 if (dynamic_value)
3184 valobj = dynamic_value;
3185 }
3186
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003187 clang_type_t clang_type = valobj->GetClangType();
3188
Greg Clayton73b472d2010-10-27 03:32:59 +00003189 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003190 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00003191 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
3192 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003193
Enrico Granata0c489f52012-03-01 04:24:26 +00003194 const bool print_valobj = options.m_flat_output == false || has_value;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003195
3196 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003197 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003198 if (options.m_show_location)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003199 {
Jim Ingham6035b672011-03-31 00:19:25 +00003200 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003201 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003202
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003203 s.Indent();
Enrico Granata2b2631c2012-08-09 16:51:25 +00003204
3205 bool show_type = true;
3206 // if we are at the root-level and been asked to hide the root's type, then hide it
3207 if (curr_depth == 0 && options.m_hide_root_type)
3208 show_type = false;
3209 else
3210 // otherwise decide according to the usual rules (asked to show types - always at the root level)
3211 show_type = options.m_show_types || (curr_depth == 0 && !options.m_flat_output);
3212
3213 if (show_type)
Enrico Granatac3e320a2011-08-02 17:27:39 +00003214 {
Greg Clayton84db9102012-03-26 23:03:23 +00003215 const char* typeName = valobj->GetQualifiedTypeName().AsCString("<invalid type>");
3216 //const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
Enrico Granata9910bc82011-08-03 02:18:51 +00003217 s.Printf("(%s", typeName);
3218 // only show dynamic types if the user really wants to see types
Enrico Granata0c489f52012-03-01 04:24:26 +00003219 if (options.m_show_types && options.m_use_dynamic != eNoDynamicValues &&
Enrico Granata9910bc82011-08-03 02:18:51 +00003220 (/*strstr(typeName, "id") == typeName ||*/
Greg Claytonafacd142011-09-02 01:15:17 +00003221 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003222 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003223 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3224 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatac3e320a2011-08-02 17:27:39 +00003225 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003226 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003227 else
3228 {
3229 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
3230 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003231 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003232 else
3233 {
Greg Claytonf0246d12012-10-11 18:07:21 +00003234 ObjCLanguageRuntime::ClassDescriptorSP objc_class_sp (runtime->GetNonKVOClassDescriptor(*valobj));
3235 if (objc_class_sp)
3236 s.Printf(", dynamic type: %s) ", objc_class_sp->GetClassName().GetCString());
Enrico Granatac3e320a2011-08-02 17:27:39 +00003237 else
Greg Claytonf0246d12012-10-11 18:07:21 +00003238 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003239 }
3240 }
3241 }
3242 else
3243 s.Printf(") ");
3244 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003245
Greg Clayton1d3afba2010-10-05 00:00:42 +00003246
Enrico Granata0c489f52012-03-01 04:24:26 +00003247 if (options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003248 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003249 // If we are showing types, also qualify the C++ base classes
Enrico Granata0c489f52012-03-01 04:24:26 +00003250 const bool qualify_cxx_base_classes = options.m_show_types;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003251 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003252 s.PutCString(" =");
3253 }
3254 else
3255 {
3256 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3257 s.Printf ("%s =", name_cstr);
3258 }
3259
Enrico Granata0c489f52012-03-01 04:24:26 +00003260 if (!options.m_scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003261 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003262 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003263 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003264 }
3265
Enrico Granata0c489f52012-03-01 04:24:26 +00003266 std::string summary_str;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003267 std::string value_str;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003268 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003269 const char *sum_cstr = NULL;
Enrico Granata0c489f52012-03-01 04:24:26 +00003270 TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003271
Enrico Granata0c489f52012-03-01 04:24:26 +00003272 if (options.m_omit_summary_depth > 0)
Enrico Granata0c5ef692011-07-16 01:22:04 +00003273 entry = NULL;
3274
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003275 if (err_cstr == NULL)
3276 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003277 if (options.m_format != eFormatDefault && options.m_format != valobj->GetFormat())
Greg Clayton6efba4f2012-01-26 21:08:30 +00003278 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003279 valobj->GetValueAsCString(options.m_format,
3280 value_str);
Greg Clayton6efba4f2012-01-26 21:08:30 +00003281 }
Enrico Granata0c489f52012-03-01 04:24:26 +00003282 else
Greg Clayton6efba4f2012-01-26 21:08:30 +00003283 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003284 val_cstr = valobj->GetValueAsCString();
3285 if (val_cstr)
3286 value_str = val_cstr;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003287 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003288 err_cstr = valobj->GetError().AsCString();
3289 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003290
3291 if (err_cstr)
3292 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003293 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003294 }
3295 else
3296 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003297 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003298 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003299 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003300 if (options.m_omit_summary_depth == 0)
3301 {
3302 if (options.m_summary_sp)
3303 {
3304 valobj->GetSummaryAsCString(entry, summary_str);
3305 sum_cstr = summary_str.c_str();
3306 }
3307 else
3308 sum_cstr = valobj->GetSummaryAsCString();
3309 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003310
Greg Clayton6efba4f2012-01-26 21:08:30 +00003311 // Make sure we have a value and make sure the summary didn't
3312 // specify that the value should not be printed
3313 if (!value_str.empty() && (entry == NULL || entry->DoesPrintValue() || sum_cstr == NULL))
3314 s.Printf(" %s", value_str.c_str());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003315
Enrico Granata9dd75c82011-07-15 23:30:15 +00003316 if (sum_cstr)
Enrico Granata0c489f52012-03-01 04:24:26 +00003317 s.Printf(" %s", sum_cstr);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003318
Enrico Granata0c489f52012-03-01 04:24:26 +00003319 if (options.m_use_objc)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003320 {
Jim Ingham6035b672011-03-31 00:19:25 +00003321 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003322 if (object_desc)
3323 s.Printf(" %s\n", object_desc);
3324 else
Sean Callanan672ad942010-10-23 00:18:49 +00003325 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003326 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003327 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003328 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003329
Enrico Granata0c489f52012-03-01 04:24:26 +00003330 if (curr_depth < options.m_max_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003331 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003332 // We will show children for all concrete types. We won't show
3333 // pointer contents unless a pointer depth has been specified.
3334 // We won't reference contents unless the reference is the
3335 // root object (depth of zero).
3336 bool print_children = true;
3337
3338 // Use a new temporary pointer depth in case we override the
3339 // current pointer depth below...
3340 uint32_t curr_ptr_depth = ptr_depth;
3341
3342 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3343 if (is_ptr || is_ref)
3344 {
3345 // We have a pointer or reference whose value is an address.
3346 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003347 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003348 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003349 print_children = false;
3350
3351 else if (is_ref && curr_depth == 0)
3352 {
3353 // If this is the root object (depth is zero) that we are showing
3354 // and it is a reference, and no pointer depth has been supplied
3355 // print out what it references. Don't do this at deeper depths
3356 // otherwise we can end up with infinite recursion...
3357 curr_ptr_depth = 1;
3358 }
3359
3360 if (curr_ptr_depth == 0)
3361 print_children = false;
3362 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003363
Enrico Granata0a3958e2011-07-02 00:25:22 +00003364 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003365 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003366 ValueObject* synth_valobj;
3367 ValueObjectSP synth_valobj_sp = valobj->GetSyntheticValue (options.m_use_synthetic);
3368 synth_valobj = (synth_valobj_sp ? synth_valobj_sp.get() : valobj);
Enrico Granatac5bc4122012-03-27 02:35:13 +00003369
Enrico Granatac482a192011-08-17 22:13:59 +00003370 uint32_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003371 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003372 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003373 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003374 if (options.m_flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003375 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003376 if (print_valobj)
3377 s.EOL();
3378 }
3379 else
3380 {
3381 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003382 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003383 s.IndentMore();
3384 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003385
Greg Claytoncc4d0142012-02-17 07:49:44 +00003386 uint32_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00003387
Enrico Granata0c489f52012-03-01 04:24:26 +00003388 if (num_children > max_num_children && !options.m_ignore_cap)
Enrico Granata22c55d12011-08-12 02:00:06 +00003389 {
3390 num_children = max_num_children;
3391 print_dotdotdot = true;
3392 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003393
Enrico Granata0c489f52012-03-01 04:24:26 +00003394 ValueObject::DumpValueObjectOptions child_options(options);
3395 child_options.SetFormat().SetSummary().SetRootValueObjectName();
3396 child_options.SetScopeChecked(true)
3397 .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003398 for (uint32_t idx=0; idx<num_children; ++idx)
3399 {
Enrico Granatac482a192011-08-17 22:13:59 +00003400 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003401 if (child_sp.get())
3402 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003403 DumpValueObject_Impl (s,
3404 child_sp.get(),
3405 child_options,
3406 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
3407 curr_depth + 1);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003408 }
3409 }
3410
Enrico Granata0c489f52012-03-01 04:24:26 +00003411 if (!options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003412 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003413 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003414 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003415 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3416 Target *target = exe_ctx.GetTargetPtr();
3417 if (target)
3418 target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003419 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003420 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003421 s.IndentLess();
3422 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003423 }
3424 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003425 else if (has_children)
3426 {
3427 // Aggregate, no children...
3428 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003429 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003430 }
3431 else
3432 {
3433 if (print_valobj)
3434 s.EOL();
3435 }
3436
Greg Clayton1d3afba2010-10-05 00:00:42 +00003437 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003438 else
3439 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003440 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003441 }
3442 }
3443 else
3444 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003445 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003446 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003447 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003448 }
3449 }
3450 }
3451 }
3452}
3453
Enrico Granata0c489f52012-03-01 04:24:26 +00003454void
Greg Claytonf830dbb2012-03-22 18:15:37 +00003455ValueObject::LogValueObject (Log *log,
3456 ValueObject *valobj)
3457{
3458 if (log && valobj)
3459 return LogValueObject (log, valobj, DumpValueObjectOptions::DefaultOptions());
3460}
3461
3462void
3463ValueObject::LogValueObject (Log *log,
3464 ValueObject *valobj,
3465 const DumpValueObjectOptions& options)
3466{
3467 if (log && valobj)
3468 {
3469 StreamString s;
3470 ValueObject::DumpValueObject (s, valobj, options);
3471 if (s.GetSize())
3472 log->PutCString(s.GetData());
3473 }
3474}
3475
3476void
Enrico Granata0c489f52012-03-01 04:24:26 +00003477ValueObject::DumpValueObject (Stream &s,
3478 ValueObject *valobj)
3479{
3480
3481 if (!valobj)
3482 return;
3483
3484 DumpValueObject_Impl(s,
3485 valobj,
3486 DumpValueObjectOptions::DefaultOptions(),
3487 0,
3488 0);
3489}
3490
3491void
3492ValueObject::DumpValueObject (Stream &s,
3493 ValueObject *valobj,
3494 const DumpValueObjectOptions& options)
3495{
3496 DumpValueObject_Impl(s,
3497 valobj,
3498 options,
3499 options.m_max_ptr_depth, // max pointer depth allowed, we will go down from here
3500 0 // current object depth is 0 since we are just starting
3501 );
3502}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003503
3504ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003505ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003506{
3507 ValueObjectSP valobj_sp;
3508
Enrico Granatac3e320a2011-08-02 17:27:39 +00003509 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003510 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003511 ExecutionContext exe_ctx (GetExecutionContextRef());
3512 clang::ASTContext *ast = GetClangAST ();
3513
3514 DataExtractor data;
3515 data.SetByteOrder (m_data.GetByteOrder());
3516 data.SetAddressByteSize(m_data.GetAddressByteSize());
3517
Enrico Granata9f1e2042012-04-24 22:15:37 +00003518 if (IsBitfield())
3519 {
3520 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
3521 m_error = v.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
3522 }
3523 else
3524 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003525
3526 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3527 ast,
3528 GetClangType(),
3529 name,
3530 data,
3531 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003532 }
Jim Ingham6035b672011-03-31 00:19:25 +00003533
3534 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003535 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003536 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003537 }
3538 return valobj_sp;
3539}
3540
Greg Claytonafacd142011-09-02 01:15:17 +00003541ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003542ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003543{
Jim Ingham58b59f92011-04-22 23:53:53 +00003544 if (m_deref_valobj)
3545 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003546
Greg Clayton54979cd2010-12-15 05:08:08 +00003547 const bool is_pointer_type = IsPointerType();
3548 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003549 {
3550 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003551 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003552
3553 std::string child_name_str;
3554 uint32_t child_byte_size = 0;
3555 int32_t child_byte_offset = 0;
3556 uint32_t child_bitfield_bit_size = 0;
3557 uint32_t child_bitfield_bit_offset = 0;
3558 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003559 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003560 const bool transparent_pointers = false;
3561 clang::ASTContext *clang_ast = GetClangAST();
3562 clang_type_t clang_type = GetClangType();
3563 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003564
Greg Claytoncc4d0142012-02-17 07:49:44 +00003565 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003566
3567 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3568 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003569 GetName().GetCString(),
3570 clang_type,
3571 0,
3572 transparent_pointers,
3573 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003574 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003575 child_name_str,
3576 child_byte_size,
3577 child_byte_offset,
3578 child_bitfield_bit_size,
3579 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003580 child_is_base_class,
3581 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003582 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003583 {
3584 ConstString child_name;
3585 if (!child_name_str.empty())
3586 child_name.SetCString (child_name_str.c_str());
3587
Jim Ingham58b59f92011-04-22 23:53:53 +00003588 m_deref_valobj = new ValueObjectChild (*this,
3589 clang_ast,
3590 child_clang_type,
3591 child_name,
3592 child_byte_size,
3593 child_byte_offset,
3594 child_bitfield_bit_size,
3595 child_bitfield_bit_offset,
3596 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003597 child_is_deref_of_parent,
3598 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003599 }
3600 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003601
Jim Ingham58b59f92011-04-22 23:53:53 +00003602 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003603 {
3604 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003605 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003606 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003607 else
3608 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003609 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003610 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003611
3612 if (is_pointer_type)
3613 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3614 else
3615 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003616 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003617 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003618}
3619
Greg Claytonafacd142011-09-02 01:15:17 +00003620ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003621ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003622{
Jim Ingham78a685a2011-04-16 00:01:13 +00003623 if (m_addr_of_valobj_sp)
3624 return m_addr_of_valobj_sp;
3625
Greg Claytone0d378b2011-03-24 21:19:54 +00003626 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003627 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003628 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003629 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003630 if (addr != LLDB_INVALID_ADDRESS)
3631 {
3632 switch (address_type)
3633 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003634 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003635 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003636 {
3637 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003638 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003639 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3640 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003641 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003642
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003643 case eAddressTypeFile:
3644 case eAddressTypeLoad:
3645 case eAddressTypeHost:
3646 {
3647 clang::ASTContext *ast = GetClangAST();
3648 clang_type_t clang_type = GetClangType();
3649 if (ast && clang_type)
3650 {
3651 std::string name (1, '&');
3652 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003653 ExecutionContext exe_ctx (GetExecutionContextRef());
3654 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003655 ast,
3656 ClangASTContext::CreatePointerType (ast, clang_type),
3657 ConstString (name.c_str()),
3658 addr,
3659 eAddressTypeInvalid,
3660 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003661 }
3662 }
3663 break;
3664 }
3665 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003666 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003667}
3668
Greg Clayton9a142cf2012-02-03 05:34:10 +00003669ValueObjectSP
3670ValueObject::Cast (const ClangASTType &clang_ast_type)
3671{
Greg Clayton81e871e2012-02-04 02:27:34 +00003672 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003673}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003674
Greg Claytonafacd142011-09-02 01:15:17 +00003675ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003676ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3677{
Greg Claytonafacd142011-09-02 01:15:17 +00003678 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003679 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003680 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003681
3682 if (ptr_value != LLDB_INVALID_ADDRESS)
3683 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003684 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003685 ExecutionContext exe_ctx (GetExecutionContextRef());
3686 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003687 name,
3688 ptr_addr,
3689 clang_ast_type);
3690 }
3691 return valobj_sp;
3692}
3693
Greg Claytonafacd142011-09-02 01:15:17 +00003694ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003695ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3696{
Greg Claytonafacd142011-09-02 01:15:17 +00003697 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003698 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003699 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003700
3701 if (ptr_value != LLDB_INVALID_ADDRESS)
3702 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003703 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003704 ExecutionContext exe_ctx (GetExecutionContextRef());
3705 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003706 name,
3707 ptr_addr,
3708 type_sp);
3709 }
3710 return valobj_sp;
3711}
3712
Jim Ingham6035b672011-03-31 00:19:25 +00003713ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003714 m_mod_id(),
3715 m_exe_ctx_ref(),
3716 m_needs_update (true),
3717 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003718{
3719}
3720
3721ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003722 m_mod_id(),
3723 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003724 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003725 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003726{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003727 ExecutionContext exe_ctx(exe_scope);
3728 TargetSP target_sp (exe_ctx.GetTargetSP());
3729 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003730 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003731 m_exe_ctx_ref.SetTargetSP (target_sp);
3732 ProcessSP process_sp (exe_ctx.GetProcessSP());
3733 if (!process_sp)
3734 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003735
Greg Claytoncc4d0142012-02-17 07:49:44 +00003736 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003737 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003738 m_mod_id = process_sp->GetModID();
3739 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003740
Greg Claytoncc4d0142012-02-17 07:49:44 +00003741 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003742
Greg Claytoncc4d0142012-02-17 07:49:44 +00003743 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003744 {
3745 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003746 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003747 }
Jim Ingham6035b672011-03-31 00:19:25 +00003748
Greg Claytoncc4d0142012-02-17 07:49:44 +00003749 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003750 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003751 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003752
Greg Claytoncc4d0142012-02-17 07:49:44 +00003753 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3754 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003755 {
3756 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003757 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003758 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003759 if (frame_sp)
3760 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003761 }
3762 }
3763 }
Jim Ingham6035b672011-03-31 00:19:25 +00003764}
3765
3766ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003767 m_mod_id(),
3768 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3769 m_needs_update (true),
3770 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003771{
3772}
3773
3774ValueObject::EvaluationPoint::~EvaluationPoint ()
3775{
3776}
3777
Jim Ingham6035b672011-03-31 00:19:25 +00003778// This function checks the EvaluationPoint against the current process state. If the current
3779// state matches the evaluation point, or the evaluation point is already invalid, then we return
3780// false, meaning "no change". If the current state is different, we update our state, and return
3781// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3782// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003783// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003784
3785bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003786ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003787{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003788
3789 // 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 +00003790 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00003791
Greg Claytoncc4d0142012-02-17 07:49:44 +00003792 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003793 return false;
3794
Jim Ingham6035b672011-03-31 00:19:25 +00003795 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003796 Process *process = exe_ctx.GetProcessPtr();
3797 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003798 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003799
Jim Ingham6035b672011-03-31 00:19:25 +00003800 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003801 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003802
Jim Ingham78a685a2011-04-16 00:01:13 +00003803 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3804 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003805 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003806 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003807
Greg Clayton23f59502012-07-17 03:23:13 +00003808 bool changed = false;
3809 const bool was_valid = m_mod_id.IsValid();
3810 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003811 {
3812 if (m_mod_id == current_mod_id)
3813 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003814 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003815 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003816 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003817 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003818 else
3819 {
3820 m_mod_id = current_mod_id;
3821 m_needs_update = true;
3822 changed = true;
3823 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003824 }
Jim Ingham6035b672011-03-31 00:19:25 +00003825
Jim Ingham73ca05a2011-12-17 01:35:57 +00003826 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3827 // That way we'll be sure to return a valid exe_scope.
3828 // 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 +00003829
Greg Claytoncc4d0142012-02-17 07:49:44 +00003830 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003831 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003832 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3833 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003834 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003835 if (m_exe_ctx_ref.HasFrameRef())
3836 {
3837 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3838 if (!frame_sp)
3839 {
3840 // We used to have a frame, but now it is gone
3841 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003842 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00003843 }
3844 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003845 }
Jim Ingham6035b672011-03-31 00:19:25 +00003846 else
3847 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003848 // We used to have a thread, but now it is gone
3849 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003850 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00003851 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003852
Jim Ingham6035b672011-03-31 00:19:25 +00003853 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003854 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003855}
3856
Jim Ingham61be0902011-05-02 18:13:59 +00003857void
3858ValueObject::EvaluationPoint::SetUpdated ()
3859{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003860 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3861 if (process_sp)
3862 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003863 m_first_update = false;
3864 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003865}
3866
3867
Greg Claytoncc4d0142012-02-17 07:49:44 +00003868//bool
3869//ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3870//{
3871// if (!IsValid())
3872// return false;
3873//
3874// bool needs_update = false;
3875//
3876// // The target has to be non-null, and the
3877// Target *target = exe_scope->CalculateTarget();
3878// if (target != NULL)
3879// {
3880// Target *old_target = m_target_sp.get();
3881// assert (target == old_target);
3882// Process *process = exe_scope->CalculateProcess();
3883// if (process != NULL)
3884// {
3885// // FOR NOW - assume you can't update variable objects across process boundaries.
3886// Process *old_process = m_process_sp.get();
3887// assert (process == old_process);
3888// ProcessModID current_mod_id = process->GetModID();
3889// if (m_mod_id != current_mod_id)
3890// {
3891// needs_update = true;
3892// m_mod_id = current_mod_id;
3893// }
3894// // See if we're switching the thread or stack context. If no thread is given, this is
3895// // being evaluated in a global context.
3896// Thread *thread = exe_scope->CalculateThread();
3897// if (thread != NULL)
3898// {
3899// user_id_t new_thread_index = thread->GetIndexID();
3900// if (new_thread_index != m_thread_id)
3901// {
3902// needs_update = true;
3903// m_thread_id = new_thread_index;
3904// m_stack_id.Clear();
3905// }
3906//
3907// StackFrame *new_frame = exe_scope->CalculateStackFrame();
3908// if (new_frame != NULL)
3909// {
3910// if (new_frame->GetStackID() != m_stack_id)
3911// {
3912// needs_update = true;
3913// m_stack_id = new_frame->GetStackID();
3914// }
3915// }
3916// else
3917// {
3918// m_stack_id.Clear();
3919// needs_update = true;
3920// }
3921// }
3922// else
3923// {
3924// // If this had been given a thread, and now there is none, we should update.
3925// // Otherwise we don't have to do anything.
3926// if (m_thread_id != LLDB_INVALID_UID)
3927// {
3928// m_thread_id = LLDB_INVALID_UID;
3929// m_stack_id.Clear();
3930// needs_update = true;
3931// }
3932// }
3933// }
3934// else
3935// {
3936// // If there is no process, then we don't need to update anything.
3937// // But if we're switching from having a process to not, we should try to update.
3938// if (m_process_sp.get() != NULL)
3939// {
3940// needs_update = true;
3941// m_process_sp.reset();
3942// m_thread_id = LLDB_INVALID_UID;
3943// m_stack_id.Clear();
3944// }
3945// }
3946// }
3947// else
3948// {
3949// // If there's no target, nothing can change so we don't need to update anything.
3950// // But if we're switching from having a target to not, we should try to update.
3951// if (m_target_sp.get() != NULL)
3952// {
3953// needs_update = true;
3954// m_target_sp.reset();
3955// m_process_sp.reset();
3956// m_thread_id = LLDB_INVALID_UID;
3957// m_stack_id.Clear();
3958// }
3959// }
3960// if (!m_needs_update)
3961// m_needs_update = needs_update;
3962//
3963// return needs_update;
3964//}
Enrico Granataf2bbf712011-07-15 02:26:42 +00003965
3966void
Enrico Granata86cc9822012-03-19 22:58:49 +00003967ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00003968{
Enrico Granata86cc9822012-03-19 22:58:49 +00003969 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
3970 m_value_str.clear();
3971
3972 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
3973 m_location_str.clear();
3974
3975 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
3976 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003977 m_summary_str.clear();
3978 }
3979
3980 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
3981 m_object_desc_str.clear();
3982
3983 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
3984 {
3985 if (m_synthetic_value)
3986 m_synthetic_value = NULL;
3987 }
Johnny Chen44805302011-07-19 19:48:13 +00003988}
Enrico Granata9128ee22011-09-06 19:20:51 +00003989
3990SymbolContextScope *
3991ValueObject::GetSymbolContextScope()
3992{
3993 if (m_parent)
3994 {
3995 if (!m_parent->IsPointerOrReferenceType())
3996 return m_parent->GetSymbolContextScope();
3997 }
3998 return NULL;
3999}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004000
4001lldb::ValueObjectSP
4002ValueObject::CreateValueObjectFromExpression (const char* name,
4003 const char* expression,
4004 const ExecutionContext& exe_ctx)
4005{
4006 lldb::ValueObjectSP retval_sp;
4007 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4008 if (!target_sp)
4009 return retval_sp;
4010 if (!expression || !*expression)
4011 return retval_sp;
4012 target_sp->EvaluateExpression (expression,
4013 exe_ctx.GetFrameSP().get(),
4014 retval_sp);
4015 if (retval_sp && name && *name)
4016 retval_sp->SetName(ConstString(name));
4017 return retval_sp;
4018}
4019
4020lldb::ValueObjectSP
4021ValueObject::CreateValueObjectFromAddress (const char* name,
4022 uint64_t address,
4023 const ExecutionContext& exe_ctx,
4024 ClangASTType type)
4025{
4026 ClangASTType pointer_type(type.GetASTContext(),type.GetPointerType());
4027 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4028 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4029 pointer_type.GetASTContext(),
4030 pointer_type.GetOpaqueQualType(),
4031 ConstString(name),
4032 buffer,
4033 lldb::endian::InlHostByteOrder(),
4034 exe_ctx.GetAddressByteSize()));
4035 if (ptr_result_valobj_sp)
4036 {
4037 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4038 Error err;
4039 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4040 if (ptr_result_valobj_sp && name && *name)
4041 ptr_result_valobj_sp->SetName(ConstString(name));
4042 }
4043 return ptr_result_valobj_sp;
4044}
4045
4046lldb::ValueObjectSP
4047ValueObject::CreateValueObjectFromData (const char* name,
4048 DataExtractor& data,
4049 const ExecutionContext& exe_ctx,
4050 ClangASTType type)
4051{
4052 lldb::ValueObjectSP new_value_sp;
4053 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4054 type.GetASTContext() ,
4055 type.GetOpaqueQualType(),
4056 ConstString(name),
4057 data,
4058 LLDB_INVALID_ADDRESS);
4059 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4060 if (new_value_sp && name && *name)
4061 new_value_sp->SetName(ConstString(name));
4062 return new_value_sp;
4063}