blob: b0b1a67095a3d11b8e34cc5213a97688ca4f9f04 [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"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025#include "lldb/Core/StreamString.h"
26#include "lldb/Core/ValueObjectChild.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000027#include "lldb/Core/ValueObjectConstResult.h"
Jim Ingham78a685a2011-04-16 00:01:13 +000028#include "lldb/Core/ValueObjectDynamicValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Core/ValueObjectList.h"
Greg Claytonb2dcc362011-05-05 23:32:56 +000030#include "lldb/Core/ValueObjectMemory.h"
Enrico Granatad55546b2011-07-22 00:16:08 +000031#include "lldb/Core/ValueObjectSyntheticFilter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032
Greg Clayton7fb56d02011-02-01 01:31:41 +000033#include "lldb/Host/Endian.h"
34
Enrico Granata61a80ba2011-08-12 16:42:31 +000035#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granataf2bbf712011-07-15 02:26:42 +000036#include "lldb/Interpreter/ScriptInterpreterPython.h"
37
Greg Claytone1a916a2010-07-21 22:12:05 +000038#include "lldb/Symbol/ClangASTType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039#include "lldb/Symbol/ClangASTContext.h"
40#include "lldb/Symbol/Type.h"
41
Jim Ingham53c47f12010-09-10 23:12:17 +000042#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000043#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000044#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000045#include "lldb/Target/Process.h"
46#include "lldb/Target/RegisterContext.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000047#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000048#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049
Enrico Granataf4efecd2011-07-12 22:56:10 +000050#include "lldb/Utility/RefCounter.h"
51
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052using namespace lldb;
53using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000054using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000055
Greg Claytonafacd142011-09-02 01:15:17 +000056static user_id_t g_value_obj_uid = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057
58//----------------------------------------------------------------------
59// ValueObject constructor
60//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000061ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000062 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000063 m_parent (&parent),
Stephen Wilson71c21d12011-04-11 19:41:40 +000064 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065 m_name (),
66 m_data (),
67 m_value (),
68 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000069 m_value_str (),
70 m_old_value_str (),
71 m_location_str (),
72 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000073 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +000074 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000075 m_children (),
76 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000077 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000078 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000079 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000080 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000081 m_last_format_mgr_revision(0),
Enrico Granatad8b5fce2011-08-02 23:12:24 +000082 m_last_format_mgr_dynamic(parent.m_last_format_mgr_dynamic),
Enrico Granata0c489f52012-03-01 04:24:26 +000083 m_type_summary_sp(),
84 m_type_format_sp(),
85 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +000086 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +000087 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
Greg Clayton288bdf92010-09-02 02:59:18 +000088 m_value_is_valid (false),
89 m_value_did_change (false),
90 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000091 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +000092 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +000093 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +000094 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +000095 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +000096 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +000097 m_is_getting_summary(false),
98 m_did_calculate_complete_objc_class_type(false)
Jim Ingham6035b672011-03-31 00:19:25 +000099{
Jim Ingham58b59f92011-04-22 23:53:53 +0000100 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000101}
102
103//----------------------------------------------------------------------
104// ValueObject constructor
105//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000106ValueObject::ValueObject (ExecutionContextScope *exe_scope,
107 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000108 UserID (++g_value_obj_uid), // Unique identifier for every value object
109 m_parent (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000110 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000111 m_name (),
112 m_data (),
113 m_value (),
114 m_error (),
115 m_value_str (),
116 m_old_value_str (),
117 m_location_str (),
118 m_summary_str (),
119 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000120 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000121 m_children (),
122 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000123 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000124 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000125 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000126 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000127 m_last_format_mgr_revision(0),
Greg Claytonafacd142011-09-02 01:15:17 +0000128 m_last_format_mgr_dynamic(eNoDynamicValues),
Enrico Granata0c489f52012-03-01 04:24:26 +0000129 m_type_summary_sp(),
130 m_type_format_sp(),
131 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000132 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000133 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Jim Ingham6035b672011-03-31 00:19:25 +0000134 m_value_is_valid (false),
135 m_value_did_change (false),
136 m_children_count_valid (false),
137 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000138 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000139 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000140 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +0000141 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000142 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000143 m_is_getting_summary(false),
144 m_did_calculate_complete_objc_class_type(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000145{
Jim Ingham58b59f92011-04-22 23:53:53 +0000146 m_manager = new ValueObjectManager();
147 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000148}
149
150//----------------------------------------------------------------------
151// Destructor
152//----------------------------------------------------------------------
153ValueObject::~ValueObject ()
154{
155}
156
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000157bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000158ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000159{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000160 return UpdateValueIfNeeded(m_last_format_mgr_dynamic, update_format);
161}
162
163bool
Greg Claytonafacd142011-09-02 01:15:17 +0000164ValueObject::UpdateValueIfNeeded (DynamicValueType use_dynamic, bool update_format)
Enrico Granatac3e320a2011-08-02 17:27:39 +0000165{
Enrico Granata4becb372011-06-29 22:27:15 +0000166
Enrico Granata9128ee22011-09-06 19:20:51 +0000167 bool did_change_formats = false;
168
Enrico Granata0a3958e2011-07-02 00:25:22 +0000169 if (update_format)
Enrico Granata9128ee22011-09-06 19:20:51 +0000170 did_change_formats = UpdateFormatsIfNeeded(use_dynamic);
Enrico Granata4becb372011-06-29 22:27:15 +0000171
Greg Claytonb71f3842010-10-05 03:13:51 +0000172 // If this is a constant value, then our success is predicated on whether
173 // we have an error or not
174 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000175 {
176 // if you were asked to update your formatters, but did not get a chance to do it
177 // clear your own values (this serves the purpose of faking a stop-id for frozen
178 // objects (which are regarded as constant, but could have changes behind their backs
179 // because of the frozen-pointer depth limit)
180 // TODO: decouple summary from value and then remove this code and only force-clear the summary
181 if (update_format && !did_change_formats)
Enrico Granata86cc9822012-03-19 22:58:49 +0000182 ClearUserVisibleData(eClearUserVisibleDataItemsSummary);
Greg Claytonb71f3842010-10-05 03:13:51 +0000183 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000184 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000185
Jim Ingham6035b672011-03-31 00:19:25 +0000186 bool first_update = m_update_point.IsFirstEvaluation();
187
188 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000189 {
Jim Ingham6035b672011-03-31 00:19:25 +0000190 m_update_point.SetUpdated();
191
192 // Save the old value using swap to avoid a string copy which
193 // also will clear our m_value_str
194 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000195 {
Jim Ingham6035b672011-03-31 00:19:25 +0000196 m_old_value_valid = false;
197 }
198 else
199 {
200 m_old_value_valid = true;
201 m_old_value_str.swap (m_value_str);
Enrico Granata86cc9822012-03-19 22:58:49 +0000202 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham6035b672011-03-31 00:19:25 +0000203 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000204
Enrico Granataf2bbf712011-07-15 02:26:42 +0000205 ClearUserVisibleData();
206
Greg Claytonefbc7d22012-03-09 04:23:44 +0000207 if (IsInScope())
Jim Ingham6035b672011-03-31 00:19:25 +0000208 {
Greg Claytonefbc7d22012-03-09 04:23:44 +0000209 const bool value_was_valid = GetValueIsValid();
210 SetValueDidChange (false);
211
212 m_error.Clear();
213
214 // Call the pure virtual function to update the value
215 bool success = UpdateValue ();
216
217 SetValueIsValid (success);
218
219 if (first_update)
220 SetValueDidChange (false);
221 else if (!m_value_did_change && success == false)
222 {
223 // The value wasn't gotten successfully, so we mark this
224 // as changed if the value used to be valid and now isn't
225 SetValueDidChange (value_was_valid);
226 }
227 }
228 else
229 {
230 m_error.SetErrorString("out of scope");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000231 }
232 }
233 return m_error.Success();
234}
235
Enrico Granata9128ee22011-09-06 19:20:51 +0000236bool
Greg Claytonafacd142011-09-02 01:15:17 +0000237ValueObject::UpdateFormatsIfNeeded(DynamicValueType use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000238{
Enrico Granata6f3533f2011-07-29 19:53:35 +0000239 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
240 if (log)
241 log->Printf("checking for FormatManager revisions. VO named %s is at revision %d, while the format manager is at revision %d",
242 GetName().GetCString(),
Enrico Granata4becb372011-06-29 22:27:15 +0000243 m_last_format_mgr_revision,
Enrico Granata85933ed2011-08-18 16:38:26 +0000244 DataVisualization::GetCurrentRevision());
Enrico Granata9128ee22011-09-06 19:20:51 +0000245
246 bool any_change = false;
247
Enrico Granata85933ed2011-08-18 16:38:26 +0000248 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()) ||
Enrico Granatac3e320a2011-08-02 17:27:39 +0000249 m_last_format_mgr_dynamic != use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000250 {
Enrico Granata78d06382011-09-09 23:33:14 +0000251 SetValueFormat(DataVisualization::ValueFormats::GetFormat (*this, eNoDynamicValues));
252 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, use_dynamic));
253 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, use_dynamic));
Enrico Granata1490c6f2011-07-19 02:34:21 +0000254
Enrico Granata85933ed2011-08-18 16:38:26 +0000255 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
Enrico Granatac3e320a2011-08-02 17:27:39 +0000256 m_last_format_mgr_dynamic = use_dynamic;
Enrico Granata855cd902011-09-06 22:59:55 +0000257
258 any_change = true;
Enrico Granata4becb372011-06-29 22:27:15 +0000259 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000260
261 return any_change;
262
Enrico Granata4becb372011-06-29 22:27:15 +0000263}
264
Jim Ingham16e0c682011-08-12 23:34:31 +0000265void
266ValueObject::SetNeedsUpdate ()
267{
268 m_update_point.SetNeedsUpdate();
269 // We have to clear the value string here so ConstResult children will notice if their values are
270 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000271 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000272}
273
Sean Callanan72772842012-02-22 23:57:45 +0000274ClangASTType
275ValueObject::MaybeCalculateCompleteType ()
276{
277 ClangASTType ret(GetClangASTImpl(), GetClangTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000278
Sean Callanan72772842012-02-22 23:57:45 +0000279 if (m_did_calculate_complete_objc_class_type)
280 {
281 if (m_override_type.IsValid())
282 return m_override_type;
283 else
284 return ret;
285 }
286
287 clang_type_t ast_type(GetClangTypeImpl());
288 clang_type_t class_type;
289 bool is_pointer_type;
290
291 if (ClangASTContext::IsObjCObjectPointerType(ast_type, &class_type))
292 {
293 is_pointer_type = true;
294 }
295 else if (ClangASTContext::IsObjCClassType(ast_type))
296 {
297 is_pointer_type = false;
298 class_type = ast_type;
299 }
300 else
301 {
302 return ret;
303 }
304
305 m_did_calculate_complete_objc_class_type = true;
306
307 if (!class_type)
308 return ret;
309
310 std::string class_name;
311
312 if (!ClangASTContext::GetObjCClassName(class_type, class_name))
313 return ret;
314
315 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
316
317 if (!process_sp)
318 return ret;
319
320 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
321
322 if (!objc_language_runtime)
323 return ret;
324
325 ConstString class_name_cs(class_name.c_str());
326
327 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name_cs);
328
329 if (!complete_objc_class_type_sp)
330 return ret;
331
332 ClangASTType complete_class(complete_objc_class_type_sp->GetClangAST(),
333 complete_objc_class_type_sp->GetClangFullType());
334
335 if (!ClangASTContext::GetCompleteType(complete_class.GetASTContext(),
336 complete_class.GetOpaqueQualType()))
337 return ret;
338
339 if (is_pointer_type)
340 {
341 clang_type_t pointer_type = ClangASTContext::CreatePointerType(complete_class.GetASTContext(),
342 complete_class.GetOpaqueQualType());
343
344 m_override_type = ClangASTType(complete_class.GetASTContext(),
345 pointer_type);
346 }
347 else
348 {
349 m_override_type = complete_class;
350 }
351
Sean Callanan356e17c2012-03-30 02:04:38 +0000352 if (m_override_type.IsValid())
353 return m_override_type;
354 else
355 return ret;
Sean Callanan72772842012-02-22 23:57:45 +0000356}
357
358clang::ASTContext *
359ValueObject::GetClangAST ()
360{
361 ClangASTType type = MaybeCalculateCompleteType();
362
363 return type.GetASTContext();
364}
365
366lldb::clang_type_t
367ValueObject::GetClangType ()
368{
369 ClangASTType type = MaybeCalculateCompleteType();
370
371 return type.GetOpaqueQualType();
372}
373
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000374DataExtractor &
375ValueObject::GetDataExtractor ()
376{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000377 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000378 return m_data;
379}
380
381const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000382ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000383{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000384 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000385 return m_error;
386}
387
388const ConstString &
389ValueObject::GetName() const
390{
391 return m_name;
392}
393
394const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000395ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000396{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000397 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000398 {
399 if (m_location_str.empty())
400 {
401 StreamString sstr;
402
403 switch (m_value.GetValueType())
404 {
405 default:
406 break;
407
408 case Value::eValueTypeScalar:
Greg Clayton526e5af2010-11-13 03:52:47 +0000409 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000410 {
411 RegisterInfo *reg_info = m_value.GetRegisterInfo();
412 if (reg_info)
413 {
414 if (reg_info->name)
415 m_location_str = reg_info->name;
416 else if (reg_info->alt_name)
417 m_location_str = reg_info->alt_name;
418 break;
419 }
420 }
421 m_location_str = "scalar";
422 break;
423
424 case Value::eValueTypeLoadAddress:
425 case Value::eValueTypeFileAddress:
426 case Value::eValueTypeHostAddress:
427 {
428 uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2;
429 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
430 m_location_str.swap(sstr.GetString());
431 }
432 break;
433 }
434 }
435 }
436 return m_location_str.c_str();
437}
438
439Value &
440ValueObject::GetValue()
441{
442 return m_value;
443}
444
445const Value &
446ValueObject::GetValue() const
447{
448 return m_value;
449}
450
451bool
Jim Ingham6035b672011-03-31 00:19:25 +0000452ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000453{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000454 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
455 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000456 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000457 Value tmp_value(m_value);
458 scalar = tmp_value.ResolveValue(&exe_ctx, GetClangAST ());
Greg Claytondcad5022011-12-29 01:26:56 +0000459 if (scalar.IsValid())
460 {
461 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
462 if (bitfield_bit_size)
463 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
464 return true;
465 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000466 }
Greg Claytondcad5022011-12-29 01:26:56 +0000467 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000468}
469
470bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000471ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000472{
Greg Clayton288bdf92010-09-02 02:59:18 +0000473 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000474}
475
476
477void
478ValueObject::SetValueIsValid (bool b)
479{
Greg Clayton288bdf92010-09-02 02:59:18 +0000480 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000481}
482
483bool
Jim Ingham6035b672011-03-31 00:19:25 +0000484ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000485{
Jim Ingham6035b672011-03-31 00:19:25 +0000486 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000487 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000488}
489
490void
491ValueObject::SetValueDidChange (bool value_changed)
492{
Greg Clayton288bdf92010-09-02 02:59:18 +0000493 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000494}
495
496ValueObjectSP
497ValueObject::GetChildAtIndex (uint32_t idx, bool can_create)
498{
499 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000500 // We may need to update our value if we are dynamic
501 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000502 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000503 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000504 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000505 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000506 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000507 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000508 // No we haven't created the child at this index, so lets have our
509 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000510 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000511 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000512
Enrico Granata9d60f602012-03-09 03:09:58 +0000513 ValueObject* child = m_children.GetChildAtIndex(idx);
514 if (child != NULL)
515 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000516 }
517 return child_sp;
518}
519
520uint32_t
521ValueObject::GetIndexOfChildWithName (const ConstString &name)
522{
523 bool omit_empty_base_classes = true;
524 return ClangASTContext::GetIndexOfChildWithName (GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +0000525 GetClangType(),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000526 name.GetCString(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000527 omit_empty_base_classes);
528}
529
530ValueObjectSP
531ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
532{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000533 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000534 // classes (which really aren't part of the expression path), so we
535 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000536 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000537
Greg Claytondea8cb42011-06-29 22:09:02 +0000538 // We may need to update our value if we are dynamic
539 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000540 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000541
542 std::vector<uint32_t> child_indexes;
543 clang::ASTContext *clang_ast = GetClangAST();
544 void *clang_type = GetClangType();
545 bool omit_empty_base_classes = true;
546 const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast,
547 clang_type,
548 name.GetCString(),
549 omit_empty_base_classes,
550 child_indexes);
551 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000552 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000553 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
554 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
555
556 child_sp = GetChildAtIndex(*pos, can_create);
557 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000558 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000559 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000560 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000561 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
562 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000563 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000564 else
565 {
566 child_sp.reset();
567 }
568
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000569 }
570 }
571 return child_sp;
572}
573
574
575uint32_t
576ValueObject::GetNumChildren ()
577{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000578 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000579 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000580 {
581 SetNumChildren (CalculateNumChildren());
582 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000583 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000584}
585void
586ValueObject::SetNumChildren (uint32_t num_children)
587{
Greg Clayton288bdf92010-09-02 02:59:18 +0000588 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000589 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000590}
591
592void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000593ValueObject::SetName (const ConstString &name)
594{
595 m_name = name;
596}
597
Jim Ingham58b59f92011-04-22 23:53:53 +0000598ValueObject *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000599ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index)
600{
Jim Ingham2eec4872011-05-07 00:10:58 +0000601 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000602
Greg Claytondea8cb42011-06-29 22:09:02 +0000603 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000604 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000605 std::string child_name_str;
606 uint32_t child_byte_size = 0;
607 int32_t child_byte_offset = 0;
608 uint32_t child_bitfield_bit_size = 0;
609 uint32_t child_bitfield_bit_offset = 0;
610 bool child_is_base_class = false;
611 bool child_is_deref_of_parent = false;
612
613 const bool transparent_pointers = synthetic_array_member == false;
614 clang::ASTContext *clang_ast = GetClangAST();
615 clang_type_t clang_type = GetClangType();
616 clang_type_t child_clang_type;
617
Greg Claytoncc4d0142012-02-17 07:49:44 +0000618 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000619
620 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
621 clang_ast,
622 GetName().GetCString(),
623 clang_type,
624 idx,
625 transparent_pointers,
626 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +0000627 ignore_array_bounds,
Greg Claytondea8cb42011-06-29 22:09:02 +0000628 child_name_str,
629 child_byte_size,
630 child_byte_offset,
631 child_bitfield_bit_size,
632 child_bitfield_bit_offset,
633 child_is_base_class,
634 child_is_deref_of_parent);
635 if (child_clang_type && child_byte_size)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000636 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000637 if (synthetic_index)
638 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000639
Greg Claytondea8cb42011-06-29 22:09:02 +0000640 ConstString child_name;
641 if (!child_name_str.empty())
642 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000643
Greg Claytondea8cb42011-06-29 22:09:02 +0000644 valobj = new ValueObjectChild (*this,
645 clang_ast,
646 child_clang_type,
647 child_name,
648 child_byte_size,
649 child_byte_offset,
650 child_bitfield_bit_size,
651 child_bitfield_bit_offset,
652 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000653 child_is_deref_of_parent,
654 eAddressTypeInvalid);
655 //if (valobj)
656 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
657 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000658
Jim Ingham58b59f92011-04-22 23:53:53 +0000659 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000660}
661
Enrico Granata0c489f52012-03-01 04:24:26 +0000662bool
663ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
664 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000665{
Enrico Granata0c489f52012-03-01 04:24:26 +0000666 destination.clear();
667
668 // ideally we would like to bail out if passing NULL, but if we do so
669 // we end up not providing the summary for function pointers anymore
670 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
671 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000672
673 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000674
675 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
676 // information that we might care to see in a crash log. might be useful in very specific situations though.
677 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
678 GetTypeName().GetCString(),
679 GetName().GetCString(),
680 summary_ptr->GetDescription().c_str());*/
681
Enrico Granata0c489f52012-03-01 04:24:26 +0000682 if (UpdateValueIfNeeded (false))
683 {
684 if (summary_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000685 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000686 if (HasSyntheticValue())
687 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
688 summary_ptr->FormatObject(this, destination);
Enrico Granata0c489f52012-03-01 04:24:26 +0000689 }
690 else
691 {
692 clang_type_t clang_type = GetClangType();
693
694 // Do some default printout for function pointers
695 if (clang_type)
Enrico Granata4becb372011-06-29 22:27:15 +0000696 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000697 StreamString sstr;
698 clang_type_t elem_or_pointee_clang_type;
699 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
700 GetClangAST(),
701 &elem_or_pointee_clang_type));
702
703 if (ClangASTContext::IsFunctionPointerType (clang_type))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000704 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000705 AddressType func_ptr_address_type = eAddressTypeInvalid;
706 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
707 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000708 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000709 switch (func_ptr_address_type)
Jim Ingham6035b672011-03-31 00:19:25 +0000710 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000711 case eAddressTypeInvalid:
712 case eAddressTypeFile:
713 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000714
Greg Claytoncc4d0142012-02-17 07:49:44 +0000715 case eAddressTypeLoad:
Enrico Granata0c489f52012-03-01 04:24:26 +0000716 {
717 ExecutionContext exe_ctx (GetExecutionContextRef());
718
719 Address so_addr;
720 Target *target = exe_ctx.GetTargetPtr();
721 if (target && target->GetSectionLoadList().IsEmpty() == false)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000722 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000723 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000724 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000725 so_addr.Dump (&sstr,
726 exe_ctx.GetBestExecutionContextScope(),
727 Address::DumpStyleResolvedDescription,
728 Address::DumpStyleSectionNameOffset);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000729 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000730 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000731 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000732 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000733
Greg Claytoncc4d0142012-02-17 07:49:44 +0000734 case eAddressTypeHost:
735 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +0000736 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000737 }
738 if (sstr.GetSize() > 0)
739 {
740 destination.assign (1, '(');
741 destination.append (sstr.GetData(), sstr.GetSize());
742 destination.append (1, ')');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000743 }
744 }
745 }
746 }
747 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000748 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000749 return !destination.empty();
750}
751
752const char *
753ValueObject::GetSummaryAsCString ()
754{
755 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
756 {
757 GetSummaryAsCString(GetSummaryFormat().get(),
758 m_summary_str);
759 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000760 if (m_summary_str.empty())
761 return NULL;
762 return m_summary_str.c_str();
763}
764
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000765bool
766ValueObject::IsCStringContainer(bool check_pointer)
767{
768 clang_type_t elem_or_pointee_clang_type;
769 const Flags type_flags (ClangASTContext::GetTypeInfo (GetClangType(),
770 GetClangAST(),
771 &elem_or_pointee_clang_type));
772 bool is_char_arr_ptr (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
773 ClangASTContext::IsCharType (elem_or_pointee_clang_type));
774 if (!is_char_arr_ptr)
775 return false;
776 if (!check_pointer)
777 return true;
778 if (type_flags.Test(ClangASTContext::eTypeIsArray))
779 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000780 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000781 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000782 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000783 return (cstr_address != LLDB_INVALID_ADDRESS);
784}
785
Enrico Granata9128ee22011-09-06 19:20:51 +0000786size_t
787ValueObject::GetPointeeData (DataExtractor& data,
788 uint32_t item_idx,
789 uint32_t item_count)
790{
791 if (!IsPointerType() && !IsArrayType())
792 return 0;
793
794 if (item_count == 0)
795 return 0;
796
797 uint32_t stride = 0;
798
799 ClangASTType type(GetClangAST(),
800 GetClangType());
801
802 const uint64_t item_type_size = (IsPointerType() ? ClangASTType::GetTypeByteSize(GetClangAST(), type.GetPointeeType()) :
803 ClangASTType::GetTypeByteSize(GetClangAST(), type.GetArrayElementType(stride)));
804
805 const uint64_t bytes = item_count * item_type_size;
806
807 const uint64_t offset = item_idx * item_type_size;
808
809 if (item_idx == 0 && item_count == 1) // simply a deref
810 {
811 if (IsPointerType())
812 {
813 Error error;
814 ValueObjectSP pointee_sp = Dereference(error);
815 if (error.Fail() || pointee_sp.get() == NULL)
816 return 0;
817 return pointee_sp->GetDataExtractor().Copy(data);
818 }
819 else
820 {
821 ValueObjectSP child_sp = GetChildAtIndex(0, true);
822 if (child_sp.get() == NULL)
823 return 0;
824 return child_sp->GetDataExtractor().Copy(data);
825 }
826 return true;
827 }
828 else /* (items > 1) */
829 {
830 Error error;
831 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
832 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
833
834 AddressType addr_type;
835 lldb::addr_t addr = IsPointerType() ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
836
Enrico Granata9128ee22011-09-06 19:20:51 +0000837 switch (addr_type)
838 {
839 case eAddressTypeFile:
840 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000841 ModuleSP module_sp (GetModule());
842 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000843 {
844 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +0000845 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000846 ExecutionContext exe_ctx (GetExecutionContextRef());
847 Target* target = exe_ctx.GetTargetPtr();
848 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +0000849 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000850 heap_buf_ptr->SetByteSize(bytes);
851 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
852 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +0000853 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000854 data.SetData(data_sp);
855 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +0000856 }
857 }
858 }
859 }
860 break;
861 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +0000862 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000863 ExecutionContext exe_ctx (GetExecutionContextRef());
864 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +0000865 if (process)
866 {
867 heap_buf_ptr->SetByteSize(bytes);
868 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
869 if (error.Success())
870 {
871 data.SetData(data_sp);
872 return bytes_read;
873 }
874 }
875 }
876 break;
877 case eAddressTypeHost:
878 {
879 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes);
880 data.SetData(data_sp);
881 return bytes;
882 }
883 break;
884 case eAddressTypeInvalid:
885 default:
886 break;
887 }
888 }
889 return 0;
890}
891
892size_t
893ValueObject::GetData (DataExtractor& data)
894{
895 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000896 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytone72dfb32012-02-24 01:59:29 +0000897 Error error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +0000898 if (error.Fail())
899 return 0;
900 data.SetAddressByteSize(m_data.GetAddressByteSize());
901 data.SetByteOrder(m_data.GetByteOrder());
902 return data.GetByteSize();
903}
904
905// will compute strlen(str), but without consuming more than
906// maxlen bytes out of str (this serves the purpose of reading
907// chunks of a string without having to worry about
908// missing NULL terminators in the chunk)
909// of course, if strlen(str) > maxlen, the function will return
910// maxlen_value (which should be != maxlen, because that allows you
911// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
912static uint32_t
913strlen_or_inf (const char* str,
914 uint32_t maxlen,
915 uint32_t maxlen_value)
916{
917 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +0000918 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +0000919 {
Greg Clayton8dd5c172011-10-05 22:19:51 +0000920 while(*str)
921 {
922 len++;str++;
923 if (len > maxlen)
924 return maxlen_value;
925 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000926 }
927 return len;
928}
929
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000930void
Greg Claytoncc4d0142012-02-17 07:49:44 +0000931ValueObject::ReadPointedString (Stream& s,
932 Error& error,
933 uint32_t max_length,
934 bool honor_array,
935 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000936{
Greg Claytoncc4d0142012-02-17 07:49:44 +0000937 ExecutionContext exe_ctx (GetExecutionContextRef());
938 Target* target = exe_ctx.GetTargetPtr();
939
940 if (target && max_length == 0)
941 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000942
943 clang_type_t clang_type = GetClangType();
944 clang_type_t elem_or_pointee_clang_type;
945 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
946 GetClangAST(),
947 &elem_or_pointee_clang_type));
948 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
949 ClangASTContext::IsCharType (elem_or_pointee_clang_type))
950 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000951 if (target == NULL)
952 {
953 s << "<no target to read from>";
954 }
955 else
956 {
957 addr_t cstr_address = LLDB_INVALID_ADDRESS;
958 AddressType cstr_address_type = eAddressTypeInvalid;
959
960 size_t cstr_len = 0;
961 bool capped_data = false;
962 if (type_flags.Test (ClangASTContext::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000963 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000964 // We have an array
965 cstr_len = ClangASTContext::GetArraySize (clang_type);
966 if (cstr_len > max_length)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000967 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000968 capped_data = true;
969 cstr_len = max_length;
970 }
971 cstr_address = GetAddressOf (true, &cstr_address_type);
972 }
973 else
974 {
975 // We have a pointer
976 cstr_address = GetPointerValue (&cstr_address_type);
977 }
978 if (cstr_address != 0 && cstr_address != LLDB_INVALID_ADDRESS)
979 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000980 Address cstr_so_addr (cstr_address);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000981 DataExtractor data;
982 size_t bytes_read = 0;
983 if (cstr_len > 0 && honor_array)
984 {
985 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
986 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
987 GetPointeeData(data, 0, cstr_len);
988
989 if ((bytes_read = data.GetByteSize()) > 0)
990 {
991 s << '"';
992 data.Dump (&s,
993 0, // Start offset in "data"
994 item_format,
995 1, // Size of item (1 byte for a char!)
996 bytes_read, // How many bytes to print?
997 UINT32_MAX, // num per line
998 LLDB_INVALID_ADDRESS,// base address
999 0, // bitfield bit size
1000 0); // bitfield bit offset
1001 if (capped_data)
1002 s << "...";
1003 s << '"';
1004 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00001005 }
1006 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001007 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001008 cstr_len = max_length;
1009 const size_t k_max_buf_size = 64;
1010
1011 size_t offset = 0;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001012
Greg Claytoncc4d0142012-02-17 07:49:44 +00001013 int cstr_len_displayed = -1;
1014 bool capped_cstr = false;
1015 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1016 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1017 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001018 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001019 const char *cstr = data.PeekCStr(0);
1020 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1021 if (len > k_max_buf_size)
1022 len = k_max_buf_size;
1023 if (cstr && cstr_len_displayed < 0)
1024 s << '"';
1025
1026 if (cstr_len_displayed < 0)
1027 cstr_len_displayed = len;
1028
1029 if (len == 0)
1030 break;
1031 cstr_len_displayed += len;
1032 if (len > bytes_read)
1033 len = bytes_read;
1034 if (len > cstr_len)
1035 len = cstr_len;
1036
1037 data.Dump (&s,
1038 0, // Start offset in "data"
1039 item_format,
1040 1, // Size of item (1 byte for a char!)
1041 len, // How many bytes to print?
1042 UINT32_MAX, // num per line
1043 LLDB_INVALID_ADDRESS,// base address
1044 0, // bitfield bit size
1045 0); // bitfield bit offset
1046
1047 if (len < k_max_buf_size)
1048 break;
1049
1050 if (len >= cstr_len)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001051 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001052 capped_cstr = true;
1053 break;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001054 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001055
1056 cstr_len -= len;
1057 offset += len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001058 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001059
1060 if (cstr_len_displayed >= 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001061 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001062 s << '"';
1063 if (capped_cstr)
1064 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001065 }
1066 }
1067 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001068 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001069 }
1070 else
1071 {
1072 error.SetErrorString("impossible to read a string from this object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001073 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001074 }
1075}
1076
Jim Ingham53c47f12010-09-10 23:12:17 +00001077const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001078ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001079{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001080
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001081 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001082 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001083
1084 if (!m_object_desc_str.empty())
1085 return m_object_desc_str.c_str();
1086
Greg Claytoncc4d0142012-02-17 07:49:44 +00001087 ExecutionContext exe_ctx (GetExecutionContextRef());
1088 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001089 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001090 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001091
Jim Ingham53c47f12010-09-10 23:12:17 +00001092 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001093
Greg Claytonafacd142011-09-02 01:15:17 +00001094 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001095 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1096
Jim Inghama2cf2632010-12-23 02:29:54 +00001097 if (runtime == NULL)
1098 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001099 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Jim Inghama2cf2632010-12-23 02:29:54 +00001100 clang_type_t opaque_qual_type = GetClangType();
1101 if (opaque_qual_type != NULL)
1102 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001103 bool is_signed;
1104 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed)
1105 || ClangASTContext::IsPointerType (opaque_qual_type))
1106 {
Greg Claytonafacd142011-09-02 01:15:17 +00001107 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001108 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001109 }
1110 }
1111
Jim Ingham8d543de2011-03-31 23:01:21 +00001112 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001113 {
1114 m_object_desc_str.append (s.GetData());
1115 }
Sean Callanan672ad942010-10-23 00:18:49 +00001116
1117 if (m_object_desc_str.empty())
1118 return NULL;
1119 else
1120 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001121}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001122
Enrico Granata0c489f52012-03-01 04:24:26 +00001123bool
1124ValueObject::GetValueAsCString (lldb::Format format,
1125 std::string& destination)
1126{
1127 if (ClangASTContext::IsAggregateType (GetClangType()) == false &&
1128 UpdateValueIfNeeded(false))
1129 {
1130 const Value::ContextType context_type = m_value.GetContextType();
1131
1132 switch (context_type)
1133 {
1134 case Value::eContextTypeClangType:
1135 case Value::eContextTypeLLDBType:
1136 case Value::eContextTypeVariable:
1137 {
1138 clang_type_t clang_type = GetClangType ();
1139 if (clang_type)
1140 {
1141 StreamString sstr;
1142 ExecutionContext exe_ctx (GetExecutionContextRef());
1143 ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
1144 clang_type, // The clang type to display
1145 &sstr,
1146 format, // Format to display this type with
1147 m_data, // Data to extract from
1148 0, // Byte offset into "m_data"
1149 GetByteSize(), // Byte size of item in "m_data"
1150 GetBitfieldBitSize(), // Bitfield bit size
1151 GetBitfieldBitOffset(), // Bitfield bit offset
1152 exe_ctx.GetBestExecutionContextScope());
1153 // Don't set the m_error to anything here otherwise
1154 // we won't be able to re-format as anything else. The
1155 // code for ClangASTType::DumpTypeValue() should always
1156 // return something, even if that something contains
1157 // an error messsage. "m_error" is used to detect errors
1158 // when reading the valid object, not for formatting errors.
1159 if (sstr.GetString().empty())
1160 destination.clear();
1161 else
1162 destination.swap(sstr.GetString());
1163 }
1164 }
1165 break;
1166
1167 case Value::eContextTypeRegisterInfo:
1168 {
1169 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1170 if (reg_info)
1171 {
1172 ExecutionContext exe_ctx (GetExecutionContextRef());
1173
1174 StreamString reg_sstr;
1175 m_data.Dump (&reg_sstr,
1176 0,
1177 format,
1178 reg_info->byte_size,
1179 1,
1180 UINT32_MAX,
1181 LLDB_INVALID_ADDRESS,
1182 0,
1183 0,
1184 exe_ctx.GetBestExecutionContextScope());
1185 destination.swap(reg_sstr.GetString());
1186 }
1187 }
1188 break;
1189
1190 default:
1191 break;
1192 }
1193 return !destination.empty();
1194 }
1195 else
1196 return false;
1197}
1198
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001199const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001200ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001201{
Enrico Granata0c489f52012-03-01 04:24:26 +00001202 if (UpdateValueIfNeeded(true) && m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001203 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001204 lldb::Format my_format = GetFormat();
1205 if (m_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001206 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001207 if (m_type_format_sp)
1208 my_format = m_type_format_sp->GetFormat();
1209 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001210 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001211 if (m_is_bitfield_for_scalar)
1212 my_format = eFormatUnsigned;
1213 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001214 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001215 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001216 {
1217 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1218 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001219 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001220 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001221 else
1222 {
1223 clang_type_t clang_type = GetClangType ();
1224 my_format = ClangASTType::GetFormat(clang_type);
1225 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001226 }
1227 }
1228 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001229 if (GetValueAsCString(my_format, m_value_str))
1230 {
1231 if (!m_value_did_change && m_old_value_valid)
1232 {
1233 // The value was gotten successfully, so we consider the
1234 // value as changed if the value string differs
1235 SetValueDidChange (m_old_value_str != m_value_str);
1236 }
1237 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001238 }
1239 if (m_value_str.empty())
1240 return NULL;
1241 return m_value_str.c_str();
1242}
1243
Enrico Granatac3e320a2011-08-02 17:27:39 +00001244// if > 8bytes, 0 is returned. this method should mostly be used
1245// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001246uint64_t
1247ValueObject::GetValueAsUnsigned (uint64_t fail_value)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001248{
1249 // If our byte size is zero this is an aggregate type that has children
1250 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
1251 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001252 Scalar scalar;
1253 if (ResolveValue (scalar))
1254 return scalar.GetRawBits64(fail_value);
Enrico Granatac3e320a2011-08-02 17:27:39 +00001255 }
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001256 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001257}
1258
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001259// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1260// this call up to date by returning true for your new special cases. We will eventually move
1261// to checking this call result before trying to display special cases
1262bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001263ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1264 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001265{
1266 clang_type_t elem_or_pointee_type;
1267 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
1268
1269 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001270 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001271 {
1272 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001273 (custom_format == eFormatCString ||
1274 custom_format == eFormatCharArray ||
1275 custom_format == eFormatChar ||
1276 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001277 return true;
1278
1279 if (flags.Test(ClangASTContext::eTypeIsArray))
1280 {
Greg Claytonafacd142011-09-02 01:15:17 +00001281 if ((custom_format == eFormatBytes) ||
1282 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001283 return true;
1284
Greg Claytonafacd142011-09-02 01:15:17 +00001285 if ((custom_format == eFormatVectorOfChar) ||
1286 (custom_format == eFormatVectorOfFloat32) ||
1287 (custom_format == eFormatVectorOfFloat64) ||
1288 (custom_format == eFormatVectorOfSInt16) ||
1289 (custom_format == eFormatVectorOfSInt32) ||
1290 (custom_format == eFormatVectorOfSInt64) ||
1291 (custom_format == eFormatVectorOfSInt8) ||
1292 (custom_format == eFormatVectorOfUInt128) ||
1293 (custom_format == eFormatVectorOfUInt16) ||
1294 (custom_format == eFormatVectorOfUInt32) ||
1295 (custom_format == eFormatVectorOfUInt64) ||
1296 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001297 return true;
1298 }
1299 }
1300 return false;
1301}
1302
Enrico Granata9fc19442011-07-06 02:13:41 +00001303bool
1304ValueObject::DumpPrintableRepresentation(Stream& s,
1305 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001306 Format custom_format,
Enrico Granata86cc9822012-03-19 22:58:49 +00001307 PrintableRepresentationSpecialCases special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001308{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001309
1310 clang_type_t elem_or_pointee_type;
1311 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001312
Enrico Granata86cc9822012-03-19 22:58:49 +00001313 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1314 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1315
1316 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001317 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001318 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1319 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001320 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001321 // when being asked to get a printable display an array or pointer type directly,
1322 // try to "do the right thing"
1323
1324 if (IsCStringContainer(true) &&
1325 (custom_format == eFormatCString ||
1326 custom_format == eFormatCharArray ||
1327 custom_format == eFormatChar ||
1328 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001329 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001330 Error error;
1331 ReadPointedString(s,
1332 error,
1333 0,
1334 (custom_format == eFormatVectorOfChar) ||
1335 (custom_format == eFormatCharArray));
1336 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001337 }
1338
Enrico Granata86cc9822012-03-19 22:58:49 +00001339 if (custom_format == eFormatEnum)
1340 return false;
1341
1342 // this only works for arrays, because I have no way to know when
1343 // the pointed memory ends, and no special \0 end of data marker
1344 if (flags.Test(ClangASTContext::eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001345 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001346 if ((custom_format == eFormatBytes) ||
1347 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001348 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001349 uint32_t count = GetNumChildren();
1350
1351 s << '[';
1352 for (uint32_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001353 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001354
1355 if (low)
1356 s << ',';
1357
1358 ValueObjectSP child = GetChildAtIndex(low,true);
1359 if (!child.get())
1360 {
1361 s << "<invalid child>";
1362 continue;
1363 }
1364 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1365 }
1366
1367 s << ']';
1368
1369 return true;
1370 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001371
Enrico Granata86cc9822012-03-19 22:58:49 +00001372 if ((custom_format == eFormatVectorOfChar) ||
1373 (custom_format == eFormatVectorOfFloat32) ||
1374 (custom_format == eFormatVectorOfFloat64) ||
1375 (custom_format == eFormatVectorOfSInt16) ||
1376 (custom_format == eFormatVectorOfSInt32) ||
1377 (custom_format == eFormatVectorOfSInt64) ||
1378 (custom_format == eFormatVectorOfSInt8) ||
1379 (custom_format == eFormatVectorOfUInt128) ||
1380 (custom_format == eFormatVectorOfUInt16) ||
1381 (custom_format == eFormatVectorOfUInt32) ||
1382 (custom_format == eFormatVectorOfUInt64) ||
1383 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1384 {
1385 uint32_t count = GetNumChildren();
1386
1387 Format format = FormatManager::GetSingleItemFormat(custom_format);
1388
1389 s << '[';
1390 for (uint32_t low = 0; low < count; low++)
1391 {
1392
1393 if (low)
1394 s << ',';
1395
1396 ValueObjectSP child = GetChildAtIndex(low,true);
1397 if (!child.get())
1398 {
1399 s << "<invalid child>";
1400 continue;
1401 }
1402 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1403 }
1404
1405 s << ']';
1406
1407 return true;
1408 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001409 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001410
1411 if ((custom_format == eFormatBoolean) ||
1412 (custom_format == eFormatBinary) ||
1413 (custom_format == eFormatChar) ||
1414 (custom_format == eFormatCharPrintable) ||
1415 (custom_format == eFormatComplexFloat) ||
1416 (custom_format == eFormatDecimal) ||
1417 (custom_format == eFormatHex) ||
1418 (custom_format == eFormatFloat) ||
1419 (custom_format == eFormatOctal) ||
1420 (custom_format == eFormatOSType) ||
1421 (custom_format == eFormatUnicode16) ||
1422 (custom_format == eFormatUnicode32) ||
1423 (custom_format == eFormatUnsigned) ||
1424 (custom_format == eFormatPointer) ||
1425 (custom_format == eFormatComplexInteger) ||
1426 (custom_format == eFormatComplex) ||
1427 (custom_format == eFormatDefault)) // use the [] operator
1428 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001429 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001430 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001431
1432 if (only_special)
1433 return false;
1434
Enrico Granata86cc9822012-03-19 22:58:49 +00001435 bool var_success = false;
1436
1437 {
1438 const char * return_value;
1439 std::string alloc_mem;
1440
1441 if (custom_format != eFormatInvalid)
1442 SetFormat(custom_format);
1443
1444 switch(val_obj_display)
1445 {
1446 case eValueObjectRepresentationStyleValue:
1447 return_value = GetValueAsCString();
1448 break;
1449
1450 case eValueObjectRepresentationStyleSummary:
1451 return_value = GetSummaryAsCString();
1452 break;
1453
1454 case eValueObjectRepresentationStyleLanguageSpecific:
1455 return_value = GetObjectDescription();
1456 break;
1457
1458 case eValueObjectRepresentationStyleLocation:
1459 return_value = GetLocationAsCString();
1460 break;
1461
1462 case eValueObjectRepresentationStyleChildrenCount:
1463 {
1464 alloc_mem.resize(512);
1465 return_value = &alloc_mem[0];
1466 int count = GetNumChildren();
1467 snprintf((char*)return_value, 512, "%d", count);
1468 }
1469 break;
1470
1471 case eValueObjectRepresentationStyleType:
1472 return_value = GetTypeName().AsCString();
1473 break;
1474
1475 default:
1476 break;
1477 }
1478
1479 if (!return_value)
1480 {
1481 if (val_obj_display == eValueObjectRepresentationStyleValue)
1482 return_value = GetSummaryAsCString();
1483 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1484 {
1485 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1486 {
1487 // this thing has no value, and it seems to have no summary
1488 // some combination of unitialized data and other factors can also
1489 // raise this condition, so let's print a nice generic description
1490 {
1491 alloc_mem.resize(684);
1492 return_value = &alloc_mem[0];
1493 snprintf((char*)return_value, 684, "%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1494 }
1495 }
1496 else
1497 return_value = GetValueAsCString();
1498 }
1499 }
1500
1501 if (return_value)
1502 s.PutCString(return_value);
1503 else
1504 {
1505 if (m_error.Fail())
1506 s.Printf("<%s>", m_error.AsCString());
1507 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1508 s.PutCString("<no summary available>");
1509 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1510 s.PutCString("<no value available>");
1511 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1512 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1513 else
1514 s.PutCString("<no printable representation>");
1515 }
1516
1517 // we should only return false here if we could not do *anything*
1518 // even if we have an error message as output, that's a success
1519 // from our callers' perspective, so return true
1520 var_success = true;
1521
1522 if (custom_format != eFormatInvalid)
1523 SetFormat(eFormatDefault);
1524 }
1525
Enrico Granataf4efecd2011-07-12 22:56:10 +00001526 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001527}
1528
Greg Clayton737b9322010-09-13 03:32:57 +00001529addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001530ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001531{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001532 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001533 return LLDB_INVALID_ADDRESS;
1534
Greg Clayton73b472d2010-10-27 03:32:59 +00001535 switch (m_value.GetValueType())
1536 {
1537 case Value::eValueTypeScalar:
1538 if (scalar_is_load_address)
1539 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001540 if(address_type)
1541 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001542 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1543 }
1544 break;
1545
1546 case Value::eValueTypeLoadAddress:
1547 case Value::eValueTypeFileAddress:
1548 case Value::eValueTypeHostAddress:
1549 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001550 if(address_type)
1551 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001552 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1553 }
1554 break;
1555 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001556 if (address_type)
1557 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001558 return LLDB_INVALID_ADDRESS;
1559}
1560
1561addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001562ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001563{
Greg Claytonafacd142011-09-02 01:15:17 +00001564 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001565 if(address_type)
1566 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001567
Enrico Granatac3e320a2011-08-02 17:27:39 +00001568 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001569 return address;
1570
Greg Clayton73b472d2010-10-27 03:32:59 +00001571 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001572 {
1573 case Value::eValueTypeScalar:
Enrico Granata9128ee22011-09-06 19:20:51 +00001574 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001575 break;
1576
Enrico Granata9128ee22011-09-06 19:20:51 +00001577 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001578 case Value::eValueTypeLoadAddress:
1579 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001580 {
1581 uint32_t data_offset = 0;
1582 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001583 }
1584 break;
1585 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001586
Enrico Granata9128ee22011-09-06 19:20:51 +00001587 if (address_type)
1588 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001589
Greg Clayton737b9322010-09-13 03:32:57 +00001590 return address;
1591}
1592
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001593bool
Jim Ingham6035b672011-03-31 00:19:25 +00001594ValueObject::SetValueFromCString (const char *value_str)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001595{
1596 // Make sure our value is up to date first so that our location and location
1597 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001598 if (!UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001599 return false;
1600
1601 uint32_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001602 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001603
Greg Claytonb1320972010-07-14 00:18:15 +00001604 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001605
Jim Ingham16e0c682011-08-12 23:34:31 +00001606 Value::ValueType value_type = m_value.GetValueType();
1607
1608 if (value_type == Value::eValueTypeScalar)
1609 {
1610 // If the value is already a scalar, then let the scalar change itself:
1611 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1612 }
1613 else if (byte_size <= Scalar::GetMaxByteSize())
1614 {
1615 // If the value fits in a scalar, then make a new scalar and again let the
1616 // scalar code do the conversion, then figure out where to put the new value.
1617 Scalar new_scalar;
1618 Error error;
1619 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1620 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001621 {
Jim Ingham4b536182011-08-09 02:12:22 +00001622 switch (value_type)
1623 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001624 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001625 {
1626 // If it is a load address, then the scalar value is the storage location
1627 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001628 ExecutionContext exe_ctx (GetExecutionContextRef());
1629 Process *process = exe_ctx.GetProcessPtr();
1630 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001631 {
Greg Claytonafacd142011-09-02 01:15:17 +00001632 addr_t target_addr = m_value.GetScalar().GetRawBits64(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001633 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1634 new_scalar,
1635 byte_size,
1636 error);
Jim Ingham16e0c682011-08-12 23:34:31 +00001637 if (!error.Success() || bytes_written != byte_size)
1638 return false;
1639 }
1640 }
Jim Ingham4b536182011-08-09 02:12:22 +00001641 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001642 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001643 {
1644 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1645 DataExtractor new_data;
1646 new_data.SetByteOrder (m_data.GetByteOrder());
1647
1648 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1649 m_data.SetData(buffer_sp, 0);
1650 bool success = new_scalar.GetData(new_data);
1651 if (success)
1652 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001653 new_data.CopyByteOrderedData (0,
1654 byte_size,
1655 const_cast<uint8_t *>(m_data.GetDataStart()),
1656 byte_size,
1657 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001658 }
1659 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1660
1661 }
Jim Ingham4b536182011-08-09 02:12:22 +00001662 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001663 case Value::eValueTypeFileAddress:
1664 case Value::eValueTypeScalar:
Jim Ingham16e0c682011-08-12 23:34:31 +00001665 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001666 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001667 }
1668 else
1669 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001670 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001671 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001672 }
1673 else
1674 {
1675 // We don't support setting things bigger than a scalar at present.
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001676 return false;
1677 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001678
1679 // If we have reached this point, then we have successfully changed the value.
1680 SetNeedsUpdate();
1681 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001682}
1683
Greg Clayton81e871e2012-02-04 02:27:34 +00001684bool
1685ValueObject::GetDeclaration (Declaration &decl)
1686{
1687 decl.Clear();
1688 return false;
1689}
1690
Greg Clayton84db9102012-03-26 23:03:23 +00001691ConstString
1692ValueObject::GetTypeName()
1693{
1694 return ClangASTType::GetConstTypeName (GetClangAST(), GetClangType());
1695}
1696
1697ConstString
1698ValueObject::GetQualifiedTypeName()
1699{
1700 return ClangASTType::GetConstQualifiedTypeName (GetClangAST(), GetClangType());
1701}
1702
1703
Greg Claytonafacd142011-09-02 01:15:17 +00001704LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001705ValueObject::GetObjectRuntimeLanguage ()
1706{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001707 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1708 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001709}
1710
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001711void
Jim Ingham58b59f92011-04-22 23:53:53 +00001712ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001713{
Jim Ingham58b59f92011-04-22 23:53:53 +00001714 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001715}
1716
1717ValueObjectSP
1718ValueObject::GetSyntheticChild (const ConstString &key) const
1719{
1720 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001721 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001722 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001723 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001724 return synthetic_child_sp;
1725}
1726
1727bool
1728ValueObject::IsPointerType ()
1729{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001730 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001731}
1732
Jim Inghamb7603bb2011-03-18 00:05:18 +00001733bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001734ValueObject::IsArrayType ()
1735{
1736 return ClangASTContext::IsArrayType (GetClangType());
1737}
1738
1739bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001740ValueObject::IsScalarType ()
1741{
1742 return ClangASTContext::IsScalarType (GetClangType());
1743}
1744
1745bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001746ValueObject::IsIntegerType (bool &is_signed)
1747{
1748 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1749}
Greg Clayton73b472d2010-10-27 03:32:59 +00001750
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001751bool
1752ValueObject::IsPointerOrReferenceType ()
1753{
Greg Clayton007d5be2011-05-30 00:49:24 +00001754 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1755}
1756
1757bool
1758ValueObject::IsPossibleCPlusPlusDynamicType ()
1759{
1760 return ClangASTContext::IsPossibleCPlusPlusDynamicType (GetClangAST (), GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001761}
1762
Greg Claytondea8cb42011-06-29 22:09:02 +00001763bool
1764ValueObject::IsPossibleDynamicType ()
1765{
1766 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType());
1767}
1768
Greg Claytonafacd142011-09-02 01:15:17 +00001769ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001770ValueObject::GetSyntheticArrayMember (int32_t index, bool can_create)
1771{
1772 if (IsArrayType())
1773 return GetSyntheticArrayMemberFromArray(index, can_create);
1774
1775 if (IsPointerType())
1776 return GetSyntheticArrayMemberFromPointer(index, can_create);
1777
1778 return ValueObjectSP();
1779
1780}
1781
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001782ValueObjectSP
1783ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1784{
1785 ValueObjectSP synthetic_child_sp;
1786 if (IsPointerType ())
1787 {
1788 char index_str[64];
1789 snprintf(index_str, sizeof(index_str), "[%i]", index);
1790 ConstString index_const_str(index_str);
1791 // Check if we have already created a synthetic array member in this
1792 // valid object. If we have we will re-use it.
1793 synthetic_child_sp = GetSyntheticChild (index_const_str);
1794 if (!synthetic_child_sp)
1795 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001796 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001797 // We haven't made a synthetic array member for INDEX yet, so
1798 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001799 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001800
1801 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001802 if (synthetic_child)
1803 {
1804 AddSyntheticChild(index_const_str, synthetic_child);
1805 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001806 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001807 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001808 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001809 }
1810 }
1811 return synthetic_child_sp;
1812}
Jim Ingham22777012010-09-23 02:01:19 +00001813
Greg Claytondaf515f2011-07-09 20:12:33 +00001814// This allows you to create an array member using and index
1815// that doesn't not fall in the normal bounds of the array.
1816// Many times structure can be defined as:
1817// struct Collection
1818// {
1819// uint32_t item_count;
1820// Item item_array[0];
1821// };
1822// The size of the "item_array" is 1, but many times in practice
1823// there are more items in "item_array".
1824
1825ValueObjectSP
1826ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1827{
1828 ValueObjectSP synthetic_child_sp;
1829 if (IsArrayType ())
1830 {
1831 char index_str[64];
1832 snprintf(index_str, sizeof(index_str), "[%i]", index);
1833 ConstString index_const_str(index_str);
1834 // Check if we have already created a synthetic array member in this
1835 // valid object. If we have we will re-use it.
1836 synthetic_child_sp = GetSyntheticChild (index_const_str);
1837 if (!synthetic_child_sp)
1838 {
1839 ValueObject *synthetic_child;
1840 // We haven't made a synthetic array member for INDEX yet, so
1841 // lets make one and cache it for any future reference.
1842 synthetic_child = CreateChildAtIndex(0, true, index);
1843
1844 // Cache the value if we got one back...
1845 if (synthetic_child)
1846 {
1847 AddSyntheticChild(index_const_str, synthetic_child);
1848 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001849 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001850 synthetic_child_sp->m_is_array_item_for_pointer = true;
1851 }
1852 }
1853 }
1854 return synthetic_child_sp;
1855}
1856
Enrico Granata9fc19442011-07-06 02:13:41 +00001857ValueObjectSP
1858ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1859{
1860 ValueObjectSP synthetic_child_sp;
1861 if (IsScalarType ())
1862 {
1863 char index_str[64];
1864 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1865 ConstString index_const_str(index_str);
1866 // Check if we have already created a synthetic array member in this
1867 // valid object. If we have we will re-use it.
1868 synthetic_child_sp = GetSyntheticChild (index_const_str);
1869 if (!synthetic_child_sp)
1870 {
1871 ValueObjectChild *synthetic_child;
1872 // We haven't made a synthetic array member for INDEX yet, so
1873 // lets make one and cache it for any future reference.
1874 synthetic_child = new ValueObjectChild(*this,
1875 GetClangAST(),
1876 GetClangType(),
1877 index_const_str,
1878 GetByteSize(),
1879 0,
1880 to-from+1,
1881 from,
1882 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001883 false,
1884 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00001885
1886 // Cache the value if we got one back...
1887 if (synthetic_child)
1888 {
1889 AddSyntheticChild(index_const_str, synthetic_child);
1890 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001891 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00001892 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1893 }
1894 }
1895 }
1896 return synthetic_child_sp;
1897}
1898
Greg Claytonafacd142011-09-02 01:15:17 +00001899ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001900ValueObject::GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create)
1901{
1902 ValueObjectSP synthetic_child_sp;
1903 if (IsArrayType () || IsPointerType ())
1904 {
1905 char index_str[64];
1906 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1907 ConstString index_const_str(index_str);
1908 // Check if we have already created a synthetic array member in this
1909 // valid object. If we have we will re-use it.
1910 synthetic_child_sp = GetSyntheticChild (index_const_str);
1911 if (!synthetic_child_sp)
1912 {
1913 ValueObjectSynthetic *synthetic_child;
1914
1915 // We haven't made a synthetic array member for INDEX yet, so
1916 // lets make one and cache it for any future reference.
Enrico Granata061858c2012-02-15 02:34:21 +00001917 SyntheticArrayView *view = new SyntheticArrayView(SyntheticChildren::Flags());
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001918 view->AddRange(from,to);
1919 SyntheticChildrenSP view_sp(view);
1920 synthetic_child = new ValueObjectSynthetic(*this, view_sp);
1921
1922 // Cache the value if we got one back...
1923 if (synthetic_child)
1924 {
1925 AddSyntheticChild(index_const_str, synthetic_child);
1926 synthetic_child_sp = synthetic_child->GetSP();
1927 synthetic_child_sp->SetName(ConstString(index_str));
1928 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1929 }
1930 }
1931 }
1932 return synthetic_child_sp;
1933}
1934
Greg Claytonafacd142011-09-02 01:15:17 +00001935ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00001936ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
1937{
1938
1939 ValueObjectSP synthetic_child_sp;
1940
1941 char name_str[64];
1942 snprintf(name_str, sizeof(name_str), "@%i", offset);
1943 ConstString name_const_str(name_str);
1944
1945 // Check if we have already created a synthetic array member in this
1946 // valid object. If we have we will re-use it.
1947 synthetic_child_sp = GetSyntheticChild (name_const_str);
1948
1949 if (synthetic_child_sp.get())
1950 return synthetic_child_sp;
1951
1952 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00001953 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001954
1955 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
1956 type.GetASTContext(),
1957 type.GetOpaqueQualType(),
1958 name_const_str,
1959 type.GetTypeByteSize(),
1960 offset,
1961 0,
1962 0,
1963 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001964 false,
1965 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001966 if (synthetic_child)
1967 {
1968 AddSyntheticChild(name_const_str, synthetic_child);
1969 synthetic_child_sp = synthetic_child->GetSP();
1970 synthetic_child_sp->SetName(name_const_str);
1971 synthetic_child_sp->m_is_child_at_offset = true;
1972 }
1973 return synthetic_child_sp;
1974}
1975
Enrico Granatad55546b2011-07-22 00:16:08 +00001976// your expression path needs to have a leading . or ->
1977// (unless it somehow "looks like" an array, in which case it has
1978// a leading [ symbol). while the [ is meaningful and should be shown
1979// to the user, . and -> are just parser design, but by no means
1980// added information for the user.. strip them off
1981static const char*
1982SkipLeadingExpressionPathSeparators(const char* expression)
1983{
1984 if (!expression || !expression[0])
1985 return expression;
1986 if (expression[0] == '.')
1987 return expression+1;
1988 if (expression[0] == '-' && expression[1] == '>')
1989 return expression+2;
1990 return expression;
1991}
1992
Greg Claytonafacd142011-09-02 01:15:17 +00001993ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00001994ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
1995{
1996 ValueObjectSP synthetic_child_sp;
1997 ConstString name_const_string(expression);
1998 // Check if we have already created a synthetic array member in this
1999 // valid object. If we have we will re-use it.
2000 synthetic_child_sp = GetSyntheticChild (name_const_string);
2001 if (!synthetic_child_sp)
2002 {
2003 // We haven't made a synthetic array member for expression yet, so
2004 // lets make one and cache it for any future reference.
2005 synthetic_child_sp = GetValueForExpressionPath(expression);
2006
2007 // Cache the value if we got one back...
2008 if (synthetic_child_sp.get())
2009 {
2010 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002011 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002012 synthetic_child_sp->m_is_expression_path_child = true;
2013 }
2014 }
2015 return synthetic_child_sp;
2016}
2017
2018void
Enrico Granata86cc9822012-03-19 22:58:49 +00002019ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002020{
Enrico Granata86cc9822012-03-19 22:58:49 +00002021 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002022 return;
2023
Enrico Granatac5bc4122012-03-27 02:35:13 +00002024 TargetSP target_sp(GetTargetSP());
2025 if (target_sp && (target_sp->GetEnableSyntheticValue() == false || target_sp->GetSuppressSyntheticValue() == true))
2026 {
2027 m_synthetic_value = NULL;
2028 return;
2029 }
2030
Enrico Granata86cc9822012-03-19 22:58:49 +00002031 if (!UpdateFormatsIfNeeded(m_last_format_mgr_dynamic) && m_synthetic_value)
2032 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002033
Enrico Granata0c489f52012-03-01 04:24:26 +00002034 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002035 return;
2036
Enrico Granata86cc9822012-03-19 22:58:49 +00002037 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002038}
2039
Jim Ingham78a685a2011-04-16 00:01:13 +00002040void
Greg Claytonafacd142011-09-02 01:15:17 +00002041ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002042{
Greg Claytonafacd142011-09-02 01:15:17 +00002043 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002044 return;
2045
Jim Ingham58b59f92011-04-22 23:53:53 +00002046 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002047 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002048 ExecutionContext exe_ctx (GetExecutionContextRef());
2049 Process *process = exe_ctx.GetProcessPtr();
2050 if (process)
Jim Ingham78a685a2011-04-16 00:01:13 +00002051 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002052 bool worth_having_dynamic_value = false;
Jim Ingham78a685a2011-04-16 00:01:13 +00002053
Greg Claytoncc4d0142012-02-17 07:49:44 +00002054
2055 // FIXME: Process should have some kind of "map over Runtimes" so we don't have to
2056 // hard code this everywhere.
2057 LanguageType known_type = GetObjectRuntimeLanguage();
2058 if (known_type != eLanguageTypeUnknown && known_type != eLanguageTypeC)
Jim Ingham78a685a2011-04-16 00:01:13 +00002059 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002060 LanguageRuntime *runtime = process->GetLanguageRuntime (known_type);
2061 if (runtime)
2062 worth_having_dynamic_value = runtime->CouldHaveDynamicValue(*this);
Jim Ingham78a685a2011-04-16 00:01:13 +00002063 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00002064 else
2065 {
2066 LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (eLanguageTypeC_plus_plus);
2067 if (cpp_runtime)
2068 worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this);
2069
2070 if (!worth_having_dynamic_value)
2071 {
2072 LanguageRuntime *objc_runtime = process->GetLanguageRuntime (eLanguageTypeObjC);
2073 if (objc_runtime)
2074 worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this);
2075 }
2076 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002077
Greg Claytoncc4d0142012-02-17 07:49:44 +00002078 if (worth_having_dynamic_value)
2079 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
2080 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002081 }
2082}
2083
Jim Ingham58b59f92011-04-22 23:53:53 +00002084ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002085ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002086{
Greg Claytonafacd142011-09-02 01:15:17 +00002087 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002088 return ValueObjectSP();
2089
2090 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002091 {
Jim Ingham2837b762011-05-04 03:43:18 +00002092 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002093 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002094 if (m_dynamic_value)
2095 return m_dynamic_value->GetSP();
2096 else
2097 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002098}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002099
Jim Ingham60dbabb2011-12-08 19:44:08 +00002100ValueObjectSP
2101ValueObject::GetStaticValue()
2102{
2103 return GetSP();
2104}
2105
Enrico Granata886147f2012-05-08 18:47:08 +00002106lldb::ValueObjectSP
2107ValueObject::GetNonSyntheticValue ()
2108{
2109 return GetSP();
2110}
2111
Enrico Granatad55546b2011-07-22 00:16:08 +00002112ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002113ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002114{
Enrico Granata86cc9822012-03-19 22:58:49 +00002115 if (use_synthetic == false)
2116 return ValueObjectSP();
2117
Enrico Granatad55546b2011-07-22 00:16:08 +00002118 CalculateSyntheticValue(use_synthetic);
2119
2120 if (m_synthetic_value)
2121 return m_synthetic_value->GetSP();
2122 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002123 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002124}
2125
Greg Claytone221f822011-01-21 01:59:00 +00002126bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002127ValueObject::HasSyntheticValue()
2128{
2129 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
2130
Enrico Granata0c489f52012-03-01 04:24:26 +00002131 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002132 return false;
2133
Enrico Granata86cc9822012-03-19 22:58:49 +00002134 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002135
2136 if (m_synthetic_value)
2137 return true;
2138 else
2139 return false;
2140}
2141
2142bool
Greg Claytone221f822011-01-21 01:59:00 +00002143ValueObject::GetBaseClassPath (Stream &s)
2144{
2145 if (IsBaseClass())
2146 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002147 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00002148 clang_type_t clang_type = GetClangType();
2149 std::string cxx_class_name;
2150 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
2151 if (this_had_base_class)
2152 {
2153 if (parent_had_base_class)
2154 s.PutCString("::");
2155 s.PutCString(cxx_class_name.c_str());
2156 }
2157 return parent_had_base_class || this_had_base_class;
2158 }
2159 return false;
2160}
2161
2162
2163ValueObject *
2164ValueObject::GetNonBaseClassParent()
2165{
Jim Ingham78a685a2011-04-16 00:01:13 +00002166 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002167 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002168 if (GetParent()->IsBaseClass())
2169 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002170 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002171 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002172 }
2173 return NULL;
2174}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002175
2176void
Enrico Granata4becb372011-06-29 22:27:15 +00002177ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002178{
Greg Claytone221f822011-01-21 01:59:00 +00002179 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002180
Enrico Granata86cc9822012-03-19 22:58:49 +00002181 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002182 {
Enrico Granata4becb372011-06-29 22:27:15 +00002183 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2184 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2185 // the eHonorPointers mode is meant to produce strings in this latter format
2186 s.PutCString("*(");
2187 }
Greg Claytone221f822011-01-21 01:59:00 +00002188
Enrico Granata4becb372011-06-29 22:27:15 +00002189 ValueObject* parent = GetParent();
2190
2191 if (parent)
2192 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002193
2194 // if we are a deref_of_parent just because we are synthetic array
2195 // members made up to allow ptr[%d] syntax to work in variable
2196 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002197 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002198 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002199
Greg Claytone221f822011-01-21 01:59:00 +00002200 if (!IsBaseClass())
2201 {
2202 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002203 {
Greg Claytone221f822011-01-21 01:59:00 +00002204 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2205 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002206 {
Greg Claytone221f822011-01-21 01:59:00 +00002207 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2208 if (non_base_class_parent_clang_type)
2209 {
2210 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2211
Enrico Granata86cc9822012-03-19 22:58:49 +00002212 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002213 {
2214 s.PutCString("->");
2215 }
Enrico Granata4becb372011-06-29 22:27:15 +00002216 else
2217 {
2218 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2219 {
2220 s.PutCString("->");
2221 }
2222 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2223 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2224 {
2225 s.PutChar('.');
2226 }
Greg Claytone221f822011-01-21 01:59:00 +00002227 }
2228 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002229 }
Greg Claytone221f822011-01-21 01:59:00 +00002230
2231 const char *name = GetName().GetCString();
2232 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002233 {
Greg Claytone221f822011-01-21 01:59:00 +00002234 if (qualify_cxx_base_classes)
2235 {
2236 if (GetBaseClassPath (s))
2237 s.PutCString("::");
2238 }
2239 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002240 }
2241 }
2242 }
2243
Enrico Granata86cc9822012-03-19 22:58:49 +00002244 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002245 {
Greg Claytone221f822011-01-21 01:59:00 +00002246 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002247 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002248}
2249
Greg Claytonafacd142011-09-02 01:15:17 +00002250ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002251ValueObject::GetValueForExpressionPath(const char* expression,
2252 const char** first_unparsed,
2253 ExpressionPathScanEndReason* reason_to_stop,
2254 ExpressionPathEndResultType* final_value_type,
2255 const GetValueForExpressionPathOptions& options,
2256 ExpressionPathAftermath* final_task_on_target)
2257{
2258
2259 const char* dummy_first_unparsed;
2260 ExpressionPathScanEndReason dummy_reason_to_stop;
2261 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002262 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002263
2264 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2265 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2266 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2267 final_value_type ? final_value_type : &dummy_final_value_type,
2268 options,
2269 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2270
Enrico Granata86cc9822012-03-19 22:58:49 +00002271 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002272 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002273
Enrico Granata86cc9822012-03-19 22:58:49 +00002274 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 +00002275 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002276 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002277 {
2278 Error error;
2279 ValueObjectSP final_value = ret_val->Dereference(error);
2280 if (error.Fail() || !final_value.get())
2281 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002282 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002283 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002284 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002285 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002286 return ValueObjectSP();
2287 }
2288 else
2289 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002290 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002291 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002292 return final_value;
2293 }
2294 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002295 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002296 {
2297 Error error;
2298 ValueObjectSP final_value = ret_val->AddressOf(error);
2299 if (error.Fail() || !final_value.get())
2300 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002301 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002302 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002303 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002304 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002305 return ValueObjectSP();
2306 }
2307 else
2308 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002309 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002310 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002311 return final_value;
2312 }
2313 }
2314 }
2315 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2316}
2317
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002318int
2319ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002320 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002321 const char** first_unparsed,
2322 ExpressionPathScanEndReason* reason_to_stop,
2323 ExpressionPathEndResultType* final_value_type,
2324 const GetValueForExpressionPathOptions& options,
2325 ExpressionPathAftermath* final_task_on_target)
2326{
2327 const char* dummy_first_unparsed;
2328 ExpressionPathScanEndReason dummy_reason_to_stop;
2329 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002330 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002331
2332 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2333 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2334 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2335 final_value_type ? final_value_type : &dummy_final_value_type,
2336 options,
2337 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2338
2339 if (!ret_val.get()) // if there are errors, I add nothing to the list
2340 return 0;
2341
Enrico Granata86ea8d82012-03-29 01:34:34 +00002342 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002343 {
2344 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002345 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002346 {
2347 list->Append(ret_val);
2348 return 1;
2349 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002350 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 +00002351 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002352 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002353 {
2354 Error error;
2355 ValueObjectSP final_value = ret_val->Dereference(error);
2356 if (error.Fail() || !final_value.get())
2357 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002358 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2359 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002360 return 0;
2361 }
2362 else
2363 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002364 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002365 list->Append(final_value);
2366 return 1;
2367 }
2368 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002369 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002370 {
2371 Error error;
2372 ValueObjectSP final_value = ret_val->AddressOf(error);
2373 if (error.Fail() || !final_value.get())
2374 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002375 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2376 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002377 return 0;
2378 }
2379 else
2380 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002381 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002382 list->Append(final_value);
2383 return 1;
2384 }
2385 }
2386 }
2387 }
2388 else
2389 {
2390 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2391 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2392 ret_val,
2393 list,
2394 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2395 final_value_type ? final_value_type : &dummy_final_value_type,
2396 options,
2397 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2398 }
2399 // in any non-covered case, just do the obviously right thing
2400 list->Append(ret_val);
2401 return 1;
2402}
2403
Greg Claytonafacd142011-09-02 01:15:17 +00002404ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002405ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2406 const char** first_unparsed,
2407 ExpressionPathScanEndReason* reason_to_stop,
2408 ExpressionPathEndResultType* final_result,
2409 const GetValueForExpressionPathOptions& options,
2410 ExpressionPathAftermath* what_next)
2411{
2412 ValueObjectSP root = GetSP();
2413
2414 if (!root.get())
2415 return ValueObjectSP();
2416
2417 *first_unparsed = expression_cstr;
2418
2419 while (true)
2420 {
2421
2422 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2423
Greg Claytonafacd142011-09-02 01:15:17 +00002424 clang_type_t root_clang_type = root->GetClangType();
2425 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002426 Flags root_clang_type_info,pointee_clang_type_info;
2427
2428 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2429 if (pointee_clang_type)
2430 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002431
2432 if (!expression_cstr || *expression_cstr == '\0')
2433 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002434 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002435 return root;
2436 }
2437
2438 switch (*expression_cstr)
2439 {
2440 case '-':
2441 {
2442 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002443 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 +00002444 {
2445 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002446 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2447 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002448 return ValueObjectSP();
2449 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002450 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2451 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002452 options.m_no_fragile_ivar)
2453 {
2454 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002455 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2456 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002457 return ValueObjectSP();
2458 }
2459 if (expression_cstr[1] != '>')
2460 {
2461 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002462 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2463 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002464 return ValueObjectSP();
2465 }
2466 expression_cstr++; // skip the -
2467 }
2468 case '.': // or fallthrough from ->
2469 {
2470 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002471 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 +00002472 {
2473 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002474 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2475 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002476 return ValueObjectSP();
2477 }
2478 expression_cstr++; // skip .
2479 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2480 ConstString child_name;
2481 if (!next_separator) // if no other separator just expand this last layer
2482 {
2483 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002484 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2485
2486 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002487 {
2488 *first_unparsed = '\0';
Enrico Granata86cc9822012-03-19 22:58:49 +00002489 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2490 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002491 return child_valobj_sp;
2492 }
2493 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2494 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002495 if (root->IsSynthetic())
2496 child_valobj_sp = root;
2497 else
2498 child_valobj_sp = root->GetSyntheticValue();
2499
2500 if (child_valobj_sp.get())
2501 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002502 }
2503
2504 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2505 // so we hit the "else" branch, and return an error
2506 if(child_valobj_sp.get()) // if it worked, just return
2507 {
2508 *first_unparsed = '\0';
Enrico Granata86cc9822012-03-19 22:58:49 +00002509 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2510 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002511 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002512 }
2513 else
2514 {
2515 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002516 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2517 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002518 return ValueObjectSP();
2519 }
2520 }
2521 else // other layers do expand
2522 {
2523 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002524 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2525 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002526 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002527 root = child_valobj_sp;
2528 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002529 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002530 continue;
2531 }
2532 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2533 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002534 child_valobj_sp = root->GetSyntheticValue(true);
2535 if (child_valobj_sp)
2536 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002537 }
2538
2539 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2540 // so we hit the "else" branch, and return an error
2541 if(child_valobj_sp.get()) // if it worked, move on
2542 {
2543 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002544 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002545 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002546 continue;
2547 }
2548 else
2549 {
2550 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002551 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2552 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002553 return ValueObjectSP();
2554 }
2555 }
2556 break;
2557 }
2558 case '[':
2559 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002560 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 +00002561 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002562 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002563 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002564 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2565 {
2566 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002567 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2568 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002569 return ValueObjectSP();
2570 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002571 }
2572 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2573 {
2574 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002575 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2576 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002577 return ValueObjectSP();
2578 }
2579 }
2580 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2581 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002582 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002583 {
2584 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002585 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2586 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002587 return ValueObjectSP();
2588 }
2589 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2590 {
2591 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002592 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2593 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002594 return root;
2595 }
2596 }
2597 const char *separator_position = ::strchr(expression_cstr+1,'-');
2598 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2599 if (!close_bracket_position) // if there is no ], this is a syntax error
2600 {
2601 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002602 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2603 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002604 return ValueObjectSP();
2605 }
2606 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2607 {
2608 char *end = NULL;
2609 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2610 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2611 {
2612 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002613 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2614 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002615 return ValueObjectSP();
2616 }
2617 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2618 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002619 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002620 {
2621 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002622 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2623 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002624 return root;
2625 }
2626 else
2627 {
2628 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002629 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2630 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002631 return ValueObjectSP();
2632 }
2633 }
2634 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002635 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002636 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002637 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2638 if (!child_valobj_sp)
2639 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002640 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002641 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2642 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002643 if (child_valobj_sp)
2644 {
2645 root = child_valobj_sp;
2646 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002647 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002648 continue;
2649 }
2650 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002651 {
2652 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002653 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2654 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002655 return ValueObjectSP();
2656 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002657 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002658 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002659 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002660 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 +00002661 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002662 {
2663 Error error;
2664 root = root->Dereference(error);
2665 if (error.Fail() || !root.get())
2666 {
2667 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002668 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2669 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002670 return ValueObjectSP();
2671 }
2672 else
2673 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002674 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002675 continue;
2676 }
2677 }
2678 else
2679 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002680 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Clayton84db9102012-03-26 23:03:23 +00002681 root->GetClangType()) == eLanguageTypeObjC
2682 && ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2683 && root->HasSyntheticValue()
2684 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002685 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002686 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002687 }
2688 else
2689 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002690 if (!root.get())
2691 {
2692 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002693 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2694 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002695 return ValueObjectSP();
2696 }
2697 else
2698 {
2699 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002700 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002701 continue;
2702 }
2703 }
2704 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002705 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002706 {
2707 root = root->GetSyntheticBitFieldChild(index, index, true);
2708 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 // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2716 {
2717 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002718 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2719 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002720 return root;
2721 }
2722 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002723 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002724 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002725 if (root->HasSyntheticValue())
2726 root = root->GetSyntheticValue();
2727 else if (!root->IsSynthetic())
2728 {
2729 *first_unparsed = expression_cstr;
2730 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2731 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2732 return ValueObjectSP();
2733 }
2734 // if we are here, then root itself is a synthetic VO.. should be good to go
2735
Enrico Granata27b625e2011-08-09 01:04:56 +00002736 if (!root.get())
2737 {
2738 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002739 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2740 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2741 return ValueObjectSP();
2742 }
2743 root = root->GetChildAtIndex(index, true);
2744 if (!root.get())
2745 {
2746 *first_unparsed = expression_cstr;
2747 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2748 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002749 return ValueObjectSP();
2750 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002751 else
2752 {
2753 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002754 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002755 continue;
2756 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002757 }
2758 else
2759 {
2760 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002761 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2762 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002763 return ValueObjectSP();
2764 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002765 }
2766 else // we have a low and a high index
2767 {
2768 char *end = NULL;
2769 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2770 if (!end || end != separator_position) // if something weird is in our way return an error
2771 {
2772 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002773 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2774 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002775 return ValueObjectSP();
2776 }
2777 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2778 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2779 {
2780 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002781 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2782 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002783 return ValueObjectSP();
2784 }
2785 if (index_lower > index_higher) // swap indices if required
2786 {
2787 unsigned long temp = index_lower;
2788 index_lower = index_higher;
2789 index_higher = temp;
2790 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002791 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002792 {
2793 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2794 if (!root.get())
2795 {
2796 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002797 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2798 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002799 return ValueObjectSP();
2800 }
2801 else
2802 {
2803 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002804 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2805 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002806 return root;
2807 }
2808 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002809 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 +00002810 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002811 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002812 {
2813 Error error;
2814 root = root->Dereference(error);
2815 if (error.Fail() || !root.get())
2816 {
2817 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002818 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2819 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002820 return ValueObjectSP();
2821 }
2822 else
2823 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002824 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002825 continue;
2826 }
2827 }
2828 else
2829 {
2830 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002831 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2832 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002833 return root;
2834 }
2835 }
2836 break;
2837 }
2838 default: // some non-separator is in the way
2839 {
2840 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002841 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2842 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002843 return ValueObjectSP();
2844 break;
2845 }
2846 }
2847 }
2848}
2849
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002850int
2851ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2852 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002853 ValueObjectSP root,
2854 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002855 ExpressionPathScanEndReason* reason_to_stop,
2856 ExpressionPathEndResultType* final_result,
2857 const GetValueForExpressionPathOptions& options,
2858 ExpressionPathAftermath* what_next)
2859{
2860 if (!root.get())
2861 return 0;
2862
2863 *first_unparsed = expression_cstr;
2864
2865 while (true)
2866 {
2867
2868 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2869
Greg Claytonafacd142011-09-02 01:15:17 +00002870 clang_type_t root_clang_type = root->GetClangType();
2871 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002872 Flags root_clang_type_info,pointee_clang_type_info;
2873
2874 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2875 if (pointee_clang_type)
2876 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2877
2878 if (!expression_cstr || *expression_cstr == '\0')
2879 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002880 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002881 list->Append(root);
2882 return 1;
2883 }
2884
2885 switch (*expression_cstr)
2886 {
2887 case '[':
2888 {
2889 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2890 {
2891 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2892 {
2893 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002894 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2895 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002896 return 0;
2897 }
2898 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2899 {
2900 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002901 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2902 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002903 return 0;
2904 }
2905 }
2906 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2907 {
2908 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2909 {
2910 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002911 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2912 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002913 return 0;
2914 }
2915 else // expand this into list
2916 {
2917 int max_index = root->GetNumChildren() - 1;
2918 for (int index = 0; index < max_index; index++)
2919 {
2920 ValueObjectSP child =
2921 root->GetChildAtIndex(index, true);
2922 list->Append(child);
2923 }
2924 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002925 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
2926 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002927 return max_index; // tell me number of items I added to the VOList
2928 }
2929 }
2930 const char *separator_position = ::strchr(expression_cstr+1,'-');
2931 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2932 if (!close_bracket_position) // if there is no ], this is a syntax error
2933 {
2934 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002935 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2936 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002937 return 0;
2938 }
2939 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2940 {
2941 char *end = NULL;
2942 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2943 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2944 {
2945 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002946 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2947 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002948 return 0;
2949 }
2950 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2951 {
2952 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2953 {
2954 int max_index = root->GetNumChildren() - 1;
2955 for (int index = 0; index < max_index; index++)
2956 {
2957 ValueObjectSP child =
2958 root->GetChildAtIndex(index, true);
2959 list->Append(child);
2960 }
2961 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002962 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
2963 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002964 return max_index; // tell me number of items I added to the VOList
2965 }
2966 else
2967 {
2968 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002969 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2970 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002971 return 0;
2972 }
2973 }
2974 // from here on we do have a valid index
2975 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2976 {
2977 root = root->GetChildAtIndex(index, true);
2978 if (!root.get())
2979 {
2980 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002981 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2982 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002983 return 0;
2984 }
2985 else
2986 {
2987 list->Append(root);
2988 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002989 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
2990 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002991 return 1;
2992 }
2993 }
2994 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
2995 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002996 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 +00002997 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2998 {
2999 Error error;
3000 root = root->Dereference(error);
3001 if (error.Fail() || !root.get())
3002 {
3003 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003004 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3005 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003006 return 0;
3007 }
3008 else
3009 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003010 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003011 continue;
3012 }
3013 }
3014 else
3015 {
3016 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3017 if (!root.get())
3018 {
3019 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003020 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3021 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003022 return 0;
3023 }
3024 else
3025 {
3026 list->Append(root);
3027 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003028 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3029 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003030 return 1;
3031 }
3032 }
3033 }
3034 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3035 {
3036 root = root->GetSyntheticBitFieldChild(index, index, true);
3037 if (!root.get())
3038 {
3039 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003040 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3041 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003042 return 0;
3043 }
3044 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3045 {
3046 list->Append(root);
3047 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003048 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3049 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003050 return 1;
3051 }
3052 }
3053 }
3054 else // we have a low and a high index
3055 {
3056 char *end = NULL;
3057 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3058 if (!end || end != separator_position) // if something weird is in our way return an error
3059 {
3060 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003061 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3062 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003063 return 0;
3064 }
3065 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3066 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3067 {
3068 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003069 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3070 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003071 return 0;
3072 }
3073 if (index_lower > index_higher) // swap indices if required
3074 {
3075 unsigned long temp = index_lower;
3076 index_lower = index_higher;
3077 index_higher = temp;
3078 }
3079 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
3080 {
3081 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3082 if (!root.get())
3083 {
3084 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003085 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3086 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003087 return 0;
3088 }
3089 else
3090 {
3091 list->Append(root);
3092 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003093 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3094 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003095 return 1;
3096 }
3097 }
3098 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 +00003099 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003100 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3101 {
3102 Error error;
3103 root = root->Dereference(error);
3104 if (error.Fail() || !root.get())
3105 {
3106 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003107 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3108 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003109 return 0;
3110 }
3111 else
3112 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003113 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003114 continue;
3115 }
3116 }
3117 else
3118 {
Johnny Chen44805302011-07-19 19:48:13 +00003119 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003120 index <= index_higher; index++)
3121 {
3122 ValueObjectSP child =
3123 root->GetChildAtIndex(index, true);
3124 list->Append(child);
3125 }
3126 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003127 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3128 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003129 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3130 }
3131 }
3132 break;
3133 }
3134 default: // some non-[ separator, or something entirely wrong, is in the way
3135 {
3136 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003137 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3138 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003139 return 0;
3140 break;
3141 }
3142 }
3143 }
3144}
3145
Enrico Granata0c489f52012-03-01 04:24:26 +00003146static void
3147DumpValueObject_Impl (Stream &s,
3148 ValueObject *valobj,
3149 const ValueObject::DumpValueObjectOptions& options,
3150 uint32_t ptr_depth,
3151 uint32_t curr_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003152{
Greg Clayton007d5be2011-05-30 00:49:24 +00003153 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003154 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003155 bool update_success = valobj->UpdateValueIfNeeded (options.m_use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00003156
Enrico Granata0c489f52012-03-01 04:24:26 +00003157 const char *root_valobj_name =
3158 options.m_root_valobj_name.empty() ?
3159 valobj->GetName().AsCString() :
3160 options.m_root_valobj_name.c_str();
3161
3162 if (update_success && options.m_use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00003163 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003164 ValueObject *dynamic_value = valobj->GetDynamicValue(options.m_use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003165 if (dynamic_value)
3166 valobj = dynamic_value;
3167 }
3168
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003169 clang_type_t clang_type = valobj->GetClangType();
3170
Greg Clayton73b472d2010-10-27 03:32:59 +00003171 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003172 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00003173 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
3174 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003175
Enrico Granata0c489f52012-03-01 04:24:26 +00003176 const bool print_valobj = options.m_flat_output == false || has_value;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003177
3178 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003179 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003180 if (options.m_show_location)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003181 {
Jim Ingham6035b672011-03-31 00:19:25 +00003182 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003183 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003184
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003185 s.Indent();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003186
Greg Clayton7c8a9662010-11-02 01:50:16 +00003187 // Always show the type for the top level items.
Enrico Granata0c489f52012-03-01 04:24:26 +00003188 if (options.m_show_types || (curr_depth == 0 && !options.m_flat_output))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003189 {
Greg Clayton84db9102012-03-26 23:03:23 +00003190 const char* typeName = valobj->GetQualifiedTypeName().AsCString("<invalid type>");
3191 //const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
Enrico Granata9910bc82011-08-03 02:18:51 +00003192 s.Printf("(%s", typeName);
3193 // only show dynamic types if the user really wants to see types
Enrico Granata0c489f52012-03-01 04:24:26 +00003194 if (options.m_show_types && options.m_use_dynamic != eNoDynamicValues &&
Enrico Granata9910bc82011-08-03 02:18:51 +00003195 (/*strstr(typeName, "id") == typeName ||*/
Greg Claytonafacd142011-09-02 01:15:17 +00003196 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003197 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003198 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3199 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatac3e320a2011-08-02 17:27:39 +00003200 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003201 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003202 else
3203 {
3204 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
3205 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003206 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003207 else
3208 {
3209 ObjCLanguageRuntime::ObjCISA isa = runtime->GetISA(*valobj);
3210 if (!runtime->IsValidISA(isa))
Enrico Granata9910bc82011-08-03 02:18:51 +00003211 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003212 else
3213 s.Printf(", dynamic type: %s) ",
3214 runtime->GetActualTypeName(isa).GetCString());
3215 }
3216 }
3217 }
3218 else
3219 s.Printf(") ");
3220 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003221
Greg Clayton1d3afba2010-10-05 00:00:42 +00003222
Enrico Granata0c489f52012-03-01 04:24:26 +00003223 if (options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003224 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003225 // If we are showing types, also qualify the C++ base classes
Enrico Granata0c489f52012-03-01 04:24:26 +00003226 const bool qualify_cxx_base_classes = options.m_show_types;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003227 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003228 s.PutCString(" =");
3229 }
3230 else
3231 {
3232 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3233 s.Printf ("%s =", name_cstr);
3234 }
3235
Enrico Granata0c489f52012-03-01 04:24:26 +00003236 if (!options.m_scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003237 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003238 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003239 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003240 }
3241
Enrico Granata0c489f52012-03-01 04:24:26 +00003242 std::string summary_str;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003243 std::string value_str;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003244 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003245 const char *sum_cstr = NULL;
Enrico Granata0c489f52012-03-01 04:24:26 +00003246 TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003247
Enrico Granata0c489f52012-03-01 04:24:26 +00003248 if (options.m_omit_summary_depth > 0)
Enrico Granata0c5ef692011-07-16 01:22:04 +00003249 entry = NULL;
3250
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003251 if (err_cstr == NULL)
3252 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003253 if (options.m_format != eFormatDefault && options.m_format != valobj->GetFormat())
Greg Clayton6efba4f2012-01-26 21:08:30 +00003254 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003255 valobj->GetValueAsCString(options.m_format,
3256 value_str);
Greg Clayton6efba4f2012-01-26 21:08:30 +00003257 }
Enrico Granata0c489f52012-03-01 04:24:26 +00003258 else
Greg Clayton6efba4f2012-01-26 21:08:30 +00003259 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003260 val_cstr = valobj->GetValueAsCString();
3261 if (val_cstr)
3262 value_str = val_cstr;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003263 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003264 err_cstr = valobj->GetError().AsCString();
3265 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003266
3267 if (err_cstr)
3268 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003269 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003270 }
3271 else
3272 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003273 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003274 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003275 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003276 if (options.m_omit_summary_depth == 0)
3277 {
3278 if (options.m_summary_sp)
3279 {
3280 valobj->GetSummaryAsCString(entry, summary_str);
3281 sum_cstr = summary_str.c_str();
3282 }
3283 else
3284 sum_cstr = valobj->GetSummaryAsCString();
3285 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003286
Greg Clayton6efba4f2012-01-26 21:08:30 +00003287 // Make sure we have a value and make sure the summary didn't
3288 // specify that the value should not be printed
3289 if (!value_str.empty() && (entry == NULL || entry->DoesPrintValue() || sum_cstr == NULL))
3290 s.Printf(" %s", value_str.c_str());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003291
Enrico Granata9dd75c82011-07-15 23:30:15 +00003292 if (sum_cstr)
Enrico Granata0c489f52012-03-01 04:24:26 +00003293 s.Printf(" %s", sum_cstr);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003294
Enrico Granata0c489f52012-03-01 04:24:26 +00003295 if (options.m_use_objc)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003296 {
Jim Ingham6035b672011-03-31 00:19:25 +00003297 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003298 if (object_desc)
3299 s.Printf(" %s\n", object_desc);
3300 else
Sean Callanan672ad942010-10-23 00:18:49 +00003301 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003302 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003303 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003304 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003305
Enrico Granata0c489f52012-03-01 04:24:26 +00003306 if (curr_depth < options.m_max_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003307 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003308 // We will show children for all concrete types. We won't show
3309 // pointer contents unless a pointer depth has been specified.
3310 // We won't reference contents unless the reference is the
3311 // root object (depth of zero).
3312 bool print_children = true;
3313
3314 // Use a new temporary pointer depth in case we override the
3315 // current pointer depth below...
3316 uint32_t curr_ptr_depth = ptr_depth;
3317
3318 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3319 if (is_ptr || is_ref)
3320 {
3321 // We have a pointer or reference whose value is an address.
3322 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003323 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003324 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003325 print_children = false;
3326
3327 else if (is_ref && curr_depth == 0)
3328 {
3329 // If this is the root object (depth is zero) that we are showing
3330 // and it is a reference, and no pointer depth has been supplied
3331 // print out what it references. Don't do this at deeper depths
3332 // otherwise we can end up with infinite recursion...
3333 curr_ptr_depth = 1;
3334 }
3335
3336 if (curr_ptr_depth == 0)
3337 print_children = false;
3338 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003339
Enrico Granata0a3958e2011-07-02 00:25:22 +00003340 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003341 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003342 ValueObject* synth_valobj;
3343 ValueObjectSP synth_valobj_sp = valobj->GetSyntheticValue (options.m_use_synthetic);
3344 synth_valobj = (synth_valobj_sp ? synth_valobj_sp.get() : valobj);
Enrico Granatac5bc4122012-03-27 02:35:13 +00003345
Enrico Granatac482a192011-08-17 22:13:59 +00003346 uint32_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003347 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003348 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003349 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003350 if (options.m_flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003351 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003352 if (print_valobj)
3353 s.EOL();
3354 }
3355 else
3356 {
3357 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003358 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003359 s.IndentMore();
3360 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003361
Greg Claytoncc4d0142012-02-17 07:49:44 +00003362 uint32_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00003363
Enrico Granata0c489f52012-03-01 04:24:26 +00003364 if (num_children > max_num_children && !options.m_ignore_cap)
Enrico Granata22c55d12011-08-12 02:00:06 +00003365 {
3366 num_children = max_num_children;
3367 print_dotdotdot = true;
3368 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003369
Enrico Granata0c489f52012-03-01 04:24:26 +00003370 ValueObject::DumpValueObjectOptions child_options(options);
3371 child_options.SetFormat().SetSummary().SetRootValueObjectName();
3372 child_options.SetScopeChecked(true)
3373 .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003374 for (uint32_t idx=0; idx<num_children; ++idx)
3375 {
Enrico Granatac482a192011-08-17 22:13:59 +00003376 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003377 if (child_sp.get())
3378 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003379 DumpValueObject_Impl (s,
3380 child_sp.get(),
3381 child_options,
3382 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
3383 curr_depth + 1);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003384 }
3385 }
3386
Enrico Granata0c489f52012-03-01 04:24:26 +00003387 if (!options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003388 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003389 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003390 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003391 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3392 Target *target = exe_ctx.GetTargetPtr();
3393 if (target)
3394 target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003395 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003396 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003397 s.IndentLess();
3398 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003399 }
3400 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003401 else if (has_children)
3402 {
3403 // Aggregate, no children...
3404 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003405 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003406 }
3407 else
3408 {
3409 if (print_valobj)
3410 s.EOL();
3411 }
3412
Greg Clayton1d3afba2010-10-05 00:00:42 +00003413 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003414 else
3415 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003416 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003417 }
3418 }
3419 else
3420 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003421 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003422 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003423 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003424 }
3425 }
3426 }
3427 }
3428}
3429
Enrico Granata0c489f52012-03-01 04:24:26 +00003430void
Greg Claytonf830dbb2012-03-22 18:15:37 +00003431ValueObject::LogValueObject (Log *log,
3432 ValueObject *valobj)
3433{
3434 if (log && valobj)
3435 return LogValueObject (log, valobj, DumpValueObjectOptions::DefaultOptions());
3436}
3437
3438void
3439ValueObject::LogValueObject (Log *log,
3440 ValueObject *valobj,
3441 const DumpValueObjectOptions& options)
3442{
3443 if (log && valobj)
3444 {
3445 StreamString s;
3446 ValueObject::DumpValueObject (s, valobj, options);
3447 if (s.GetSize())
3448 log->PutCString(s.GetData());
3449 }
3450}
3451
3452void
Enrico Granata0c489f52012-03-01 04:24:26 +00003453ValueObject::DumpValueObject (Stream &s,
3454 ValueObject *valobj)
3455{
3456
3457 if (!valobj)
3458 return;
3459
3460 DumpValueObject_Impl(s,
3461 valobj,
3462 DumpValueObjectOptions::DefaultOptions(),
3463 0,
3464 0);
3465}
3466
3467void
3468ValueObject::DumpValueObject (Stream &s,
3469 ValueObject *valobj,
3470 const DumpValueObjectOptions& options)
3471{
3472 DumpValueObject_Impl(s,
3473 valobj,
3474 options,
3475 options.m_max_ptr_depth, // max pointer depth allowed, we will go down from here
3476 0 // current object depth is 0 since we are just starting
3477 );
3478}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003479
3480ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003481ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003482{
3483 ValueObjectSP valobj_sp;
3484
Enrico Granatac3e320a2011-08-02 17:27:39 +00003485 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003486 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003487 ExecutionContext exe_ctx (GetExecutionContextRef());
3488 clang::ASTContext *ast = GetClangAST ();
3489
3490 DataExtractor data;
3491 data.SetByteOrder (m_data.GetByteOrder());
3492 data.SetAddressByteSize(m_data.GetAddressByteSize());
3493
Enrico Granata9f1e2042012-04-24 22:15:37 +00003494 if (IsBitfield())
3495 {
3496 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
3497 m_error = v.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
3498 }
3499 else
3500 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003501
3502 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3503 ast,
3504 GetClangType(),
3505 name,
3506 data,
3507 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003508 }
Jim Ingham6035b672011-03-31 00:19:25 +00003509
3510 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003511 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003512 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003513 }
3514 return valobj_sp;
3515}
3516
Greg Claytonafacd142011-09-02 01:15:17 +00003517ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003518ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003519{
Jim Ingham58b59f92011-04-22 23:53:53 +00003520 if (m_deref_valobj)
3521 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003522
Greg Clayton54979cd2010-12-15 05:08:08 +00003523 const bool is_pointer_type = IsPointerType();
3524 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003525 {
3526 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003527 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003528
3529 std::string child_name_str;
3530 uint32_t child_byte_size = 0;
3531 int32_t child_byte_offset = 0;
3532 uint32_t child_bitfield_bit_size = 0;
3533 uint32_t child_bitfield_bit_offset = 0;
3534 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003535 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003536 const bool transparent_pointers = false;
3537 clang::ASTContext *clang_ast = GetClangAST();
3538 clang_type_t clang_type = GetClangType();
3539 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003540
Greg Claytoncc4d0142012-02-17 07:49:44 +00003541 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003542
3543 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3544 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003545 GetName().GetCString(),
3546 clang_type,
3547 0,
3548 transparent_pointers,
3549 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003550 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003551 child_name_str,
3552 child_byte_size,
3553 child_byte_offset,
3554 child_bitfield_bit_size,
3555 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003556 child_is_base_class,
3557 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003558 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003559 {
3560 ConstString child_name;
3561 if (!child_name_str.empty())
3562 child_name.SetCString (child_name_str.c_str());
3563
Jim Ingham58b59f92011-04-22 23:53:53 +00003564 m_deref_valobj = new ValueObjectChild (*this,
3565 clang_ast,
3566 child_clang_type,
3567 child_name,
3568 child_byte_size,
3569 child_byte_offset,
3570 child_bitfield_bit_size,
3571 child_bitfield_bit_offset,
3572 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003573 child_is_deref_of_parent,
3574 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003575 }
3576 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003577
Jim Ingham58b59f92011-04-22 23:53:53 +00003578 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003579 {
3580 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003581 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003582 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003583 else
3584 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003585 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003586 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003587
3588 if (is_pointer_type)
3589 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3590 else
3591 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003592 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003593 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003594}
3595
Greg Claytonafacd142011-09-02 01:15:17 +00003596ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003597ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003598{
Jim Ingham78a685a2011-04-16 00:01:13 +00003599 if (m_addr_of_valobj_sp)
3600 return m_addr_of_valobj_sp;
3601
Greg Claytone0d378b2011-03-24 21:19:54 +00003602 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003603 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003604 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003605 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003606 if (addr != LLDB_INVALID_ADDRESS)
3607 {
3608 switch (address_type)
3609 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003610 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003611 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003612 {
3613 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003614 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003615 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3616 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003617 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003618
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003619 case eAddressTypeFile:
3620 case eAddressTypeLoad:
3621 case eAddressTypeHost:
3622 {
3623 clang::ASTContext *ast = GetClangAST();
3624 clang_type_t clang_type = GetClangType();
3625 if (ast && clang_type)
3626 {
3627 std::string name (1, '&');
3628 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003629 ExecutionContext exe_ctx (GetExecutionContextRef());
3630 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003631 ast,
3632 ClangASTContext::CreatePointerType (ast, clang_type),
3633 ConstString (name.c_str()),
3634 addr,
3635 eAddressTypeInvalid,
3636 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003637 }
3638 }
3639 break;
3640 }
3641 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003642 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003643}
3644
Greg Clayton9a142cf2012-02-03 05:34:10 +00003645ValueObjectSP
3646ValueObject::Cast (const ClangASTType &clang_ast_type)
3647{
Greg Clayton81e871e2012-02-04 02:27:34 +00003648 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003649}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003650
Greg Claytonafacd142011-09-02 01:15:17 +00003651ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003652ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3653{
Greg Claytonafacd142011-09-02 01:15:17 +00003654 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003655 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003656 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003657
3658 if (ptr_value != LLDB_INVALID_ADDRESS)
3659 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003660 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003661 ExecutionContext exe_ctx (GetExecutionContextRef());
3662 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003663 name,
3664 ptr_addr,
3665 clang_ast_type);
3666 }
3667 return valobj_sp;
3668}
3669
Greg Claytonafacd142011-09-02 01:15:17 +00003670ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003671ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3672{
Greg Claytonafacd142011-09-02 01:15:17 +00003673 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003674 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003675 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003676
3677 if (ptr_value != LLDB_INVALID_ADDRESS)
3678 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003679 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003680 ExecutionContext exe_ctx (GetExecutionContextRef());
3681 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003682 name,
3683 ptr_addr,
3684 type_sp);
3685 }
3686 return valobj_sp;
3687}
3688
Jim Ingham6035b672011-03-31 00:19:25 +00003689ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003690 m_mod_id(),
3691 m_exe_ctx_ref(),
3692 m_needs_update (true),
3693 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003694{
3695}
3696
3697ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003698 m_mod_id(),
3699 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003700 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003701 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003702{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003703 ExecutionContext exe_ctx(exe_scope);
3704 TargetSP target_sp (exe_ctx.GetTargetSP());
3705 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003706 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003707 m_exe_ctx_ref.SetTargetSP (target_sp);
3708 ProcessSP process_sp (exe_ctx.GetProcessSP());
3709 if (!process_sp)
3710 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003711
Greg Claytoncc4d0142012-02-17 07:49:44 +00003712 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003713 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003714 m_mod_id = process_sp->GetModID();
3715 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003716
Greg Claytoncc4d0142012-02-17 07:49:44 +00003717 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003718
Greg Claytoncc4d0142012-02-17 07:49:44 +00003719 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003720 {
3721 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003722 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003723 }
Jim Ingham6035b672011-03-31 00:19:25 +00003724
Greg Claytoncc4d0142012-02-17 07:49:44 +00003725 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003726 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003727 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003728
Greg Claytoncc4d0142012-02-17 07:49:44 +00003729 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3730 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003731 {
3732 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003733 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003734 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003735 if (frame_sp)
3736 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003737 }
3738 }
3739 }
Jim Ingham6035b672011-03-31 00:19:25 +00003740}
3741
3742ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003743 m_mod_id(),
3744 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3745 m_needs_update (true),
3746 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003747{
3748}
3749
3750ValueObject::EvaluationPoint::~EvaluationPoint ()
3751{
3752}
3753
Jim Ingham6035b672011-03-31 00:19:25 +00003754// This function checks the EvaluationPoint against the current process state. If the current
3755// state matches the evaluation point, or the evaluation point is already invalid, then we return
3756// false, meaning "no change". If the current state is different, we update our state, and return
3757// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3758// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003759// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003760
3761bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003762ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003763{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003764
3765 // 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 +00003766 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00003767
Greg Claytoncc4d0142012-02-17 07:49:44 +00003768 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003769 return false;
3770
Jim Ingham6035b672011-03-31 00:19:25 +00003771 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003772 Process *process = exe_ctx.GetProcessPtr();
3773 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003774 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003775
Jim Ingham6035b672011-03-31 00:19:25 +00003776 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003777 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003778
Jim Ingham78a685a2011-04-16 00:01:13 +00003779 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3780 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003781 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003782 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003783
3784 bool changed;
3785
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003786 if (m_mod_id.IsValid())
3787 {
3788 if (m_mod_id == current_mod_id)
3789 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003790 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003791 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003792 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003793 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003794 else
3795 {
3796 m_mod_id = current_mod_id;
3797 m_needs_update = true;
3798 changed = true;
3799 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003800 }
Jim Ingham6035b672011-03-31 00:19:25 +00003801
Jim Ingham73ca05a2011-12-17 01:35:57 +00003802 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3803 // That way we'll be sure to return a valid exe_scope.
3804 // 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 +00003805
Greg Claytoncc4d0142012-02-17 07:49:44 +00003806 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003807 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003808 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3809 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003810 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003811 if (m_exe_ctx_ref.HasFrameRef())
3812 {
3813 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3814 if (!frame_sp)
3815 {
3816 // We used to have a frame, but now it is gone
3817 SetInvalid();
3818 }
3819 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003820 }
Jim Ingham6035b672011-03-31 00:19:25 +00003821 else
3822 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003823 // We used to have a thread, but now it is gone
3824 SetInvalid();
Jim Ingham6035b672011-03-31 00:19:25 +00003825 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003826
Jim Ingham6035b672011-03-31 00:19:25 +00003827 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003828 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003829}
3830
Jim Ingham61be0902011-05-02 18:13:59 +00003831void
3832ValueObject::EvaluationPoint::SetUpdated ()
3833{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003834 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3835 if (process_sp)
3836 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003837 m_first_update = false;
3838 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003839}
3840
3841
Greg Claytoncc4d0142012-02-17 07:49:44 +00003842//bool
3843//ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3844//{
3845// if (!IsValid())
3846// return false;
3847//
3848// bool needs_update = false;
3849//
3850// // The target has to be non-null, and the
3851// Target *target = exe_scope->CalculateTarget();
3852// if (target != NULL)
3853// {
3854// Target *old_target = m_target_sp.get();
3855// assert (target == old_target);
3856// Process *process = exe_scope->CalculateProcess();
3857// if (process != NULL)
3858// {
3859// // FOR NOW - assume you can't update variable objects across process boundaries.
3860// Process *old_process = m_process_sp.get();
3861// assert (process == old_process);
3862// ProcessModID current_mod_id = process->GetModID();
3863// if (m_mod_id != current_mod_id)
3864// {
3865// needs_update = true;
3866// m_mod_id = current_mod_id;
3867// }
3868// // See if we're switching the thread or stack context. If no thread is given, this is
3869// // being evaluated in a global context.
3870// Thread *thread = exe_scope->CalculateThread();
3871// if (thread != NULL)
3872// {
3873// user_id_t new_thread_index = thread->GetIndexID();
3874// if (new_thread_index != m_thread_id)
3875// {
3876// needs_update = true;
3877// m_thread_id = new_thread_index;
3878// m_stack_id.Clear();
3879// }
3880//
3881// StackFrame *new_frame = exe_scope->CalculateStackFrame();
3882// if (new_frame != NULL)
3883// {
3884// if (new_frame->GetStackID() != m_stack_id)
3885// {
3886// needs_update = true;
3887// m_stack_id = new_frame->GetStackID();
3888// }
3889// }
3890// else
3891// {
3892// m_stack_id.Clear();
3893// needs_update = true;
3894// }
3895// }
3896// else
3897// {
3898// // If this had been given a thread, and now there is none, we should update.
3899// // Otherwise we don't have to do anything.
3900// if (m_thread_id != LLDB_INVALID_UID)
3901// {
3902// m_thread_id = LLDB_INVALID_UID;
3903// m_stack_id.Clear();
3904// needs_update = true;
3905// }
3906// }
3907// }
3908// else
3909// {
3910// // If there is no process, then we don't need to update anything.
3911// // But if we're switching from having a process to not, we should try to update.
3912// if (m_process_sp.get() != NULL)
3913// {
3914// needs_update = true;
3915// m_process_sp.reset();
3916// m_thread_id = LLDB_INVALID_UID;
3917// m_stack_id.Clear();
3918// }
3919// }
3920// }
3921// else
3922// {
3923// // If there's no target, nothing can change so we don't need to update anything.
3924// // But if we're switching from having a target to not, we should try to update.
3925// if (m_target_sp.get() != NULL)
3926// {
3927// needs_update = true;
3928// m_target_sp.reset();
3929// m_process_sp.reset();
3930// m_thread_id = LLDB_INVALID_UID;
3931// m_stack_id.Clear();
3932// }
3933// }
3934// if (!m_needs_update)
3935// m_needs_update = needs_update;
3936//
3937// return needs_update;
3938//}
Enrico Granataf2bbf712011-07-15 02:26:42 +00003939
3940void
Enrico Granata86cc9822012-03-19 22:58:49 +00003941ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00003942{
Enrico Granata86cc9822012-03-19 22:58:49 +00003943 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
3944 m_value_str.clear();
3945
3946 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
3947 m_location_str.clear();
3948
3949 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
3950 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003951 m_summary_str.clear();
3952 }
3953
3954 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
3955 m_object_desc_str.clear();
3956
3957 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
3958 {
3959 if (m_synthetic_value)
3960 m_synthetic_value = NULL;
3961 }
Johnny Chen44805302011-07-19 19:48:13 +00003962}
Enrico Granata9128ee22011-09-06 19:20:51 +00003963
3964SymbolContextScope *
3965ValueObject::GetSymbolContextScope()
3966{
3967 if (m_parent)
3968 {
3969 if (!m_parent->IsPointerOrReferenceType())
3970 return m_parent->GetSymbolContextScope();
3971 }
3972 return NULL;
3973}