blob: cd41f1d689fcb5fb672b05e4d19134040d13c09e [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
Enrico Granata07a4ac22012-05-08 21:25:06 +00001594ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001595{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001596 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001597 // Make sure our value is up to date first so that our location and location
1598 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001599 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001600 {
1601 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001602 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001603 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001604
1605 uint32_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001606 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001607
Greg Claytonb1320972010-07-14 00:18:15 +00001608 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001609
Jim Ingham16e0c682011-08-12 23:34:31 +00001610 Value::ValueType value_type = m_value.GetValueType();
1611
1612 if (value_type == Value::eValueTypeScalar)
1613 {
1614 // If the value is already a scalar, then let the scalar change itself:
1615 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1616 }
1617 else if (byte_size <= Scalar::GetMaxByteSize())
1618 {
1619 // If the value fits in a scalar, then make a new scalar and again let the
1620 // scalar code do the conversion, then figure out where to put the new value.
1621 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001622 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1623 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001624 {
Jim Ingham4b536182011-08-09 02:12:22 +00001625 switch (value_type)
1626 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001627 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001628 {
1629 // If it is a load address, then the scalar value is the storage location
1630 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001631 ExecutionContext exe_ctx (GetExecutionContextRef());
1632 Process *process = exe_ctx.GetProcessPtr();
1633 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001634 {
Greg Claytonafacd142011-09-02 01:15:17 +00001635 addr_t target_addr = m_value.GetScalar().GetRawBits64(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001636 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1637 new_scalar,
1638 byte_size,
1639 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001640 if (!error.Success())
1641 return false;
1642 if (bytes_written != byte_size)
1643 {
1644 error.SetErrorString("unable to write value to memory");
1645 return false;
1646 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001647 }
1648 }
Jim Ingham4b536182011-08-09 02:12:22 +00001649 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001650 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001651 {
1652 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1653 DataExtractor new_data;
1654 new_data.SetByteOrder (m_data.GetByteOrder());
1655
1656 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1657 m_data.SetData(buffer_sp, 0);
1658 bool success = new_scalar.GetData(new_data);
1659 if (success)
1660 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001661 new_data.CopyByteOrderedData (0,
1662 byte_size,
1663 const_cast<uint8_t *>(m_data.GetDataStart()),
1664 byte_size,
1665 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001666 }
1667 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1668
1669 }
Jim Ingham4b536182011-08-09 02:12:22 +00001670 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001671 case Value::eValueTypeFileAddress:
1672 case Value::eValueTypeScalar:
Jim Ingham16e0c682011-08-12 23:34:31 +00001673 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001674 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001675 }
1676 else
1677 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001678 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001679 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001680 }
1681 else
1682 {
1683 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001684 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001685 return false;
1686 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001687
1688 // If we have reached this point, then we have successfully changed the value.
1689 SetNeedsUpdate();
1690 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001691}
1692
Greg Clayton81e871e2012-02-04 02:27:34 +00001693bool
1694ValueObject::GetDeclaration (Declaration &decl)
1695{
1696 decl.Clear();
1697 return false;
1698}
1699
Greg Clayton84db9102012-03-26 23:03:23 +00001700ConstString
1701ValueObject::GetTypeName()
1702{
1703 return ClangASTType::GetConstTypeName (GetClangAST(), GetClangType());
1704}
1705
1706ConstString
1707ValueObject::GetQualifiedTypeName()
1708{
1709 return ClangASTType::GetConstQualifiedTypeName (GetClangAST(), GetClangType());
1710}
1711
1712
Greg Claytonafacd142011-09-02 01:15:17 +00001713LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001714ValueObject::GetObjectRuntimeLanguage ()
1715{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001716 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1717 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001718}
1719
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001720void
Jim Ingham58b59f92011-04-22 23:53:53 +00001721ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001722{
Jim Ingham58b59f92011-04-22 23:53:53 +00001723 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001724}
1725
1726ValueObjectSP
1727ValueObject::GetSyntheticChild (const ConstString &key) const
1728{
1729 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001730 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001731 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001732 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001733 return synthetic_child_sp;
1734}
1735
1736bool
1737ValueObject::IsPointerType ()
1738{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001739 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001740}
1741
Jim Inghamb7603bb2011-03-18 00:05:18 +00001742bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001743ValueObject::IsArrayType ()
1744{
1745 return ClangASTContext::IsArrayType (GetClangType());
1746}
1747
1748bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001749ValueObject::IsScalarType ()
1750{
1751 return ClangASTContext::IsScalarType (GetClangType());
1752}
1753
1754bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001755ValueObject::IsIntegerType (bool &is_signed)
1756{
1757 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1758}
Greg Clayton73b472d2010-10-27 03:32:59 +00001759
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001760bool
1761ValueObject::IsPointerOrReferenceType ()
1762{
Greg Clayton007d5be2011-05-30 00:49:24 +00001763 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1764}
1765
1766bool
1767ValueObject::IsPossibleCPlusPlusDynamicType ()
1768{
1769 return ClangASTContext::IsPossibleCPlusPlusDynamicType (GetClangAST (), GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001770}
1771
Greg Claytondea8cb42011-06-29 22:09:02 +00001772bool
1773ValueObject::IsPossibleDynamicType ()
1774{
1775 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType());
1776}
1777
Greg Claytonafacd142011-09-02 01:15:17 +00001778ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001779ValueObject::GetSyntheticArrayMember (int32_t index, bool can_create)
1780{
1781 if (IsArrayType())
1782 return GetSyntheticArrayMemberFromArray(index, can_create);
1783
1784 if (IsPointerType())
1785 return GetSyntheticArrayMemberFromPointer(index, can_create);
1786
1787 return ValueObjectSP();
1788
1789}
1790
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001791ValueObjectSP
1792ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1793{
1794 ValueObjectSP synthetic_child_sp;
1795 if (IsPointerType ())
1796 {
1797 char index_str[64];
1798 snprintf(index_str, sizeof(index_str), "[%i]", index);
1799 ConstString index_const_str(index_str);
1800 // Check if we have already created a synthetic array member in this
1801 // valid object. If we have we will re-use it.
1802 synthetic_child_sp = GetSyntheticChild (index_const_str);
1803 if (!synthetic_child_sp)
1804 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001805 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001806 // We haven't made a synthetic array member for INDEX yet, so
1807 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001808 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001809
1810 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001811 if (synthetic_child)
1812 {
1813 AddSyntheticChild(index_const_str, synthetic_child);
1814 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001815 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001816 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001817 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001818 }
1819 }
1820 return synthetic_child_sp;
1821}
Jim Ingham22777012010-09-23 02:01:19 +00001822
Greg Claytondaf515f2011-07-09 20:12:33 +00001823// This allows you to create an array member using and index
1824// that doesn't not fall in the normal bounds of the array.
1825// Many times structure can be defined as:
1826// struct Collection
1827// {
1828// uint32_t item_count;
1829// Item item_array[0];
1830// };
1831// The size of the "item_array" is 1, but many times in practice
1832// there are more items in "item_array".
1833
1834ValueObjectSP
1835ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1836{
1837 ValueObjectSP synthetic_child_sp;
1838 if (IsArrayType ())
1839 {
1840 char index_str[64];
1841 snprintf(index_str, sizeof(index_str), "[%i]", index);
1842 ConstString index_const_str(index_str);
1843 // Check if we have already created a synthetic array member in this
1844 // valid object. If we have we will re-use it.
1845 synthetic_child_sp = GetSyntheticChild (index_const_str);
1846 if (!synthetic_child_sp)
1847 {
1848 ValueObject *synthetic_child;
1849 // We haven't made a synthetic array member for INDEX yet, so
1850 // lets make one and cache it for any future reference.
1851 synthetic_child = CreateChildAtIndex(0, true, index);
1852
1853 // Cache the value if we got one back...
1854 if (synthetic_child)
1855 {
1856 AddSyntheticChild(index_const_str, synthetic_child);
1857 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001858 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001859 synthetic_child_sp->m_is_array_item_for_pointer = true;
1860 }
1861 }
1862 }
1863 return synthetic_child_sp;
1864}
1865
Enrico Granata9fc19442011-07-06 02:13:41 +00001866ValueObjectSP
1867ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1868{
1869 ValueObjectSP synthetic_child_sp;
1870 if (IsScalarType ())
1871 {
1872 char index_str[64];
1873 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1874 ConstString index_const_str(index_str);
1875 // Check if we have already created a synthetic array member in this
1876 // valid object. If we have we will re-use it.
1877 synthetic_child_sp = GetSyntheticChild (index_const_str);
1878 if (!synthetic_child_sp)
1879 {
1880 ValueObjectChild *synthetic_child;
1881 // We haven't made a synthetic array member for INDEX yet, so
1882 // lets make one and cache it for any future reference.
1883 synthetic_child = new ValueObjectChild(*this,
1884 GetClangAST(),
1885 GetClangType(),
1886 index_const_str,
1887 GetByteSize(),
1888 0,
1889 to-from+1,
1890 from,
1891 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001892 false,
1893 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00001894
1895 // Cache the value if we got one back...
1896 if (synthetic_child)
1897 {
1898 AddSyntheticChild(index_const_str, synthetic_child);
1899 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001900 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00001901 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1902 }
1903 }
1904 }
1905 return synthetic_child_sp;
1906}
1907
Greg Claytonafacd142011-09-02 01:15:17 +00001908ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001909ValueObject::GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create)
1910{
1911 ValueObjectSP synthetic_child_sp;
1912 if (IsArrayType () || IsPointerType ())
1913 {
1914 char index_str[64];
1915 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1916 ConstString index_const_str(index_str);
1917 // Check if we have already created a synthetic array member in this
1918 // valid object. If we have we will re-use it.
1919 synthetic_child_sp = GetSyntheticChild (index_const_str);
1920 if (!synthetic_child_sp)
1921 {
1922 ValueObjectSynthetic *synthetic_child;
1923
1924 // We haven't made a synthetic array member for INDEX yet, so
1925 // lets make one and cache it for any future reference.
Enrico Granata061858c2012-02-15 02:34:21 +00001926 SyntheticArrayView *view = new SyntheticArrayView(SyntheticChildren::Flags());
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001927 view->AddRange(from,to);
1928 SyntheticChildrenSP view_sp(view);
1929 synthetic_child = new ValueObjectSynthetic(*this, view_sp);
1930
1931 // Cache the value if we got one back...
1932 if (synthetic_child)
1933 {
1934 AddSyntheticChild(index_const_str, synthetic_child);
1935 synthetic_child_sp = synthetic_child->GetSP();
1936 synthetic_child_sp->SetName(ConstString(index_str));
1937 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1938 }
1939 }
1940 }
1941 return synthetic_child_sp;
1942}
1943
Greg Claytonafacd142011-09-02 01:15:17 +00001944ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00001945ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
1946{
1947
1948 ValueObjectSP synthetic_child_sp;
1949
1950 char name_str[64];
1951 snprintf(name_str, sizeof(name_str), "@%i", offset);
1952 ConstString name_const_str(name_str);
1953
1954 // Check if we have already created a synthetic array member in this
1955 // valid object. If we have we will re-use it.
1956 synthetic_child_sp = GetSyntheticChild (name_const_str);
1957
1958 if (synthetic_child_sp.get())
1959 return synthetic_child_sp;
1960
1961 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00001962 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001963
1964 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
1965 type.GetASTContext(),
1966 type.GetOpaqueQualType(),
1967 name_const_str,
1968 type.GetTypeByteSize(),
1969 offset,
1970 0,
1971 0,
1972 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001973 false,
1974 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001975 if (synthetic_child)
1976 {
1977 AddSyntheticChild(name_const_str, synthetic_child);
1978 synthetic_child_sp = synthetic_child->GetSP();
1979 synthetic_child_sp->SetName(name_const_str);
1980 synthetic_child_sp->m_is_child_at_offset = true;
1981 }
1982 return synthetic_child_sp;
1983}
1984
Enrico Granatad55546b2011-07-22 00:16:08 +00001985// your expression path needs to have a leading . or ->
1986// (unless it somehow "looks like" an array, in which case it has
1987// a leading [ symbol). while the [ is meaningful and should be shown
1988// to the user, . and -> are just parser design, but by no means
1989// added information for the user.. strip them off
1990static const char*
1991SkipLeadingExpressionPathSeparators(const char* expression)
1992{
1993 if (!expression || !expression[0])
1994 return expression;
1995 if (expression[0] == '.')
1996 return expression+1;
1997 if (expression[0] == '-' && expression[1] == '>')
1998 return expression+2;
1999 return expression;
2000}
2001
Greg Claytonafacd142011-09-02 01:15:17 +00002002ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002003ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2004{
2005 ValueObjectSP synthetic_child_sp;
2006 ConstString name_const_string(expression);
2007 // Check if we have already created a synthetic array member in this
2008 // valid object. If we have we will re-use it.
2009 synthetic_child_sp = GetSyntheticChild (name_const_string);
2010 if (!synthetic_child_sp)
2011 {
2012 // We haven't made a synthetic array member for expression yet, so
2013 // lets make one and cache it for any future reference.
2014 synthetic_child_sp = GetValueForExpressionPath(expression);
2015
2016 // Cache the value if we got one back...
2017 if (synthetic_child_sp.get())
2018 {
2019 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002020 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002021 synthetic_child_sp->m_is_expression_path_child = true;
2022 }
2023 }
2024 return synthetic_child_sp;
2025}
2026
2027void
Enrico Granata86cc9822012-03-19 22:58:49 +00002028ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002029{
Enrico Granata86cc9822012-03-19 22:58:49 +00002030 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002031 return;
2032
Enrico Granatac5bc4122012-03-27 02:35:13 +00002033 TargetSP target_sp(GetTargetSP());
2034 if (target_sp && (target_sp->GetEnableSyntheticValue() == false || target_sp->GetSuppressSyntheticValue() == true))
2035 {
2036 m_synthetic_value = NULL;
2037 return;
2038 }
2039
Enrico Granata86cc9822012-03-19 22:58:49 +00002040 if (!UpdateFormatsIfNeeded(m_last_format_mgr_dynamic) && m_synthetic_value)
2041 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002042
Enrico Granata0c489f52012-03-01 04:24:26 +00002043 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002044 return;
2045
Enrico Granata86cc9822012-03-19 22:58:49 +00002046 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002047}
2048
Jim Ingham78a685a2011-04-16 00:01:13 +00002049void
Greg Claytonafacd142011-09-02 01:15:17 +00002050ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002051{
Greg Claytonafacd142011-09-02 01:15:17 +00002052 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002053 return;
2054
Jim Ingham58b59f92011-04-22 23:53:53 +00002055 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002056 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002057 ExecutionContext exe_ctx (GetExecutionContextRef());
2058 Process *process = exe_ctx.GetProcessPtr();
2059 if (process)
Jim Ingham78a685a2011-04-16 00:01:13 +00002060 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002061 bool worth_having_dynamic_value = false;
Jim Ingham78a685a2011-04-16 00:01:13 +00002062
Greg Claytoncc4d0142012-02-17 07:49:44 +00002063
2064 // FIXME: Process should have some kind of "map over Runtimes" so we don't have to
2065 // hard code this everywhere.
2066 LanguageType known_type = GetObjectRuntimeLanguage();
2067 if (known_type != eLanguageTypeUnknown && known_type != eLanguageTypeC)
Jim Ingham78a685a2011-04-16 00:01:13 +00002068 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002069 LanguageRuntime *runtime = process->GetLanguageRuntime (known_type);
2070 if (runtime)
2071 worth_having_dynamic_value = runtime->CouldHaveDynamicValue(*this);
Jim Ingham78a685a2011-04-16 00:01:13 +00002072 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00002073 else
2074 {
2075 LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (eLanguageTypeC_plus_plus);
2076 if (cpp_runtime)
2077 worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this);
2078
2079 if (!worth_having_dynamic_value)
2080 {
2081 LanguageRuntime *objc_runtime = process->GetLanguageRuntime (eLanguageTypeObjC);
2082 if (objc_runtime)
2083 worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this);
2084 }
2085 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002086
Greg Claytoncc4d0142012-02-17 07:49:44 +00002087 if (worth_having_dynamic_value)
2088 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
2089 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002090 }
2091}
2092
Jim Ingham58b59f92011-04-22 23:53:53 +00002093ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002094ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002095{
Greg Claytonafacd142011-09-02 01:15:17 +00002096 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002097 return ValueObjectSP();
2098
2099 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002100 {
Jim Ingham2837b762011-05-04 03:43:18 +00002101 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002102 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002103 if (m_dynamic_value)
2104 return m_dynamic_value->GetSP();
2105 else
2106 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002107}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002108
Jim Ingham60dbabb2011-12-08 19:44:08 +00002109ValueObjectSP
2110ValueObject::GetStaticValue()
2111{
2112 return GetSP();
2113}
2114
Enrico Granata886147f2012-05-08 18:47:08 +00002115lldb::ValueObjectSP
2116ValueObject::GetNonSyntheticValue ()
2117{
2118 return GetSP();
2119}
2120
Enrico Granatad55546b2011-07-22 00:16:08 +00002121ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002122ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002123{
Enrico Granata86cc9822012-03-19 22:58:49 +00002124 if (use_synthetic == false)
2125 return ValueObjectSP();
2126
Enrico Granatad55546b2011-07-22 00:16:08 +00002127 CalculateSyntheticValue(use_synthetic);
2128
2129 if (m_synthetic_value)
2130 return m_synthetic_value->GetSP();
2131 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002132 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002133}
2134
Greg Claytone221f822011-01-21 01:59:00 +00002135bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002136ValueObject::HasSyntheticValue()
2137{
2138 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
2139
Enrico Granata0c489f52012-03-01 04:24:26 +00002140 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002141 return false;
2142
Enrico Granata86cc9822012-03-19 22:58:49 +00002143 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002144
2145 if (m_synthetic_value)
2146 return true;
2147 else
2148 return false;
2149}
2150
2151bool
Greg Claytone221f822011-01-21 01:59:00 +00002152ValueObject::GetBaseClassPath (Stream &s)
2153{
2154 if (IsBaseClass())
2155 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002156 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00002157 clang_type_t clang_type = GetClangType();
2158 std::string cxx_class_name;
2159 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
2160 if (this_had_base_class)
2161 {
2162 if (parent_had_base_class)
2163 s.PutCString("::");
2164 s.PutCString(cxx_class_name.c_str());
2165 }
2166 return parent_had_base_class || this_had_base_class;
2167 }
2168 return false;
2169}
2170
2171
2172ValueObject *
2173ValueObject::GetNonBaseClassParent()
2174{
Jim Ingham78a685a2011-04-16 00:01:13 +00002175 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002176 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002177 if (GetParent()->IsBaseClass())
2178 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002179 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002180 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002181 }
2182 return NULL;
2183}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002184
2185void
Enrico Granata4becb372011-06-29 22:27:15 +00002186ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002187{
Greg Claytone221f822011-01-21 01:59:00 +00002188 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002189
Enrico Granata86cc9822012-03-19 22:58:49 +00002190 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002191 {
Enrico Granata4becb372011-06-29 22:27:15 +00002192 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2193 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2194 // the eHonorPointers mode is meant to produce strings in this latter format
2195 s.PutCString("*(");
2196 }
Greg Claytone221f822011-01-21 01:59:00 +00002197
Enrico Granata4becb372011-06-29 22:27:15 +00002198 ValueObject* parent = GetParent();
2199
2200 if (parent)
2201 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002202
2203 // if we are a deref_of_parent just because we are synthetic array
2204 // members made up to allow ptr[%d] syntax to work in variable
2205 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002206 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002207 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002208
Greg Claytone221f822011-01-21 01:59:00 +00002209 if (!IsBaseClass())
2210 {
2211 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002212 {
Greg Claytone221f822011-01-21 01:59:00 +00002213 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2214 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002215 {
Greg Claytone221f822011-01-21 01:59:00 +00002216 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2217 if (non_base_class_parent_clang_type)
2218 {
2219 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2220
Enrico Granata86cc9822012-03-19 22:58:49 +00002221 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002222 {
2223 s.PutCString("->");
2224 }
Enrico Granata4becb372011-06-29 22:27:15 +00002225 else
2226 {
2227 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2228 {
2229 s.PutCString("->");
2230 }
2231 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2232 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2233 {
2234 s.PutChar('.');
2235 }
Greg Claytone221f822011-01-21 01:59:00 +00002236 }
2237 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002238 }
Greg Claytone221f822011-01-21 01:59:00 +00002239
2240 const char *name = GetName().GetCString();
2241 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002242 {
Greg Claytone221f822011-01-21 01:59:00 +00002243 if (qualify_cxx_base_classes)
2244 {
2245 if (GetBaseClassPath (s))
2246 s.PutCString("::");
2247 }
2248 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002249 }
2250 }
2251 }
2252
Enrico Granata86cc9822012-03-19 22:58:49 +00002253 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002254 {
Greg Claytone221f822011-01-21 01:59:00 +00002255 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002256 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002257}
2258
Greg Claytonafacd142011-09-02 01:15:17 +00002259ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002260ValueObject::GetValueForExpressionPath(const char* expression,
2261 const char** first_unparsed,
2262 ExpressionPathScanEndReason* reason_to_stop,
2263 ExpressionPathEndResultType* final_value_type,
2264 const GetValueForExpressionPathOptions& options,
2265 ExpressionPathAftermath* final_task_on_target)
2266{
2267
2268 const char* dummy_first_unparsed;
2269 ExpressionPathScanEndReason dummy_reason_to_stop;
2270 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002271 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002272
2273 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2274 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2275 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2276 final_value_type ? final_value_type : &dummy_final_value_type,
2277 options,
2278 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2279
Enrico Granata86cc9822012-03-19 22:58:49 +00002280 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002281 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002282
Enrico Granata86cc9822012-03-19 22:58:49 +00002283 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 +00002284 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002285 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002286 {
2287 Error error;
2288 ValueObjectSP final_value = ret_val->Dereference(error);
2289 if (error.Fail() || !final_value.get())
2290 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002291 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002292 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002293 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002294 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002295 return ValueObjectSP();
2296 }
2297 else
2298 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002299 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002300 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002301 return final_value;
2302 }
2303 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002304 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002305 {
2306 Error error;
2307 ValueObjectSP final_value = ret_val->AddressOf(error);
2308 if (error.Fail() || !final_value.get())
2309 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002310 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002311 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002312 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002313 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002314 return ValueObjectSP();
2315 }
2316 else
2317 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002318 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002319 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002320 return final_value;
2321 }
2322 }
2323 }
2324 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2325}
2326
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002327int
2328ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002329 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002330 const char** first_unparsed,
2331 ExpressionPathScanEndReason* reason_to_stop,
2332 ExpressionPathEndResultType* final_value_type,
2333 const GetValueForExpressionPathOptions& options,
2334 ExpressionPathAftermath* final_task_on_target)
2335{
2336 const char* dummy_first_unparsed;
2337 ExpressionPathScanEndReason dummy_reason_to_stop;
2338 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002339 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002340
2341 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2342 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2343 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2344 final_value_type ? final_value_type : &dummy_final_value_type,
2345 options,
2346 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2347
2348 if (!ret_val.get()) // if there are errors, I add nothing to the list
2349 return 0;
2350
Enrico Granata86ea8d82012-03-29 01:34:34 +00002351 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002352 {
2353 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002354 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002355 {
2356 list->Append(ret_val);
2357 return 1;
2358 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002359 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 +00002360 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002361 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002362 {
2363 Error error;
2364 ValueObjectSP final_value = ret_val->Dereference(error);
2365 if (error.Fail() || !final_value.get())
2366 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002367 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2368 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002369 return 0;
2370 }
2371 else
2372 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002373 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002374 list->Append(final_value);
2375 return 1;
2376 }
2377 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002378 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002379 {
2380 Error error;
2381 ValueObjectSP final_value = ret_val->AddressOf(error);
2382 if (error.Fail() || !final_value.get())
2383 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002384 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2385 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002386 return 0;
2387 }
2388 else
2389 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002390 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002391 list->Append(final_value);
2392 return 1;
2393 }
2394 }
2395 }
2396 }
2397 else
2398 {
2399 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2400 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2401 ret_val,
2402 list,
2403 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2404 final_value_type ? final_value_type : &dummy_final_value_type,
2405 options,
2406 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2407 }
2408 // in any non-covered case, just do the obviously right thing
2409 list->Append(ret_val);
2410 return 1;
2411}
2412
Greg Claytonafacd142011-09-02 01:15:17 +00002413ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002414ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2415 const char** first_unparsed,
2416 ExpressionPathScanEndReason* reason_to_stop,
2417 ExpressionPathEndResultType* final_result,
2418 const GetValueForExpressionPathOptions& options,
2419 ExpressionPathAftermath* what_next)
2420{
2421 ValueObjectSP root = GetSP();
2422
2423 if (!root.get())
2424 return ValueObjectSP();
2425
2426 *first_unparsed = expression_cstr;
2427
2428 while (true)
2429 {
2430
2431 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2432
Greg Claytonafacd142011-09-02 01:15:17 +00002433 clang_type_t root_clang_type = root->GetClangType();
2434 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002435 Flags root_clang_type_info,pointee_clang_type_info;
2436
2437 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2438 if (pointee_clang_type)
2439 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002440
2441 if (!expression_cstr || *expression_cstr == '\0')
2442 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002443 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002444 return root;
2445 }
2446
2447 switch (*expression_cstr)
2448 {
2449 case '-':
2450 {
2451 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002452 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 +00002453 {
2454 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002455 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2456 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002457 return ValueObjectSP();
2458 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002459 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2460 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002461 options.m_no_fragile_ivar)
2462 {
2463 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002464 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2465 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002466 return ValueObjectSP();
2467 }
2468 if (expression_cstr[1] != '>')
2469 {
2470 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002471 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2472 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002473 return ValueObjectSP();
2474 }
2475 expression_cstr++; // skip the -
2476 }
2477 case '.': // or fallthrough from ->
2478 {
2479 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002480 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 +00002481 {
2482 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002483 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2484 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002485 return ValueObjectSP();
2486 }
2487 expression_cstr++; // skip .
2488 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2489 ConstString child_name;
2490 if (!next_separator) // if no other separator just expand this last layer
2491 {
2492 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002493 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2494
2495 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002496 {
2497 *first_unparsed = '\0';
Enrico Granata86cc9822012-03-19 22:58:49 +00002498 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2499 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002500 return child_valobj_sp;
2501 }
2502 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2503 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002504 if (root->IsSynthetic())
2505 child_valobj_sp = root;
2506 else
2507 child_valobj_sp = root->GetSyntheticValue();
2508
2509 if (child_valobj_sp.get())
2510 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002511 }
2512
2513 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2514 // so we hit the "else" branch, and return an error
2515 if(child_valobj_sp.get()) // if it worked, just return
2516 {
2517 *first_unparsed = '\0';
Enrico Granata86cc9822012-03-19 22:58:49 +00002518 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2519 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002520 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002521 }
2522 else
2523 {
2524 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002525 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2526 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002527 return ValueObjectSP();
2528 }
2529 }
2530 else // other layers do expand
2531 {
2532 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002533 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2534 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002535 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002536 root = child_valobj_sp;
2537 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002538 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002539 continue;
2540 }
2541 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2542 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002543 child_valobj_sp = root->GetSyntheticValue(true);
2544 if (child_valobj_sp)
2545 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002546 }
2547
2548 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2549 // so we hit the "else" branch, and return an error
2550 if(child_valobj_sp.get()) // if it worked, move on
2551 {
2552 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002553 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002554 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002555 continue;
2556 }
2557 else
2558 {
2559 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002560 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2561 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002562 return ValueObjectSP();
2563 }
2564 }
2565 break;
2566 }
2567 case '[':
2568 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002569 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 +00002570 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002571 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002572 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002573 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2574 {
2575 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002576 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2577 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002578 return ValueObjectSP();
2579 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002580 }
2581 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2582 {
2583 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002584 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2585 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002586 return ValueObjectSP();
2587 }
2588 }
2589 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2590 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002591 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002592 {
2593 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002594 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2595 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002596 return ValueObjectSP();
2597 }
2598 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2599 {
2600 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002601 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2602 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002603 return root;
2604 }
2605 }
2606 const char *separator_position = ::strchr(expression_cstr+1,'-');
2607 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2608 if (!close_bracket_position) // if there is no ], this is a syntax error
2609 {
2610 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002611 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2612 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002613 return ValueObjectSP();
2614 }
2615 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2616 {
2617 char *end = NULL;
2618 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2619 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2620 {
2621 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002622 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2623 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002624 return ValueObjectSP();
2625 }
2626 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2627 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002628 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002629 {
2630 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002631 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2632 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002633 return root;
2634 }
2635 else
2636 {
2637 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002638 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2639 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002640 return ValueObjectSP();
2641 }
2642 }
2643 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002644 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002645 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002646 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2647 if (!child_valobj_sp)
2648 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002649 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002650 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2651 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002652 if (child_valobj_sp)
2653 {
2654 root = child_valobj_sp;
2655 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002656 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002657 continue;
2658 }
2659 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002660 {
2661 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002662 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2663 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002664 return ValueObjectSP();
2665 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002666 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002667 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002668 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002669 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 +00002670 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002671 {
2672 Error error;
2673 root = root->Dereference(error);
2674 if (error.Fail() || !root.get())
2675 {
2676 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002677 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2678 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002679 return ValueObjectSP();
2680 }
2681 else
2682 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002683 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002684 continue;
2685 }
2686 }
2687 else
2688 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002689 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Clayton84db9102012-03-26 23:03:23 +00002690 root->GetClangType()) == eLanguageTypeObjC
2691 && ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2692 && root->HasSyntheticValue()
2693 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002694 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002695 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002696 }
2697 else
2698 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002699 if (!root.get())
2700 {
2701 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002702 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2703 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002704 return ValueObjectSP();
2705 }
2706 else
2707 {
2708 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002709 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002710 continue;
2711 }
2712 }
2713 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002714 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002715 {
2716 root = root->GetSyntheticBitFieldChild(index, index, true);
2717 if (!root.get())
2718 {
2719 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002720 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2721 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002722 return ValueObjectSP();
2723 }
2724 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2725 {
2726 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002727 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2728 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002729 return root;
2730 }
2731 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002732 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002733 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002734 if (root->HasSyntheticValue())
2735 root = root->GetSyntheticValue();
2736 else if (!root->IsSynthetic())
2737 {
2738 *first_unparsed = expression_cstr;
2739 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2740 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2741 return ValueObjectSP();
2742 }
2743 // if we are here, then root itself is a synthetic VO.. should be good to go
2744
Enrico Granata27b625e2011-08-09 01:04:56 +00002745 if (!root.get())
2746 {
2747 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002748 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2749 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2750 return ValueObjectSP();
2751 }
2752 root = root->GetChildAtIndex(index, true);
2753 if (!root.get())
2754 {
2755 *first_unparsed = expression_cstr;
2756 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2757 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002758 return ValueObjectSP();
2759 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002760 else
2761 {
2762 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002763 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002764 continue;
2765 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002766 }
2767 else
2768 {
2769 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002770 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2771 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002772 return ValueObjectSP();
2773 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002774 }
2775 else // we have a low and a high index
2776 {
2777 char *end = NULL;
2778 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2779 if (!end || end != separator_position) // if something weird is in our way return an error
2780 {
2781 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002782 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2783 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002784 return ValueObjectSP();
2785 }
2786 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2787 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2788 {
2789 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002790 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2791 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002792 return ValueObjectSP();
2793 }
2794 if (index_lower > index_higher) // swap indices if required
2795 {
2796 unsigned long temp = index_lower;
2797 index_lower = index_higher;
2798 index_higher = temp;
2799 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002800 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002801 {
2802 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2803 if (!root.get())
2804 {
2805 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002806 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2807 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002808 return ValueObjectSP();
2809 }
2810 else
2811 {
2812 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002813 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2814 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002815 return root;
2816 }
2817 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002818 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 +00002819 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002820 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002821 {
2822 Error error;
2823 root = root->Dereference(error);
2824 if (error.Fail() || !root.get())
2825 {
2826 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002827 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2828 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002829 return ValueObjectSP();
2830 }
2831 else
2832 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002833 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002834 continue;
2835 }
2836 }
2837 else
2838 {
2839 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002840 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2841 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002842 return root;
2843 }
2844 }
2845 break;
2846 }
2847 default: // some non-separator is in the way
2848 {
2849 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002850 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2851 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002852 return ValueObjectSP();
2853 break;
2854 }
2855 }
2856 }
2857}
2858
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002859int
2860ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2861 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002862 ValueObjectSP root,
2863 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002864 ExpressionPathScanEndReason* reason_to_stop,
2865 ExpressionPathEndResultType* final_result,
2866 const GetValueForExpressionPathOptions& options,
2867 ExpressionPathAftermath* what_next)
2868{
2869 if (!root.get())
2870 return 0;
2871
2872 *first_unparsed = expression_cstr;
2873
2874 while (true)
2875 {
2876
2877 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2878
Greg Claytonafacd142011-09-02 01:15:17 +00002879 clang_type_t root_clang_type = root->GetClangType();
2880 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002881 Flags root_clang_type_info,pointee_clang_type_info;
2882
2883 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2884 if (pointee_clang_type)
2885 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2886
2887 if (!expression_cstr || *expression_cstr == '\0')
2888 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002889 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002890 list->Append(root);
2891 return 1;
2892 }
2893
2894 switch (*expression_cstr)
2895 {
2896 case '[':
2897 {
2898 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2899 {
2900 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2901 {
2902 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002903 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2904 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002905 return 0;
2906 }
2907 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2908 {
2909 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002910 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2911 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002912 return 0;
2913 }
2914 }
2915 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2916 {
2917 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2918 {
2919 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002920 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2921 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002922 return 0;
2923 }
2924 else // expand this into list
2925 {
2926 int max_index = root->GetNumChildren() - 1;
2927 for (int index = 0; index < max_index; index++)
2928 {
2929 ValueObjectSP child =
2930 root->GetChildAtIndex(index, true);
2931 list->Append(child);
2932 }
2933 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002934 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
2935 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002936 return max_index; // tell me number of items I added to the VOList
2937 }
2938 }
2939 const char *separator_position = ::strchr(expression_cstr+1,'-');
2940 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2941 if (!close_bracket_position) // if there is no ], this is a syntax error
2942 {
2943 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002944 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2945 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002946 return 0;
2947 }
2948 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2949 {
2950 char *end = NULL;
2951 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2952 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2953 {
2954 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002955 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2956 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002957 return 0;
2958 }
2959 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2960 {
2961 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2962 {
2963 int max_index = root->GetNumChildren() - 1;
2964 for (int index = 0; index < max_index; index++)
2965 {
2966 ValueObjectSP child =
2967 root->GetChildAtIndex(index, true);
2968 list->Append(child);
2969 }
2970 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002971 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
2972 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002973 return max_index; // tell me number of items I added to the VOList
2974 }
2975 else
2976 {
2977 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002978 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2979 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002980 return 0;
2981 }
2982 }
2983 // from here on we do have a valid index
2984 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2985 {
2986 root = root->GetChildAtIndex(index, true);
2987 if (!root.get())
2988 {
2989 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002990 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2991 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002992 return 0;
2993 }
2994 else
2995 {
2996 list->Append(root);
2997 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002998 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
2999 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003000 return 1;
3001 }
3002 }
3003 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
3004 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003005 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 +00003006 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3007 {
3008 Error error;
3009 root = root->Dereference(error);
3010 if (error.Fail() || !root.get())
3011 {
3012 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003013 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3014 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003015 return 0;
3016 }
3017 else
3018 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003019 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003020 continue;
3021 }
3022 }
3023 else
3024 {
3025 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3026 if (!root.get())
3027 {
3028 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003029 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3030 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003031 return 0;
3032 }
3033 else
3034 {
3035 list->Append(root);
3036 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003037 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3038 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003039 return 1;
3040 }
3041 }
3042 }
3043 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3044 {
3045 root = root->GetSyntheticBitFieldChild(index, index, true);
3046 if (!root.get())
3047 {
3048 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003049 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3050 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003051 return 0;
3052 }
3053 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3054 {
3055 list->Append(root);
3056 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003057 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3058 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003059 return 1;
3060 }
3061 }
3062 }
3063 else // we have a low and a high index
3064 {
3065 char *end = NULL;
3066 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3067 if (!end || end != separator_position) // if something weird is in our way return an error
3068 {
3069 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003070 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3071 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003072 return 0;
3073 }
3074 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3075 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3076 {
3077 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003078 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3079 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003080 return 0;
3081 }
3082 if (index_lower > index_higher) // swap indices if required
3083 {
3084 unsigned long temp = index_lower;
3085 index_lower = index_higher;
3086 index_higher = temp;
3087 }
3088 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
3089 {
3090 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3091 if (!root.get())
3092 {
3093 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003094 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3095 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003096 return 0;
3097 }
3098 else
3099 {
3100 list->Append(root);
3101 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003102 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3103 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003104 return 1;
3105 }
3106 }
3107 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 +00003108 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003109 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3110 {
3111 Error error;
3112 root = root->Dereference(error);
3113 if (error.Fail() || !root.get())
3114 {
3115 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003116 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3117 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003118 return 0;
3119 }
3120 else
3121 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003122 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003123 continue;
3124 }
3125 }
3126 else
3127 {
Johnny Chen44805302011-07-19 19:48:13 +00003128 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003129 index <= index_higher; index++)
3130 {
3131 ValueObjectSP child =
3132 root->GetChildAtIndex(index, true);
3133 list->Append(child);
3134 }
3135 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003136 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3137 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003138 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3139 }
3140 }
3141 break;
3142 }
3143 default: // some non-[ separator, or something entirely wrong, is in the way
3144 {
3145 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003146 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3147 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003148 return 0;
3149 break;
3150 }
3151 }
3152 }
3153}
3154
Enrico Granata0c489f52012-03-01 04:24:26 +00003155static void
3156DumpValueObject_Impl (Stream &s,
3157 ValueObject *valobj,
3158 const ValueObject::DumpValueObjectOptions& options,
3159 uint32_t ptr_depth,
3160 uint32_t curr_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003161{
Greg Clayton007d5be2011-05-30 00:49:24 +00003162 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003163 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003164 bool update_success = valobj->UpdateValueIfNeeded (options.m_use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00003165
Enrico Granata0c489f52012-03-01 04:24:26 +00003166 const char *root_valobj_name =
3167 options.m_root_valobj_name.empty() ?
3168 valobj->GetName().AsCString() :
3169 options.m_root_valobj_name.c_str();
3170
3171 if (update_success && options.m_use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00003172 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003173 ValueObject *dynamic_value = valobj->GetDynamicValue(options.m_use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003174 if (dynamic_value)
3175 valobj = dynamic_value;
3176 }
3177
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003178 clang_type_t clang_type = valobj->GetClangType();
3179
Greg Clayton73b472d2010-10-27 03:32:59 +00003180 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003181 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00003182 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
3183 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003184
Enrico Granata0c489f52012-03-01 04:24:26 +00003185 const bool print_valobj = options.m_flat_output == false || has_value;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003186
3187 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003188 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003189 if (options.m_show_location)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003190 {
Jim Ingham6035b672011-03-31 00:19:25 +00003191 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003192 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003193
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003194 s.Indent();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003195
Greg Clayton7c8a9662010-11-02 01:50:16 +00003196 // Always show the type for the top level items.
Enrico Granata0c489f52012-03-01 04:24:26 +00003197 if (options.m_show_types || (curr_depth == 0 && !options.m_flat_output))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003198 {
Greg Clayton84db9102012-03-26 23:03:23 +00003199 const char* typeName = valobj->GetQualifiedTypeName().AsCString("<invalid type>");
3200 //const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
Enrico Granata9910bc82011-08-03 02:18:51 +00003201 s.Printf("(%s", typeName);
3202 // only show dynamic types if the user really wants to see types
Enrico Granata0c489f52012-03-01 04:24:26 +00003203 if (options.m_show_types && options.m_use_dynamic != eNoDynamicValues &&
Enrico Granata9910bc82011-08-03 02:18:51 +00003204 (/*strstr(typeName, "id") == typeName ||*/
Greg Claytonafacd142011-09-02 01:15:17 +00003205 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003206 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003207 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3208 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatac3e320a2011-08-02 17:27:39 +00003209 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003210 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003211 else
3212 {
3213 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
3214 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003215 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003216 else
3217 {
3218 ObjCLanguageRuntime::ObjCISA isa = runtime->GetISA(*valobj);
3219 if (!runtime->IsValidISA(isa))
Enrico Granata9910bc82011-08-03 02:18:51 +00003220 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003221 else
3222 s.Printf(", dynamic type: %s) ",
3223 runtime->GetActualTypeName(isa).GetCString());
3224 }
3225 }
3226 }
3227 else
3228 s.Printf(") ");
3229 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003230
Greg Clayton1d3afba2010-10-05 00:00:42 +00003231
Enrico Granata0c489f52012-03-01 04:24:26 +00003232 if (options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003233 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003234 // If we are showing types, also qualify the C++ base classes
Enrico Granata0c489f52012-03-01 04:24:26 +00003235 const bool qualify_cxx_base_classes = options.m_show_types;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003236 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003237 s.PutCString(" =");
3238 }
3239 else
3240 {
3241 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3242 s.Printf ("%s =", name_cstr);
3243 }
3244
Enrico Granata0c489f52012-03-01 04:24:26 +00003245 if (!options.m_scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003246 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003247 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003248 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003249 }
3250
Enrico Granata0c489f52012-03-01 04:24:26 +00003251 std::string summary_str;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003252 std::string value_str;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003253 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003254 const char *sum_cstr = NULL;
Enrico Granata0c489f52012-03-01 04:24:26 +00003255 TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003256
Enrico Granata0c489f52012-03-01 04:24:26 +00003257 if (options.m_omit_summary_depth > 0)
Enrico Granata0c5ef692011-07-16 01:22:04 +00003258 entry = NULL;
3259
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003260 if (err_cstr == NULL)
3261 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003262 if (options.m_format != eFormatDefault && options.m_format != valobj->GetFormat())
Greg Clayton6efba4f2012-01-26 21:08:30 +00003263 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003264 valobj->GetValueAsCString(options.m_format,
3265 value_str);
Greg Clayton6efba4f2012-01-26 21:08:30 +00003266 }
Enrico Granata0c489f52012-03-01 04:24:26 +00003267 else
Greg Clayton6efba4f2012-01-26 21:08:30 +00003268 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003269 val_cstr = valobj->GetValueAsCString();
3270 if (val_cstr)
3271 value_str = val_cstr;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003272 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003273 err_cstr = valobj->GetError().AsCString();
3274 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003275
3276 if (err_cstr)
3277 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003278 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003279 }
3280 else
3281 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003282 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003283 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003284 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003285 if (options.m_omit_summary_depth == 0)
3286 {
3287 if (options.m_summary_sp)
3288 {
3289 valobj->GetSummaryAsCString(entry, summary_str);
3290 sum_cstr = summary_str.c_str();
3291 }
3292 else
3293 sum_cstr = valobj->GetSummaryAsCString();
3294 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003295
Greg Clayton6efba4f2012-01-26 21:08:30 +00003296 // Make sure we have a value and make sure the summary didn't
3297 // specify that the value should not be printed
3298 if (!value_str.empty() && (entry == NULL || entry->DoesPrintValue() || sum_cstr == NULL))
3299 s.Printf(" %s", value_str.c_str());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003300
Enrico Granata9dd75c82011-07-15 23:30:15 +00003301 if (sum_cstr)
Enrico Granata0c489f52012-03-01 04:24:26 +00003302 s.Printf(" %s", sum_cstr);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003303
Enrico Granata0c489f52012-03-01 04:24:26 +00003304 if (options.m_use_objc)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003305 {
Jim Ingham6035b672011-03-31 00:19:25 +00003306 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003307 if (object_desc)
3308 s.Printf(" %s\n", object_desc);
3309 else
Sean Callanan672ad942010-10-23 00:18:49 +00003310 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003311 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003312 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003313 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003314
Enrico Granata0c489f52012-03-01 04:24:26 +00003315 if (curr_depth < options.m_max_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003316 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003317 // We will show children for all concrete types. We won't show
3318 // pointer contents unless a pointer depth has been specified.
3319 // We won't reference contents unless the reference is the
3320 // root object (depth of zero).
3321 bool print_children = true;
3322
3323 // Use a new temporary pointer depth in case we override the
3324 // current pointer depth below...
3325 uint32_t curr_ptr_depth = ptr_depth;
3326
3327 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3328 if (is_ptr || is_ref)
3329 {
3330 // We have a pointer or reference whose value is an address.
3331 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003332 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003333 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003334 print_children = false;
3335
3336 else if (is_ref && curr_depth == 0)
3337 {
3338 // If this is the root object (depth is zero) that we are showing
3339 // and it is a reference, and no pointer depth has been supplied
3340 // print out what it references. Don't do this at deeper depths
3341 // otherwise we can end up with infinite recursion...
3342 curr_ptr_depth = 1;
3343 }
3344
3345 if (curr_ptr_depth == 0)
3346 print_children = false;
3347 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003348
Enrico Granata0a3958e2011-07-02 00:25:22 +00003349 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003350 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003351 ValueObject* synth_valobj;
3352 ValueObjectSP synth_valobj_sp = valobj->GetSyntheticValue (options.m_use_synthetic);
3353 synth_valobj = (synth_valobj_sp ? synth_valobj_sp.get() : valobj);
Enrico Granatac5bc4122012-03-27 02:35:13 +00003354
Enrico Granatac482a192011-08-17 22:13:59 +00003355 uint32_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003356 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003357 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003358 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003359 if (options.m_flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003360 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003361 if (print_valobj)
3362 s.EOL();
3363 }
3364 else
3365 {
3366 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003367 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003368 s.IndentMore();
3369 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003370
Greg Claytoncc4d0142012-02-17 07:49:44 +00003371 uint32_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00003372
Enrico Granata0c489f52012-03-01 04:24:26 +00003373 if (num_children > max_num_children && !options.m_ignore_cap)
Enrico Granata22c55d12011-08-12 02:00:06 +00003374 {
3375 num_children = max_num_children;
3376 print_dotdotdot = true;
3377 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003378
Enrico Granata0c489f52012-03-01 04:24:26 +00003379 ValueObject::DumpValueObjectOptions child_options(options);
3380 child_options.SetFormat().SetSummary().SetRootValueObjectName();
3381 child_options.SetScopeChecked(true)
3382 .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003383 for (uint32_t idx=0; idx<num_children; ++idx)
3384 {
Enrico Granatac482a192011-08-17 22:13:59 +00003385 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003386 if (child_sp.get())
3387 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003388 DumpValueObject_Impl (s,
3389 child_sp.get(),
3390 child_options,
3391 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
3392 curr_depth + 1);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003393 }
3394 }
3395
Enrico Granata0c489f52012-03-01 04:24:26 +00003396 if (!options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003397 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003398 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003399 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003400 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3401 Target *target = exe_ctx.GetTargetPtr();
3402 if (target)
3403 target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003404 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003405 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003406 s.IndentLess();
3407 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003408 }
3409 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003410 else if (has_children)
3411 {
3412 // Aggregate, no children...
3413 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003414 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003415 }
3416 else
3417 {
3418 if (print_valobj)
3419 s.EOL();
3420 }
3421
Greg Clayton1d3afba2010-10-05 00:00:42 +00003422 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003423 else
3424 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003425 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003426 }
3427 }
3428 else
3429 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003430 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003431 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003432 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003433 }
3434 }
3435 }
3436 }
3437}
3438
Enrico Granata0c489f52012-03-01 04:24:26 +00003439void
Greg Claytonf830dbb2012-03-22 18:15:37 +00003440ValueObject::LogValueObject (Log *log,
3441 ValueObject *valobj)
3442{
3443 if (log && valobj)
3444 return LogValueObject (log, valobj, DumpValueObjectOptions::DefaultOptions());
3445}
3446
3447void
3448ValueObject::LogValueObject (Log *log,
3449 ValueObject *valobj,
3450 const DumpValueObjectOptions& options)
3451{
3452 if (log && valobj)
3453 {
3454 StreamString s;
3455 ValueObject::DumpValueObject (s, valobj, options);
3456 if (s.GetSize())
3457 log->PutCString(s.GetData());
3458 }
3459}
3460
3461void
Enrico Granata0c489f52012-03-01 04:24:26 +00003462ValueObject::DumpValueObject (Stream &s,
3463 ValueObject *valobj)
3464{
3465
3466 if (!valobj)
3467 return;
3468
3469 DumpValueObject_Impl(s,
3470 valobj,
3471 DumpValueObjectOptions::DefaultOptions(),
3472 0,
3473 0);
3474}
3475
3476void
3477ValueObject::DumpValueObject (Stream &s,
3478 ValueObject *valobj,
3479 const DumpValueObjectOptions& options)
3480{
3481 DumpValueObject_Impl(s,
3482 valobj,
3483 options,
3484 options.m_max_ptr_depth, // max pointer depth allowed, we will go down from here
3485 0 // current object depth is 0 since we are just starting
3486 );
3487}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003488
3489ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003490ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003491{
3492 ValueObjectSP valobj_sp;
3493
Enrico Granatac3e320a2011-08-02 17:27:39 +00003494 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003495 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003496 ExecutionContext exe_ctx (GetExecutionContextRef());
3497 clang::ASTContext *ast = GetClangAST ();
3498
3499 DataExtractor data;
3500 data.SetByteOrder (m_data.GetByteOrder());
3501 data.SetAddressByteSize(m_data.GetAddressByteSize());
3502
Enrico Granata9f1e2042012-04-24 22:15:37 +00003503 if (IsBitfield())
3504 {
3505 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
3506 m_error = v.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
3507 }
3508 else
3509 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003510
3511 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3512 ast,
3513 GetClangType(),
3514 name,
3515 data,
3516 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003517 }
Jim Ingham6035b672011-03-31 00:19:25 +00003518
3519 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003520 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003521 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003522 }
3523 return valobj_sp;
3524}
3525
Greg Claytonafacd142011-09-02 01:15:17 +00003526ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003527ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003528{
Jim Ingham58b59f92011-04-22 23:53:53 +00003529 if (m_deref_valobj)
3530 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003531
Greg Clayton54979cd2010-12-15 05:08:08 +00003532 const bool is_pointer_type = IsPointerType();
3533 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003534 {
3535 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003536 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003537
3538 std::string child_name_str;
3539 uint32_t child_byte_size = 0;
3540 int32_t child_byte_offset = 0;
3541 uint32_t child_bitfield_bit_size = 0;
3542 uint32_t child_bitfield_bit_offset = 0;
3543 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003544 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003545 const bool transparent_pointers = false;
3546 clang::ASTContext *clang_ast = GetClangAST();
3547 clang_type_t clang_type = GetClangType();
3548 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003549
Greg Claytoncc4d0142012-02-17 07:49:44 +00003550 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003551
3552 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3553 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003554 GetName().GetCString(),
3555 clang_type,
3556 0,
3557 transparent_pointers,
3558 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003559 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003560 child_name_str,
3561 child_byte_size,
3562 child_byte_offset,
3563 child_bitfield_bit_size,
3564 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003565 child_is_base_class,
3566 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003567 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003568 {
3569 ConstString child_name;
3570 if (!child_name_str.empty())
3571 child_name.SetCString (child_name_str.c_str());
3572
Jim Ingham58b59f92011-04-22 23:53:53 +00003573 m_deref_valobj = new ValueObjectChild (*this,
3574 clang_ast,
3575 child_clang_type,
3576 child_name,
3577 child_byte_size,
3578 child_byte_offset,
3579 child_bitfield_bit_size,
3580 child_bitfield_bit_offset,
3581 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003582 child_is_deref_of_parent,
3583 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003584 }
3585 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003586
Jim Ingham58b59f92011-04-22 23:53:53 +00003587 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003588 {
3589 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003590 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003591 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003592 else
3593 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003594 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003595 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003596
3597 if (is_pointer_type)
3598 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3599 else
3600 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003601 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003602 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003603}
3604
Greg Claytonafacd142011-09-02 01:15:17 +00003605ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003606ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003607{
Jim Ingham78a685a2011-04-16 00:01:13 +00003608 if (m_addr_of_valobj_sp)
3609 return m_addr_of_valobj_sp;
3610
Greg Claytone0d378b2011-03-24 21:19:54 +00003611 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003612 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003613 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003614 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003615 if (addr != LLDB_INVALID_ADDRESS)
3616 {
3617 switch (address_type)
3618 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003619 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003620 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003621 {
3622 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003623 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003624 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3625 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003626 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003627
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003628 case eAddressTypeFile:
3629 case eAddressTypeLoad:
3630 case eAddressTypeHost:
3631 {
3632 clang::ASTContext *ast = GetClangAST();
3633 clang_type_t clang_type = GetClangType();
3634 if (ast && clang_type)
3635 {
3636 std::string name (1, '&');
3637 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003638 ExecutionContext exe_ctx (GetExecutionContextRef());
3639 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003640 ast,
3641 ClangASTContext::CreatePointerType (ast, clang_type),
3642 ConstString (name.c_str()),
3643 addr,
3644 eAddressTypeInvalid,
3645 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003646 }
3647 }
3648 break;
3649 }
3650 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003651 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003652}
3653
Greg Clayton9a142cf2012-02-03 05:34:10 +00003654ValueObjectSP
3655ValueObject::Cast (const ClangASTType &clang_ast_type)
3656{
Greg Clayton81e871e2012-02-04 02:27:34 +00003657 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003658}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003659
Greg Claytonafacd142011-09-02 01:15:17 +00003660ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003661ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3662{
Greg Claytonafacd142011-09-02 01:15:17 +00003663 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003664 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003665 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003666
3667 if (ptr_value != LLDB_INVALID_ADDRESS)
3668 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003669 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003670 ExecutionContext exe_ctx (GetExecutionContextRef());
3671 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003672 name,
3673 ptr_addr,
3674 clang_ast_type);
3675 }
3676 return valobj_sp;
3677}
3678
Greg Claytonafacd142011-09-02 01:15:17 +00003679ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003680ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3681{
Greg Claytonafacd142011-09-02 01:15:17 +00003682 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003683 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003684 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003685
3686 if (ptr_value != LLDB_INVALID_ADDRESS)
3687 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003688 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003689 ExecutionContext exe_ctx (GetExecutionContextRef());
3690 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003691 name,
3692 ptr_addr,
3693 type_sp);
3694 }
3695 return valobj_sp;
3696}
3697
Jim Ingham6035b672011-03-31 00:19:25 +00003698ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003699 m_mod_id(),
3700 m_exe_ctx_ref(),
3701 m_needs_update (true),
3702 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003703{
3704}
3705
3706ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003707 m_mod_id(),
3708 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003709 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003710 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003711{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003712 ExecutionContext exe_ctx(exe_scope);
3713 TargetSP target_sp (exe_ctx.GetTargetSP());
3714 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003715 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003716 m_exe_ctx_ref.SetTargetSP (target_sp);
3717 ProcessSP process_sp (exe_ctx.GetProcessSP());
3718 if (!process_sp)
3719 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003720
Greg Claytoncc4d0142012-02-17 07:49:44 +00003721 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003722 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003723 m_mod_id = process_sp->GetModID();
3724 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003725
Greg Claytoncc4d0142012-02-17 07:49:44 +00003726 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003727
Greg Claytoncc4d0142012-02-17 07:49:44 +00003728 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003729 {
3730 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003731 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003732 }
Jim Ingham6035b672011-03-31 00:19:25 +00003733
Greg Claytoncc4d0142012-02-17 07:49:44 +00003734 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003735 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003736 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003737
Greg Claytoncc4d0142012-02-17 07:49:44 +00003738 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3739 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003740 {
3741 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003742 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003743 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003744 if (frame_sp)
3745 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003746 }
3747 }
3748 }
Jim Ingham6035b672011-03-31 00:19:25 +00003749}
3750
3751ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003752 m_mod_id(),
3753 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3754 m_needs_update (true),
3755 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003756{
3757}
3758
3759ValueObject::EvaluationPoint::~EvaluationPoint ()
3760{
3761}
3762
Jim Ingham6035b672011-03-31 00:19:25 +00003763// This function checks the EvaluationPoint against the current process state. If the current
3764// state matches the evaluation point, or the evaluation point is already invalid, then we return
3765// false, meaning "no change". If the current state is different, we update our state, and return
3766// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3767// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003768// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003769
3770bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003771ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003772{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003773
3774 // 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 +00003775 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00003776
Greg Claytoncc4d0142012-02-17 07:49:44 +00003777 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003778 return false;
3779
Jim Ingham6035b672011-03-31 00:19:25 +00003780 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003781 Process *process = exe_ctx.GetProcessPtr();
3782 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003783 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003784
Jim Ingham6035b672011-03-31 00:19:25 +00003785 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003786 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003787
Jim Ingham78a685a2011-04-16 00:01:13 +00003788 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3789 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003790 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003791 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003792
3793 bool changed;
3794
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003795 if (m_mod_id.IsValid())
3796 {
3797 if (m_mod_id == current_mod_id)
3798 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003799 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003800 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003801 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003802 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003803 else
3804 {
3805 m_mod_id = current_mod_id;
3806 m_needs_update = true;
3807 changed = true;
3808 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003809 }
Jim Ingham6035b672011-03-31 00:19:25 +00003810
Jim Ingham73ca05a2011-12-17 01:35:57 +00003811 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3812 // That way we'll be sure to return a valid exe_scope.
3813 // 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 +00003814
Greg Claytoncc4d0142012-02-17 07:49:44 +00003815 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003816 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003817 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3818 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003819 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003820 if (m_exe_ctx_ref.HasFrameRef())
3821 {
3822 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3823 if (!frame_sp)
3824 {
3825 // We used to have a frame, but now it is gone
3826 SetInvalid();
3827 }
3828 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003829 }
Jim Ingham6035b672011-03-31 00:19:25 +00003830 else
3831 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003832 // We used to have a thread, but now it is gone
3833 SetInvalid();
Jim Ingham6035b672011-03-31 00:19:25 +00003834 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003835
Jim Ingham6035b672011-03-31 00:19:25 +00003836 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003837 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003838}
3839
Jim Ingham61be0902011-05-02 18:13:59 +00003840void
3841ValueObject::EvaluationPoint::SetUpdated ()
3842{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003843 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3844 if (process_sp)
3845 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003846 m_first_update = false;
3847 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003848}
3849
3850
Greg Claytoncc4d0142012-02-17 07:49:44 +00003851//bool
3852//ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3853//{
3854// if (!IsValid())
3855// return false;
3856//
3857// bool needs_update = false;
3858//
3859// // The target has to be non-null, and the
3860// Target *target = exe_scope->CalculateTarget();
3861// if (target != NULL)
3862// {
3863// Target *old_target = m_target_sp.get();
3864// assert (target == old_target);
3865// Process *process = exe_scope->CalculateProcess();
3866// if (process != NULL)
3867// {
3868// // FOR NOW - assume you can't update variable objects across process boundaries.
3869// Process *old_process = m_process_sp.get();
3870// assert (process == old_process);
3871// ProcessModID current_mod_id = process->GetModID();
3872// if (m_mod_id != current_mod_id)
3873// {
3874// needs_update = true;
3875// m_mod_id = current_mod_id;
3876// }
3877// // See if we're switching the thread or stack context. If no thread is given, this is
3878// // being evaluated in a global context.
3879// Thread *thread = exe_scope->CalculateThread();
3880// if (thread != NULL)
3881// {
3882// user_id_t new_thread_index = thread->GetIndexID();
3883// if (new_thread_index != m_thread_id)
3884// {
3885// needs_update = true;
3886// m_thread_id = new_thread_index;
3887// m_stack_id.Clear();
3888// }
3889//
3890// StackFrame *new_frame = exe_scope->CalculateStackFrame();
3891// if (new_frame != NULL)
3892// {
3893// if (new_frame->GetStackID() != m_stack_id)
3894// {
3895// needs_update = true;
3896// m_stack_id = new_frame->GetStackID();
3897// }
3898// }
3899// else
3900// {
3901// m_stack_id.Clear();
3902// needs_update = true;
3903// }
3904// }
3905// else
3906// {
3907// // If this had been given a thread, and now there is none, we should update.
3908// // Otherwise we don't have to do anything.
3909// if (m_thread_id != LLDB_INVALID_UID)
3910// {
3911// m_thread_id = LLDB_INVALID_UID;
3912// m_stack_id.Clear();
3913// needs_update = true;
3914// }
3915// }
3916// }
3917// else
3918// {
3919// // If there is no process, then we don't need to update anything.
3920// // But if we're switching from having a process to not, we should try to update.
3921// if (m_process_sp.get() != NULL)
3922// {
3923// needs_update = true;
3924// m_process_sp.reset();
3925// m_thread_id = LLDB_INVALID_UID;
3926// m_stack_id.Clear();
3927// }
3928// }
3929// }
3930// else
3931// {
3932// // If there's no target, nothing can change so we don't need to update anything.
3933// // But if we're switching from having a target to not, we should try to update.
3934// if (m_target_sp.get() != NULL)
3935// {
3936// needs_update = true;
3937// m_target_sp.reset();
3938// m_process_sp.reset();
3939// m_thread_id = LLDB_INVALID_UID;
3940// m_stack_id.Clear();
3941// }
3942// }
3943// if (!m_needs_update)
3944// m_needs_update = needs_update;
3945//
3946// return needs_update;
3947//}
Enrico Granataf2bbf712011-07-15 02:26:42 +00003948
3949void
Enrico Granata86cc9822012-03-19 22:58:49 +00003950ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00003951{
Enrico Granata86cc9822012-03-19 22:58:49 +00003952 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
3953 m_value_str.clear();
3954
3955 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
3956 m_location_str.clear();
3957
3958 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
3959 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003960 m_summary_str.clear();
3961 }
3962
3963 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
3964 m_object_desc_str.clear();
3965
3966 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
3967 {
3968 if (m_synthetic_value)
3969 m_synthetic_value = NULL;
3970 }
Johnny Chen44805302011-07-19 19:48:13 +00003971}
Enrico Granata9128ee22011-09-06 19:20:51 +00003972
3973SymbolContextScope *
3974ValueObject::GetSymbolContextScope()
3975{
3976 if (m_parent)
3977 {
3978 if (!m_parent->IsPointerOrReferenceType())
3979 return m_parent->GetSymbolContextScope();
3980 }
3981 return NULL;
3982}