blob: 008ff4f21c5b282e44837fd6635b5fca49d39044 [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 Granatad55546b2011-07-22 00:16:08 +00002106ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002107ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002108{
Enrico Granata86cc9822012-03-19 22:58:49 +00002109 if (use_synthetic == false)
2110 return ValueObjectSP();
2111
Enrico Granatad55546b2011-07-22 00:16:08 +00002112 CalculateSyntheticValue(use_synthetic);
2113
2114 if (m_synthetic_value)
2115 return m_synthetic_value->GetSP();
2116 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002117 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002118}
2119
Greg Claytone221f822011-01-21 01:59:00 +00002120bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002121ValueObject::HasSyntheticValue()
2122{
2123 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
2124
Enrico Granata0c489f52012-03-01 04:24:26 +00002125 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002126 return false;
2127
Enrico Granata86cc9822012-03-19 22:58:49 +00002128 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002129
2130 if (m_synthetic_value)
2131 return true;
2132 else
2133 return false;
2134}
2135
2136bool
Greg Claytone221f822011-01-21 01:59:00 +00002137ValueObject::GetBaseClassPath (Stream &s)
2138{
2139 if (IsBaseClass())
2140 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002141 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00002142 clang_type_t clang_type = GetClangType();
2143 std::string cxx_class_name;
2144 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
2145 if (this_had_base_class)
2146 {
2147 if (parent_had_base_class)
2148 s.PutCString("::");
2149 s.PutCString(cxx_class_name.c_str());
2150 }
2151 return parent_had_base_class || this_had_base_class;
2152 }
2153 return false;
2154}
2155
2156
2157ValueObject *
2158ValueObject::GetNonBaseClassParent()
2159{
Jim Ingham78a685a2011-04-16 00:01:13 +00002160 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002161 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002162 if (GetParent()->IsBaseClass())
2163 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002164 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002165 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002166 }
2167 return NULL;
2168}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002169
2170void
Enrico Granata4becb372011-06-29 22:27:15 +00002171ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002172{
Greg Claytone221f822011-01-21 01:59:00 +00002173 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002174
Enrico Granata86cc9822012-03-19 22:58:49 +00002175 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002176 {
Enrico Granata4becb372011-06-29 22:27:15 +00002177 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2178 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2179 // the eHonorPointers mode is meant to produce strings in this latter format
2180 s.PutCString("*(");
2181 }
Greg Claytone221f822011-01-21 01:59:00 +00002182
Enrico Granata4becb372011-06-29 22:27:15 +00002183 ValueObject* parent = GetParent();
2184
2185 if (parent)
2186 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002187
2188 // if we are a deref_of_parent just because we are synthetic array
2189 // members made up to allow ptr[%d] syntax to work in variable
2190 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002191 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002192 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002193
Greg Claytone221f822011-01-21 01:59:00 +00002194 if (!IsBaseClass())
2195 {
2196 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002197 {
Greg Claytone221f822011-01-21 01:59:00 +00002198 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2199 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002200 {
Greg Claytone221f822011-01-21 01:59:00 +00002201 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2202 if (non_base_class_parent_clang_type)
2203 {
2204 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2205
Enrico Granata86cc9822012-03-19 22:58:49 +00002206 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002207 {
2208 s.PutCString("->");
2209 }
Enrico Granata4becb372011-06-29 22:27:15 +00002210 else
2211 {
2212 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2213 {
2214 s.PutCString("->");
2215 }
2216 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2217 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2218 {
2219 s.PutChar('.');
2220 }
Greg Claytone221f822011-01-21 01:59:00 +00002221 }
2222 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002223 }
Greg Claytone221f822011-01-21 01:59:00 +00002224
2225 const char *name = GetName().GetCString();
2226 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002227 {
Greg Claytone221f822011-01-21 01:59:00 +00002228 if (qualify_cxx_base_classes)
2229 {
2230 if (GetBaseClassPath (s))
2231 s.PutCString("::");
2232 }
2233 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002234 }
2235 }
2236 }
2237
Enrico Granata86cc9822012-03-19 22:58:49 +00002238 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002239 {
Greg Claytone221f822011-01-21 01:59:00 +00002240 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002241 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002242}
2243
Greg Claytonafacd142011-09-02 01:15:17 +00002244ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002245ValueObject::GetValueForExpressionPath(const char* expression,
2246 const char** first_unparsed,
2247 ExpressionPathScanEndReason* reason_to_stop,
2248 ExpressionPathEndResultType* final_value_type,
2249 const GetValueForExpressionPathOptions& options,
2250 ExpressionPathAftermath* final_task_on_target)
2251{
2252
2253 const char* dummy_first_unparsed;
2254 ExpressionPathScanEndReason dummy_reason_to_stop;
2255 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002256 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002257
2258 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2259 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2260 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2261 final_value_type ? final_value_type : &dummy_final_value_type,
2262 options,
2263 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2264
Enrico Granata86cc9822012-03-19 22:58:49 +00002265 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002266 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002267
Enrico Granata86cc9822012-03-19 22:58:49 +00002268 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 +00002269 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002270 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002271 {
2272 Error error;
2273 ValueObjectSP final_value = ret_val->Dereference(error);
2274 if (error.Fail() || !final_value.get())
2275 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002276 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002277 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002278 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002279 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002280 return ValueObjectSP();
2281 }
2282 else
2283 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002284 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002285 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002286 return final_value;
2287 }
2288 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002289 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002290 {
2291 Error error;
2292 ValueObjectSP final_value = ret_val->AddressOf(error);
2293 if (error.Fail() || !final_value.get())
2294 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002295 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002296 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002297 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002298 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002299 return ValueObjectSP();
2300 }
2301 else
2302 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002303 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002304 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002305 return final_value;
2306 }
2307 }
2308 }
2309 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2310}
2311
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002312int
2313ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002314 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002315 const char** first_unparsed,
2316 ExpressionPathScanEndReason* reason_to_stop,
2317 ExpressionPathEndResultType* final_value_type,
2318 const GetValueForExpressionPathOptions& options,
2319 ExpressionPathAftermath* final_task_on_target)
2320{
2321 const char* dummy_first_unparsed;
2322 ExpressionPathScanEndReason dummy_reason_to_stop;
2323 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002324 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002325
2326 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2327 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2328 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2329 final_value_type ? final_value_type : &dummy_final_value_type,
2330 options,
2331 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2332
2333 if (!ret_val.get()) // if there are errors, I add nothing to the list
2334 return 0;
2335
Enrico Granata86ea8d82012-03-29 01:34:34 +00002336 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002337 {
2338 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002339 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002340 {
2341 list->Append(ret_val);
2342 return 1;
2343 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002344 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 +00002345 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002346 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002347 {
2348 Error error;
2349 ValueObjectSP final_value = ret_val->Dereference(error);
2350 if (error.Fail() || !final_value.get())
2351 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002352 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2353 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002354 return 0;
2355 }
2356 else
2357 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002358 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002359 list->Append(final_value);
2360 return 1;
2361 }
2362 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002363 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002364 {
2365 Error error;
2366 ValueObjectSP final_value = ret_val->AddressOf(error);
2367 if (error.Fail() || !final_value.get())
2368 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002369 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2370 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002371 return 0;
2372 }
2373 else
2374 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002375 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002376 list->Append(final_value);
2377 return 1;
2378 }
2379 }
2380 }
2381 }
2382 else
2383 {
2384 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2385 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2386 ret_val,
2387 list,
2388 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2389 final_value_type ? final_value_type : &dummy_final_value_type,
2390 options,
2391 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2392 }
2393 // in any non-covered case, just do the obviously right thing
2394 list->Append(ret_val);
2395 return 1;
2396}
2397
Greg Claytonafacd142011-09-02 01:15:17 +00002398ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002399ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2400 const char** first_unparsed,
2401 ExpressionPathScanEndReason* reason_to_stop,
2402 ExpressionPathEndResultType* final_result,
2403 const GetValueForExpressionPathOptions& options,
2404 ExpressionPathAftermath* what_next)
2405{
2406 ValueObjectSP root = GetSP();
2407
2408 if (!root.get())
2409 return ValueObjectSP();
2410
2411 *first_unparsed = expression_cstr;
2412
2413 while (true)
2414 {
2415
2416 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2417
Greg Claytonafacd142011-09-02 01:15:17 +00002418 clang_type_t root_clang_type = root->GetClangType();
2419 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002420 Flags root_clang_type_info,pointee_clang_type_info;
2421
2422 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2423 if (pointee_clang_type)
2424 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002425
2426 if (!expression_cstr || *expression_cstr == '\0')
2427 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002428 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002429 return root;
2430 }
2431
2432 switch (*expression_cstr)
2433 {
2434 case '-':
2435 {
2436 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002437 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 +00002438 {
2439 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002440 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2441 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002442 return ValueObjectSP();
2443 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002444 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2445 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002446 options.m_no_fragile_ivar)
2447 {
2448 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002449 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2450 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002451 return ValueObjectSP();
2452 }
2453 if (expression_cstr[1] != '>')
2454 {
2455 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002456 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2457 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002458 return ValueObjectSP();
2459 }
2460 expression_cstr++; // skip the -
2461 }
2462 case '.': // or fallthrough from ->
2463 {
2464 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002465 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 +00002466 {
2467 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002468 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2469 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002470 return ValueObjectSP();
2471 }
2472 expression_cstr++; // skip .
2473 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2474 ConstString child_name;
2475 if (!next_separator) // if no other separator just expand this last layer
2476 {
2477 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002478 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2479
2480 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002481 {
2482 *first_unparsed = '\0';
Enrico Granata86cc9822012-03-19 22:58:49 +00002483 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2484 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002485 return child_valobj_sp;
2486 }
2487 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2488 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002489 if (root->IsSynthetic())
2490 child_valobj_sp = root;
2491 else
2492 child_valobj_sp = root->GetSyntheticValue();
2493
2494 if (child_valobj_sp.get())
2495 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002496 }
2497
2498 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2499 // so we hit the "else" branch, and return an error
2500 if(child_valobj_sp.get()) // if it worked, just return
2501 {
2502 *first_unparsed = '\0';
Enrico Granata86cc9822012-03-19 22:58:49 +00002503 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2504 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002505 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002506 }
2507 else
2508 {
2509 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002510 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2511 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002512 return ValueObjectSP();
2513 }
2514 }
2515 else // other layers do expand
2516 {
2517 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002518 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2519 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002520 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002521 root = child_valobj_sp;
2522 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002523 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002524 continue;
2525 }
2526 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2527 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002528 child_valobj_sp = root->GetSyntheticValue(true);
2529 if (child_valobj_sp)
2530 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002531 }
2532
2533 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2534 // so we hit the "else" branch, and return an error
2535 if(child_valobj_sp.get()) // if it worked, move on
2536 {
2537 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002538 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002539 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002540 continue;
2541 }
2542 else
2543 {
2544 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002545 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2546 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002547 return ValueObjectSP();
2548 }
2549 }
2550 break;
2551 }
2552 case '[':
2553 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002554 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 +00002555 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002556 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002557 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002558 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2559 {
2560 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002561 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2562 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002563 return ValueObjectSP();
2564 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002565 }
2566 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2567 {
2568 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002569 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2570 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002571 return ValueObjectSP();
2572 }
2573 }
2574 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2575 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002576 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002577 {
2578 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002579 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2580 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002581 return ValueObjectSP();
2582 }
2583 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2584 {
2585 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002586 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2587 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002588 return root;
2589 }
2590 }
2591 const char *separator_position = ::strchr(expression_cstr+1,'-');
2592 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2593 if (!close_bracket_position) // if there is no ], this is a syntax error
2594 {
2595 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002596 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2597 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002598 return ValueObjectSP();
2599 }
2600 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2601 {
2602 char *end = NULL;
2603 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2604 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2605 {
2606 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002607 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2608 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002609 return ValueObjectSP();
2610 }
2611 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2612 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002613 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002614 {
2615 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002616 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2617 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002618 return root;
2619 }
2620 else
2621 {
2622 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002623 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2624 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002625 return ValueObjectSP();
2626 }
2627 }
2628 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002629 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002630 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002631 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2632 if (!child_valobj_sp)
2633 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002634 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002635 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2636 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002637 if (child_valobj_sp)
2638 {
2639 root = child_valobj_sp;
2640 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002641 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002642 continue;
2643 }
2644 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002645 {
2646 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002647 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2648 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002649 return ValueObjectSP();
2650 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002651 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002652 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002653 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002654 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 +00002655 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002656 {
2657 Error error;
2658 root = root->Dereference(error);
2659 if (error.Fail() || !root.get())
2660 {
2661 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002662 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2663 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002664 return ValueObjectSP();
2665 }
2666 else
2667 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002668 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002669 continue;
2670 }
2671 }
2672 else
2673 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002674 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Clayton84db9102012-03-26 23:03:23 +00002675 root->GetClangType()) == eLanguageTypeObjC
2676 && ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2677 && root->HasSyntheticValue()
2678 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002679 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002680 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002681 }
2682 else
2683 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002684 if (!root.get())
2685 {
2686 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002687 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2688 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002689 return ValueObjectSP();
2690 }
2691 else
2692 {
2693 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002694 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002695 continue;
2696 }
2697 }
2698 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002699 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002700 {
2701 root = root->GetSyntheticBitFieldChild(index, index, true);
2702 if (!root.get())
2703 {
2704 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002705 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2706 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002707 return ValueObjectSP();
2708 }
2709 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2710 {
2711 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002712 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2713 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002714 return root;
2715 }
2716 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002717 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002718 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002719 if (root->HasSyntheticValue())
2720 root = root->GetSyntheticValue();
2721 else if (!root->IsSynthetic())
2722 {
2723 *first_unparsed = expression_cstr;
2724 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2725 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2726 return ValueObjectSP();
2727 }
2728 // if we are here, then root itself is a synthetic VO.. should be good to go
2729
Enrico Granata27b625e2011-08-09 01:04:56 +00002730 if (!root.get())
2731 {
2732 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002733 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2734 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2735 return ValueObjectSP();
2736 }
2737 root = root->GetChildAtIndex(index, true);
2738 if (!root.get())
2739 {
2740 *first_unparsed = expression_cstr;
2741 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2742 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002743 return ValueObjectSP();
2744 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002745 else
2746 {
2747 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002748 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002749 continue;
2750 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002751 }
2752 else
2753 {
2754 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002755 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2756 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002757 return ValueObjectSP();
2758 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002759 }
2760 else // we have a low and a high index
2761 {
2762 char *end = NULL;
2763 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2764 if (!end || end != separator_position) // if something weird is in our way return an error
2765 {
2766 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002767 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2768 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002769 return ValueObjectSP();
2770 }
2771 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2772 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2773 {
2774 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002775 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2776 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002777 return ValueObjectSP();
2778 }
2779 if (index_lower > index_higher) // swap indices if required
2780 {
2781 unsigned long temp = index_lower;
2782 index_lower = index_higher;
2783 index_higher = temp;
2784 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002785 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002786 {
2787 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2788 if (!root.get())
2789 {
2790 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002791 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2792 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002793 return ValueObjectSP();
2794 }
2795 else
2796 {
2797 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002798 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2799 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002800 return root;
2801 }
2802 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002803 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 +00002804 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002805 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002806 {
2807 Error error;
2808 root = root->Dereference(error);
2809 if (error.Fail() || !root.get())
2810 {
2811 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002812 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2813 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002814 return ValueObjectSP();
2815 }
2816 else
2817 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002818 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002819 continue;
2820 }
2821 }
2822 else
2823 {
2824 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002825 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2826 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002827 return root;
2828 }
2829 }
2830 break;
2831 }
2832 default: // some non-separator is in the way
2833 {
2834 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002835 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2836 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002837 return ValueObjectSP();
2838 break;
2839 }
2840 }
2841 }
2842}
2843
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002844int
2845ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2846 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002847 ValueObjectSP root,
2848 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002849 ExpressionPathScanEndReason* reason_to_stop,
2850 ExpressionPathEndResultType* final_result,
2851 const GetValueForExpressionPathOptions& options,
2852 ExpressionPathAftermath* what_next)
2853{
2854 if (!root.get())
2855 return 0;
2856
2857 *first_unparsed = expression_cstr;
2858
2859 while (true)
2860 {
2861
2862 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2863
Greg Claytonafacd142011-09-02 01:15:17 +00002864 clang_type_t root_clang_type = root->GetClangType();
2865 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002866 Flags root_clang_type_info,pointee_clang_type_info;
2867
2868 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2869 if (pointee_clang_type)
2870 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2871
2872 if (!expression_cstr || *expression_cstr == '\0')
2873 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002874 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002875 list->Append(root);
2876 return 1;
2877 }
2878
2879 switch (*expression_cstr)
2880 {
2881 case '[':
2882 {
2883 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2884 {
2885 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2886 {
2887 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002888 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2889 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002890 return 0;
2891 }
2892 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2893 {
2894 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002895 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2896 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002897 return 0;
2898 }
2899 }
2900 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2901 {
2902 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2903 {
2904 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002905 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2906 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002907 return 0;
2908 }
2909 else // expand this into list
2910 {
2911 int max_index = root->GetNumChildren() - 1;
2912 for (int index = 0; index < max_index; index++)
2913 {
2914 ValueObjectSP child =
2915 root->GetChildAtIndex(index, true);
2916 list->Append(child);
2917 }
2918 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002919 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
2920 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002921 return max_index; // tell me number of items I added to the VOList
2922 }
2923 }
2924 const char *separator_position = ::strchr(expression_cstr+1,'-');
2925 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2926 if (!close_bracket_position) // if there is no ], this is a syntax error
2927 {
2928 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002929 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2930 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002931 return 0;
2932 }
2933 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2934 {
2935 char *end = NULL;
2936 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2937 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2938 {
2939 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002940 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2941 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002942 return 0;
2943 }
2944 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2945 {
2946 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2947 {
2948 int max_index = root->GetNumChildren() - 1;
2949 for (int index = 0; index < max_index; index++)
2950 {
2951 ValueObjectSP child =
2952 root->GetChildAtIndex(index, true);
2953 list->Append(child);
2954 }
2955 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002956 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
2957 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002958 return max_index; // tell me number of items I added to the VOList
2959 }
2960 else
2961 {
2962 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002963 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2964 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002965 return 0;
2966 }
2967 }
2968 // from here on we do have a valid index
2969 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2970 {
2971 root = root->GetChildAtIndex(index, true);
2972 if (!root.get())
2973 {
2974 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002975 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2976 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002977 return 0;
2978 }
2979 else
2980 {
2981 list->Append(root);
2982 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002983 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
2984 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002985 return 1;
2986 }
2987 }
2988 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
2989 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002990 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 +00002991 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2992 {
2993 Error error;
2994 root = root->Dereference(error);
2995 if (error.Fail() || !root.get())
2996 {
2997 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002998 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2999 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003000 return 0;
3001 }
3002 else
3003 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003004 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003005 continue;
3006 }
3007 }
3008 else
3009 {
3010 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3011 if (!root.get())
3012 {
3013 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003014 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3015 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003016 return 0;
3017 }
3018 else
3019 {
3020 list->Append(root);
3021 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003022 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3023 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003024 return 1;
3025 }
3026 }
3027 }
3028 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3029 {
3030 root = root->GetSyntheticBitFieldChild(index, index, true);
3031 if (!root.get())
3032 {
3033 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003034 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3035 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003036 return 0;
3037 }
3038 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3039 {
3040 list->Append(root);
3041 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003042 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3043 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003044 return 1;
3045 }
3046 }
3047 }
3048 else // we have a low and a high index
3049 {
3050 char *end = NULL;
3051 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3052 if (!end || end != separator_position) // if something weird is in our way return an error
3053 {
3054 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003055 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3056 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003057 return 0;
3058 }
3059 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3060 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3061 {
3062 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003063 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3064 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003065 return 0;
3066 }
3067 if (index_lower > index_higher) // swap indices if required
3068 {
3069 unsigned long temp = index_lower;
3070 index_lower = index_higher;
3071 index_higher = temp;
3072 }
3073 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
3074 {
3075 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3076 if (!root.get())
3077 {
3078 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003079 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3080 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003081 return 0;
3082 }
3083 else
3084 {
3085 list->Append(root);
3086 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003087 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3088 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003089 return 1;
3090 }
3091 }
3092 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 +00003093 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003094 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3095 {
3096 Error error;
3097 root = root->Dereference(error);
3098 if (error.Fail() || !root.get())
3099 {
3100 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003101 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3102 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003103 return 0;
3104 }
3105 else
3106 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003107 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003108 continue;
3109 }
3110 }
3111 else
3112 {
Johnny Chen44805302011-07-19 19:48:13 +00003113 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003114 index <= index_higher; index++)
3115 {
3116 ValueObjectSP child =
3117 root->GetChildAtIndex(index, true);
3118 list->Append(child);
3119 }
3120 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003121 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3122 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003123 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3124 }
3125 }
3126 break;
3127 }
3128 default: // some non-[ separator, or something entirely wrong, is in the way
3129 {
3130 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003131 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3132 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003133 return 0;
3134 break;
3135 }
3136 }
3137 }
3138}
3139
Enrico Granata0c489f52012-03-01 04:24:26 +00003140static void
3141DumpValueObject_Impl (Stream &s,
3142 ValueObject *valobj,
3143 const ValueObject::DumpValueObjectOptions& options,
3144 uint32_t ptr_depth,
3145 uint32_t curr_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003146{
Greg Clayton007d5be2011-05-30 00:49:24 +00003147 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003148 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003149 bool update_success = valobj->UpdateValueIfNeeded (options.m_use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00003150
Enrico Granata0c489f52012-03-01 04:24:26 +00003151 const char *root_valobj_name =
3152 options.m_root_valobj_name.empty() ?
3153 valobj->GetName().AsCString() :
3154 options.m_root_valobj_name.c_str();
3155
3156 if (update_success && options.m_use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00003157 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003158 ValueObject *dynamic_value = valobj->GetDynamicValue(options.m_use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003159 if (dynamic_value)
3160 valobj = dynamic_value;
3161 }
3162
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003163 clang_type_t clang_type = valobj->GetClangType();
3164
Greg Clayton73b472d2010-10-27 03:32:59 +00003165 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003166 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00003167 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
3168 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003169
Enrico Granata0c489f52012-03-01 04:24:26 +00003170 const bool print_valobj = options.m_flat_output == false || has_value;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003171
3172 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003173 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003174 if (options.m_show_location)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003175 {
Jim Ingham6035b672011-03-31 00:19:25 +00003176 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003177 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003178
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003179 s.Indent();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003180
Greg Clayton7c8a9662010-11-02 01:50:16 +00003181 // Always show the type for the top level items.
Enrico Granata0c489f52012-03-01 04:24:26 +00003182 if (options.m_show_types || (curr_depth == 0 && !options.m_flat_output))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003183 {
Greg Clayton84db9102012-03-26 23:03:23 +00003184 const char* typeName = valobj->GetQualifiedTypeName().AsCString("<invalid type>");
3185 //const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
Enrico Granata9910bc82011-08-03 02:18:51 +00003186 s.Printf("(%s", typeName);
3187 // only show dynamic types if the user really wants to see types
Enrico Granata0c489f52012-03-01 04:24:26 +00003188 if (options.m_show_types && options.m_use_dynamic != eNoDynamicValues &&
Enrico Granata9910bc82011-08-03 02:18:51 +00003189 (/*strstr(typeName, "id") == typeName ||*/
Greg Claytonafacd142011-09-02 01:15:17 +00003190 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003191 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003192 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3193 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatac3e320a2011-08-02 17:27:39 +00003194 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003195 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003196 else
3197 {
3198 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
3199 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003200 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003201 else
3202 {
3203 ObjCLanguageRuntime::ObjCISA isa = runtime->GetISA(*valobj);
3204 if (!runtime->IsValidISA(isa))
Enrico Granata9910bc82011-08-03 02:18:51 +00003205 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003206 else
3207 s.Printf(", dynamic type: %s) ",
3208 runtime->GetActualTypeName(isa).GetCString());
3209 }
3210 }
3211 }
3212 else
3213 s.Printf(") ");
3214 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003215
Greg Clayton1d3afba2010-10-05 00:00:42 +00003216
Enrico Granata0c489f52012-03-01 04:24:26 +00003217 if (options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003218 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003219 // If we are showing types, also qualify the C++ base classes
Enrico Granata0c489f52012-03-01 04:24:26 +00003220 const bool qualify_cxx_base_classes = options.m_show_types;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003221 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003222 s.PutCString(" =");
3223 }
3224 else
3225 {
3226 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3227 s.Printf ("%s =", name_cstr);
3228 }
3229
Enrico Granata0c489f52012-03-01 04:24:26 +00003230 if (!options.m_scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003231 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003232 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003233 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003234 }
3235
Enrico Granata0c489f52012-03-01 04:24:26 +00003236 std::string summary_str;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003237 std::string value_str;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003238 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003239 const char *sum_cstr = NULL;
Enrico Granata0c489f52012-03-01 04:24:26 +00003240 TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003241
Enrico Granata0c489f52012-03-01 04:24:26 +00003242 if (options.m_omit_summary_depth > 0)
Enrico Granata0c5ef692011-07-16 01:22:04 +00003243 entry = NULL;
3244
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003245 if (err_cstr == NULL)
3246 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003247 if (options.m_format != eFormatDefault && options.m_format != valobj->GetFormat())
Greg Clayton6efba4f2012-01-26 21:08:30 +00003248 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003249 valobj->GetValueAsCString(options.m_format,
3250 value_str);
Greg Clayton6efba4f2012-01-26 21:08:30 +00003251 }
Enrico Granata0c489f52012-03-01 04:24:26 +00003252 else
Greg Clayton6efba4f2012-01-26 21:08:30 +00003253 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003254 val_cstr = valobj->GetValueAsCString();
3255 if (val_cstr)
3256 value_str = val_cstr;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003257 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003258 err_cstr = valobj->GetError().AsCString();
3259 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003260
3261 if (err_cstr)
3262 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003263 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003264 }
3265 else
3266 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003267 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003268 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003269 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003270 if (options.m_omit_summary_depth == 0)
3271 {
3272 if (options.m_summary_sp)
3273 {
3274 valobj->GetSummaryAsCString(entry, summary_str);
3275 sum_cstr = summary_str.c_str();
3276 }
3277 else
3278 sum_cstr = valobj->GetSummaryAsCString();
3279 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003280
Greg Clayton6efba4f2012-01-26 21:08:30 +00003281 // Make sure we have a value and make sure the summary didn't
3282 // specify that the value should not be printed
3283 if (!value_str.empty() && (entry == NULL || entry->DoesPrintValue() || sum_cstr == NULL))
3284 s.Printf(" %s", value_str.c_str());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003285
Enrico Granata9dd75c82011-07-15 23:30:15 +00003286 if (sum_cstr)
Enrico Granata0c489f52012-03-01 04:24:26 +00003287 s.Printf(" %s", sum_cstr);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003288
Enrico Granata0c489f52012-03-01 04:24:26 +00003289 if (options.m_use_objc)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003290 {
Jim Ingham6035b672011-03-31 00:19:25 +00003291 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003292 if (object_desc)
3293 s.Printf(" %s\n", object_desc);
3294 else
Sean Callanan672ad942010-10-23 00:18:49 +00003295 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003296 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003297 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003298 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003299
Enrico Granata0c489f52012-03-01 04:24:26 +00003300 if (curr_depth < options.m_max_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003301 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003302 // We will show children for all concrete types. We won't show
3303 // pointer contents unless a pointer depth has been specified.
3304 // We won't reference contents unless the reference is the
3305 // root object (depth of zero).
3306 bool print_children = true;
3307
3308 // Use a new temporary pointer depth in case we override the
3309 // current pointer depth below...
3310 uint32_t curr_ptr_depth = ptr_depth;
3311
3312 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3313 if (is_ptr || is_ref)
3314 {
3315 // We have a pointer or reference whose value is an address.
3316 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003317 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003318 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003319 print_children = false;
3320
3321 else if (is_ref && curr_depth == 0)
3322 {
3323 // If this is the root object (depth is zero) that we are showing
3324 // and it is a reference, and no pointer depth has been supplied
3325 // print out what it references. Don't do this at deeper depths
3326 // otherwise we can end up with infinite recursion...
3327 curr_ptr_depth = 1;
3328 }
3329
3330 if (curr_ptr_depth == 0)
3331 print_children = false;
3332 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003333
Enrico Granata0a3958e2011-07-02 00:25:22 +00003334 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003335 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003336 ValueObject* synth_valobj;
3337 ValueObjectSP synth_valobj_sp = valobj->GetSyntheticValue (options.m_use_synthetic);
3338 synth_valobj = (synth_valobj_sp ? synth_valobj_sp.get() : valobj);
Enrico Granatac5bc4122012-03-27 02:35:13 +00003339
Enrico Granatac482a192011-08-17 22:13:59 +00003340 uint32_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003341 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003342 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003343 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003344 if (options.m_flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003345 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003346 if (print_valobj)
3347 s.EOL();
3348 }
3349 else
3350 {
3351 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003352 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003353 s.IndentMore();
3354 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003355
Greg Claytoncc4d0142012-02-17 07:49:44 +00003356 uint32_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00003357
Enrico Granata0c489f52012-03-01 04:24:26 +00003358 if (num_children > max_num_children && !options.m_ignore_cap)
Enrico Granata22c55d12011-08-12 02:00:06 +00003359 {
3360 num_children = max_num_children;
3361 print_dotdotdot = true;
3362 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003363
Enrico Granata0c489f52012-03-01 04:24:26 +00003364 ValueObject::DumpValueObjectOptions child_options(options);
3365 child_options.SetFormat().SetSummary().SetRootValueObjectName();
3366 child_options.SetScopeChecked(true)
3367 .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003368 for (uint32_t idx=0; idx<num_children; ++idx)
3369 {
Enrico Granatac482a192011-08-17 22:13:59 +00003370 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003371 if (child_sp.get())
3372 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003373 DumpValueObject_Impl (s,
3374 child_sp.get(),
3375 child_options,
3376 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
3377 curr_depth + 1);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003378 }
3379 }
3380
Enrico Granata0c489f52012-03-01 04:24:26 +00003381 if (!options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003382 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003383 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003384 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003385 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3386 Target *target = exe_ctx.GetTargetPtr();
3387 if (target)
3388 target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003389 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003390 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003391 s.IndentLess();
3392 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003393 }
3394 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003395 else if (has_children)
3396 {
3397 // Aggregate, no children...
3398 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003399 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003400 }
3401 else
3402 {
3403 if (print_valobj)
3404 s.EOL();
3405 }
3406
Greg Clayton1d3afba2010-10-05 00:00:42 +00003407 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003408 else
3409 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003410 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003411 }
3412 }
3413 else
3414 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003415 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003416 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003417 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003418 }
3419 }
3420 }
3421 }
3422}
3423
Enrico Granata0c489f52012-03-01 04:24:26 +00003424void
Greg Claytonf830dbb2012-03-22 18:15:37 +00003425ValueObject::LogValueObject (Log *log,
3426 ValueObject *valobj)
3427{
3428 if (log && valobj)
3429 return LogValueObject (log, valobj, DumpValueObjectOptions::DefaultOptions());
3430}
3431
3432void
3433ValueObject::LogValueObject (Log *log,
3434 ValueObject *valobj,
3435 const DumpValueObjectOptions& options)
3436{
3437 if (log && valobj)
3438 {
3439 StreamString s;
3440 ValueObject::DumpValueObject (s, valobj, options);
3441 if (s.GetSize())
3442 log->PutCString(s.GetData());
3443 }
3444}
3445
3446void
Enrico Granata0c489f52012-03-01 04:24:26 +00003447ValueObject::DumpValueObject (Stream &s,
3448 ValueObject *valobj)
3449{
3450
3451 if (!valobj)
3452 return;
3453
3454 DumpValueObject_Impl(s,
3455 valobj,
3456 DumpValueObjectOptions::DefaultOptions(),
3457 0,
3458 0);
3459}
3460
3461void
3462ValueObject::DumpValueObject (Stream &s,
3463 ValueObject *valobj,
3464 const DumpValueObjectOptions& options)
3465{
3466 DumpValueObject_Impl(s,
3467 valobj,
3468 options,
3469 options.m_max_ptr_depth, // max pointer depth allowed, we will go down from here
3470 0 // current object depth is 0 since we are just starting
3471 );
3472}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003473
3474ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003475ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003476{
3477 ValueObjectSP valobj_sp;
3478
Enrico Granatac3e320a2011-08-02 17:27:39 +00003479 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003480 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003481 ExecutionContext exe_ctx (GetExecutionContextRef());
3482 clang::ASTContext *ast = GetClangAST ();
3483
3484 DataExtractor data;
3485 data.SetByteOrder (m_data.GetByteOrder());
3486 data.SetAddressByteSize(m_data.GetAddressByteSize());
3487
Enrico Granata9f1e2042012-04-24 22:15:37 +00003488 if (IsBitfield())
3489 {
3490 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
3491 m_error = v.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
3492 }
3493 else
3494 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003495
3496 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3497 ast,
3498 GetClangType(),
3499 name,
3500 data,
3501 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003502 }
Jim Ingham6035b672011-03-31 00:19:25 +00003503
3504 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003505 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003506 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003507 }
3508 return valobj_sp;
3509}
3510
Greg Claytonafacd142011-09-02 01:15:17 +00003511ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003512ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003513{
Jim Ingham58b59f92011-04-22 23:53:53 +00003514 if (m_deref_valobj)
3515 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003516
Greg Clayton54979cd2010-12-15 05:08:08 +00003517 const bool is_pointer_type = IsPointerType();
3518 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003519 {
3520 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003521 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003522
3523 std::string child_name_str;
3524 uint32_t child_byte_size = 0;
3525 int32_t child_byte_offset = 0;
3526 uint32_t child_bitfield_bit_size = 0;
3527 uint32_t child_bitfield_bit_offset = 0;
3528 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003529 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003530 const bool transparent_pointers = false;
3531 clang::ASTContext *clang_ast = GetClangAST();
3532 clang_type_t clang_type = GetClangType();
3533 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003534
Greg Claytoncc4d0142012-02-17 07:49:44 +00003535 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003536
3537 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3538 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003539 GetName().GetCString(),
3540 clang_type,
3541 0,
3542 transparent_pointers,
3543 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003544 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003545 child_name_str,
3546 child_byte_size,
3547 child_byte_offset,
3548 child_bitfield_bit_size,
3549 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003550 child_is_base_class,
3551 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003552 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003553 {
3554 ConstString child_name;
3555 if (!child_name_str.empty())
3556 child_name.SetCString (child_name_str.c_str());
3557
Jim Ingham58b59f92011-04-22 23:53:53 +00003558 m_deref_valobj = new ValueObjectChild (*this,
3559 clang_ast,
3560 child_clang_type,
3561 child_name,
3562 child_byte_size,
3563 child_byte_offset,
3564 child_bitfield_bit_size,
3565 child_bitfield_bit_offset,
3566 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003567 child_is_deref_of_parent,
3568 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003569 }
3570 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003571
Jim Ingham58b59f92011-04-22 23:53:53 +00003572 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003573 {
3574 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003575 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003576 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003577 else
3578 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003579 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003580 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003581
3582 if (is_pointer_type)
3583 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3584 else
3585 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003586 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003587 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003588}
3589
Greg Claytonafacd142011-09-02 01:15:17 +00003590ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003591ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003592{
Jim Ingham78a685a2011-04-16 00:01:13 +00003593 if (m_addr_of_valobj_sp)
3594 return m_addr_of_valobj_sp;
3595
Greg Claytone0d378b2011-03-24 21:19:54 +00003596 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003597 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003598 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003599 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003600 if (addr != LLDB_INVALID_ADDRESS)
3601 {
3602 switch (address_type)
3603 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003604 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003605 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003606 {
3607 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003608 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003609 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3610 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003611 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003612
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003613 case eAddressTypeFile:
3614 case eAddressTypeLoad:
3615 case eAddressTypeHost:
3616 {
3617 clang::ASTContext *ast = GetClangAST();
3618 clang_type_t clang_type = GetClangType();
3619 if (ast && clang_type)
3620 {
3621 std::string name (1, '&');
3622 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003623 ExecutionContext exe_ctx (GetExecutionContextRef());
3624 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003625 ast,
3626 ClangASTContext::CreatePointerType (ast, clang_type),
3627 ConstString (name.c_str()),
3628 addr,
3629 eAddressTypeInvalid,
3630 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003631 }
3632 }
3633 break;
3634 }
3635 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003636 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003637}
3638
Greg Clayton9a142cf2012-02-03 05:34:10 +00003639ValueObjectSP
3640ValueObject::Cast (const ClangASTType &clang_ast_type)
3641{
Greg Clayton81e871e2012-02-04 02:27:34 +00003642 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003643}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003644
Greg Claytonafacd142011-09-02 01:15:17 +00003645ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003646ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3647{
Greg Claytonafacd142011-09-02 01:15:17 +00003648 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003649 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003650 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003651
3652 if (ptr_value != LLDB_INVALID_ADDRESS)
3653 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003654 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003655 ExecutionContext exe_ctx (GetExecutionContextRef());
3656 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003657 name,
3658 ptr_addr,
3659 clang_ast_type);
3660 }
3661 return valobj_sp;
3662}
3663
Greg Claytonafacd142011-09-02 01:15:17 +00003664ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003665ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3666{
Greg Claytonafacd142011-09-02 01:15:17 +00003667 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003668 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003669 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003670
3671 if (ptr_value != LLDB_INVALID_ADDRESS)
3672 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003673 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003674 ExecutionContext exe_ctx (GetExecutionContextRef());
3675 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003676 name,
3677 ptr_addr,
3678 type_sp);
3679 }
3680 return valobj_sp;
3681}
3682
Jim Ingham6035b672011-03-31 00:19:25 +00003683ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003684 m_mod_id(),
3685 m_exe_ctx_ref(),
3686 m_needs_update (true),
3687 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003688{
3689}
3690
3691ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003692 m_mod_id(),
3693 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003694 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003695 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003696{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003697 ExecutionContext exe_ctx(exe_scope);
3698 TargetSP target_sp (exe_ctx.GetTargetSP());
3699 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003700 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003701 m_exe_ctx_ref.SetTargetSP (target_sp);
3702 ProcessSP process_sp (exe_ctx.GetProcessSP());
3703 if (!process_sp)
3704 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003705
Greg Claytoncc4d0142012-02-17 07:49:44 +00003706 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003707 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003708 m_mod_id = process_sp->GetModID();
3709 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003710
Greg Claytoncc4d0142012-02-17 07:49:44 +00003711 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003712
Greg Claytoncc4d0142012-02-17 07:49:44 +00003713 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003714 {
3715 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003716 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003717 }
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 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003721 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003722
Greg Claytoncc4d0142012-02-17 07:49:44 +00003723 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3724 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003725 {
3726 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003727 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003728 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003729 if (frame_sp)
3730 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003731 }
3732 }
3733 }
Jim Ingham6035b672011-03-31 00:19:25 +00003734}
3735
3736ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003737 m_mod_id(),
3738 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3739 m_needs_update (true),
3740 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003741{
3742}
3743
3744ValueObject::EvaluationPoint::~EvaluationPoint ()
3745{
3746}
3747
Jim Ingham6035b672011-03-31 00:19:25 +00003748// This function checks the EvaluationPoint against the current process state. If the current
3749// state matches the evaluation point, or the evaluation point is already invalid, then we return
3750// false, meaning "no change". If the current state is different, we update our state, and return
3751// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3752// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003753// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003754
3755bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003756ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003757{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003758
3759 // 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 +00003760 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00003761
Greg Claytoncc4d0142012-02-17 07:49:44 +00003762 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003763 return false;
3764
Jim Ingham6035b672011-03-31 00:19:25 +00003765 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003766 Process *process = exe_ctx.GetProcessPtr();
3767 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003768 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003769
Jim Ingham6035b672011-03-31 00:19:25 +00003770 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003771 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003772
Jim Ingham78a685a2011-04-16 00:01:13 +00003773 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3774 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003775 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003776 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003777
3778 bool changed;
3779
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003780 if (m_mod_id.IsValid())
3781 {
3782 if (m_mod_id == current_mod_id)
3783 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003784 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003785 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003786 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003787 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003788 else
3789 {
3790 m_mod_id = current_mod_id;
3791 m_needs_update = true;
3792 changed = true;
3793 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003794 }
Jim Ingham6035b672011-03-31 00:19:25 +00003795
Jim Ingham73ca05a2011-12-17 01:35:57 +00003796 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3797 // That way we'll be sure to return a valid exe_scope.
3798 // 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 +00003799
Greg Claytoncc4d0142012-02-17 07:49:44 +00003800 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003801 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003802 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3803 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003804 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003805 if (m_exe_ctx_ref.HasFrameRef())
3806 {
3807 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3808 if (!frame_sp)
3809 {
3810 // We used to have a frame, but now it is gone
3811 SetInvalid();
3812 }
3813 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003814 }
Jim Ingham6035b672011-03-31 00:19:25 +00003815 else
3816 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003817 // We used to have a thread, but now it is gone
3818 SetInvalid();
Jim Ingham6035b672011-03-31 00:19:25 +00003819 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003820
Jim Ingham6035b672011-03-31 00:19:25 +00003821 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003822 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003823}
3824
Jim Ingham61be0902011-05-02 18:13:59 +00003825void
3826ValueObject::EvaluationPoint::SetUpdated ()
3827{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003828 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3829 if (process_sp)
3830 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003831 m_first_update = false;
3832 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003833}
3834
3835
Greg Claytoncc4d0142012-02-17 07:49:44 +00003836//bool
3837//ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3838//{
3839// if (!IsValid())
3840// return false;
3841//
3842// bool needs_update = false;
3843//
3844// // The target has to be non-null, and the
3845// Target *target = exe_scope->CalculateTarget();
3846// if (target != NULL)
3847// {
3848// Target *old_target = m_target_sp.get();
3849// assert (target == old_target);
3850// Process *process = exe_scope->CalculateProcess();
3851// if (process != NULL)
3852// {
3853// // FOR NOW - assume you can't update variable objects across process boundaries.
3854// Process *old_process = m_process_sp.get();
3855// assert (process == old_process);
3856// ProcessModID current_mod_id = process->GetModID();
3857// if (m_mod_id != current_mod_id)
3858// {
3859// needs_update = true;
3860// m_mod_id = current_mod_id;
3861// }
3862// // See if we're switching the thread or stack context. If no thread is given, this is
3863// // being evaluated in a global context.
3864// Thread *thread = exe_scope->CalculateThread();
3865// if (thread != NULL)
3866// {
3867// user_id_t new_thread_index = thread->GetIndexID();
3868// if (new_thread_index != m_thread_id)
3869// {
3870// needs_update = true;
3871// m_thread_id = new_thread_index;
3872// m_stack_id.Clear();
3873// }
3874//
3875// StackFrame *new_frame = exe_scope->CalculateStackFrame();
3876// if (new_frame != NULL)
3877// {
3878// if (new_frame->GetStackID() != m_stack_id)
3879// {
3880// needs_update = true;
3881// m_stack_id = new_frame->GetStackID();
3882// }
3883// }
3884// else
3885// {
3886// m_stack_id.Clear();
3887// needs_update = true;
3888// }
3889// }
3890// else
3891// {
3892// // If this had been given a thread, and now there is none, we should update.
3893// // Otherwise we don't have to do anything.
3894// if (m_thread_id != LLDB_INVALID_UID)
3895// {
3896// m_thread_id = LLDB_INVALID_UID;
3897// m_stack_id.Clear();
3898// needs_update = true;
3899// }
3900// }
3901// }
3902// else
3903// {
3904// // If there is no process, then we don't need to update anything.
3905// // But if we're switching from having a process to not, we should try to update.
3906// if (m_process_sp.get() != NULL)
3907// {
3908// needs_update = true;
3909// m_process_sp.reset();
3910// m_thread_id = LLDB_INVALID_UID;
3911// m_stack_id.Clear();
3912// }
3913// }
3914// }
3915// else
3916// {
3917// // If there's no target, nothing can change so we don't need to update anything.
3918// // But if we're switching from having a target to not, we should try to update.
3919// if (m_target_sp.get() != NULL)
3920// {
3921// needs_update = true;
3922// m_target_sp.reset();
3923// m_process_sp.reset();
3924// m_thread_id = LLDB_INVALID_UID;
3925// m_stack_id.Clear();
3926// }
3927// }
3928// if (!m_needs_update)
3929// m_needs_update = needs_update;
3930//
3931// return needs_update;
3932//}
Enrico Granataf2bbf712011-07-15 02:26:42 +00003933
3934void
Enrico Granata86cc9822012-03-19 22:58:49 +00003935ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00003936{
Enrico Granata86cc9822012-03-19 22:58:49 +00003937 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
3938 m_value_str.clear();
3939
3940 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
3941 m_location_str.clear();
3942
3943 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
3944 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003945 m_summary_str.clear();
3946 }
3947
3948 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
3949 m_object_desc_str.clear();
3950
3951 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
3952 {
3953 if (m_synthetic_value)
3954 m_synthetic_value = NULL;
3955 }
Johnny Chen44805302011-07-19 19:48:13 +00003956}
Enrico Granata9128ee22011-09-06 19:20:51 +00003957
3958SymbolContextScope *
3959ValueObject::GetSymbolContextScope()
3960{
3961 if (m_parent)
3962 {
3963 if (!m_parent->IsPointerOrReferenceType())
3964 return m_parent->GetSymbolContextScope();
3965 }
3966 return NULL;
3967}