blob: b3c0a0b8c348be178cd5e8dab73f509e916a7e25 [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));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000253#ifndef LLDB_DISABLE_PYTHON
Enrico Granata78d06382011-09-09 23:33:14 +0000254 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, use_dynamic));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000255#endif
Enrico Granata1490c6f2011-07-19 02:34:21 +0000256
Enrico Granata85933ed2011-08-18 16:38:26 +0000257 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
Enrico Granatac3e320a2011-08-02 17:27:39 +0000258 m_last_format_mgr_dynamic = use_dynamic;
Enrico Granata855cd902011-09-06 22:59:55 +0000259
260 any_change = true;
Enrico Granata4becb372011-06-29 22:27:15 +0000261 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000262
263 return any_change;
264
Enrico Granata4becb372011-06-29 22:27:15 +0000265}
266
Jim Ingham16e0c682011-08-12 23:34:31 +0000267void
268ValueObject::SetNeedsUpdate ()
269{
270 m_update_point.SetNeedsUpdate();
271 // We have to clear the value string here so ConstResult children will notice if their values are
272 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000273 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000274}
275
Sean Callanan72772842012-02-22 23:57:45 +0000276ClangASTType
277ValueObject::MaybeCalculateCompleteType ()
278{
279 ClangASTType ret(GetClangASTImpl(), GetClangTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000280
Sean Callanan72772842012-02-22 23:57:45 +0000281 if (m_did_calculate_complete_objc_class_type)
282 {
283 if (m_override_type.IsValid())
284 return m_override_type;
285 else
286 return ret;
287 }
288
289 clang_type_t ast_type(GetClangTypeImpl());
290 clang_type_t class_type;
291 bool is_pointer_type;
292
293 if (ClangASTContext::IsObjCObjectPointerType(ast_type, &class_type))
294 {
295 is_pointer_type = true;
296 }
297 else if (ClangASTContext::IsObjCClassType(ast_type))
298 {
299 is_pointer_type = false;
300 class_type = ast_type;
301 }
302 else
303 {
304 return ret;
305 }
306
307 m_did_calculate_complete_objc_class_type = true;
308
309 if (!class_type)
310 return ret;
311
312 std::string class_name;
313
314 if (!ClangASTContext::GetObjCClassName(class_type, class_name))
315 return ret;
316
317 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
318
319 if (!process_sp)
320 return ret;
321
322 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
323
324 if (!objc_language_runtime)
325 return ret;
326
327 ConstString class_name_cs(class_name.c_str());
328
329 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name_cs);
330
331 if (!complete_objc_class_type_sp)
332 return ret;
333
334 ClangASTType complete_class(complete_objc_class_type_sp->GetClangAST(),
335 complete_objc_class_type_sp->GetClangFullType());
336
337 if (!ClangASTContext::GetCompleteType(complete_class.GetASTContext(),
338 complete_class.GetOpaqueQualType()))
339 return ret;
340
341 if (is_pointer_type)
342 {
343 clang_type_t pointer_type = ClangASTContext::CreatePointerType(complete_class.GetASTContext(),
344 complete_class.GetOpaqueQualType());
345
346 m_override_type = ClangASTType(complete_class.GetASTContext(),
347 pointer_type);
348 }
349 else
350 {
351 m_override_type = complete_class;
352 }
353
Sean Callanan356e17c2012-03-30 02:04:38 +0000354 if (m_override_type.IsValid())
355 return m_override_type;
356 else
357 return ret;
Sean Callanan72772842012-02-22 23:57:45 +0000358}
359
360clang::ASTContext *
361ValueObject::GetClangAST ()
362{
363 ClangASTType type = MaybeCalculateCompleteType();
364
365 return type.GetASTContext();
366}
367
368lldb::clang_type_t
369ValueObject::GetClangType ()
370{
371 ClangASTType type = MaybeCalculateCompleteType();
372
373 return type.GetOpaqueQualType();
374}
375
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000376DataExtractor &
377ValueObject::GetDataExtractor ()
378{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000379 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000380 return m_data;
381}
382
383const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000384ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000385{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000386 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000387 return m_error;
388}
389
390const ConstString &
391ValueObject::GetName() const
392{
393 return m_name;
394}
395
396const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000397ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000398{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000399 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000400 {
401 if (m_location_str.empty())
402 {
403 StreamString sstr;
404
405 switch (m_value.GetValueType())
406 {
407 default:
408 break;
409
410 case Value::eValueTypeScalar:
Greg Clayton526e5af2010-11-13 03:52:47 +0000411 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000412 {
413 RegisterInfo *reg_info = m_value.GetRegisterInfo();
414 if (reg_info)
415 {
416 if (reg_info->name)
417 m_location_str = reg_info->name;
418 else if (reg_info->alt_name)
419 m_location_str = reg_info->alt_name;
420 break;
421 }
422 }
423 m_location_str = "scalar";
424 break;
425
426 case Value::eValueTypeLoadAddress:
427 case Value::eValueTypeFileAddress:
428 case Value::eValueTypeHostAddress:
429 {
430 uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2;
431 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
432 m_location_str.swap(sstr.GetString());
433 }
434 break;
435 }
436 }
437 }
438 return m_location_str.c_str();
439}
440
441Value &
442ValueObject::GetValue()
443{
444 return m_value;
445}
446
447const Value &
448ValueObject::GetValue() const
449{
450 return m_value;
451}
452
453bool
Jim Ingham6035b672011-03-31 00:19:25 +0000454ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000455{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000456 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
457 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000458 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000459 Value tmp_value(m_value);
460 scalar = tmp_value.ResolveValue(&exe_ctx, GetClangAST ());
Greg Claytondcad5022011-12-29 01:26:56 +0000461 if (scalar.IsValid())
462 {
463 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
464 if (bitfield_bit_size)
465 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
466 return true;
467 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000468 }
Greg Claytondcad5022011-12-29 01:26:56 +0000469 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000470}
471
472bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000473ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000474{
Greg Clayton288bdf92010-09-02 02:59:18 +0000475 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000476}
477
478
479void
480ValueObject::SetValueIsValid (bool b)
481{
Greg Clayton288bdf92010-09-02 02:59:18 +0000482 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000483}
484
485bool
Jim Ingham6035b672011-03-31 00:19:25 +0000486ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000487{
Jim Ingham6035b672011-03-31 00:19:25 +0000488 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000489 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000490}
491
492void
493ValueObject::SetValueDidChange (bool value_changed)
494{
Greg Clayton288bdf92010-09-02 02:59:18 +0000495 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000496}
497
498ValueObjectSP
499ValueObject::GetChildAtIndex (uint32_t idx, bool can_create)
500{
501 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000502 // We may need to update our value if we are dynamic
503 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000504 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000505 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000506 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000507 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000508 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000509 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000510 // No we haven't created the child at this index, so lets have our
511 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000512 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000513 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000514
Enrico Granata9d60f602012-03-09 03:09:58 +0000515 ValueObject* child = m_children.GetChildAtIndex(idx);
516 if (child != NULL)
517 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000518 }
519 return child_sp;
520}
521
522uint32_t
523ValueObject::GetIndexOfChildWithName (const ConstString &name)
524{
525 bool omit_empty_base_classes = true;
526 return ClangASTContext::GetIndexOfChildWithName (GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +0000527 GetClangType(),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000528 name.GetCString(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000529 omit_empty_base_classes);
530}
531
532ValueObjectSP
533ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
534{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000535 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000536 // classes (which really aren't part of the expression path), so we
537 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000538 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000539
Greg Claytondea8cb42011-06-29 22:09:02 +0000540 // We may need to update our value if we are dynamic
541 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000542 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000543
544 std::vector<uint32_t> child_indexes;
545 clang::ASTContext *clang_ast = GetClangAST();
546 void *clang_type = GetClangType();
547 bool omit_empty_base_classes = true;
548 const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast,
549 clang_type,
550 name.GetCString(),
551 omit_empty_base_classes,
552 child_indexes);
553 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000554 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000555 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
556 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
557
558 child_sp = GetChildAtIndex(*pos, can_create);
559 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000560 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000561 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000562 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000563 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
564 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000565 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000566 else
567 {
568 child_sp.reset();
569 }
570
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000571 }
572 }
573 return child_sp;
574}
575
576
577uint32_t
578ValueObject::GetNumChildren ()
579{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000580 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000581 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000582 {
583 SetNumChildren (CalculateNumChildren());
584 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000585 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000586}
587void
588ValueObject::SetNumChildren (uint32_t num_children)
589{
Greg Clayton288bdf92010-09-02 02:59:18 +0000590 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000591 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000592}
593
594void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000595ValueObject::SetName (const ConstString &name)
596{
597 m_name = name;
598}
599
Jim Ingham58b59f92011-04-22 23:53:53 +0000600ValueObject *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000601ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index)
602{
Jim Ingham2eec4872011-05-07 00:10:58 +0000603 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000604
Greg Claytondea8cb42011-06-29 22:09:02 +0000605 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000606 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000607 std::string child_name_str;
608 uint32_t child_byte_size = 0;
609 int32_t child_byte_offset = 0;
610 uint32_t child_bitfield_bit_size = 0;
611 uint32_t child_bitfield_bit_offset = 0;
612 bool child_is_base_class = false;
613 bool child_is_deref_of_parent = false;
614
615 const bool transparent_pointers = synthetic_array_member == false;
616 clang::ASTContext *clang_ast = GetClangAST();
617 clang_type_t clang_type = GetClangType();
618 clang_type_t child_clang_type;
619
Greg Claytoncc4d0142012-02-17 07:49:44 +0000620 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000621
622 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
623 clang_ast,
624 GetName().GetCString(),
625 clang_type,
626 idx,
627 transparent_pointers,
628 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +0000629 ignore_array_bounds,
Greg Claytondea8cb42011-06-29 22:09:02 +0000630 child_name_str,
631 child_byte_size,
632 child_byte_offset,
633 child_bitfield_bit_size,
634 child_bitfield_bit_offset,
635 child_is_base_class,
636 child_is_deref_of_parent);
637 if (child_clang_type && child_byte_size)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000638 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000639 if (synthetic_index)
640 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000641
Greg Claytondea8cb42011-06-29 22:09:02 +0000642 ConstString child_name;
643 if (!child_name_str.empty())
644 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000645
Greg Claytondea8cb42011-06-29 22:09:02 +0000646 valobj = new ValueObjectChild (*this,
647 clang_ast,
648 child_clang_type,
649 child_name,
650 child_byte_size,
651 child_byte_offset,
652 child_bitfield_bit_size,
653 child_bitfield_bit_offset,
654 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000655 child_is_deref_of_parent,
656 eAddressTypeInvalid);
657 //if (valobj)
658 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
659 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000660
Jim Ingham58b59f92011-04-22 23:53:53 +0000661 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000662}
663
Enrico Granata0c489f52012-03-01 04:24:26 +0000664bool
665ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
666 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000667{
Enrico Granata0c489f52012-03-01 04:24:26 +0000668 destination.clear();
669
670 // ideally we would like to bail out if passing NULL, but if we do so
671 // we end up not providing the summary for function pointers anymore
672 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
673 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000674
675 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000676
677 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
678 // information that we might care to see in a crash log. might be useful in very specific situations though.
679 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
680 GetTypeName().GetCString(),
681 GetName().GetCString(),
682 summary_ptr->GetDescription().c_str());*/
683
Enrico Granata0c489f52012-03-01 04:24:26 +0000684 if (UpdateValueIfNeeded (false))
685 {
686 if (summary_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000687 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000688 if (HasSyntheticValue())
689 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
690 summary_ptr->FormatObject(this, destination);
Enrico Granata0c489f52012-03-01 04:24:26 +0000691 }
692 else
693 {
694 clang_type_t clang_type = GetClangType();
695
696 // Do some default printout for function pointers
697 if (clang_type)
Enrico Granata4becb372011-06-29 22:27:15 +0000698 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000699 StreamString sstr;
700 clang_type_t elem_or_pointee_clang_type;
701 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
702 GetClangAST(),
703 &elem_or_pointee_clang_type));
704
705 if (ClangASTContext::IsFunctionPointerType (clang_type))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000706 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000707 AddressType func_ptr_address_type = eAddressTypeInvalid;
708 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
709 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000710 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000711 switch (func_ptr_address_type)
Jim Ingham6035b672011-03-31 00:19:25 +0000712 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000713 case eAddressTypeInvalid:
714 case eAddressTypeFile:
715 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000716
Greg Claytoncc4d0142012-02-17 07:49:44 +0000717 case eAddressTypeLoad:
Enrico Granata0c489f52012-03-01 04:24:26 +0000718 {
719 ExecutionContext exe_ctx (GetExecutionContextRef());
720
721 Address so_addr;
722 Target *target = exe_ctx.GetTargetPtr();
723 if (target && target->GetSectionLoadList().IsEmpty() == false)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000724 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000725 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000726 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000727 so_addr.Dump (&sstr,
728 exe_ctx.GetBestExecutionContextScope(),
729 Address::DumpStyleResolvedDescription,
730 Address::DumpStyleSectionNameOffset);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000731 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000732 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000733 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000734 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000735
Greg Claytoncc4d0142012-02-17 07:49:44 +0000736 case eAddressTypeHost:
737 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +0000738 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000739 }
740 if (sstr.GetSize() > 0)
741 {
742 destination.assign (1, '(');
743 destination.append (sstr.GetData(), sstr.GetSize());
744 destination.append (1, ')');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000745 }
746 }
747 }
748 }
749 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000750 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000751 return !destination.empty();
752}
753
754const char *
755ValueObject::GetSummaryAsCString ()
756{
757 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
758 {
759 GetSummaryAsCString(GetSummaryFormat().get(),
760 m_summary_str);
761 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000762 if (m_summary_str.empty())
763 return NULL;
764 return m_summary_str.c_str();
765}
766
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000767bool
768ValueObject::IsCStringContainer(bool check_pointer)
769{
770 clang_type_t elem_or_pointee_clang_type;
771 const Flags type_flags (ClangASTContext::GetTypeInfo (GetClangType(),
772 GetClangAST(),
773 &elem_or_pointee_clang_type));
774 bool is_char_arr_ptr (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
775 ClangASTContext::IsCharType (elem_or_pointee_clang_type));
776 if (!is_char_arr_ptr)
777 return false;
778 if (!check_pointer)
779 return true;
780 if (type_flags.Test(ClangASTContext::eTypeIsArray))
781 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000782 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000783 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000784 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000785 return (cstr_address != LLDB_INVALID_ADDRESS);
786}
787
Enrico Granata9128ee22011-09-06 19:20:51 +0000788size_t
789ValueObject::GetPointeeData (DataExtractor& data,
790 uint32_t item_idx,
791 uint32_t item_count)
792{
793 if (!IsPointerType() && !IsArrayType())
794 return 0;
795
796 if (item_count == 0)
797 return 0;
798
799 uint32_t stride = 0;
800
801 ClangASTType type(GetClangAST(),
802 GetClangType());
803
804 const uint64_t item_type_size = (IsPointerType() ? ClangASTType::GetTypeByteSize(GetClangAST(), type.GetPointeeType()) :
805 ClangASTType::GetTypeByteSize(GetClangAST(), type.GetArrayElementType(stride)));
806
807 const uint64_t bytes = item_count * item_type_size;
808
809 const uint64_t offset = item_idx * item_type_size;
810
811 if (item_idx == 0 && item_count == 1) // simply a deref
812 {
813 if (IsPointerType())
814 {
815 Error error;
816 ValueObjectSP pointee_sp = Dereference(error);
817 if (error.Fail() || pointee_sp.get() == NULL)
818 return 0;
819 return pointee_sp->GetDataExtractor().Copy(data);
820 }
821 else
822 {
823 ValueObjectSP child_sp = GetChildAtIndex(0, true);
824 if (child_sp.get() == NULL)
825 return 0;
826 return child_sp->GetDataExtractor().Copy(data);
827 }
828 return true;
829 }
830 else /* (items > 1) */
831 {
832 Error error;
833 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
834 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
835
836 AddressType addr_type;
837 lldb::addr_t addr = IsPointerType() ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
838
Enrico Granata9128ee22011-09-06 19:20:51 +0000839 switch (addr_type)
840 {
841 case eAddressTypeFile:
842 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000843 ModuleSP module_sp (GetModule());
844 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000845 {
846 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +0000847 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000848 ExecutionContext exe_ctx (GetExecutionContextRef());
849 Target* target = exe_ctx.GetTargetPtr();
850 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +0000851 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000852 heap_buf_ptr->SetByteSize(bytes);
853 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
854 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +0000855 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000856 data.SetData(data_sp);
857 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +0000858 }
859 }
860 }
861 }
862 break;
863 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +0000864 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000865 ExecutionContext exe_ctx (GetExecutionContextRef());
866 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +0000867 if (process)
868 {
869 heap_buf_ptr->SetByteSize(bytes);
870 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
871 if (error.Success())
872 {
873 data.SetData(data_sp);
874 return bytes_read;
875 }
876 }
877 }
878 break;
879 case eAddressTypeHost:
880 {
881 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes);
882 data.SetData(data_sp);
883 return bytes;
884 }
885 break;
886 case eAddressTypeInvalid:
887 default:
888 break;
889 }
890 }
891 return 0;
892}
893
894size_t
895ValueObject::GetData (DataExtractor& data)
896{
897 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000898 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytone72dfb32012-02-24 01:59:29 +0000899 Error error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +0000900 if (error.Fail())
901 return 0;
902 data.SetAddressByteSize(m_data.GetAddressByteSize());
903 data.SetByteOrder(m_data.GetByteOrder());
904 return data.GetByteSize();
905}
906
907// will compute strlen(str), but without consuming more than
908// maxlen bytes out of str (this serves the purpose of reading
909// chunks of a string without having to worry about
910// missing NULL terminators in the chunk)
911// of course, if strlen(str) > maxlen, the function will return
912// maxlen_value (which should be != maxlen, because that allows you
913// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
914static uint32_t
915strlen_or_inf (const char* str,
916 uint32_t maxlen,
917 uint32_t maxlen_value)
918{
919 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +0000920 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +0000921 {
Greg Clayton8dd5c172011-10-05 22:19:51 +0000922 while(*str)
923 {
924 len++;str++;
925 if (len > maxlen)
926 return maxlen_value;
927 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000928 }
929 return len;
930}
931
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000932void
Greg Claytoncc4d0142012-02-17 07:49:44 +0000933ValueObject::ReadPointedString (Stream& s,
934 Error& error,
935 uint32_t max_length,
936 bool honor_array,
937 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000938{
Greg Claytoncc4d0142012-02-17 07:49:44 +0000939 ExecutionContext exe_ctx (GetExecutionContextRef());
940 Target* target = exe_ctx.GetTargetPtr();
941
942 if (target && max_length == 0)
943 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000944
945 clang_type_t clang_type = GetClangType();
946 clang_type_t elem_or_pointee_clang_type;
947 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
948 GetClangAST(),
949 &elem_or_pointee_clang_type));
950 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
951 ClangASTContext::IsCharType (elem_or_pointee_clang_type))
952 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000953 if (target == NULL)
954 {
955 s << "<no target to read from>";
956 }
957 else
958 {
959 addr_t cstr_address = LLDB_INVALID_ADDRESS;
960 AddressType cstr_address_type = eAddressTypeInvalid;
961
962 size_t cstr_len = 0;
963 bool capped_data = false;
964 if (type_flags.Test (ClangASTContext::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000965 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000966 // We have an array
967 cstr_len = ClangASTContext::GetArraySize (clang_type);
968 if (cstr_len > max_length)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000969 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000970 capped_data = true;
971 cstr_len = max_length;
972 }
973 cstr_address = GetAddressOf (true, &cstr_address_type);
974 }
975 else
976 {
977 // We have a pointer
978 cstr_address = GetPointerValue (&cstr_address_type);
979 }
980 if (cstr_address != 0 && cstr_address != LLDB_INVALID_ADDRESS)
981 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000982 Address cstr_so_addr (cstr_address);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000983 DataExtractor data;
984 size_t bytes_read = 0;
985 if (cstr_len > 0 && honor_array)
986 {
987 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
988 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
989 GetPointeeData(data, 0, cstr_len);
990
991 if ((bytes_read = data.GetByteSize()) > 0)
992 {
993 s << '"';
994 data.Dump (&s,
995 0, // Start offset in "data"
996 item_format,
997 1, // Size of item (1 byte for a char!)
998 bytes_read, // How many bytes to print?
999 UINT32_MAX, // num per line
1000 LLDB_INVALID_ADDRESS,// base address
1001 0, // bitfield bit size
1002 0); // bitfield bit offset
1003 if (capped_data)
1004 s << "...";
1005 s << '"';
1006 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00001007 }
1008 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001009 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001010 cstr_len = max_length;
1011 const size_t k_max_buf_size = 64;
1012
1013 size_t offset = 0;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001014
Greg Claytoncc4d0142012-02-17 07:49:44 +00001015 int cstr_len_displayed = -1;
1016 bool capped_cstr = false;
1017 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1018 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1019 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001020 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001021 const char *cstr = data.PeekCStr(0);
1022 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1023 if (len > k_max_buf_size)
1024 len = k_max_buf_size;
1025 if (cstr && cstr_len_displayed < 0)
1026 s << '"';
1027
1028 if (cstr_len_displayed < 0)
1029 cstr_len_displayed = len;
1030
1031 if (len == 0)
1032 break;
1033 cstr_len_displayed += len;
1034 if (len > bytes_read)
1035 len = bytes_read;
1036 if (len > cstr_len)
1037 len = cstr_len;
1038
1039 data.Dump (&s,
1040 0, // Start offset in "data"
1041 item_format,
1042 1, // Size of item (1 byte for a char!)
1043 len, // How many bytes to print?
1044 UINT32_MAX, // num per line
1045 LLDB_INVALID_ADDRESS,// base address
1046 0, // bitfield bit size
1047 0); // bitfield bit offset
1048
1049 if (len < k_max_buf_size)
1050 break;
1051
1052 if (len >= cstr_len)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001053 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001054 capped_cstr = true;
1055 break;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001056 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001057
1058 cstr_len -= len;
1059 offset += len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001060 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001061
1062 if (cstr_len_displayed >= 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001063 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001064 s << '"';
1065 if (capped_cstr)
1066 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001067 }
1068 }
1069 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001070 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001071 }
1072 else
1073 {
1074 error.SetErrorString("impossible to read a string from this object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001075 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001076 }
1077}
1078
Jim Ingham53c47f12010-09-10 23:12:17 +00001079const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001080ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001081{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001082
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001083 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001084 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001085
1086 if (!m_object_desc_str.empty())
1087 return m_object_desc_str.c_str();
1088
Greg Claytoncc4d0142012-02-17 07:49:44 +00001089 ExecutionContext exe_ctx (GetExecutionContextRef());
1090 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001091 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001092 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001093
Jim Ingham53c47f12010-09-10 23:12:17 +00001094 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001095
Greg Claytonafacd142011-09-02 01:15:17 +00001096 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001097 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1098
Jim Inghama2cf2632010-12-23 02:29:54 +00001099 if (runtime == NULL)
1100 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001101 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Jim Inghama2cf2632010-12-23 02:29:54 +00001102 clang_type_t opaque_qual_type = GetClangType();
1103 if (opaque_qual_type != NULL)
1104 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001105 bool is_signed;
1106 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed)
1107 || ClangASTContext::IsPointerType (opaque_qual_type))
1108 {
Greg Claytonafacd142011-09-02 01:15:17 +00001109 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001110 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001111 }
1112 }
1113
Jim Ingham8d543de2011-03-31 23:01:21 +00001114 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001115 {
1116 m_object_desc_str.append (s.GetData());
1117 }
Sean Callanan672ad942010-10-23 00:18:49 +00001118
1119 if (m_object_desc_str.empty())
1120 return NULL;
1121 else
1122 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001123}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001124
Enrico Granata0c489f52012-03-01 04:24:26 +00001125bool
1126ValueObject::GetValueAsCString (lldb::Format format,
1127 std::string& destination)
1128{
1129 if (ClangASTContext::IsAggregateType (GetClangType()) == false &&
1130 UpdateValueIfNeeded(false))
1131 {
1132 const Value::ContextType context_type = m_value.GetContextType();
1133
1134 switch (context_type)
1135 {
1136 case Value::eContextTypeClangType:
1137 case Value::eContextTypeLLDBType:
1138 case Value::eContextTypeVariable:
1139 {
1140 clang_type_t clang_type = GetClangType ();
1141 if (clang_type)
1142 {
1143 StreamString sstr;
1144 ExecutionContext exe_ctx (GetExecutionContextRef());
1145 ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
1146 clang_type, // The clang type to display
1147 &sstr,
1148 format, // Format to display this type with
1149 m_data, // Data to extract from
1150 0, // Byte offset into "m_data"
1151 GetByteSize(), // Byte size of item in "m_data"
1152 GetBitfieldBitSize(), // Bitfield bit size
1153 GetBitfieldBitOffset(), // Bitfield bit offset
1154 exe_ctx.GetBestExecutionContextScope());
1155 // Don't set the m_error to anything here otherwise
1156 // we won't be able to re-format as anything else. The
1157 // code for ClangASTType::DumpTypeValue() should always
1158 // return something, even if that something contains
1159 // an error messsage. "m_error" is used to detect errors
1160 // when reading the valid object, not for formatting errors.
1161 if (sstr.GetString().empty())
1162 destination.clear();
1163 else
1164 destination.swap(sstr.GetString());
1165 }
1166 }
1167 break;
1168
1169 case Value::eContextTypeRegisterInfo:
1170 {
1171 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1172 if (reg_info)
1173 {
1174 ExecutionContext exe_ctx (GetExecutionContextRef());
1175
1176 StreamString reg_sstr;
1177 m_data.Dump (&reg_sstr,
1178 0,
1179 format,
1180 reg_info->byte_size,
1181 1,
1182 UINT32_MAX,
1183 LLDB_INVALID_ADDRESS,
1184 0,
1185 0,
1186 exe_ctx.GetBestExecutionContextScope());
1187 destination.swap(reg_sstr.GetString());
1188 }
1189 }
1190 break;
1191
1192 default:
1193 break;
1194 }
1195 return !destination.empty();
1196 }
1197 else
1198 return false;
1199}
1200
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001201const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001202ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001203{
Enrico Granata0c489f52012-03-01 04:24:26 +00001204 if (UpdateValueIfNeeded(true) && m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001205 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001206 lldb::Format my_format = GetFormat();
1207 if (m_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001208 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001209 if (m_type_format_sp)
1210 my_format = m_type_format_sp->GetFormat();
1211 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001212 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001213 if (m_is_bitfield_for_scalar)
1214 my_format = eFormatUnsigned;
1215 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001216 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001217 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001218 {
1219 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1220 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001221 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001222 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001223 else
1224 {
1225 clang_type_t clang_type = GetClangType ();
1226 my_format = ClangASTType::GetFormat(clang_type);
1227 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001228 }
1229 }
1230 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001231 if (GetValueAsCString(my_format, m_value_str))
1232 {
1233 if (!m_value_did_change && m_old_value_valid)
1234 {
1235 // The value was gotten successfully, so we consider the
1236 // value as changed if the value string differs
1237 SetValueDidChange (m_old_value_str != m_value_str);
1238 }
1239 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001240 }
1241 if (m_value_str.empty())
1242 return NULL;
1243 return m_value_str.c_str();
1244}
1245
Enrico Granatac3e320a2011-08-02 17:27:39 +00001246// if > 8bytes, 0 is returned. this method should mostly be used
1247// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001248uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001249ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001250{
1251 // If our byte size is zero this is an aggregate type that has children
1252 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
1253 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001254 Scalar scalar;
1255 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001256 {
1257 if (success)
1258 *success = true;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001259 return scalar.GetRawBits64(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001260 }
1261 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001262 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001263
1264 if (success)
1265 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001266 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001267}
1268
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001269// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1270// this call up to date by returning true for your new special cases. We will eventually move
1271// to checking this call result before trying to display special cases
1272bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001273ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1274 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001275{
1276 clang_type_t elem_or_pointee_type;
1277 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
1278
1279 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001280 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001281 {
1282 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001283 (custom_format == eFormatCString ||
1284 custom_format == eFormatCharArray ||
1285 custom_format == eFormatChar ||
1286 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001287 return true;
1288
1289 if (flags.Test(ClangASTContext::eTypeIsArray))
1290 {
Greg Claytonafacd142011-09-02 01:15:17 +00001291 if ((custom_format == eFormatBytes) ||
1292 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001293 return true;
1294
Greg Claytonafacd142011-09-02 01:15:17 +00001295 if ((custom_format == eFormatVectorOfChar) ||
1296 (custom_format == eFormatVectorOfFloat32) ||
1297 (custom_format == eFormatVectorOfFloat64) ||
1298 (custom_format == eFormatVectorOfSInt16) ||
1299 (custom_format == eFormatVectorOfSInt32) ||
1300 (custom_format == eFormatVectorOfSInt64) ||
1301 (custom_format == eFormatVectorOfSInt8) ||
1302 (custom_format == eFormatVectorOfUInt128) ||
1303 (custom_format == eFormatVectorOfUInt16) ||
1304 (custom_format == eFormatVectorOfUInt32) ||
1305 (custom_format == eFormatVectorOfUInt64) ||
1306 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001307 return true;
1308 }
1309 }
1310 return false;
1311}
1312
Enrico Granata9fc19442011-07-06 02:13:41 +00001313bool
1314ValueObject::DumpPrintableRepresentation(Stream& s,
1315 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001316 Format custom_format,
Enrico Granata86cc9822012-03-19 22:58:49 +00001317 PrintableRepresentationSpecialCases special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001318{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001319
1320 clang_type_t elem_or_pointee_type;
1321 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001322
Enrico Granata86cc9822012-03-19 22:58:49 +00001323 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1324 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1325
1326 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001327 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001328 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1329 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001330 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001331 // when being asked to get a printable display an array or pointer type directly,
1332 // try to "do the right thing"
1333
1334 if (IsCStringContainer(true) &&
1335 (custom_format == eFormatCString ||
1336 custom_format == eFormatCharArray ||
1337 custom_format == eFormatChar ||
1338 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001339 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001340 Error error;
1341 ReadPointedString(s,
1342 error,
1343 0,
1344 (custom_format == eFormatVectorOfChar) ||
1345 (custom_format == eFormatCharArray));
1346 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001347 }
1348
Enrico Granata86cc9822012-03-19 22:58:49 +00001349 if (custom_format == eFormatEnum)
1350 return false;
1351
1352 // this only works for arrays, because I have no way to know when
1353 // the pointed memory ends, and no special \0 end of data marker
1354 if (flags.Test(ClangASTContext::eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001355 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001356 if ((custom_format == eFormatBytes) ||
1357 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001358 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001359 uint32_t count = GetNumChildren();
1360
1361 s << '[';
1362 for (uint32_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001363 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001364
1365 if (low)
1366 s << ',';
1367
1368 ValueObjectSP child = GetChildAtIndex(low,true);
1369 if (!child.get())
1370 {
1371 s << "<invalid child>";
1372 continue;
1373 }
1374 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1375 }
1376
1377 s << ']';
1378
1379 return true;
1380 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001381
Enrico Granata86cc9822012-03-19 22:58:49 +00001382 if ((custom_format == eFormatVectorOfChar) ||
1383 (custom_format == eFormatVectorOfFloat32) ||
1384 (custom_format == eFormatVectorOfFloat64) ||
1385 (custom_format == eFormatVectorOfSInt16) ||
1386 (custom_format == eFormatVectorOfSInt32) ||
1387 (custom_format == eFormatVectorOfSInt64) ||
1388 (custom_format == eFormatVectorOfSInt8) ||
1389 (custom_format == eFormatVectorOfUInt128) ||
1390 (custom_format == eFormatVectorOfUInt16) ||
1391 (custom_format == eFormatVectorOfUInt32) ||
1392 (custom_format == eFormatVectorOfUInt64) ||
1393 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1394 {
1395 uint32_t count = GetNumChildren();
1396
1397 Format format = FormatManager::GetSingleItemFormat(custom_format);
1398
1399 s << '[';
1400 for (uint32_t low = 0; low < count; low++)
1401 {
1402
1403 if (low)
1404 s << ',';
1405
1406 ValueObjectSP child = GetChildAtIndex(low,true);
1407 if (!child.get())
1408 {
1409 s << "<invalid child>";
1410 continue;
1411 }
1412 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1413 }
1414
1415 s << ']';
1416
1417 return true;
1418 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001419 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001420
1421 if ((custom_format == eFormatBoolean) ||
1422 (custom_format == eFormatBinary) ||
1423 (custom_format == eFormatChar) ||
1424 (custom_format == eFormatCharPrintable) ||
1425 (custom_format == eFormatComplexFloat) ||
1426 (custom_format == eFormatDecimal) ||
1427 (custom_format == eFormatHex) ||
1428 (custom_format == eFormatFloat) ||
1429 (custom_format == eFormatOctal) ||
1430 (custom_format == eFormatOSType) ||
1431 (custom_format == eFormatUnicode16) ||
1432 (custom_format == eFormatUnicode32) ||
1433 (custom_format == eFormatUnsigned) ||
1434 (custom_format == eFormatPointer) ||
1435 (custom_format == eFormatComplexInteger) ||
1436 (custom_format == eFormatComplex) ||
1437 (custom_format == eFormatDefault)) // use the [] operator
1438 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001439 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001440 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001441
1442 if (only_special)
1443 return false;
1444
Enrico Granata86cc9822012-03-19 22:58:49 +00001445 bool var_success = false;
1446
1447 {
1448 const char * return_value;
1449 std::string alloc_mem;
1450
1451 if (custom_format != eFormatInvalid)
1452 SetFormat(custom_format);
1453
1454 switch(val_obj_display)
1455 {
1456 case eValueObjectRepresentationStyleValue:
1457 return_value = GetValueAsCString();
1458 break;
1459
1460 case eValueObjectRepresentationStyleSummary:
1461 return_value = GetSummaryAsCString();
1462 break;
1463
1464 case eValueObjectRepresentationStyleLanguageSpecific:
1465 return_value = GetObjectDescription();
1466 break;
1467
1468 case eValueObjectRepresentationStyleLocation:
1469 return_value = GetLocationAsCString();
1470 break;
1471
1472 case eValueObjectRepresentationStyleChildrenCount:
1473 {
1474 alloc_mem.resize(512);
1475 return_value = &alloc_mem[0];
1476 int count = GetNumChildren();
1477 snprintf((char*)return_value, 512, "%d", count);
1478 }
1479 break;
1480
1481 case eValueObjectRepresentationStyleType:
1482 return_value = GetTypeName().AsCString();
1483 break;
1484
1485 default:
1486 break;
1487 }
1488
1489 if (!return_value)
1490 {
1491 if (val_obj_display == eValueObjectRepresentationStyleValue)
1492 return_value = GetSummaryAsCString();
1493 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1494 {
1495 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1496 {
1497 // this thing has no value, and it seems to have no summary
1498 // some combination of unitialized data and other factors can also
1499 // raise this condition, so let's print a nice generic description
1500 {
1501 alloc_mem.resize(684);
1502 return_value = &alloc_mem[0];
1503 snprintf((char*)return_value, 684, "%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1504 }
1505 }
1506 else
1507 return_value = GetValueAsCString();
1508 }
1509 }
1510
1511 if (return_value)
1512 s.PutCString(return_value);
1513 else
1514 {
1515 if (m_error.Fail())
1516 s.Printf("<%s>", m_error.AsCString());
1517 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1518 s.PutCString("<no summary available>");
1519 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1520 s.PutCString("<no value available>");
1521 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1522 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1523 else
1524 s.PutCString("<no printable representation>");
1525 }
1526
1527 // we should only return false here if we could not do *anything*
1528 // even if we have an error message as output, that's a success
1529 // from our callers' perspective, so return true
1530 var_success = true;
1531
1532 if (custom_format != eFormatInvalid)
1533 SetFormat(eFormatDefault);
1534 }
1535
Enrico Granataf4efecd2011-07-12 22:56:10 +00001536 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001537}
1538
Greg Clayton737b9322010-09-13 03:32:57 +00001539addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001540ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001541{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001542 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001543 return LLDB_INVALID_ADDRESS;
1544
Greg Clayton73b472d2010-10-27 03:32:59 +00001545 switch (m_value.GetValueType())
1546 {
1547 case Value::eValueTypeScalar:
1548 if (scalar_is_load_address)
1549 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001550 if(address_type)
1551 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001552 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1553 }
1554 break;
1555
1556 case Value::eValueTypeLoadAddress:
1557 case Value::eValueTypeFileAddress:
1558 case Value::eValueTypeHostAddress:
1559 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001560 if(address_type)
1561 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001562 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1563 }
1564 break;
1565 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001566 if (address_type)
1567 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001568 return LLDB_INVALID_ADDRESS;
1569}
1570
1571addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001572ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001573{
Greg Claytonafacd142011-09-02 01:15:17 +00001574 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001575 if(address_type)
1576 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001577
Enrico Granatac3e320a2011-08-02 17:27:39 +00001578 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001579 return address;
1580
Greg Clayton73b472d2010-10-27 03:32:59 +00001581 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001582 {
1583 case Value::eValueTypeScalar:
Enrico Granata9128ee22011-09-06 19:20:51 +00001584 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001585 break;
1586
Enrico Granata9128ee22011-09-06 19:20:51 +00001587 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001588 case Value::eValueTypeLoadAddress:
1589 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001590 {
1591 uint32_t data_offset = 0;
1592 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001593 }
1594 break;
1595 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001596
Enrico Granata9128ee22011-09-06 19:20:51 +00001597 if (address_type)
1598 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001599
Greg Clayton737b9322010-09-13 03:32:57 +00001600 return address;
1601}
1602
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001603bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001604ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001605{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001606 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001607 // Make sure our value is up to date first so that our location and location
1608 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001609 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001610 {
1611 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001612 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001613 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001614
1615 uint32_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001616 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001617
Greg Claytonb1320972010-07-14 00:18:15 +00001618 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001619
Jim Ingham16e0c682011-08-12 23:34:31 +00001620 Value::ValueType value_type = m_value.GetValueType();
1621
1622 if (value_type == Value::eValueTypeScalar)
1623 {
1624 // If the value is already a scalar, then let the scalar change itself:
1625 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1626 }
1627 else if (byte_size <= Scalar::GetMaxByteSize())
1628 {
1629 // If the value fits in a scalar, then make a new scalar and again let the
1630 // scalar code do the conversion, then figure out where to put the new value.
1631 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001632 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1633 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001634 {
Jim Ingham4b536182011-08-09 02:12:22 +00001635 switch (value_type)
1636 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001637 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001638 {
1639 // If it is a load address, then the scalar value is the storage location
1640 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001641 ExecutionContext exe_ctx (GetExecutionContextRef());
1642 Process *process = exe_ctx.GetProcessPtr();
1643 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001644 {
Greg Claytonafacd142011-09-02 01:15:17 +00001645 addr_t target_addr = m_value.GetScalar().GetRawBits64(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001646 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1647 new_scalar,
1648 byte_size,
1649 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001650 if (!error.Success())
1651 return false;
1652 if (bytes_written != byte_size)
1653 {
1654 error.SetErrorString("unable to write value to memory");
1655 return false;
1656 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001657 }
1658 }
Jim Ingham4b536182011-08-09 02:12:22 +00001659 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001660 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001661 {
1662 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1663 DataExtractor new_data;
1664 new_data.SetByteOrder (m_data.GetByteOrder());
1665
1666 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1667 m_data.SetData(buffer_sp, 0);
1668 bool success = new_scalar.GetData(new_data);
1669 if (success)
1670 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001671 new_data.CopyByteOrderedData (0,
1672 byte_size,
1673 const_cast<uint8_t *>(m_data.GetDataStart()),
1674 byte_size,
1675 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001676 }
1677 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1678
1679 }
Jim Ingham4b536182011-08-09 02:12:22 +00001680 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001681 case Value::eValueTypeFileAddress:
1682 case Value::eValueTypeScalar:
Jim Ingham16e0c682011-08-12 23:34:31 +00001683 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001684 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001685 }
1686 else
1687 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001688 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001689 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001690 }
1691 else
1692 {
1693 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001694 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001695 return false;
1696 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001697
1698 // If we have reached this point, then we have successfully changed the value.
1699 SetNeedsUpdate();
1700 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001701}
1702
Greg Clayton81e871e2012-02-04 02:27:34 +00001703bool
1704ValueObject::GetDeclaration (Declaration &decl)
1705{
1706 decl.Clear();
1707 return false;
1708}
1709
Greg Clayton84db9102012-03-26 23:03:23 +00001710ConstString
1711ValueObject::GetTypeName()
1712{
1713 return ClangASTType::GetConstTypeName (GetClangAST(), GetClangType());
1714}
1715
1716ConstString
1717ValueObject::GetQualifiedTypeName()
1718{
1719 return ClangASTType::GetConstQualifiedTypeName (GetClangAST(), GetClangType());
1720}
1721
1722
Greg Claytonafacd142011-09-02 01:15:17 +00001723LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001724ValueObject::GetObjectRuntimeLanguage ()
1725{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001726 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1727 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001728}
1729
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001730void
Jim Ingham58b59f92011-04-22 23:53:53 +00001731ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001732{
Jim Ingham58b59f92011-04-22 23:53:53 +00001733 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001734}
1735
1736ValueObjectSP
1737ValueObject::GetSyntheticChild (const ConstString &key) const
1738{
1739 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001740 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001741 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001742 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001743 return synthetic_child_sp;
1744}
1745
1746bool
1747ValueObject::IsPointerType ()
1748{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001749 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001750}
1751
Jim Inghamb7603bb2011-03-18 00:05:18 +00001752bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001753ValueObject::IsArrayType ()
1754{
1755 return ClangASTContext::IsArrayType (GetClangType());
1756}
1757
1758bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001759ValueObject::IsScalarType ()
1760{
1761 return ClangASTContext::IsScalarType (GetClangType());
1762}
1763
1764bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001765ValueObject::IsIntegerType (bool &is_signed)
1766{
1767 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1768}
Greg Clayton73b472d2010-10-27 03:32:59 +00001769
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001770bool
1771ValueObject::IsPointerOrReferenceType ()
1772{
Greg Clayton007d5be2011-05-30 00:49:24 +00001773 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1774}
1775
1776bool
Greg Claytondea8cb42011-06-29 22:09:02 +00001777ValueObject::IsPossibleDynamicType ()
1778{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00001779 ExecutionContext exe_ctx (GetExecutionContextRef());
1780 Process *process = exe_ctx.GetProcessPtr();
1781 if (process)
1782 return process->IsPossibleDynamicValue(*this);
1783 else
1784 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType());
Greg Claytondea8cb42011-06-29 22:09:02 +00001785}
1786
Greg Claytonafacd142011-09-02 01:15:17 +00001787ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001788ValueObject::GetSyntheticArrayMember (int32_t index, bool can_create)
1789{
1790 if (IsArrayType())
1791 return GetSyntheticArrayMemberFromArray(index, can_create);
1792
1793 if (IsPointerType())
1794 return GetSyntheticArrayMemberFromPointer(index, can_create);
1795
1796 return ValueObjectSP();
1797
1798}
1799
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001800ValueObjectSP
1801ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1802{
1803 ValueObjectSP synthetic_child_sp;
1804 if (IsPointerType ())
1805 {
1806 char index_str[64];
1807 snprintf(index_str, sizeof(index_str), "[%i]", index);
1808 ConstString index_const_str(index_str);
1809 // Check if we have already created a synthetic array member in this
1810 // valid object. If we have we will re-use it.
1811 synthetic_child_sp = GetSyntheticChild (index_const_str);
1812 if (!synthetic_child_sp)
1813 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001814 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001815 // We haven't made a synthetic array member for INDEX yet, so
1816 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001817 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001818
1819 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001820 if (synthetic_child)
1821 {
1822 AddSyntheticChild(index_const_str, synthetic_child);
1823 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001824 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001825 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001826 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001827 }
1828 }
1829 return synthetic_child_sp;
1830}
Jim Ingham22777012010-09-23 02:01:19 +00001831
Greg Claytondaf515f2011-07-09 20:12:33 +00001832// This allows you to create an array member using and index
1833// that doesn't not fall in the normal bounds of the array.
1834// Many times structure can be defined as:
1835// struct Collection
1836// {
1837// uint32_t item_count;
1838// Item item_array[0];
1839// };
1840// The size of the "item_array" is 1, but many times in practice
1841// there are more items in "item_array".
1842
1843ValueObjectSP
1844ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1845{
1846 ValueObjectSP synthetic_child_sp;
1847 if (IsArrayType ())
1848 {
1849 char index_str[64];
1850 snprintf(index_str, sizeof(index_str), "[%i]", index);
1851 ConstString index_const_str(index_str);
1852 // Check if we have already created a synthetic array member in this
1853 // valid object. If we have we will re-use it.
1854 synthetic_child_sp = GetSyntheticChild (index_const_str);
1855 if (!synthetic_child_sp)
1856 {
1857 ValueObject *synthetic_child;
1858 // We haven't made a synthetic array member for INDEX yet, so
1859 // lets make one and cache it for any future reference.
1860 synthetic_child = CreateChildAtIndex(0, true, index);
1861
1862 // Cache the value if we got one back...
1863 if (synthetic_child)
1864 {
1865 AddSyntheticChild(index_const_str, synthetic_child);
1866 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001867 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001868 synthetic_child_sp->m_is_array_item_for_pointer = true;
1869 }
1870 }
1871 }
1872 return synthetic_child_sp;
1873}
1874
Enrico Granata9fc19442011-07-06 02:13:41 +00001875ValueObjectSP
1876ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1877{
1878 ValueObjectSP synthetic_child_sp;
1879 if (IsScalarType ())
1880 {
1881 char index_str[64];
1882 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1883 ConstString index_const_str(index_str);
1884 // Check if we have already created a synthetic array member in this
1885 // valid object. If we have we will re-use it.
1886 synthetic_child_sp = GetSyntheticChild (index_const_str);
1887 if (!synthetic_child_sp)
1888 {
1889 ValueObjectChild *synthetic_child;
1890 // We haven't made a synthetic array member for INDEX yet, so
1891 // lets make one and cache it for any future reference.
1892 synthetic_child = new ValueObjectChild(*this,
1893 GetClangAST(),
1894 GetClangType(),
1895 index_const_str,
1896 GetByteSize(),
1897 0,
1898 to-from+1,
1899 from,
1900 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001901 false,
1902 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00001903
1904 // Cache the value if we got one back...
1905 if (synthetic_child)
1906 {
1907 AddSyntheticChild(index_const_str, synthetic_child);
1908 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001909 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00001910 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1911 }
1912 }
1913 }
1914 return synthetic_child_sp;
1915}
1916
Greg Claytonafacd142011-09-02 01:15:17 +00001917ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001918ValueObject::GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create)
1919{
1920 ValueObjectSP synthetic_child_sp;
1921 if (IsArrayType () || IsPointerType ())
1922 {
1923 char index_str[64];
1924 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1925 ConstString index_const_str(index_str);
1926 // Check if we have already created a synthetic array member in this
1927 // valid object. If we have we will re-use it.
1928 synthetic_child_sp = GetSyntheticChild (index_const_str);
1929 if (!synthetic_child_sp)
1930 {
1931 ValueObjectSynthetic *synthetic_child;
1932
1933 // We haven't made a synthetic array member for INDEX yet, so
1934 // lets make one and cache it for any future reference.
Enrico Granata061858c2012-02-15 02:34:21 +00001935 SyntheticArrayView *view = new SyntheticArrayView(SyntheticChildren::Flags());
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001936 view->AddRange(from,to);
1937 SyntheticChildrenSP view_sp(view);
1938 synthetic_child = new ValueObjectSynthetic(*this, view_sp);
1939
1940 // Cache the value if we got one back...
1941 if (synthetic_child)
1942 {
1943 AddSyntheticChild(index_const_str, synthetic_child);
1944 synthetic_child_sp = synthetic_child->GetSP();
1945 synthetic_child_sp->SetName(ConstString(index_str));
1946 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1947 }
1948 }
1949 }
1950 return synthetic_child_sp;
1951}
1952
Greg Claytonafacd142011-09-02 01:15:17 +00001953ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00001954ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
1955{
1956
1957 ValueObjectSP synthetic_child_sp;
1958
1959 char name_str[64];
1960 snprintf(name_str, sizeof(name_str), "@%i", offset);
1961 ConstString name_const_str(name_str);
1962
1963 // Check if we have already created a synthetic array member in this
1964 // valid object. If we have we will re-use it.
1965 synthetic_child_sp = GetSyntheticChild (name_const_str);
1966
1967 if (synthetic_child_sp.get())
1968 return synthetic_child_sp;
1969
1970 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00001971 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001972
1973 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
1974 type.GetASTContext(),
1975 type.GetOpaqueQualType(),
1976 name_const_str,
1977 type.GetTypeByteSize(),
1978 offset,
1979 0,
1980 0,
1981 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001982 false,
1983 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001984 if (synthetic_child)
1985 {
1986 AddSyntheticChild(name_const_str, synthetic_child);
1987 synthetic_child_sp = synthetic_child->GetSP();
1988 synthetic_child_sp->SetName(name_const_str);
1989 synthetic_child_sp->m_is_child_at_offset = true;
1990 }
1991 return synthetic_child_sp;
1992}
1993
Enrico Granatad55546b2011-07-22 00:16:08 +00001994// your expression path needs to have a leading . or ->
1995// (unless it somehow "looks like" an array, in which case it has
1996// a leading [ symbol). while the [ is meaningful and should be shown
1997// to the user, . and -> are just parser design, but by no means
1998// added information for the user.. strip them off
1999static const char*
2000SkipLeadingExpressionPathSeparators(const char* expression)
2001{
2002 if (!expression || !expression[0])
2003 return expression;
2004 if (expression[0] == '.')
2005 return expression+1;
2006 if (expression[0] == '-' && expression[1] == '>')
2007 return expression+2;
2008 return expression;
2009}
2010
Greg Claytonafacd142011-09-02 01:15:17 +00002011ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002012ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2013{
2014 ValueObjectSP synthetic_child_sp;
2015 ConstString name_const_string(expression);
2016 // Check if we have already created a synthetic array member in this
2017 // valid object. If we have we will re-use it.
2018 synthetic_child_sp = GetSyntheticChild (name_const_string);
2019 if (!synthetic_child_sp)
2020 {
2021 // We haven't made a synthetic array member for expression yet, so
2022 // lets make one and cache it for any future reference.
2023 synthetic_child_sp = GetValueForExpressionPath(expression);
2024
2025 // Cache the value if we got one back...
2026 if (synthetic_child_sp.get())
2027 {
2028 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002029 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002030 synthetic_child_sp->m_is_expression_path_child = true;
2031 }
2032 }
2033 return synthetic_child_sp;
2034}
2035
2036void
Enrico Granata86cc9822012-03-19 22:58:49 +00002037ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002038{
Enrico Granata86cc9822012-03-19 22:58:49 +00002039 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002040 return;
2041
Enrico Granatac5bc4122012-03-27 02:35:13 +00002042 TargetSP target_sp(GetTargetSP());
2043 if (target_sp && (target_sp->GetEnableSyntheticValue() == false || target_sp->GetSuppressSyntheticValue() == true))
2044 {
2045 m_synthetic_value = NULL;
2046 return;
2047 }
2048
Enrico Granata86cc9822012-03-19 22:58:49 +00002049 if (!UpdateFormatsIfNeeded(m_last_format_mgr_dynamic) && m_synthetic_value)
2050 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002051
Enrico Granata0c489f52012-03-01 04:24:26 +00002052 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002053 return;
2054
Enrico Granata86cc9822012-03-19 22:58:49 +00002055 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002056}
2057
Jim Ingham78a685a2011-04-16 00:01:13 +00002058void
Greg Claytonafacd142011-09-02 01:15:17 +00002059ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002060{
Greg Claytonafacd142011-09-02 01:15:17 +00002061 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002062 return;
2063
Jim Ingham58b59f92011-04-22 23:53:53 +00002064 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002065 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002066 ExecutionContext exe_ctx (GetExecutionContextRef());
2067 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002068 if (process && process->IsPossibleDynamicValue(*this))
2069 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002070 }
2071}
2072
Jim Ingham58b59f92011-04-22 23:53:53 +00002073ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002074ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002075{
Greg Claytonafacd142011-09-02 01:15:17 +00002076 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002077 return ValueObjectSP();
2078
2079 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002080 {
Jim Ingham2837b762011-05-04 03:43:18 +00002081 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002082 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002083 if (m_dynamic_value)
2084 return m_dynamic_value->GetSP();
2085 else
2086 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002087}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002088
Jim Ingham60dbabb2011-12-08 19:44:08 +00002089ValueObjectSP
2090ValueObject::GetStaticValue()
2091{
2092 return GetSP();
2093}
2094
Enrico Granata886147f2012-05-08 18:47:08 +00002095lldb::ValueObjectSP
2096ValueObject::GetNonSyntheticValue ()
2097{
2098 return GetSP();
2099}
2100
Enrico Granatad55546b2011-07-22 00:16:08 +00002101ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002102ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002103{
Enrico Granata86cc9822012-03-19 22:58:49 +00002104 if (use_synthetic == false)
2105 return ValueObjectSP();
2106
Enrico Granatad55546b2011-07-22 00:16:08 +00002107 CalculateSyntheticValue(use_synthetic);
2108
2109 if (m_synthetic_value)
2110 return m_synthetic_value->GetSP();
2111 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002112 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002113}
2114
Greg Claytone221f822011-01-21 01:59:00 +00002115bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002116ValueObject::HasSyntheticValue()
2117{
2118 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
2119
Enrico Granata0c489f52012-03-01 04:24:26 +00002120 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002121 return false;
2122
Enrico Granata86cc9822012-03-19 22:58:49 +00002123 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002124
2125 if (m_synthetic_value)
2126 return true;
2127 else
2128 return false;
2129}
2130
2131bool
Greg Claytone221f822011-01-21 01:59:00 +00002132ValueObject::GetBaseClassPath (Stream &s)
2133{
2134 if (IsBaseClass())
2135 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002136 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00002137 clang_type_t clang_type = GetClangType();
2138 std::string cxx_class_name;
2139 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
2140 if (this_had_base_class)
2141 {
2142 if (parent_had_base_class)
2143 s.PutCString("::");
2144 s.PutCString(cxx_class_name.c_str());
2145 }
2146 return parent_had_base_class || this_had_base_class;
2147 }
2148 return false;
2149}
2150
2151
2152ValueObject *
2153ValueObject::GetNonBaseClassParent()
2154{
Jim Ingham78a685a2011-04-16 00:01:13 +00002155 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002156 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002157 if (GetParent()->IsBaseClass())
2158 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002159 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002160 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002161 }
2162 return NULL;
2163}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002164
2165void
Enrico Granata4becb372011-06-29 22:27:15 +00002166ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002167{
Greg Claytone221f822011-01-21 01:59:00 +00002168 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002169
Enrico Granata86cc9822012-03-19 22:58:49 +00002170 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002171 {
Enrico Granata4becb372011-06-29 22:27:15 +00002172 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2173 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2174 // the eHonorPointers mode is meant to produce strings in this latter format
2175 s.PutCString("*(");
2176 }
Greg Claytone221f822011-01-21 01:59:00 +00002177
Enrico Granata4becb372011-06-29 22:27:15 +00002178 ValueObject* parent = GetParent();
2179
2180 if (parent)
2181 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002182
2183 // if we are a deref_of_parent just because we are synthetic array
2184 // members made up to allow ptr[%d] syntax to work in variable
2185 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002186 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002187 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002188
Greg Claytone221f822011-01-21 01:59:00 +00002189 if (!IsBaseClass())
2190 {
2191 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002192 {
Greg Claytone221f822011-01-21 01:59:00 +00002193 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2194 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002195 {
Greg Claytone221f822011-01-21 01:59:00 +00002196 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2197 if (non_base_class_parent_clang_type)
2198 {
2199 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2200
Enrico Granata86cc9822012-03-19 22:58:49 +00002201 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002202 {
2203 s.PutCString("->");
2204 }
Enrico Granata4becb372011-06-29 22:27:15 +00002205 else
2206 {
2207 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2208 {
2209 s.PutCString("->");
2210 }
2211 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2212 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2213 {
2214 s.PutChar('.');
2215 }
Greg Claytone221f822011-01-21 01:59:00 +00002216 }
2217 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002218 }
Greg Claytone221f822011-01-21 01:59:00 +00002219
2220 const char *name = GetName().GetCString();
2221 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002222 {
Greg Claytone221f822011-01-21 01:59:00 +00002223 if (qualify_cxx_base_classes)
2224 {
2225 if (GetBaseClassPath (s))
2226 s.PutCString("::");
2227 }
2228 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002229 }
2230 }
2231 }
2232
Enrico Granata86cc9822012-03-19 22:58:49 +00002233 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002234 {
Greg Claytone221f822011-01-21 01:59:00 +00002235 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002236 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002237}
2238
Greg Claytonafacd142011-09-02 01:15:17 +00002239ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002240ValueObject::GetValueForExpressionPath(const char* expression,
2241 const char** first_unparsed,
2242 ExpressionPathScanEndReason* reason_to_stop,
2243 ExpressionPathEndResultType* final_value_type,
2244 const GetValueForExpressionPathOptions& options,
2245 ExpressionPathAftermath* final_task_on_target)
2246{
2247
2248 const char* dummy_first_unparsed;
2249 ExpressionPathScanEndReason dummy_reason_to_stop;
2250 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002251 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002252
2253 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2254 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2255 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2256 final_value_type ? final_value_type : &dummy_final_value_type,
2257 options,
2258 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2259
Enrico Granata86cc9822012-03-19 22:58:49 +00002260 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002261 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002262
Enrico Granata86cc9822012-03-19 22:58:49 +00002263 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 +00002264 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002265 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002266 {
2267 Error error;
2268 ValueObjectSP final_value = ret_val->Dereference(error);
2269 if (error.Fail() || !final_value.get())
2270 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002271 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002272 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002273 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002274 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002275 return ValueObjectSP();
2276 }
2277 else
2278 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002279 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002280 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002281 return final_value;
2282 }
2283 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002284 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002285 {
2286 Error error;
2287 ValueObjectSP final_value = ret_val->AddressOf(error);
2288 if (error.Fail() || !final_value.get())
2289 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002290 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002291 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002292 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002293 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002294 return ValueObjectSP();
2295 }
2296 else
2297 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002298 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002299 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002300 return final_value;
2301 }
2302 }
2303 }
2304 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2305}
2306
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002307int
2308ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002309 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002310 const char** first_unparsed,
2311 ExpressionPathScanEndReason* reason_to_stop,
2312 ExpressionPathEndResultType* final_value_type,
2313 const GetValueForExpressionPathOptions& options,
2314 ExpressionPathAftermath* final_task_on_target)
2315{
2316 const char* dummy_first_unparsed;
2317 ExpressionPathScanEndReason dummy_reason_to_stop;
2318 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002319 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002320
2321 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2322 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2323 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2324 final_value_type ? final_value_type : &dummy_final_value_type,
2325 options,
2326 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2327
2328 if (!ret_val.get()) // if there are errors, I add nothing to the list
2329 return 0;
2330
Enrico Granata86ea8d82012-03-29 01:34:34 +00002331 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002332 {
2333 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002334 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002335 {
2336 list->Append(ret_val);
2337 return 1;
2338 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002339 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 +00002340 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002341 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002342 {
2343 Error error;
2344 ValueObjectSP final_value = ret_val->Dereference(error);
2345 if (error.Fail() || !final_value.get())
2346 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002347 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2348 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002349 return 0;
2350 }
2351 else
2352 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002353 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002354 list->Append(final_value);
2355 return 1;
2356 }
2357 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002358 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002359 {
2360 Error error;
2361 ValueObjectSP final_value = ret_val->AddressOf(error);
2362 if (error.Fail() || !final_value.get())
2363 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002364 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2365 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002366 return 0;
2367 }
2368 else
2369 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002370 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002371 list->Append(final_value);
2372 return 1;
2373 }
2374 }
2375 }
2376 }
2377 else
2378 {
2379 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2380 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2381 ret_val,
2382 list,
2383 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2384 final_value_type ? final_value_type : &dummy_final_value_type,
2385 options,
2386 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2387 }
2388 // in any non-covered case, just do the obviously right thing
2389 list->Append(ret_val);
2390 return 1;
2391}
2392
Greg Claytonafacd142011-09-02 01:15:17 +00002393ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002394ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2395 const char** first_unparsed,
2396 ExpressionPathScanEndReason* reason_to_stop,
2397 ExpressionPathEndResultType* final_result,
2398 const GetValueForExpressionPathOptions& options,
2399 ExpressionPathAftermath* what_next)
2400{
2401 ValueObjectSP root = GetSP();
2402
2403 if (!root.get())
2404 return ValueObjectSP();
2405
2406 *first_unparsed = expression_cstr;
2407
2408 while (true)
2409 {
2410
2411 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2412
Greg Claytonafacd142011-09-02 01:15:17 +00002413 clang_type_t root_clang_type = root->GetClangType();
2414 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002415 Flags root_clang_type_info,pointee_clang_type_info;
2416
2417 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2418 if (pointee_clang_type)
2419 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002420
2421 if (!expression_cstr || *expression_cstr == '\0')
2422 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002423 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002424 return root;
2425 }
2426
2427 switch (*expression_cstr)
2428 {
2429 case '-':
2430 {
2431 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002432 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 +00002433 {
2434 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002435 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2436 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002437 return ValueObjectSP();
2438 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002439 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2440 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002441 options.m_no_fragile_ivar)
2442 {
2443 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002444 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2445 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002446 return ValueObjectSP();
2447 }
2448 if (expression_cstr[1] != '>')
2449 {
2450 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002451 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2452 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002453 return ValueObjectSP();
2454 }
2455 expression_cstr++; // skip the -
2456 }
2457 case '.': // or fallthrough from ->
2458 {
2459 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002460 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 +00002461 {
2462 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002463 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2464 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002465 return ValueObjectSP();
2466 }
2467 expression_cstr++; // skip .
2468 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2469 ConstString child_name;
2470 if (!next_separator) // if no other separator just expand this last layer
2471 {
2472 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002473 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2474
2475 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002476 {
2477 *first_unparsed = '\0';
Enrico Granata86cc9822012-03-19 22:58:49 +00002478 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2479 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002480 return child_valobj_sp;
2481 }
2482 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2483 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002484 if (root->IsSynthetic())
2485 child_valobj_sp = root;
2486 else
2487 child_valobj_sp = root->GetSyntheticValue();
2488
2489 if (child_valobj_sp.get())
2490 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002491 }
2492
2493 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2494 // so we hit the "else" branch, and return an error
2495 if(child_valobj_sp.get()) // if it worked, just return
2496 {
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;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002501 }
2502 else
2503 {
2504 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002505 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2506 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002507 return ValueObjectSP();
2508 }
2509 }
2510 else // other layers do expand
2511 {
2512 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002513 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2514 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002515 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002516 root = child_valobj_sp;
2517 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002518 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002519 continue;
2520 }
2521 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2522 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002523 child_valobj_sp = root->GetSyntheticValue(true);
2524 if (child_valobj_sp)
2525 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002526 }
2527
2528 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2529 // so we hit the "else" branch, and return an error
2530 if(child_valobj_sp.get()) // if it worked, move on
2531 {
2532 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002533 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002534 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002535 continue;
2536 }
2537 else
2538 {
2539 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002540 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2541 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002542 return ValueObjectSP();
2543 }
2544 }
2545 break;
2546 }
2547 case '[':
2548 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002549 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 +00002550 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002551 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002552 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002553 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2554 {
2555 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002556 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2557 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002558 return ValueObjectSP();
2559 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002560 }
2561 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2562 {
2563 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002564 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2565 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002566 return ValueObjectSP();
2567 }
2568 }
2569 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2570 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002571 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002572 {
2573 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002574 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2575 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002576 return ValueObjectSP();
2577 }
2578 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2579 {
2580 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002581 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2582 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002583 return root;
2584 }
2585 }
2586 const char *separator_position = ::strchr(expression_cstr+1,'-');
2587 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2588 if (!close_bracket_position) // if there is no ], this is a syntax error
2589 {
2590 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002591 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2592 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002593 return ValueObjectSP();
2594 }
2595 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2596 {
2597 char *end = NULL;
2598 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2599 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2600 {
2601 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002602 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2603 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002604 return ValueObjectSP();
2605 }
2606 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2607 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002608 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002609 {
2610 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002611 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2612 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002613 return root;
2614 }
2615 else
2616 {
2617 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002618 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2619 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002620 return ValueObjectSP();
2621 }
2622 }
2623 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002624 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002625 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002626 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2627 if (!child_valobj_sp)
2628 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002629 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002630 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2631 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002632 if (child_valobj_sp)
2633 {
2634 root = child_valobj_sp;
2635 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002636 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002637 continue;
2638 }
2639 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002640 {
2641 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002642 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2643 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002644 return ValueObjectSP();
2645 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002646 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002647 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002648 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002649 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 +00002650 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002651 {
2652 Error error;
2653 root = root->Dereference(error);
2654 if (error.Fail() || !root.get())
2655 {
2656 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002657 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2658 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002659 return ValueObjectSP();
2660 }
2661 else
2662 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002663 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002664 continue;
2665 }
2666 }
2667 else
2668 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002669 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Clayton84db9102012-03-26 23:03:23 +00002670 root->GetClangType()) == eLanguageTypeObjC
2671 && ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2672 && root->HasSyntheticValue()
2673 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002674 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002675 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002676 }
2677 else
2678 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002679 if (!root.get())
2680 {
2681 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002682 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2683 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002684 return ValueObjectSP();
2685 }
2686 else
2687 {
2688 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002689 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002690 continue;
2691 }
2692 }
2693 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002694 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002695 {
2696 root = root->GetSyntheticBitFieldChild(index, index, true);
2697 if (!root.get())
2698 {
2699 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002700 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2701 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002702 return ValueObjectSP();
2703 }
2704 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2705 {
2706 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002707 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2708 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002709 return root;
2710 }
2711 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002712 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002713 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002714 if (root->HasSyntheticValue())
2715 root = root->GetSyntheticValue();
2716 else if (!root->IsSynthetic())
2717 {
2718 *first_unparsed = expression_cstr;
2719 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2720 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2721 return ValueObjectSP();
2722 }
2723 // if we are here, then root itself is a synthetic VO.. should be good to go
2724
Enrico Granata27b625e2011-08-09 01:04:56 +00002725 if (!root.get())
2726 {
2727 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002728 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2729 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2730 return ValueObjectSP();
2731 }
2732 root = root->GetChildAtIndex(index, true);
2733 if (!root.get())
2734 {
2735 *first_unparsed = expression_cstr;
2736 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2737 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002738 return ValueObjectSP();
2739 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002740 else
2741 {
2742 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002743 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002744 continue;
2745 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002746 }
2747 else
2748 {
2749 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002750 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2751 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002752 return ValueObjectSP();
2753 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002754 }
2755 else // we have a low and a high index
2756 {
2757 char *end = NULL;
2758 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2759 if (!end || end != separator_position) // if something weird is in our way return an error
2760 {
2761 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002762 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2763 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002764 return ValueObjectSP();
2765 }
2766 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2767 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2768 {
2769 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002770 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2771 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002772 return ValueObjectSP();
2773 }
2774 if (index_lower > index_higher) // swap indices if required
2775 {
2776 unsigned long temp = index_lower;
2777 index_lower = index_higher;
2778 index_higher = temp;
2779 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002780 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002781 {
2782 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2783 if (!root.get())
2784 {
2785 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002786 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2787 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002788 return ValueObjectSP();
2789 }
2790 else
2791 {
2792 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002793 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2794 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002795 return root;
2796 }
2797 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002798 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 +00002799 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002800 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002801 {
2802 Error error;
2803 root = root->Dereference(error);
2804 if (error.Fail() || !root.get())
2805 {
2806 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002807 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2808 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002809 return ValueObjectSP();
2810 }
2811 else
2812 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002813 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002814 continue;
2815 }
2816 }
2817 else
2818 {
2819 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002820 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2821 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002822 return root;
2823 }
2824 }
2825 break;
2826 }
2827 default: // some non-separator is in the way
2828 {
2829 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002830 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2831 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002832 return ValueObjectSP();
2833 break;
2834 }
2835 }
2836 }
2837}
2838
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002839int
2840ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2841 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002842 ValueObjectSP root,
2843 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002844 ExpressionPathScanEndReason* reason_to_stop,
2845 ExpressionPathEndResultType* final_result,
2846 const GetValueForExpressionPathOptions& options,
2847 ExpressionPathAftermath* what_next)
2848{
2849 if (!root.get())
2850 return 0;
2851
2852 *first_unparsed = expression_cstr;
2853
2854 while (true)
2855 {
2856
2857 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2858
Greg Claytonafacd142011-09-02 01:15:17 +00002859 clang_type_t root_clang_type = root->GetClangType();
2860 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002861 Flags root_clang_type_info,pointee_clang_type_info;
2862
2863 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2864 if (pointee_clang_type)
2865 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2866
2867 if (!expression_cstr || *expression_cstr == '\0')
2868 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002869 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002870 list->Append(root);
2871 return 1;
2872 }
2873
2874 switch (*expression_cstr)
2875 {
2876 case '[':
2877 {
2878 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2879 {
2880 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2881 {
2882 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002883 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2884 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002885 return 0;
2886 }
2887 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2888 {
2889 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002890 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2891 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002892 return 0;
2893 }
2894 }
2895 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2896 {
2897 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2898 {
2899 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002900 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2901 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002902 return 0;
2903 }
2904 else // expand this into list
2905 {
2906 int max_index = root->GetNumChildren() - 1;
2907 for (int index = 0; index < max_index; index++)
2908 {
2909 ValueObjectSP child =
2910 root->GetChildAtIndex(index, true);
2911 list->Append(child);
2912 }
2913 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002914 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
2915 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002916 return max_index; // tell me number of items I added to the VOList
2917 }
2918 }
2919 const char *separator_position = ::strchr(expression_cstr+1,'-');
2920 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2921 if (!close_bracket_position) // if there is no ], this is a syntax error
2922 {
2923 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002924 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2925 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002926 return 0;
2927 }
2928 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2929 {
2930 char *end = NULL;
2931 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2932 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2933 {
2934 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002935 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2936 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002937 return 0;
2938 }
2939 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2940 {
2941 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2942 {
2943 int max_index = root->GetNumChildren() - 1;
2944 for (int index = 0; index < max_index; index++)
2945 {
2946 ValueObjectSP child =
2947 root->GetChildAtIndex(index, true);
2948 list->Append(child);
2949 }
2950 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002951 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
2952 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002953 return max_index; // tell me number of items I added to the VOList
2954 }
2955 else
2956 {
2957 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002958 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2959 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002960 return 0;
2961 }
2962 }
2963 // from here on we do have a valid index
2964 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2965 {
2966 root = root->GetChildAtIndex(index, true);
2967 if (!root.get())
2968 {
2969 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002970 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2971 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002972 return 0;
2973 }
2974 else
2975 {
2976 list->Append(root);
2977 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002978 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
2979 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002980 return 1;
2981 }
2982 }
2983 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
2984 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002985 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 +00002986 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
2987 {
2988 Error error;
2989 root = root->Dereference(error);
2990 if (error.Fail() || !root.get())
2991 {
2992 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002993 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2994 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002995 return 0;
2996 }
2997 else
2998 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002999 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003000 continue;
3001 }
3002 }
3003 else
3004 {
3005 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3006 if (!root.get())
3007 {
3008 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003009 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3010 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003011 return 0;
3012 }
3013 else
3014 {
3015 list->Append(root);
3016 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003017 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3018 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003019 return 1;
3020 }
3021 }
3022 }
3023 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3024 {
3025 root = root->GetSyntheticBitFieldChild(index, 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 // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
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 // we have a low and a high index
3044 {
3045 char *end = NULL;
3046 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3047 if (!end || end != separator_position) // if something weird is in our way return an error
3048 {
3049 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003050 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3051 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003052 return 0;
3053 }
3054 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3055 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3056 {
3057 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003058 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3059 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003060 return 0;
3061 }
3062 if (index_lower > index_higher) // swap indices if required
3063 {
3064 unsigned long temp = index_lower;
3065 index_lower = index_higher;
3066 index_higher = temp;
3067 }
3068 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
3069 {
3070 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3071 if (!root.get())
3072 {
3073 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003074 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3075 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003076 return 0;
3077 }
3078 else
3079 {
3080 list->Append(root);
3081 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003082 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3083 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003084 return 1;
3085 }
3086 }
3087 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 +00003088 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003089 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3090 {
3091 Error error;
3092 root = root->Dereference(error);
3093 if (error.Fail() || !root.get())
3094 {
3095 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003096 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3097 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003098 return 0;
3099 }
3100 else
3101 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003102 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003103 continue;
3104 }
3105 }
3106 else
3107 {
Johnny Chen44805302011-07-19 19:48:13 +00003108 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003109 index <= index_higher; index++)
3110 {
3111 ValueObjectSP child =
3112 root->GetChildAtIndex(index, true);
3113 list->Append(child);
3114 }
3115 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003116 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3117 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003118 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3119 }
3120 }
3121 break;
3122 }
3123 default: // some non-[ separator, or something entirely wrong, is in the way
3124 {
3125 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003126 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3127 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003128 return 0;
3129 break;
3130 }
3131 }
3132 }
3133}
3134
Enrico Granata0c489f52012-03-01 04:24:26 +00003135static void
3136DumpValueObject_Impl (Stream &s,
3137 ValueObject *valobj,
3138 const ValueObject::DumpValueObjectOptions& options,
3139 uint32_t ptr_depth,
3140 uint32_t curr_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003141{
Greg Clayton007d5be2011-05-30 00:49:24 +00003142 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003143 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003144 bool update_success = valobj->UpdateValueIfNeeded (options.m_use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00003145
Enrico Granata0c489f52012-03-01 04:24:26 +00003146 const char *root_valobj_name =
3147 options.m_root_valobj_name.empty() ?
3148 valobj->GetName().AsCString() :
3149 options.m_root_valobj_name.c_str();
3150
3151 if (update_success && options.m_use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00003152 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003153 ValueObject *dynamic_value = valobj->GetDynamicValue(options.m_use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003154 if (dynamic_value)
3155 valobj = dynamic_value;
3156 }
3157
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003158 clang_type_t clang_type = valobj->GetClangType();
3159
Greg Clayton73b472d2010-10-27 03:32:59 +00003160 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003161 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00003162 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
3163 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003164
Enrico Granata0c489f52012-03-01 04:24:26 +00003165 const bool print_valobj = options.m_flat_output == false || has_value;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003166
3167 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003168 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003169 if (options.m_show_location)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003170 {
Jim Ingham6035b672011-03-31 00:19:25 +00003171 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003172 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003173
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003174 s.Indent();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003175
Greg Clayton7c8a9662010-11-02 01:50:16 +00003176 // Always show the type for the top level items.
Enrico Granata0c489f52012-03-01 04:24:26 +00003177 if (options.m_show_types || (curr_depth == 0 && !options.m_flat_output))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003178 {
Greg Clayton84db9102012-03-26 23:03:23 +00003179 const char* typeName = valobj->GetQualifiedTypeName().AsCString("<invalid type>");
3180 //const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
Enrico Granata9910bc82011-08-03 02:18:51 +00003181 s.Printf("(%s", typeName);
3182 // only show dynamic types if the user really wants to see types
Enrico Granata0c489f52012-03-01 04:24:26 +00003183 if (options.m_show_types && options.m_use_dynamic != eNoDynamicValues &&
Enrico Granata9910bc82011-08-03 02:18:51 +00003184 (/*strstr(typeName, "id") == typeName ||*/
Greg Claytonafacd142011-09-02 01:15:17 +00003185 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003186 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003187 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3188 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatac3e320a2011-08-02 17:27:39 +00003189 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003190 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003191 else
3192 {
3193 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
3194 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003195 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003196 else
3197 {
3198 ObjCLanguageRuntime::ObjCISA isa = runtime->GetISA(*valobj);
3199 if (!runtime->IsValidISA(isa))
Enrico Granata9910bc82011-08-03 02:18:51 +00003200 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003201 else
3202 s.Printf(", dynamic type: %s) ",
3203 runtime->GetActualTypeName(isa).GetCString());
3204 }
3205 }
3206 }
3207 else
3208 s.Printf(") ");
3209 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003210
Greg Clayton1d3afba2010-10-05 00:00:42 +00003211
Enrico Granata0c489f52012-03-01 04:24:26 +00003212 if (options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003213 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003214 // If we are showing types, also qualify the C++ base classes
Enrico Granata0c489f52012-03-01 04:24:26 +00003215 const bool qualify_cxx_base_classes = options.m_show_types;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003216 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003217 s.PutCString(" =");
3218 }
3219 else
3220 {
3221 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3222 s.Printf ("%s =", name_cstr);
3223 }
3224
Enrico Granata0c489f52012-03-01 04:24:26 +00003225 if (!options.m_scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003226 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003227 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003228 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003229 }
3230
Enrico Granata0c489f52012-03-01 04:24:26 +00003231 std::string summary_str;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003232 std::string value_str;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003233 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003234 const char *sum_cstr = NULL;
Enrico Granata0c489f52012-03-01 04:24:26 +00003235 TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003236
Enrico Granata0c489f52012-03-01 04:24:26 +00003237 if (options.m_omit_summary_depth > 0)
Enrico Granata0c5ef692011-07-16 01:22:04 +00003238 entry = NULL;
3239
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003240 if (err_cstr == NULL)
3241 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003242 if (options.m_format != eFormatDefault && options.m_format != valobj->GetFormat())
Greg Clayton6efba4f2012-01-26 21:08:30 +00003243 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003244 valobj->GetValueAsCString(options.m_format,
3245 value_str);
Greg Clayton6efba4f2012-01-26 21:08:30 +00003246 }
Enrico Granata0c489f52012-03-01 04:24:26 +00003247 else
Greg Clayton6efba4f2012-01-26 21:08:30 +00003248 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003249 val_cstr = valobj->GetValueAsCString();
3250 if (val_cstr)
3251 value_str = val_cstr;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003252 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003253 err_cstr = valobj->GetError().AsCString();
3254 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003255
3256 if (err_cstr)
3257 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003258 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003259 }
3260 else
3261 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003262 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003263 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003264 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003265 if (options.m_omit_summary_depth == 0)
3266 {
3267 if (options.m_summary_sp)
3268 {
3269 valobj->GetSummaryAsCString(entry, summary_str);
3270 sum_cstr = summary_str.c_str();
3271 }
3272 else
3273 sum_cstr = valobj->GetSummaryAsCString();
3274 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003275
Greg Clayton6efba4f2012-01-26 21:08:30 +00003276 // Make sure we have a value and make sure the summary didn't
3277 // specify that the value should not be printed
3278 if (!value_str.empty() && (entry == NULL || entry->DoesPrintValue() || sum_cstr == NULL))
3279 s.Printf(" %s", value_str.c_str());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003280
Enrico Granata9dd75c82011-07-15 23:30:15 +00003281 if (sum_cstr)
Enrico Granata0c489f52012-03-01 04:24:26 +00003282 s.Printf(" %s", sum_cstr);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003283
Enrico Granata0c489f52012-03-01 04:24:26 +00003284 if (options.m_use_objc)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003285 {
Jim Ingham6035b672011-03-31 00:19:25 +00003286 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003287 if (object_desc)
3288 s.Printf(" %s\n", object_desc);
3289 else
Sean Callanan672ad942010-10-23 00:18:49 +00003290 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003291 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003292 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003293 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003294
Enrico Granata0c489f52012-03-01 04:24:26 +00003295 if (curr_depth < options.m_max_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003296 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003297 // We will show children for all concrete types. We won't show
3298 // pointer contents unless a pointer depth has been specified.
3299 // We won't reference contents unless the reference is the
3300 // root object (depth of zero).
3301 bool print_children = true;
3302
3303 // Use a new temporary pointer depth in case we override the
3304 // current pointer depth below...
3305 uint32_t curr_ptr_depth = ptr_depth;
3306
3307 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3308 if (is_ptr || is_ref)
3309 {
3310 // We have a pointer or reference whose value is an address.
3311 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003312 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003313 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003314 print_children = false;
3315
3316 else if (is_ref && curr_depth == 0)
3317 {
3318 // If this is the root object (depth is zero) that we are showing
3319 // and it is a reference, and no pointer depth has been supplied
3320 // print out what it references. Don't do this at deeper depths
3321 // otherwise we can end up with infinite recursion...
3322 curr_ptr_depth = 1;
3323 }
3324
3325 if (curr_ptr_depth == 0)
3326 print_children = false;
3327 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003328
Enrico Granata0a3958e2011-07-02 00:25:22 +00003329 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003330 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003331 ValueObject* synth_valobj;
3332 ValueObjectSP synth_valobj_sp = valobj->GetSyntheticValue (options.m_use_synthetic);
3333 synth_valobj = (synth_valobj_sp ? synth_valobj_sp.get() : valobj);
Enrico Granatac5bc4122012-03-27 02:35:13 +00003334
Enrico Granatac482a192011-08-17 22:13:59 +00003335 uint32_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003336 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003337 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003338 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003339 if (options.m_flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003340 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003341 if (print_valobj)
3342 s.EOL();
3343 }
3344 else
3345 {
3346 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003347 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003348 s.IndentMore();
3349 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003350
Greg Claytoncc4d0142012-02-17 07:49:44 +00003351 uint32_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00003352
Enrico Granata0c489f52012-03-01 04:24:26 +00003353 if (num_children > max_num_children && !options.m_ignore_cap)
Enrico Granata22c55d12011-08-12 02:00:06 +00003354 {
3355 num_children = max_num_children;
3356 print_dotdotdot = true;
3357 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003358
Enrico Granata0c489f52012-03-01 04:24:26 +00003359 ValueObject::DumpValueObjectOptions child_options(options);
3360 child_options.SetFormat().SetSummary().SetRootValueObjectName();
3361 child_options.SetScopeChecked(true)
3362 .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003363 for (uint32_t idx=0; idx<num_children; ++idx)
3364 {
Enrico Granatac482a192011-08-17 22:13:59 +00003365 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003366 if (child_sp.get())
3367 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003368 DumpValueObject_Impl (s,
3369 child_sp.get(),
3370 child_options,
3371 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
3372 curr_depth + 1);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003373 }
3374 }
3375
Enrico Granata0c489f52012-03-01 04:24:26 +00003376 if (!options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003377 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003378 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003379 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003380 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3381 Target *target = exe_ctx.GetTargetPtr();
3382 if (target)
3383 target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003384 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003385 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003386 s.IndentLess();
3387 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003388 }
3389 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003390 else if (has_children)
3391 {
3392 // Aggregate, no children...
3393 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003394 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003395 }
3396 else
3397 {
3398 if (print_valobj)
3399 s.EOL();
3400 }
3401
Greg Clayton1d3afba2010-10-05 00:00:42 +00003402 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003403 else
3404 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003405 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003406 }
3407 }
3408 else
3409 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003410 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003411 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003412 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003413 }
3414 }
3415 }
3416 }
3417}
3418
Enrico Granata0c489f52012-03-01 04:24:26 +00003419void
Greg Claytonf830dbb2012-03-22 18:15:37 +00003420ValueObject::LogValueObject (Log *log,
3421 ValueObject *valobj)
3422{
3423 if (log && valobj)
3424 return LogValueObject (log, valobj, DumpValueObjectOptions::DefaultOptions());
3425}
3426
3427void
3428ValueObject::LogValueObject (Log *log,
3429 ValueObject *valobj,
3430 const DumpValueObjectOptions& options)
3431{
3432 if (log && valobj)
3433 {
3434 StreamString s;
3435 ValueObject::DumpValueObject (s, valobj, options);
3436 if (s.GetSize())
3437 log->PutCString(s.GetData());
3438 }
3439}
3440
3441void
Enrico Granata0c489f52012-03-01 04:24:26 +00003442ValueObject::DumpValueObject (Stream &s,
3443 ValueObject *valobj)
3444{
3445
3446 if (!valobj)
3447 return;
3448
3449 DumpValueObject_Impl(s,
3450 valobj,
3451 DumpValueObjectOptions::DefaultOptions(),
3452 0,
3453 0);
3454}
3455
3456void
3457ValueObject::DumpValueObject (Stream &s,
3458 ValueObject *valobj,
3459 const DumpValueObjectOptions& options)
3460{
3461 DumpValueObject_Impl(s,
3462 valobj,
3463 options,
3464 options.m_max_ptr_depth, // max pointer depth allowed, we will go down from here
3465 0 // current object depth is 0 since we are just starting
3466 );
3467}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003468
3469ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003470ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003471{
3472 ValueObjectSP valobj_sp;
3473
Enrico Granatac3e320a2011-08-02 17:27:39 +00003474 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003475 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003476 ExecutionContext exe_ctx (GetExecutionContextRef());
3477 clang::ASTContext *ast = GetClangAST ();
3478
3479 DataExtractor data;
3480 data.SetByteOrder (m_data.GetByteOrder());
3481 data.SetAddressByteSize(m_data.GetAddressByteSize());
3482
Enrico Granata9f1e2042012-04-24 22:15:37 +00003483 if (IsBitfield())
3484 {
3485 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
3486 m_error = v.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
3487 }
3488 else
3489 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003490
3491 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3492 ast,
3493 GetClangType(),
3494 name,
3495 data,
3496 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003497 }
Jim Ingham6035b672011-03-31 00:19:25 +00003498
3499 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003500 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003501 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003502 }
3503 return valobj_sp;
3504}
3505
Greg Claytonafacd142011-09-02 01:15:17 +00003506ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003507ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003508{
Jim Ingham58b59f92011-04-22 23:53:53 +00003509 if (m_deref_valobj)
3510 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003511
Greg Clayton54979cd2010-12-15 05:08:08 +00003512 const bool is_pointer_type = IsPointerType();
3513 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003514 {
3515 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003516 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003517
3518 std::string child_name_str;
3519 uint32_t child_byte_size = 0;
3520 int32_t child_byte_offset = 0;
3521 uint32_t child_bitfield_bit_size = 0;
3522 uint32_t child_bitfield_bit_offset = 0;
3523 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003524 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003525 const bool transparent_pointers = false;
3526 clang::ASTContext *clang_ast = GetClangAST();
3527 clang_type_t clang_type = GetClangType();
3528 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003529
Greg Claytoncc4d0142012-02-17 07:49:44 +00003530 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003531
3532 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3533 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003534 GetName().GetCString(),
3535 clang_type,
3536 0,
3537 transparent_pointers,
3538 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003539 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003540 child_name_str,
3541 child_byte_size,
3542 child_byte_offset,
3543 child_bitfield_bit_size,
3544 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003545 child_is_base_class,
3546 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003547 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003548 {
3549 ConstString child_name;
3550 if (!child_name_str.empty())
3551 child_name.SetCString (child_name_str.c_str());
3552
Jim Ingham58b59f92011-04-22 23:53:53 +00003553 m_deref_valobj = new ValueObjectChild (*this,
3554 clang_ast,
3555 child_clang_type,
3556 child_name,
3557 child_byte_size,
3558 child_byte_offset,
3559 child_bitfield_bit_size,
3560 child_bitfield_bit_offset,
3561 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003562 child_is_deref_of_parent,
3563 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003564 }
3565 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003566
Jim Ingham58b59f92011-04-22 23:53:53 +00003567 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003568 {
3569 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003570 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003571 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003572 else
3573 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003574 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003575 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003576
3577 if (is_pointer_type)
3578 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3579 else
3580 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003581 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003582 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003583}
3584
Greg Claytonafacd142011-09-02 01:15:17 +00003585ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003586ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003587{
Jim Ingham78a685a2011-04-16 00:01:13 +00003588 if (m_addr_of_valobj_sp)
3589 return m_addr_of_valobj_sp;
3590
Greg Claytone0d378b2011-03-24 21:19:54 +00003591 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003592 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003593 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003594 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003595 if (addr != LLDB_INVALID_ADDRESS)
3596 {
3597 switch (address_type)
3598 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003599 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003600 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003601 {
3602 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003603 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003604 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3605 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003606 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003607
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003608 case eAddressTypeFile:
3609 case eAddressTypeLoad:
3610 case eAddressTypeHost:
3611 {
3612 clang::ASTContext *ast = GetClangAST();
3613 clang_type_t clang_type = GetClangType();
3614 if (ast && clang_type)
3615 {
3616 std::string name (1, '&');
3617 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003618 ExecutionContext exe_ctx (GetExecutionContextRef());
3619 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003620 ast,
3621 ClangASTContext::CreatePointerType (ast, clang_type),
3622 ConstString (name.c_str()),
3623 addr,
3624 eAddressTypeInvalid,
3625 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003626 }
3627 }
3628 break;
3629 }
3630 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003631 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003632}
3633
Greg Clayton9a142cf2012-02-03 05:34:10 +00003634ValueObjectSP
3635ValueObject::Cast (const ClangASTType &clang_ast_type)
3636{
Greg Clayton81e871e2012-02-04 02:27:34 +00003637 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003638}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003639
Greg Claytonafacd142011-09-02 01:15:17 +00003640ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003641ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3642{
Greg Claytonafacd142011-09-02 01:15:17 +00003643 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003644 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003645 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003646
3647 if (ptr_value != LLDB_INVALID_ADDRESS)
3648 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003649 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003650 ExecutionContext exe_ctx (GetExecutionContextRef());
3651 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003652 name,
3653 ptr_addr,
3654 clang_ast_type);
3655 }
3656 return valobj_sp;
3657}
3658
Greg Claytonafacd142011-09-02 01:15:17 +00003659ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003660ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3661{
Greg Claytonafacd142011-09-02 01:15:17 +00003662 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003663 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003664 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003665
3666 if (ptr_value != LLDB_INVALID_ADDRESS)
3667 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003668 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003669 ExecutionContext exe_ctx (GetExecutionContextRef());
3670 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003671 name,
3672 ptr_addr,
3673 type_sp);
3674 }
3675 return valobj_sp;
3676}
3677
Jim Ingham6035b672011-03-31 00:19:25 +00003678ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003679 m_mod_id(),
3680 m_exe_ctx_ref(),
3681 m_needs_update (true),
3682 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003683{
3684}
3685
3686ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003687 m_mod_id(),
3688 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003689 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003690 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003691{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003692 ExecutionContext exe_ctx(exe_scope);
3693 TargetSP target_sp (exe_ctx.GetTargetSP());
3694 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003695 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003696 m_exe_ctx_ref.SetTargetSP (target_sp);
3697 ProcessSP process_sp (exe_ctx.GetProcessSP());
3698 if (!process_sp)
3699 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003700
Greg Claytoncc4d0142012-02-17 07:49:44 +00003701 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003702 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003703 m_mod_id = process_sp->GetModID();
3704 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003705
Greg Claytoncc4d0142012-02-17 07:49:44 +00003706 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003707
Greg Claytoncc4d0142012-02-17 07:49:44 +00003708 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003709 {
3710 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003711 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003712 }
Jim Ingham6035b672011-03-31 00:19:25 +00003713
Greg Claytoncc4d0142012-02-17 07:49:44 +00003714 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003715 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003716 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003717
Greg Claytoncc4d0142012-02-17 07:49:44 +00003718 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3719 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003720 {
3721 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003722 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003723 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003724 if (frame_sp)
3725 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003726 }
3727 }
3728 }
Jim Ingham6035b672011-03-31 00:19:25 +00003729}
3730
3731ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003732 m_mod_id(),
3733 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3734 m_needs_update (true),
3735 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003736{
3737}
3738
3739ValueObject::EvaluationPoint::~EvaluationPoint ()
3740{
3741}
3742
Jim Ingham6035b672011-03-31 00:19:25 +00003743// This function checks the EvaluationPoint against the current process state. If the current
3744// state matches the evaluation point, or the evaluation point is already invalid, then we return
3745// false, meaning "no change". If the current state is different, we update our state, and return
3746// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3747// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003748// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003749
3750bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003751ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003752{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003753
3754 // 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 +00003755 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00003756
Greg Claytoncc4d0142012-02-17 07:49:44 +00003757 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003758 return false;
3759
Jim Ingham6035b672011-03-31 00:19:25 +00003760 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003761 Process *process = exe_ctx.GetProcessPtr();
3762 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003763 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003764
Jim Ingham6035b672011-03-31 00:19:25 +00003765 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003766 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003767
Jim Ingham78a685a2011-04-16 00:01:13 +00003768 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3769 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003770 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003771 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003772
3773 bool changed;
3774
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003775 if (m_mod_id.IsValid())
3776 {
3777 if (m_mod_id == current_mod_id)
3778 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003779 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003780 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003781 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003782 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003783 else
3784 {
3785 m_mod_id = current_mod_id;
3786 m_needs_update = true;
3787 changed = true;
3788 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003789 }
Jim Ingham6035b672011-03-31 00:19:25 +00003790
Jim Ingham73ca05a2011-12-17 01:35:57 +00003791 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3792 // That way we'll be sure to return a valid exe_scope.
3793 // 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 +00003794
Greg Claytoncc4d0142012-02-17 07:49:44 +00003795 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003796 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003797 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3798 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003799 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003800 if (m_exe_ctx_ref.HasFrameRef())
3801 {
3802 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3803 if (!frame_sp)
3804 {
3805 // We used to have a frame, but now it is gone
3806 SetInvalid();
3807 }
3808 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003809 }
Jim Ingham6035b672011-03-31 00:19:25 +00003810 else
3811 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003812 // We used to have a thread, but now it is gone
3813 SetInvalid();
Jim Ingham6035b672011-03-31 00:19:25 +00003814 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003815
Jim Ingham6035b672011-03-31 00:19:25 +00003816 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003817 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003818}
3819
Jim Ingham61be0902011-05-02 18:13:59 +00003820void
3821ValueObject::EvaluationPoint::SetUpdated ()
3822{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003823 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3824 if (process_sp)
3825 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003826 m_first_update = false;
3827 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003828}
3829
3830
Greg Claytoncc4d0142012-02-17 07:49:44 +00003831//bool
3832//ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3833//{
3834// if (!IsValid())
3835// return false;
3836//
3837// bool needs_update = false;
3838//
3839// // The target has to be non-null, and the
3840// Target *target = exe_scope->CalculateTarget();
3841// if (target != NULL)
3842// {
3843// Target *old_target = m_target_sp.get();
3844// assert (target == old_target);
3845// Process *process = exe_scope->CalculateProcess();
3846// if (process != NULL)
3847// {
3848// // FOR NOW - assume you can't update variable objects across process boundaries.
3849// Process *old_process = m_process_sp.get();
3850// assert (process == old_process);
3851// ProcessModID current_mod_id = process->GetModID();
3852// if (m_mod_id != current_mod_id)
3853// {
3854// needs_update = true;
3855// m_mod_id = current_mod_id;
3856// }
3857// // See if we're switching the thread or stack context. If no thread is given, this is
3858// // being evaluated in a global context.
3859// Thread *thread = exe_scope->CalculateThread();
3860// if (thread != NULL)
3861// {
3862// user_id_t new_thread_index = thread->GetIndexID();
3863// if (new_thread_index != m_thread_id)
3864// {
3865// needs_update = true;
3866// m_thread_id = new_thread_index;
3867// m_stack_id.Clear();
3868// }
3869//
3870// StackFrame *new_frame = exe_scope->CalculateStackFrame();
3871// if (new_frame != NULL)
3872// {
3873// if (new_frame->GetStackID() != m_stack_id)
3874// {
3875// needs_update = true;
3876// m_stack_id = new_frame->GetStackID();
3877// }
3878// }
3879// else
3880// {
3881// m_stack_id.Clear();
3882// needs_update = true;
3883// }
3884// }
3885// else
3886// {
3887// // If this had been given a thread, and now there is none, we should update.
3888// // Otherwise we don't have to do anything.
3889// if (m_thread_id != LLDB_INVALID_UID)
3890// {
3891// m_thread_id = LLDB_INVALID_UID;
3892// m_stack_id.Clear();
3893// needs_update = true;
3894// }
3895// }
3896// }
3897// else
3898// {
3899// // If there is no process, then we don't need to update anything.
3900// // But if we're switching from having a process to not, we should try to update.
3901// if (m_process_sp.get() != NULL)
3902// {
3903// needs_update = true;
3904// m_process_sp.reset();
3905// m_thread_id = LLDB_INVALID_UID;
3906// m_stack_id.Clear();
3907// }
3908// }
3909// }
3910// else
3911// {
3912// // If there's no target, nothing can change so we don't need to update anything.
3913// // But if we're switching from having a target to not, we should try to update.
3914// if (m_target_sp.get() != NULL)
3915// {
3916// needs_update = true;
3917// m_target_sp.reset();
3918// m_process_sp.reset();
3919// m_thread_id = LLDB_INVALID_UID;
3920// m_stack_id.Clear();
3921// }
3922// }
3923// if (!m_needs_update)
3924// m_needs_update = needs_update;
3925//
3926// return needs_update;
3927//}
Enrico Granataf2bbf712011-07-15 02:26:42 +00003928
3929void
Enrico Granata86cc9822012-03-19 22:58:49 +00003930ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00003931{
Enrico Granata86cc9822012-03-19 22:58:49 +00003932 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
3933 m_value_str.clear();
3934
3935 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
3936 m_location_str.clear();
3937
3938 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
3939 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003940 m_summary_str.clear();
3941 }
3942
3943 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
3944 m_object_desc_str.clear();
3945
3946 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
3947 {
3948 if (m_synthetic_value)
3949 m_synthetic_value = NULL;
3950 }
Johnny Chen44805302011-07-19 19:48:13 +00003951}
Enrico Granata9128ee22011-09-06 19:20:51 +00003952
3953SymbolContextScope *
3954ValueObject::GetSymbolContextScope()
3955{
3956 if (m_parent)
3957 {
3958 if (!m_parent->IsPointerOrReferenceType())
3959 return m_parent->GetSymbolContextScope();
3960 }
3961 return NULL;
3962}