blob: 4dc22f02039fa66f5ba2f1a89989d90d92ca843a [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 {
Enrico Granata9c2efe32012-08-07 01:49:34 +0000846 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +0000847 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +0000848 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000849 ExecutionContext exe_ctx (GetExecutionContextRef());
850 Target* target = exe_ctx.GetTargetPtr();
851 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +0000852 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000853 heap_buf_ptr->SetByteSize(bytes);
854 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
855 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +0000856 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000857 data.SetData(data_sp);
858 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +0000859 }
860 }
861 }
862 }
863 break;
864 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +0000865 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000866 ExecutionContext exe_ctx (GetExecutionContextRef());
867 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +0000868 if (process)
869 {
870 heap_buf_ptr->SetByteSize(bytes);
871 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
872 if (error.Success())
873 {
874 data.SetData(data_sp);
875 return bytes_read;
876 }
877 }
878 }
879 break;
880 case eAddressTypeHost:
881 {
882 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes);
883 data.SetData(data_sp);
884 return bytes;
885 }
886 break;
887 case eAddressTypeInvalid:
888 default:
889 break;
890 }
891 }
892 return 0;
893}
894
895size_t
896ValueObject::GetData (DataExtractor& data)
897{
898 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000899 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytone72dfb32012-02-24 01:59:29 +0000900 Error error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +0000901 if (error.Fail())
902 return 0;
903 data.SetAddressByteSize(m_data.GetAddressByteSize());
904 data.SetByteOrder(m_data.GetByteOrder());
905 return data.GetByteSize();
906}
907
908// will compute strlen(str), but without consuming more than
909// maxlen bytes out of str (this serves the purpose of reading
910// chunks of a string without having to worry about
911// missing NULL terminators in the chunk)
912// of course, if strlen(str) > maxlen, the function will return
913// maxlen_value (which should be != maxlen, because that allows you
914// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
915static uint32_t
916strlen_or_inf (const char* str,
917 uint32_t maxlen,
918 uint32_t maxlen_value)
919{
920 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +0000921 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +0000922 {
Greg Clayton8dd5c172011-10-05 22:19:51 +0000923 while(*str)
924 {
925 len++;str++;
926 if (len > maxlen)
927 return maxlen_value;
928 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000929 }
930 return len;
931}
932
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000933void
Greg Claytoncc4d0142012-02-17 07:49:44 +0000934ValueObject::ReadPointedString (Stream& s,
935 Error& error,
936 uint32_t max_length,
937 bool honor_array,
938 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000939{
Greg Claytoncc4d0142012-02-17 07:49:44 +0000940 ExecutionContext exe_ctx (GetExecutionContextRef());
941 Target* target = exe_ctx.GetTargetPtr();
942
943 if (target && max_length == 0)
944 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000945
946 clang_type_t clang_type = GetClangType();
947 clang_type_t elem_or_pointee_clang_type;
948 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
949 GetClangAST(),
950 &elem_or_pointee_clang_type));
951 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
952 ClangASTContext::IsCharType (elem_or_pointee_clang_type))
953 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000954 if (target == NULL)
955 {
956 s << "<no target to read from>";
957 }
958 else
959 {
960 addr_t cstr_address = LLDB_INVALID_ADDRESS;
961 AddressType cstr_address_type = eAddressTypeInvalid;
962
963 size_t cstr_len = 0;
964 bool capped_data = false;
965 if (type_flags.Test (ClangASTContext::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000966 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000967 // We have an array
968 cstr_len = ClangASTContext::GetArraySize (clang_type);
969 if (cstr_len > max_length)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000970 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000971 capped_data = true;
972 cstr_len = max_length;
973 }
974 cstr_address = GetAddressOf (true, &cstr_address_type);
975 }
976 else
977 {
978 // We have a pointer
979 cstr_address = GetPointerValue (&cstr_address_type);
980 }
981 if (cstr_address != 0 && cstr_address != LLDB_INVALID_ADDRESS)
982 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000983 Address cstr_so_addr (cstr_address);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000984 DataExtractor data;
985 size_t bytes_read = 0;
986 if (cstr_len > 0 && honor_array)
987 {
988 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
989 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
990 GetPointeeData(data, 0, cstr_len);
991
992 if ((bytes_read = data.GetByteSize()) > 0)
993 {
994 s << '"';
995 data.Dump (&s,
996 0, // Start offset in "data"
997 item_format,
998 1, // Size of item (1 byte for a char!)
999 bytes_read, // How many bytes to print?
1000 UINT32_MAX, // num per line
1001 LLDB_INVALID_ADDRESS,// base address
1002 0, // bitfield bit size
1003 0); // bitfield bit offset
1004 if (capped_data)
1005 s << "...";
1006 s << '"';
1007 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00001008 }
1009 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001010 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001011 cstr_len = max_length;
1012 const size_t k_max_buf_size = 64;
1013
1014 size_t offset = 0;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001015
Greg Claytoncc4d0142012-02-17 07:49:44 +00001016 int cstr_len_displayed = -1;
1017 bool capped_cstr = false;
1018 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1019 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1020 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001021 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001022 const char *cstr = data.PeekCStr(0);
1023 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1024 if (len > k_max_buf_size)
1025 len = k_max_buf_size;
1026 if (cstr && cstr_len_displayed < 0)
1027 s << '"';
1028
1029 if (cstr_len_displayed < 0)
1030 cstr_len_displayed = len;
1031
1032 if (len == 0)
1033 break;
1034 cstr_len_displayed += len;
1035 if (len > bytes_read)
1036 len = bytes_read;
1037 if (len > cstr_len)
1038 len = cstr_len;
1039
1040 data.Dump (&s,
1041 0, // Start offset in "data"
1042 item_format,
1043 1, // Size of item (1 byte for a char!)
1044 len, // How many bytes to print?
1045 UINT32_MAX, // num per line
1046 LLDB_INVALID_ADDRESS,// base address
1047 0, // bitfield bit size
1048 0); // bitfield bit offset
1049
1050 if (len < k_max_buf_size)
1051 break;
1052
1053 if (len >= cstr_len)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001054 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001055 capped_cstr = true;
1056 break;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001057 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001058
1059 cstr_len -= len;
1060 offset += len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001061 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001062
1063 if (cstr_len_displayed >= 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001064 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001065 s << '"';
1066 if (capped_cstr)
1067 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001068 }
1069 }
1070 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001071 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001072 }
1073 else
1074 {
1075 error.SetErrorString("impossible to read a string from this object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001076 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001077 }
1078}
1079
Jim Ingham53c47f12010-09-10 23:12:17 +00001080const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001081ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001082{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001083
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001084 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001085 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001086
1087 if (!m_object_desc_str.empty())
1088 return m_object_desc_str.c_str();
1089
Greg Claytoncc4d0142012-02-17 07:49:44 +00001090 ExecutionContext exe_ctx (GetExecutionContextRef());
1091 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001092 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001093 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001094
Jim Ingham53c47f12010-09-10 23:12:17 +00001095 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001096
Greg Claytonafacd142011-09-02 01:15:17 +00001097 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001098 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1099
Jim Inghama2cf2632010-12-23 02:29:54 +00001100 if (runtime == NULL)
1101 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001102 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Jim Inghama2cf2632010-12-23 02:29:54 +00001103 clang_type_t opaque_qual_type = GetClangType();
1104 if (opaque_qual_type != NULL)
1105 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001106 bool is_signed;
1107 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed)
1108 || ClangASTContext::IsPointerType (opaque_qual_type))
1109 {
Greg Claytonafacd142011-09-02 01:15:17 +00001110 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001111 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001112 }
1113 }
1114
Jim Ingham8d543de2011-03-31 23:01:21 +00001115 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001116 {
1117 m_object_desc_str.append (s.GetData());
1118 }
Sean Callanan672ad942010-10-23 00:18:49 +00001119
1120 if (m_object_desc_str.empty())
1121 return NULL;
1122 else
1123 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001124}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001125
Enrico Granata0c489f52012-03-01 04:24:26 +00001126bool
1127ValueObject::GetValueAsCString (lldb::Format format,
1128 std::string& destination)
1129{
1130 if (ClangASTContext::IsAggregateType (GetClangType()) == false &&
1131 UpdateValueIfNeeded(false))
1132 {
1133 const Value::ContextType context_type = m_value.GetContextType();
1134
1135 switch (context_type)
1136 {
1137 case Value::eContextTypeClangType:
1138 case Value::eContextTypeLLDBType:
1139 case Value::eContextTypeVariable:
1140 {
1141 clang_type_t clang_type = GetClangType ();
1142 if (clang_type)
1143 {
1144 StreamString sstr;
1145 ExecutionContext exe_ctx (GetExecutionContextRef());
1146 ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
1147 clang_type, // The clang type to display
1148 &sstr,
1149 format, // Format to display this type with
1150 m_data, // Data to extract from
1151 0, // Byte offset into "m_data"
1152 GetByteSize(), // Byte size of item in "m_data"
1153 GetBitfieldBitSize(), // Bitfield bit size
1154 GetBitfieldBitOffset(), // Bitfield bit offset
1155 exe_ctx.GetBestExecutionContextScope());
1156 // Don't set the m_error to anything here otherwise
1157 // we won't be able to re-format as anything else. The
1158 // code for ClangASTType::DumpTypeValue() should always
1159 // return something, even if that something contains
1160 // an error messsage. "m_error" is used to detect errors
1161 // when reading the valid object, not for formatting errors.
1162 if (sstr.GetString().empty())
1163 destination.clear();
1164 else
1165 destination.swap(sstr.GetString());
1166 }
1167 }
1168 break;
1169
1170 case Value::eContextTypeRegisterInfo:
1171 {
1172 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1173 if (reg_info)
1174 {
1175 ExecutionContext exe_ctx (GetExecutionContextRef());
1176
1177 StreamString reg_sstr;
1178 m_data.Dump (&reg_sstr,
1179 0,
1180 format,
1181 reg_info->byte_size,
1182 1,
1183 UINT32_MAX,
1184 LLDB_INVALID_ADDRESS,
1185 0,
1186 0,
1187 exe_ctx.GetBestExecutionContextScope());
1188 destination.swap(reg_sstr.GetString());
1189 }
1190 }
1191 break;
1192
1193 default:
1194 break;
1195 }
1196 return !destination.empty();
1197 }
1198 else
1199 return false;
1200}
1201
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001202const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001203ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001204{
Enrico Granata0c489f52012-03-01 04:24:26 +00001205 if (UpdateValueIfNeeded(true) && m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001206 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001207 lldb::Format my_format = GetFormat();
1208 if (m_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001209 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001210 if (m_type_format_sp)
1211 my_format = m_type_format_sp->GetFormat();
1212 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001213 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001214 if (m_is_bitfield_for_scalar)
1215 my_format = eFormatUnsigned;
1216 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001217 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001218 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001219 {
1220 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1221 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001222 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001223 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001224 else
1225 {
1226 clang_type_t clang_type = GetClangType ();
1227 my_format = ClangASTType::GetFormat(clang_type);
1228 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001229 }
1230 }
1231 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001232 if (GetValueAsCString(my_format, m_value_str))
1233 {
1234 if (!m_value_did_change && m_old_value_valid)
1235 {
1236 // The value was gotten successfully, so we consider the
1237 // value as changed if the value string differs
1238 SetValueDidChange (m_old_value_str != m_value_str);
1239 }
1240 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001241 }
1242 if (m_value_str.empty())
1243 return NULL;
1244 return m_value_str.c_str();
1245}
1246
Enrico Granatac3e320a2011-08-02 17:27:39 +00001247// if > 8bytes, 0 is returned. this method should mostly be used
1248// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001249uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001250ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001251{
1252 // If our byte size is zero this is an aggregate type that has children
1253 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
1254 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001255 Scalar scalar;
1256 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001257 {
1258 if (success)
1259 *success = true;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001260 return scalar.GetRawBits64(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001261 }
1262 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001263 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001264
1265 if (success)
1266 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001267 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001268}
1269
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001270// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1271// this call up to date by returning true for your new special cases. We will eventually move
1272// to checking this call result before trying to display special cases
1273bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001274ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1275 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001276{
1277 clang_type_t elem_or_pointee_type;
1278 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
1279
1280 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001281 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001282 {
1283 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001284 (custom_format == eFormatCString ||
1285 custom_format == eFormatCharArray ||
1286 custom_format == eFormatChar ||
1287 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001288 return true;
1289
1290 if (flags.Test(ClangASTContext::eTypeIsArray))
1291 {
Greg Claytonafacd142011-09-02 01:15:17 +00001292 if ((custom_format == eFormatBytes) ||
1293 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001294 return true;
1295
Greg Claytonafacd142011-09-02 01:15:17 +00001296 if ((custom_format == eFormatVectorOfChar) ||
1297 (custom_format == eFormatVectorOfFloat32) ||
1298 (custom_format == eFormatVectorOfFloat64) ||
1299 (custom_format == eFormatVectorOfSInt16) ||
1300 (custom_format == eFormatVectorOfSInt32) ||
1301 (custom_format == eFormatVectorOfSInt64) ||
1302 (custom_format == eFormatVectorOfSInt8) ||
1303 (custom_format == eFormatVectorOfUInt128) ||
1304 (custom_format == eFormatVectorOfUInt16) ||
1305 (custom_format == eFormatVectorOfUInt32) ||
1306 (custom_format == eFormatVectorOfUInt64) ||
1307 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001308 return true;
1309 }
1310 }
1311 return false;
1312}
1313
Enrico Granata9fc19442011-07-06 02:13:41 +00001314bool
1315ValueObject::DumpPrintableRepresentation(Stream& s,
1316 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001317 Format custom_format,
Enrico Granata86cc9822012-03-19 22:58:49 +00001318 PrintableRepresentationSpecialCases special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001319{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001320
1321 clang_type_t elem_or_pointee_type;
1322 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001323
Enrico Granata86cc9822012-03-19 22:58:49 +00001324 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1325 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1326
1327 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001328 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001329 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1330 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001331 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001332 // when being asked to get a printable display an array or pointer type directly,
1333 // try to "do the right thing"
1334
1335 if (IsCStringContainer(true) &&
1336 (custom_format == eFormatCString ||
1337 custom_format == eFormatCharArray ||
1338 custom_format == eFormatChar ||
1339 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001340 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001341 Error error;
1342 ReadPointedString(s,
1343 error,
1344 0,
1345 (custom_format == eFormatVectorOfChar) ||
1346 (custom_format == eFormatCharArray));
1347 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001348 }
1349
Enrico Granata86cc9822012-03-19 22:58:49 +00001350 if (custom_format == eFormatEnum)
1351 return false;
1352
1353 // this only works for arrays, because I have no way to know when
1354 // the pointed memory ends, and no special \0 end of data marker
1355 if (flags.Test(ClangASTContext::eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001356 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001357 if ((custom_format == eFormatBytes) ||
1358 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001359 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001360 uint32_t count = GetNumChildren();
1361
1362 s << '[';
1363 for (uint32_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001364 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001365
1366 if (low)
1367 s << ',';
1368
1369 ValueObjectSP child = GetChildAtIndex(low,true);
1370 if (!child.get())
1371 {
1372 s << "<invalid child>";
1373 continue;
1374 }
1375 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1376 }
1377
1378 s << ']';
1379
1380 return true;
1381 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001382
Enrico Granata86cc9822012-03-19 22:58:49 +00001383 if ((custom_format == eFormatVectorOfChar) ||
1384 (custom_format == eFormatVectorOfFloat32) ||
1385 (custom_format == eFormatVectorOfFloat64) ||
1386 (custom_format == eFormatVectorOfSInt16) ||
1387 (custom_format == eFormatVectorOfSInt32) ||
1388 (custom_format == eFormatVectorOfSInt64) ||
1389 (custom_format == eFormatVectorOfSInt8) ||
1390 (custom_format == eFormatVectorOfUInt128) ||
1391 (custom_format == eFormatVectorOfUInt16) ||
1392 (custom_format == eFormatVectorOfUInt32) ||
1393 (custom_format == eFormatVectorOfUInt64) ||
1394 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1395 {
1396 uint32_t count = GetNumChildren();
1397
1398 Format format = FormatManager::GetSingleItemFormat(custom_format);
1399
1400 s << '[';
1401 for (uint32_t low = 0; low < count; low++)
1402 {
1403
1404 if (low)
1405 s << ',';
1406
1407 ValueObjectSP child = GetChildAtIndex(low,true);
1408 if (!child.get())
1409 {
1410 s << "<invalid child>";
1411 continue;
1412 }
1413 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1414 }
1415
1416 s << ']';
1417
1418 return true;
1419 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001420 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001421
1422 if ((custom_format == eFormatBoolean) ||
1423 (custom_format == eFormatBinary) ||
1424 (custom_format == eFormatChar) ||
1425 (custom_format == eFormatCharPrintable) ||
1426 (custom_format == eFormatComplexFloat) ||
1427 (custom_format == eFormatDecimal) ||
1428 (custom_format == eFormatHex) ||
1429 (custom_format == eFormatFloat) ||
1430 (custom_format == eFormatOctal) ||
1431 (custom_format == eFormatOSType) ||
1432 (custom_format == eFormatUnicode16) ||
1433 (custom_format == eFormatUnicode32) ||
1434 (custom_format == eFormatUnsigned) ||
1435 (custom_format == eFormatPointer) ||
1436 (custom_format == eFormatComplexInteger) ||
1437 (custom_format == eFormatComplex) ||
1438 (custom_format == eFormatDefault)) // use the [] operator
1439 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001440 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001441 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001442
1443 if (only_special)
1444 return false;
1445
Enrico Granata86cc9822012-03-19 22:58:49 +00001446 bool var_success = false;
1447
1448 {
1449 const char * return_value;
1450 std::string alloc_mem;
1451
1452 if (custom_format != eFormatInvalid)
1453 SetFormat(custom_format);
1454
1455 switch(val_obj_display)
1456 {
1457 case eValueObjectRepresentationStyleValue:
1458 return_value = GetValueAsCString();
1459 break;
1460
1461 case eValueObjectRepresentationStyleSummary:
1462 return_value = GetSummaryAsCString();
1463 break;
1464
1465 case eValueObjectRepresentationStyleLanguageSpecific:
1466 return_value = GetObjectDescription();
1467 break;
1468
1469 case eValueObjectRepresentationStyleLocation:
1470 return_value = GetLocationAsCString();
1471 break;
1472
1473 case eValueObjectRepresentationStyleChildrenCount:
1474 {
1475 alloc_mem.resize(512);
1476 return_value = &alloc_mem[0];
1477 int count = GetNumChildren();
1478 snprintf((char*)return_value, 512, "%d", count);
1479 }
1480 break;
1481
1482 case eValueObjectRepresentationStyleType:
1483 return_value = GetTypeName().AsCString();
1484 break;
1485
1486 default:
1487 break;
1488 }
1489
1490 if (!return_value)
1491 {
1492 if (val_obj_display == eValueObjectRepresentationStyleValue)
1493 return_value = GetSummaryAsCString();
1494 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1495 {
1496 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1497 {
1498 // this thing has no value, and it seems to have no summary
1499 // some combination of unitialized data and other factors can also
1500 // raise this condition, so let's print a nice generic description
1501 {
1502 alloc_mem.resize(684);
1503 return_value = &alloc_mem[0];
1504 snprintf((char*)return_value, 684, "%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1505 }
1506 }
1507 else
1508 return_value = GetValueAsCString();
1509 }
1510 }
1511
1512 if (return_value)
1513 s.PutCString(return_value);
1514 else
1515 {
1516 if (m_error.Fail())
1517 s.Printf("<%s>", m_error.AsCString());
1518 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1519 s.PutCString("<no summary available>");
1520 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1521 s.PutCString("<no value available>");
1522 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1523 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1524 else
1525 s.PutCString("<no printable representation>");
1526 }
1527
1528 // we should only return false here if we could not do *anything*
1529 // even if we have an error message as output, that's a success
1530 // from our callers' perspective, so return true
1531 var_success = true;
1532
1533 if (custom_format != eFormatInvalid)
1534 SetFormat(eFormatDefault);
1535 }
1536
Enrico Granataf4efecd2011-07-12 22:56:10 +00001537 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001538}
1539
Greg Clayton737b9322010-09-13 03:32:57 +00001540addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001541ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001542{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001543 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001544 return LLDB_INVALID_ADDRESS;
1545
Greg Clayton73b472d2010-10-27 03:32:59 +00001546 switch (m_value.GetValueType())
1547 {
1548 case Value::eValueTypeScalar:
1549 if (scalar_is_load_address)
1550 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001551 if(address_type)
1552 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001553 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1554 }
1555 break;
1556
1557 case Value::eValueTypeLoadAddress:
1558 case Value::eValueTypeFileAddress:
1559 case Value::eValueTypeHostAddress:
1560 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001561 if(address_type)
1562 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001563 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1564 }
1565 break;
1566 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001567 if (address_type)
1568 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001569 return LLDB_INVALID_ADDRESS;
1570}
1571
1572addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001573ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001574{
Greg Claytonafacd142011-09-02 01:15:17 +00001575 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001576 if(address_type)
1577 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001578
Enrico Granatac3e320a2011-08-02 17:27:39 +00001579 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001580 return address;
1581
Greg Clayton73b472d2010-10-27 03:32:59 +00001582 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001583 {
1584 case Value::eValueTypeScalar:
Enrico Granata9128ee22011-09-06 19:20:51 +00001585 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001586 break;
1587
Enrico Granata9128ee22011-09-06 19:20:51 +00001588 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001589 case Value::eValueTypeLoadAddress:
1590 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001591 {
1592 uint32_t data_offset = 0;
1593 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001594 }
1595 break;
1596 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001597
Enrico Granata9128ee22011-09-06 19:20:51 +00001598 if (address_type)
1599 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001600
Greg Clayton737b9322010-09-13 03:32:57 +00001601 return address;
1602}
1603
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001604bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001605ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001606{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001607 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001608 // Make sure our value is up to date first so that our location and location
1609 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001610 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001611 {
1612 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001613 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001614 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001615
1616 uint32_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001617 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001618
Greg Claytonb1320972010-07-14 00:18:15 +00001619 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001620
Jim Ingham16e0c682011-08-12 23:34:31 +00001621 Value::ValueType value_type = m_value.GetValueType();
1622
1623 if (value_type == Value::eValueTypeScalar)
1624 {
1625 // If the value is already a scalar, then let the scalar change itself:
1626 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1627 }
1628 else if (byte_size <= Scalar::GetMaxByteSize())
1629 {
1630 // If the value fits in a scalar, then make a new scalar and again let the
1631 // scalar code do the conversion, then figure out where to put the new value.
1632 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001633 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1634 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001635 {
Jim Ingham4b536182011-08-09 02:12:22 +00001636 switch (value_type)
1637 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001638 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001639 {
1640 // If it is a load address, then the scalar value is the storage location
1641 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001642 ExecutionContext exe_ctx (GetExecutionContextRef());
1643 Process *process = exe_ctx.GetProcessPtr();
1644 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001645 {
Greg Claytonafacd142011-09-02 01:15:17 +00001646 addr_t target_addr = m_value.GetScalar().GetRawBits64(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001647 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1648 new_scalar,
1649 byte_size,
1650 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001651 if (!error.Success())
1652 return false;
1653 if (bytes_written != byte_size)
1654 {
1655 error.SetErrorString("unable to write value to memory");
1656 return false;
1657 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001658 }
1659 }
Jim Ingham4b536182011-08-09 02:12:22 +00001660 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001661 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001662 {
1663 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1664 DataExtractor new_data;
1665 new_data.SetByteOrder (m_data.GetByteOrder());
1666
1667 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1668 m_data.SetData(buffer_sp, 0);
1669 bool success = new_scalar.GetData(new_data);
1670 if (success)
1671 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001672 new_data.CopyByteOrderedData (0,
1673 byte_size,
1674 const_cast<uint8_t *>(m_data.GetDataStart()),
1675 byte_size,
1676 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001677 }
1678 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1679
1680 }
Jim Ingham4b536182011-08-09 02:12:22 +00001681 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001682 case Value::eValueTypeFileAddress:
1683 case Value::eValueTypeScalar:
Jim Ingham16e0c682011-08-12 23:34:31 +00001684 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001685 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001686 }
1687 else
1688 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001689 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001690 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001691 }
1692 else
1693 {
1694 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001695 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001696 return false;
1697 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001698
1699 // If we have reached this point, then we have successfully changed the value.
1700 SetNeedsUpdate();
1701 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001702}
1703
Greg Clayton81e871e2012-02-04 02:27:34 +00001704bool
1705ValueObject::GetDeclaration (Declaration &decl)
1706{
1707 decl.Clear();
1708 return false;
1709}
1710
Greg Clayton84db9102012-03-26 23:03:23 +00001711ConstString
1712ValueObject::GetTypeName()
1713{
1714 return ClangASTType::GetConstTypeName (GetClangAST(), GetClangType());
1715}
1716
1717ConstString
1718ValueObject::GetQualifiedTypeName()
1719{
1720 return ClangASTType::GetConstQualifiedTypeName (GetClangAST(), GetClangType());
1721}
1722
1723
Greg Claytonafacd142011-09-02 01:15:17 +00001724LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001725ValueObject::GetObjectRuntimeLanguage ()
1726{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001727 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1728 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001729}
1730
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001731void
Jim Ingham58b59f92011-04-22 23:53:53 +00001732ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001733{
Jim Ingham58b59f92011-04-22 23:53:53 +00001734 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001735}
1736
1737ValueObjectSP
1738ValueObject::GetSyntheticChild (const ConstString &key) const
1739{
1740 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001741 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001742 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001743 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001744 return synthetic_child_sp;
1745}
1746
1747bool
1748ValueObject::IsPointerType ()
1749{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001750 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001751}
1752
Jim Inghamb7603bb2011-03-18 00:05:18 +00001753bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001754ValueObject::IsArrayType ()
1755{
1756 return ClangASTContext::IsArrayType (GetClangType());
1757}
1758
1759bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001760ValueObject::IsScalarType ()
1761{
1762 return ClangASTContext::IsScalarType (GetClangType());
1763}
1764
1765bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001766ValueObject::IsIntegerType (bool &is_signed)
1767{
1768 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1769}
Greg Clayton73b472d2010-10-27 03:32:59 +00001770
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001771bool
1772ValueObject::IsPointerOrReferenceType ()
1773{
Greg Clayton007d5be2011-05-30 00:49:24 +00001774 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1775}
1776
1777bool
Greg Claytondea8cb42011-06-29 22:09:02 +00001778ValueObject::IsPossibleDynamicType ()
1779{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00001780 ExecutionContext exe_ctx (GetExecutionContextRef());
1781 Process *process = exe_ctx.GetProcessPtr();
1782 if (process)
1783 return process->IsPossibleDynamicValue(*this);
1784 else
1785 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType());
Greg Claytondea8cb42011-06-29 22:09:02 +00001786}
1787
Greg Claytonafacd142011-09-02 01:15:17 +00001788ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001789ValueObject::GetSyntheticArrayMember (int32_t index, bool can_create)
1790{
1791 if (IsArrayType())
1792 return GetSyntheticArrayMemberFromArray(index, can_create);
1793
1794 if (IsPointerType())
1795 return GetSyntheticArrayMemberFromPointer(index, can_create);
1796
1797 return ValueObjectSP();
1798
1799}
1800
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001801ValueObjectSP
1802ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1803{
1804 ValueObjectSP synthetic_child_sp;
1805 if (IsPointerType ())
1806 {
1807 char index_str[64];
1808 snprintf(index_str, sizeof(index_str), "[%i]", index);
1809 ConstString index_const_str(index_str);
1810 // Check if we have already created a synthetic array member in this
1811 // valid object. If we have we will re-use it.
1812 synthetic_child_sp = GetSyntheticChild (index_const_str);
1813 if (!synthetic_child_sp)
1814 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001815 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001816 // We haven't made a synthetic array member for INDEX yet, so
1817 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001818 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001819
1820 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001821 if (synthetic_child)
1822 {
1823 AddSyntheticChild(index_const_str, synthetic_child);
1824 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001825 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001826 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001827 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001828 }
1829 }
1830 return synthetic_child_sp;
1831}
Jim Ingham22777012010-09-23 02:01:19 +00001832
Greg Claytondaf515f2011-07-09 20:12:33 +00001833// This allows you to create an array member using and index
1834// that doesn't not fall in the normal bounds of the array.
1835// Many times structure can be defined as:
1836// struct Collection
1837// {
1838// uint32_t item_count;
1839// Item item_array[0];
1840// };
1841// The size of the "item_array" is 1, but many times in practice
1842// there are more items in "item_array".
1843
1844ValueObjectSP
1845ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1846{
1847 ValueObjectSP synthetic_child_sp;
1848 if (IsArrayType ())
1849 {
1850 char index_str[64];
1851 snprintf(index_str, sizeof(index_str), "[%i]", index);
1852 ConstString index_const_str(index_str);
1853 // Check if we have already created a synthetic array member in this
1854 // valid object. If we have we will re-use it.
1855 synthetic_child_sp = GetSyntheticChild (index_const_str);
1856 if (!synthetic_child_sp)
1857 {
1858 ValueObject *synthetic_child;
1859 // We haven't made a synthetic array member for INDEX yet, so
1860 // lets make one and cache it for any future reference.
1861 synthetic_child = CreateChildAtIndex(0, true, index);
1862
1863 // Cache the value if we got one back...
1864 if (synthetic_child)
1865 {
1866 AddSyntheticChild(index_const_str, synthetic_child);
1867 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001868 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001869 synthetic_child_sp->m_is_array_item_for_pointer = true;
1870 }
1871 }
1872 }
1873 return synthetic_child_sp;
1874}
1875
Enrico Granata9fc19442011-07-06 02:13:41 +00001876ValueObjectSP
1877ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1878{
1879 ValueObjectSP synthetic_child_sp;
1880 if (IsScalarType ())
1881 {
1882 char index_str[64];
1883 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1884 ConstString index_const_str(index_str);
1885 // Check if we have already created a synthetic array member in this
1886 // valid object. If we have we will re-use it.
1887 synthetic_child_sp = GetSyntheticChild (index_const_str);
1888 if (!synthetic_child_sp)
1889 {
1890 ValueObjectChild *synthetic_child;
1891 // We haven't made a synthetic array member for INDEX yet, so
1892 // lets make one and cache it for any future reference.
1893 synthetic_child = new ValueObjectChild(*this,
1894 GetClangAST(),
1895 GetClangType(),
1896 index_const_str,
1897 GetByteSize(),
1898 0,
1899 to-from+1,
1900 from,
1901 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001902 false,
1903 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00001904
1905 // Cache the value if we got one back...
1906 if (synthetic_child)
1907 {
1908 AddSyntheticChild(index_const_str, synthetic_child);
1909 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001910 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00001911 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1912 }
1913 }
1914 }
1915 return synthetic_child_sp;
1916}
1917
Greg Claytonafacd142011-09-02 01:15:17 +00001918ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001919ValueObject::GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create)
1920{
1921 ValueObjectSP synthetic_child_sp;
1922 if (IsArrayType () || IsPointerType ())
1923 {
1924 char index_str[64];
1925 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1926 ConstString index_const_str(index_str);
1927 // Check if we have already created a synthetic array member in this
1928 // valid object. If we have we will re-use it.
1929 synthetic_child_sp = GetSyntheticChild (index_const_str);
1930 if (!synthetic_child_sp)
1931 {
1932 ValueObjectSynthetic *synthetic_child;
1933
1934 // We haven't made a synthetic array member for INDEX yet, so
1935 // lets make one and cache it for any future reference.
Enrico Granata061858c2012-02-15 02:34:21 +00001936 SyntheticArrayView *view = new SyntheticArrayView(SyntheticChildren::Flags());
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001937 view->AddRange(from,to);
1938 SyntheticChildrenSP view_sp(view);
1939 synthetic_child = new ValueObjectSynthetic(*this, view_sp);
1940
1941 // Cache the value if we got one back...
1942 if (synthetic_child)
1943 {
1944 AddSyntheticChild(index_const_str, synthetic_child);
1945 synthetic_child_sp = synthetic_child->GetSP();
1946 synthetic_child_sp->SetName(ConstString(index_str));
1947 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1948 }
1949 }
1950 }
1951 return synthetic_child_sp;
1952}
1953
Greg Claytonafacd142011-09-02 01:15:17 +00001954ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00001955ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
1956{
1957
1958 ValueObjectSP synthetic_child_sp;
1959
1960 char name_str[64];
1961 snprintf(name_str, sizeof(name_str), "@%i", offset);
1962 ConstString name_const_str(name_str);
1963
1964 // Check if we have already created a synthetic array member in this
1965 // valid object. If we have we will re-use it.
1966 synthetic_child_sp = GetSyntheticChild (name_const_str);
1967
1968 if (synthetic_child_sp.get())
1969 return synthetic_child_sp;
1970
1971 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00001972 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001973
1974 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
1975 type.GetASTContext(),
1976 type.GetOpaqueQualType(),
1977 name_const_str,
1978 type.GetTypeByteSize(),
1979 offset,
1980 0,
1981 0,
1982 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001983 false,
1984 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001985 if (synthetic_child)
1986 {
1987 AddSyntheticChild(name_const_str, synthetic_child);
1988 synthetic_child_sp = synthetic_child->GetSP();
1989 synthetic_child_sp->SetName(name_const_str);
1990 synthetic_child_sp->m_is_child_at_offset = true;
1991 }
1992 return synthetic_child_sp;
1993}
1994
Enrico Granatad55546b2011-07-22 00:16:08 +00001995// your expression path needs to have a leading . or ->
1996// (unless it somehow "looks like" an array, in which case it has
1997// a leading [ symbol). while the [ is meaningful and should be shown
1998// to the user, . and -> are just parser design, but by no means
1999// added information for the user.. strip them off
2000static const char*
2001SkipLeadingExpressionPathSeparators(const char* expression)
2002{
2003 if (!expression || !expression[0])
2004 return expression;
2005 if (expression[0] == '.')
2006 return expression+1;
2007 if (expression[0] == '-' && expression[1] == '>')
2008 return expression+2;
2009 return expression;
2010}
2011
Greg Claytonafacd142011-09-02 01:15:17 +00002012ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002013ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2014{
2015 ValueObjectSP synthetic_child_sp;
2016 ConstString name_const_string(expression);
2017 // Check if we have already created a synthetic array member in this
2018 // valid object. If we have we will re-use it.
2019 synthetic_child_sp = GetSyntheticChild (name_const_string);
2020 if (!synthetic_child_sp)
2021 {
2022 // We haven't made a synthetic array member for expression yet, so
2023 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002024 synthetic_child_sp = GetValueForExpressionPath(expression,
2025 NULL, NULL, NULL,
2026 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
Enrico Granatad55546b2011-07-22 00:16:08 +00002027
2028 // Cache the value if we got one back...
2029 if (synthetic_child_sp.get())
2030 {
2031 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002032 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002033 synthetic_child_sp->m_is_expression_path_child = true;
2034 }
2035 }
2036 return synthetic_child_sp;
2037}
2038
2039void
Enrico Granata86cc9822012-03-19 22:58:49 +00002040ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002041{
Enrico Granata86cc9822012-03-19 22:58:49 +00002042 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002043 return;
2044
Enrico Granatac5bc4122012-03-27 02:35:13 +00002045 TargetSP target_sp(GetTargetSP());
2046 if (target_sp && (target_sp->GetEnableSyntheticValue() == false || target_sp->GetSuppressSyntheticValue() == true))
2047 {
2048 m_synthetic_value = NULL;
2049 return;
2050 }
2051
Enrico Granata86cc9822012-03-19 22:58:49 +00002052 if (!UpdateFormatsIfNeeded(m_last_format_mgr_dynamic) && m_synthetic_value)
2053 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002054
Enrico Granata0c489f52012-03-01 04:24:26 +00002055 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002056 return;
2057
Enrico Granata86cc9822012-03-19 22:58:49 +00002058 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002059}
2060
Jim Ingham78a685a2011-04-16 00:01:13 +00002061void
Greg Claytonafacd142011-09-02 01:15:17 +00002062ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002063{
Greg Claytonafacd142011-09-02 01:15:17 +00002064 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002065 return;
2066
Jim Ingham58b59f92011-04-22 23:53:53 +00002067 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002068 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002069 ExecutionContext exe_ctx (GetExecutionContextRef());
2070 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002071 if (process && process->IsPossibleDynamicValue(*this))
2072 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002073 }
2074}
2075
Jim Ingham58b59f92011-04-22 23:53:53 +00002076ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002077ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002078{
Greg Claytonafacd142011-09-02 01:15:17 +00002079 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002080 return ValueObjectSP();
2081
2082 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002083 {
Jim Ingham2837b762011-05-04 03:43:18 +00002084 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002085 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002086 if (m_dynamic_value)
2087 return m_dynamic_value->GetSP();
2088 else
2089 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002090}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002091
Jim Ingham60dbabb2011-12-08 19:44:08 +00002092ValueObjectSP
2093ValueObject::GetStaticValue()
2094{
2095 return GetSP();
2096}
2097
Enrico Granata886147f2012-05-08 18:47:08 +00002098lldb::ValueObjectSP
2099ValueObject::GetNonSyntheticValue ()
2100{
2101 return GetSP();
2102}
2103
Enrico Granatad55546b2011-07-22 00:16:08 +00002104ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002105ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002106{
Enrico Granata86cc9822012-03-19 22:58:49 +00002107 if (use_synthetic == false)
2108 return ValueObjectSP();
2109
Enrico Granatad55546b2011-07-22 00:16:08 +00002110 CalculateSyntheticValue(use_synthetic);
2111
2112 if (m_synthetic_value)
2113 return m_synthetic_value->GetSP();
2114 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002115 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002116}
2117
Greg Claytone221f822011-01-21 01:59:00 +00002118bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002119ValueObject::HasSyntheticValue()
2120{
2121 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
2122
Enrico Granata0c489f52012-03-01 04:24:26 +00002123 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002124 return false;
2125
Enrico Granata86cc9822012-03-19 22:58:49 +00002126 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002127
2128 if (m_synthetic_value)
2129 return true;
2130 else
2131 return false;
2132}
2133
2134bool
Greg Claytone221f822011-01-21 01:59:00 +00002135ValueObject::GetBaseClassPath (Stream &s)
2136{
2137 if (IsBaseClass())
2138 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002139 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00002140 clang_type_t clang_type = GetClangType();
2141 std::string cxx_class_name;
2142 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
2143 if (this_had_base_class)
2144 {
2145 if (parent_had_base_class)
2146 s.PutCString("::");
2147 s.PutCString(cxx_class_name.c_str());
2148 }
2149 return parent_had_base_class || this_had_base_class;
2150 }
2151 return false;
2152}
2153
2154
2155ValueObject *
2156ValueObject::GetNonBaseClassParent()
2157{
Jim Ingham78a685a2011-04-16 00:01:13 +00002158 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002159 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002160 if (GetParent()->IsBaseClass())
2161 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002162 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002163 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002164 }
2165 return NULL;
2166}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002167
2168void
Enrico Granata4becb372011-06-29 22:27:15 +00002169ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002170{
Greg Claytone221f822011-01-21 01:59:00 +00002171 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002172
Enrico Granata86cc9822012-03-19 22:58:49 +00002173 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002174 {
Enrico Granata4becb372011-06-29 22:27:15 +00002175 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2176 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2177 // the eHonorPointers mode is meant to produce strings in this latter format
2178 s.PutCString("*(");
2179 }
Greg Claytone221f822011-01-21 01:59:00 +00002180
Enrico Granata4becb372011-06-29 22:27:15 +00002181 ValueObject* parent = GetParent();
2182
2183 if (parent)
2184 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002185
2186 // if we are a deref_of_parent just because we are synthetic array
2187 // members made up to allow ptr[%d] syntax to work in variable
2188 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002189 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002190 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002191
Greg Claytone221f822011-01-21 01:59:00 +00002192 if (!IsBaseClass())
2193 {
2194 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002195 {
Greg Claytone221f822011-01-21 01:59:00 +00002196 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2197 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002198 {
Greg Claytone221f822011-01-21 01:59:00 +00002199 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2200 if (non_base_class_parent_clang_type)
2201 {
2202 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2203
Enrico Granata86cc9822012-03-19 22:58:49 +00002204 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002205 {
2206 s.PutCString("->");
2207 }
Enrico Granata4becb372011-06-29 22:27:15 +00002208 else
2209 {
2210 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2211 {
2212 s.PutCString("->");
2213 }
2214 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2215 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2216 {
2217 s.PutChar('.');
2218 }
Greg Claytone221f822011-01-21 01:59:00 +00002219 }
2220 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002221 }
Greg Claytone221f822011-01-21 01:59:00 +00002222
2223 const char *name = GetName().GetCString();
2224 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002225 {
Greg Claytone221f822011-01-21 01:59:00 +00002226 if (qualify_cxx_base_classes)
2227 {
2228 if (GetBaseClassPath (s))
2229 s.PutCString("::");
2230 }
2231 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002232 }
2233 }
2234 }
2235
Enrico Granata86cc9822012-03-19 22:58:49 +00002236 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002237 {
Greg Claytone221f822011-01-21 01:59:00 +00002238 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002239 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002240}
2241
Greg Claytonafacd142011-09-02 01:15:17 +00002242ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002243ValueObject::GetValueForExpressionPath(const char* expression,
2244 const char** first_unparsed,
2245 ExpressionPathScanEndReason* reason_to_stop,
2246 ExpressionPathEndResultType* final_value_type,
2247 const GetValueForExpressionPathOptions& options,
2248 ExpressionPathAftermath* final_task_on_target)
2249{
2250
2251 const char* dummy_first_unparsed;
2252 ExpressionPathScanEndReason dummy_reason_to_stop;
2253 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002254 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002255
2256 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2257 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2258 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2259 final_value_type ? final_value_type : &dummy_final_value_type,
2260 options,
2261 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2262
Enrico Granata86cc9822012-03-19 22:58:49 +00002263 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002264 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002265
Enrico Granata86cc9822012-03-19 22:58:49 +00002266 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 +00002267 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002268 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002269 {
2270 Error error;
2271 ValueObjectSP final_value = ret_val->Dereference(error);
2272 if (error.Fail() || !final_value.get())
2273 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002274 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002275 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002276 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002277 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002278 return ValueObjectSP();
2279 }
2280 else
2281 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002282 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002283 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002284 return final_value;
2285 }
2286 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002287 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002288 {
2289 Error error;
2290 ValueObjectSP final_value = ret_val->AddressOf(error);
2291 if (error.Fail() || !final_value.get())
2292 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002293 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002294 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002295 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002296 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002297 return ValueObjectSP();
2298 }
2299 else
2300 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002301 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002302 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002303 return final_value;
2304 }
2305 }
2306 }
2307 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2308}
2309
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002310int
2311ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002312 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002313 const char** first_unparsed,
2314 ExpressionPathScanEndReason* reason_to_stop,
2315 ExpressionPathEndResultType* final_value_type,
2316 const GetValueForExpressionPathOptions& options,
2317 ExpressionPathAftermath* final_task_on_target)
2318{
2319 const char* dummy_first_unparsed;
2320 ExpressionPathScanEndReason dummy_reason_to_stop;
2321 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002322 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002323
2324 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2325 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2326 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2327 final_value_type ? final_value_type : &dummy_final_value_type,
2328 options,
2329 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2330
2331 if (!ret_val.get()) // if there are errors, I add nothing to the list
2332 return 0;
2333
Enrico Granata86ea8d82012-03-29 01:34:34 +00002334 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002335 {
2336 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002337 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002338 {
2339 list->Append(ret_val);
2340 return 1;
2341 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002342 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 +00002343 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002344 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002345 {
2346 Error error;
2347 ValueObjectSP final_value = ret_val->Dereference(error);
2348 if (error.Fail() || !final_value.get())
2349 {
Greg Clayton23f59502012-07-17 03:23:13 +00002350 if (reason_to_stop)
2351 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2352 if (final_value_type)
2353 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002354 return 0;
2355 }
2356 else
2357 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002358 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002359 list->Append(final_value);
2360 return 1;
2361 }
2362 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002363 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002364 {
2365 Error error;
2366 ValueObjectSP final_value = ret_val->AddressOf(error);
2367 if (error.Fail() || !final_value.get())
2368 {
Greg Clayton23f59502012-07-17 03:23:13 +00002369 if (reason_to_stop)
2370 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2371 if (final_value_type)
2372 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002373 return 0;
2374 }
2375 else
2376 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002377 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002378 list->Append(final_value);
2379 return 1;
2380 }
2381 }
2382 }
2383 }
2384 else
2385 {
2386 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2387 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2388 ret_val,
2389 list,
2390 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2391 final_value_type ? final_value_type : &dummy_final_value_type,
2392 options,
2393 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2394 }
2395 // in any non-covered case, just do the obviously right thing
2396 list->Append(ret_val);
2397 return 1;
2398}
2399
Greg Claytonafacd142011-09-02 01:15:17 +00002400ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002401ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2402 const char** first_unparsed,
2403 ExpressionPathScanEndReason* reason_to_stop,
2404 ExpressionPathEndResultType* final_result,
2405 const GetValueForExpressionPathOptions& options,
2406 ExpressionPathAftermath* what_next)
2407{
2408 ValueObjectSP root = GetSP();
2409
2410 if (!root.get())
2411 return ValueObjectSP();
2412
2413 *first_unparsed = expression_cstr;
2414
2415 while (true)
2416 {
2417
2418 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2419
Greg Claytonafacd142011-09-02 01:15:17 +00002420 clang_type_t root_clang_type = root->GetClangType();
2421 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002422 Flags root_clang_type_info,pointee_clang_type_info;
2423
2424 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2425 if (pointee_clang_type)
2426 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002427
2428 if (!expression_cstr || *expression_cstr == '\0')
2429 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002430 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002431 return root;
2432 }
2433
2434 switch (*expression_cstr)
2435 {
2436 case '-':
2437 {
2438 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002439 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 +00002440 {
2441 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002442 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2443 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002444 return ValueObjectSP();
2445 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002446 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2447 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002448 options.m_no_fragile_ivar)
2449 {
2450 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002451 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2452 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002453 return ValueObjectSP();
2454 }
2455 if (expression_cstr[1] != '>')
2456 {
2457 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002458 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2459 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002460 return ValueObjectSP();
2461 }
2462 expression_cstr++; // skip the -
2463 }
2464 case '.': // or fallthrough from ->
2465 {
2466 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002467 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 +00002468 {
2469 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002470 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2471 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002472 return ValueObjectSP();
2473 }
2474 expression_cstr++; // skip .
2475 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2476 ConstString child_name;
2477 if (!next_separator) // if no other separator just expand this last layer
2478 {
2479 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002480 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2481
2482 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002483 {
2484 *first_unparsed = '\0';
Enrico Granata86cc9822012-03-19 22:58:49 +00002485 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2486 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002487 return child_valobj_sp;
2488 }
2489 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2490 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002491 if (root->IsSynthetic())
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002492 {
2493 *first_unparsed = expression_cstr;
2494 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2495 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2496 return ValueObjectSP();
2497 }
2498
2499 child_valobj_sp = root->GetSyntheticValue();
Enrico Granata86cc9822012-03-19 22:58:49 +00002500 if (child_valobj_sp.get())
2501 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002502 }
2503
2504 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2505 // so we hit the "else" branch, and return an error
2506 if(child_valobj_sp.get()) // if it worked, just return
2507 {
2508 *first_unparsed = '\0';
Enrico Granata86cc9822012-03-19 22:58:49 +00002509 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2510 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002511 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002512 }
2513 else
2514 {
2515 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002516 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2517 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002518 return ValueObjectSP();
2519 }
2520 }
2521 else // other layers do expand
2522 {
2523 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002524 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2525 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002526 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002527 root = child_valobj_sp;
2528 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002529 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002530 continue;
2531 }
2532 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2533 {
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002534 if (root->IsSynthetic())
2535 {
2536 *first_unparsed = expression_cstr;
2537 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2538 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2539 return ValueObjectSP();
2540 }
2541
Enrico Granata86cc9822012-03-19 22:58:49 +00002542 child_valobj_sp = root->GetSyntheticValue(true);
2543 if (child_valobj_sp)
2544 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002545 }
2546
2547 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2548 // so we hit the "else" branch, and return an error
2549 if(child_valobj_sp.get()) // if it worked, move on
2550 {
2551 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002552 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002553 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002554 continue;
2555 }
2556 else
2557 {
2558 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002559 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2560 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002561 return ValueObjectSP();
2562 }
2563 }
2564 break;
2565 }
2566 case '[':
2567 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002568 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 +00002569 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002570 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002571 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002572 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2573 {
2574 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002575 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2576 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002577 return ValueObjectSP();
2578 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002579 }
2580 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2581 {
2582 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002583 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2584 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002585 return ValueObjectSP();
2586 }
2587 }
2588 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2589 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002590 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002591 {
2592 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002593 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2594 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002595 return ValueObjectSP();
2596 }
2597 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2598 {
2599 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002600 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2601 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002602 return root;
2603 }
2604 }
2605 const char *separator_position = ::strchr(expression_cstr+1,'-');
2606 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2607 if (!close_bracket_position) // if there is no ], this is a syntax error
2608 {
2609 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002610 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2611 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002612 return ValueObjectSP();
2613 }
2614 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2615 {
2616 char *end = NULL;
2617 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2618 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2619 {
2620 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002621 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2622 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002623 return ValueObjectSP();
2624 }
2625 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2626 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002627 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002628 {
2629 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002630 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2631 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002632 return root;
2633 }
2634 else
2635 {
2636 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002637 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2638 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002639 return ValueObjectSP();
2640 }
2641 }
2642 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002643 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002644 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002645 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2646 if (!child_valobj_sp)
2647 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002648 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002649 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2650 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002651 if (child_valobj_sp)
2652 {
2653 root = child_valobj_sp;
2654 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002655 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002656 continue;
2657 }
2658 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002659 {
2660 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002661 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2662 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002663 return ValueObjectSP();
2664 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002665 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002666 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002667 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002668 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 +00002669 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002670 {
2671 Error error;
2672 root = root->Dereference(error);
2673 if (error.Fail() || !root.get())
2674 {
2675 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002676 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2677 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002678 return ValueObjectSP();
2679 }
2680 else
2681 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002682 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002683 continue;
2684 }
2685 }
2686 else
2687 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002688 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Clayton84db9102012-03-26 23:03:23 +00002689 root->GetClangType()) == eLanguageTypeObjC
2690 && ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2691 && root->HasSyntheticValue()
2692 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002693 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002694 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002695 }
2696 else
2697 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002698 if (!root.get())
2699 {
2700 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002701 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2702 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002703 return ValueObjectSP();
2704 }
2705 else
2706 {
2707 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002708 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002709 continue;
2710 }
2711 }
2712 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002713 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002714 {
2715 root = root->GetSyntheticBitFieldChild(index, index, true);
2716 if (!root.get())
2717 {
2718 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002719 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2720 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002721 return ValueObjectSP();
2722 }
2723 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2724 {
2725 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002726 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2727 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002728 return root;
2729 }
2730 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002731 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002732 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002733 if (root->HasSyntheticValue())
2734 root = root->GetSyntheticValue();
2735 else if (!root->IsSynthetic())
2736 {
2737 *first_unparsed = expression_cstr;
2738 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2739 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2740 return ValueObjectSP();
2741 }
2742 // if we are here, then root itself is a synthetic VO.. should be good to go
2743
Enrico Granata27b625e2011-08-09 01:04:56 +00002744 if (!root.get())
2745 {
2746 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002747 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2748 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2749 return ValueObjectSP();
2750 }
2751 root = root->GetChildAtIndex(index, true);
2752 if (!root.get())
2753 {
2754 *first_unparsed = expression_cstr;
2755 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2756 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002757 return ValueObjectSP();
2758 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002759 else
2760 {
2761 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002762 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002763 continue;
2764 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002765 }
2766 else
2767 {
2768 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002769 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2770 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002771 return ValueObjectSP();
2772 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002773 }
2774 else // we have a low and a high index
2775 {
2776 char *end = NULL;
2777 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2778 if (!end || end != separator_position) // if something weird is in our way return an error
2779 {
2780 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002781 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2782 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002783 return ValueObjectSP();
2784 }
2785 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2786 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2787 {
2788 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002789 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2790 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002791 return ValueObjectSP();
2792 }
2793 if (index_lower > index_higher) // swap indices if required
2794 {
2795 unsigned long temp = index_lower;
2796 index_lower = index_higher;
2797 index_higher = temp;
2798 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002799 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002800 {
2801 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2802 if (!root.get())
2803 {
2804 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002805 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2806 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002807 return ValueObjectSP();
2808 }
2809 else
2810 {
2811 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002812 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2813 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002814 return root;
2815 }
2816 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002817 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 +00002818 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002819 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002820 {
2821 Error error;
2822 root = root->Dereference(error);
2823 if (error.Fail() || !root.get())
2824 {
2825 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002826 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2827 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002828 return ValueObjectSP();
2829 }
2830 else
2831 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002832 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002833 continue;
2834 }
2835 }
2836 else
2837 {
2838 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002839 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2840 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002841 return root;
2842 }
2843 }
2844 break;
2845 }
2846 default: // some non-separator is in the way
2847 {
2848 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002849 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2850 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002851 return ValueObjectSP();
2852 break;
2853 }
2854 }
2855 }
2856}
2857
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002858int
2859ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2860 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002861 ValueObjectSP root,
2862 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002863 ExpressionPathScanEndReason* reason_to_stop,
2864 ExpressionPathEndResultType* final_result,
2865 const GetValueForExpressionPathOptions& options,
2866 ExpressionPathAftermath* what_next)
2867{
2868 if (!root.get())
2869 return 0;
2870
2871 *first_unparsed = expression_cstr;
2872
2873 while (true)
2874 {
2875
2876 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2877
Greg Claytonafacd142011-09-02 01:15:17 +00002878 clang_type_t root_clang_type = root->GetClangType();
2879 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002880 Flags root_clang_type_info,pointee_clang_type_info;
2881
2882 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2883 if (pointee_clang_type)
2884 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2885
2886 if (!expression_cstr || *expression_cstr == '\0')
2887 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002888 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002889 list->Append(root);
2890 return 1;
2891 }
2892
2893 switch (*expression_cstr)
2894 {
2895 case '[':
2896 {
2897 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2898 {
2899 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2900 {
2901 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002902 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2903 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002904 return 0;
2905 }
2906 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2907 {
2908 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002909 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2910 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002911 return 0;
2912 }
2913 }
2914 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2915 {
2916 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2917 {
2918 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002919 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2920 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002921 return 0;
2922 }
2923 else // expand this into list
2924 {
2925 int max_index = root->GetNumChildren() - 1;
2926 for (int index = 0; index < max_index; index++)
2927 {
2928 ValueObjectSP child =
2929 root->GetChildAtIndex(index, true);
2930 list->Append(child);
2931 }
2932 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002933 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
2934 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002935 return max_index; // tell me number of items I added to the VOList
2936 }
2937 }
2938 const char *separator_position = ::strchr(expression_cstr+1,'-');
2939 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2940 if (!close_bracket_position) // if there is no ], this is a syntax error
2941 {
2942 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002943 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2944 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002945 return 0;
2946 }
2947 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2948 {
2949 char *end = NULL;
2950 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2951 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2952 {
2953 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002954 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2955 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002956 return 0;
2957 }
2958 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2959 {
2960 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2961 {
2962 int max_index = root->GetNumChildren() - 1;
2963 for (int index = 0; index < max_index; index++)
2964 {
2965 ValueObjectSP child =
2966 root->GetChildAtIndex(index, true);
2967 list->Append(child);
2968 }
2969 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002970 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
2971 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002972 return max_index; // tell me number of items I added to the VOList
2973 }
2974 else
2975 {
2976 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002977 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2978 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002979 return 0;
2980 }
2981 }
2982 // from here on we do have a valid index
2983 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2984 {
2985 root = root->GetChildAtIndex(index, true);
2986 if (!root.get())
2987 {
2988 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002989 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2990 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002991 return 0;
2992 }
2993 else
2994 {
2995 list->Append(root);
2996 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002997 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
2998 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002999 return 1;
3000 }
3001 }
3002 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
3003 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003004 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 +00003005 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3006 {
3007 Error error;
3008 root = root->Dereference(error);
3009 if (error.Fail() || !root.get())
3010 {
3011 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003012 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3013 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003014 return 0;
3015 }
3016 else
3017 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003018 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003019 continue;
3020 }
3021 }
3022 else
3023 {
3024 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3025 if (!root.get())
3026 {
3027 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003028 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3029 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003030 return 0;
3031 }
3032 else
3033 {
3034 list->Append(root);
3035 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003036 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3037 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003038 return 1;
3039 }
3040 }
3041 }
3042 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3043 {
3044 root = root->GetSyntheticBitFieldChild(index, index, true);
3045 if (!root.get())
3046 {
3047 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003048 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3049 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003050 return 0;
3051 }
3052 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3053 {
3054 list->Append(root);
3055 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003056 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3057 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003058 return 1;
3059 }
3060 }
3061 }
3062 else // we have a low and a high index
3063 {
3064 char *end = NULL;
3065 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3066 if (!end || end != separator_position) // if something weird is in our way return an error
3067 {
3068 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003069 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3070 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003071 return 0;
3072 }
3073 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3074 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3075 {
3076 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003077 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3078 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003079 return 0;
3080 }
3081 if (index_lower > index_higher) // swap indices if required
3082 {
3083 unsigned long temp = index_lower;
3084 index_lower = index_higher;
3085 index_higher = temp;
3086 }
3087 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
3088 {
3089 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3090 if (!root.get())
3091 {
3092 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003093 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3094 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003095 return 0;
3096 }
3097 else
3098 {
3099 list->Append(root);
3100 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003101 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3102 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003103 return 1;
3104 }
3105 }
3106 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 +00003107 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003108 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3109 {
3110 Error error;
3111 root = root->Dereference(error);
3112 if (error.Fail() || !root.get())
3113 {
3114 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003115 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3116 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003117 return 0;
3118 }
3119 else
3120 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003121 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003122 continue;
3123 }
3124 }
3125 else
3126 {
Johnny Chen44805302011-07-19 19:48:13 +00003127 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003128 index <= index_higher; index++)
3129 {
3130 ValueObjectSP child =
3131 root->GetChildAtIndex(index, true);
3132 list->Append(child);
3133 }
3134 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003135 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3136 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003137 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3138 }
3139 }
3140 break;
3141 }
3142 default: // some non-[ separator, or something entirely wrong, is in the way
3143 {
3144 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003145 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3146 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003147 return 0;
3148 break;
3149 }
3150 }
3151 }
3152}
3153
Enrico Granata0c489f52012-03-01 04:24:26 +00003154static void
3155DumpValueObject_Impl (Stream &s,
3156 ValueObject *valobj,
3157 const ValueObject::DumpValueObjectOptions& options,
3158 uint32_t ptr_depth,
3159 uint32_t curr_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003160{
Greg Clayton007d5be2011-05-30 00:49:24 +00003161 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003162 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003163 bool update_success = valobj->UpdateValueIfNeeded (options.m_use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00003164
Enrico Granata0c489f52012-03-01 04:24:26 +00003165 const char *root_valobj_name =
3166 options.m_root_valobj_name.empty() ?
3167 valobj->GetName().AsCString() :
3168 options.m_root_valobj_name.c_str();
3169
3170 if (update_success && options.m_use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00003171 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003172 ValueObject *dynamic_value = valobj->GetDynamicValue(options.m_use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003173 if (dynamic_value)
3174 valobj = dynamic_value;
3175 }
3176
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003177 clang_type_t clang_type = valobj->GetClangType();
3178
Greg Clayton73b472d2010-10-27 03:32:59 +00003179 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003180 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00003181 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
3182 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003183
Enrico Granata0c489f52012-03-01 04:24:26 +00003184 const bool print_valobj = options.m_flat_output == false || has_value;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003185
3186 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003187 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003188 if (options.m_show_location)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003189 {
Jim Ingham6035b672011-03-31 00:19:25 +00003190 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003191 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003192
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003193 s.Indent();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003194
Greg Clayton7c8a9662010-11-02 01:50:16 +00003195 // Always show the type for the top level items.
Enrico Granata0c489f52012-03-01 04:24:26 +00003196 if (options.m_show_types || (curr_depth == 0 && !options.m_flat_output))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003197 {
Greg Clayton84db9102012-03-26 23:03:23 +00003198 const char* typeName = valobj->GetQualifiedTypeName().AsCString("<invalid type>");
3199 //const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
Enrico Granata9910bc82011-08-03 02:18:51 +00003200 s.Printf("(%s", typeName);
3201 // only show dynamic types if the user really wants to see types
Enrico Granata0c489f52012-03-01 04:24:26 +00003202 if (options.m_show_types && options.m_use_dynamic != eNoDynamicValues &&
Enrico Granata9910bc82011-08-03 02:18:51 +00003203 (/*strstr(typeName, "id") == typeName ||*/
Greg Claytonafacd142011-09-02 01:15:17 +00003204 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003205 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003206 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3207 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatac3e320a2011-08-02 17:27:39 +00003208 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003209 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003210 else
3211 {
3212 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
3213 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003214 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003215 else
3216 {
3217 ObjCLanguageRuntime::ObjCISA isa = runtime->GetISA(*valobj);
3218 if (!runtime->IsValidISA(isa))
Enrico Granata9910bc82011-08-03 02:18:51 +00003219 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003220 else
3221 s.Printf(", dynamic type: %s) ",
3222 runtime->GetActualTypeName(isa).GetCString());
3223 }
3224 }
3225 }
3226 else
3227 s.Printf(") ");
3228 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003229
Greg Clayton1d3afba2010-10-05 00:00:42 +00003230
Enrico Granata0c489f52012-03-01 04:24:26 +00003231 if (options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003232 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003233 // If we are showing types, also qualify the C++ base classes
Enrico Granata0c489f52012-03-01 04:24:26 +00003234 const bool qualify_cxx_base_classes = options.m_show_types;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003235 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003236 s.PutCString(" =");
3237 }
3238 else
3239 {
3240 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3241 s.Printf ("%s =", name_cstr);
3242 }
3243
Enrico Granata0c489f52012-03-01 04:24:26 +00003244 if (!options.m_scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003245 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003246 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003247 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003248 }
3249
Enrico Granata0c489f52012-03-01 04:24:26 +00003250 std::string summary_str;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003251 std::string value_str;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003252 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003253 const char *sum_cstr = NULL;
Enrico Granata0c489f52012-03-01 04:24:26 +00003254 TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003255
Enrico Granata0c489f52012-03-01 04:24:26 +00003256 if (options.m_omit_summary_depth > 0)
Enrico Granata0c5ef692011-07-16 01:22:04 +00003257 entry = NULL;
3258
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003259 if (err_cstr == NULL)
3260 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003261 if (options.m_format != eFormatDefault && options.m_format != valobj->GetFormat())
Greg Clayton6efba4f2012-01-26 21:08:30 +00003262 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003263 valobj->GetValueAsCString(options.m_format,
3264 value_str);
Greg Clayton6efba4f2012-01-26 21:08:30 +00003265 }
Enrico Granata0c489f52012-03-01 04:24:26 +00003266 else
Greg Clayton6efba4f2012-01-26 21:08:30 +00003267 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003268 val_cstr = valobj->GetValueAsCString();
3269 if (val_cstr)
3270 value_str = val_cstr;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003271 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003272 err_cstr = valobj->GetError().AsCString();
3273 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003274
3275 if (err_cstr)
3276 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003277 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003278 }
3279 else
3280 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003281 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003282 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003283 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003284 if (options.m_omit_summary_depth == 0)
3285 {
3286 if (options.m_summary_sp)
3287 {
3288 valobj->GetSummaryAsCString(entry, summary_str);
3289 sum_cstr = summary_str.c_str();
3290 }
3291 else
3292 sum_cstr = valobj->GetSummaryAsCString();
3293 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003294
Greg Clayton6efba4f2012-01-26 21:08:30 +00003295 // Make sure we have a value and make sure the summary didn't
3296 // specify that the value should not be printed
3297 if (!value_str.empty() && (entry == NULL || entry->DoesPrintValue() || sum_cstr == NULL))
3298 s.Printf(" %s", value_str.c_str());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003299
Enrico Granata9dd75c82011-07-15 23:30:15 +00003300 if (sum_cstr)
Enrico Granata0c489f52012-03-01 04:24:26 +00003301 s.Printf(" %s", sum_cstr);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003302
Enrico Granata0c489f52012-03-01 04:24:26 +00003303 if (options.m_use_objc)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003304 {
Jim Ingham6035b672011-03-31 00:19:25 +00003305 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003306 if (object_desc)
3307 s.Printf(" %s\n", object_desc);
3308 else
Sean Callanan672ad942010-10-23 00:18:49 +00003309 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003310 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003311 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003312 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003313
Enrico Granata0c489f52012-03-01 04:24:26 +00003314 if (curr_depth < options.m_max_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003315 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003316 // We will show children for all concrete types. We won't show
3317 // pointer contents unless a pointer depth has been specified.
3318 // We won't reference contents unless the reference is the
3319 // root object (depth of zero).
3320 bool print_children = true;
3321
3322 // Use a new temporary pointer depth in case we override the
3323 // current pointer depth below...
3324 uint32_t curr_ptr_depth = ptr_depth;
3325
3326 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3327 if (is_ptr || is_ref)
3328 {
3329 // We have a pointer or reference whose value is an address.
3330 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003331 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003332 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003333 print_children = false;
3334
3335 else if (is_ref && curr_depth == 0)
3336 {
3337 // If this is the root object (depth is zero) that we are showing
3338 // and it is a reference, and no pointer depth has been supplied
3339 // print out what it references. Don't do this at deeper depths
3340 // otherwise we can end up with infinite recursion...
3341 curr_ptr_depth = 1;
3342 }
3343
3344 if (curr_ptr_depth == 0)
3345 print_children = false;
3346 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003347
Enrico Granata0a3958e2011-07-02 00:25:22 +00003348 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003349 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003350 ValueObject* synth_valobj;
3351 ValueObjectSP synth_valobj_sp = valobj->GetSyntheticValue (options.m_use_synthetic);
3352 synth_valobj = (synth_valobj_sp ? synth_valobj_sp.get() : valobj);
Enrico Granatac5bc4122012-03-27 02:35:13 +00003353
Enrico Granatac482a192011-08-17 22:13:59 +00003354 uint32_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003355 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003356 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003357 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003358 if (options.m_flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003359 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003360 if (print_valobj)
3361 s.EOL();
3362 }
3363 else
3364 {
3365 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003366 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003367 s.IndentMore();
3368 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003369
Greg Claytoncc4d0142012-02-17 07:49:44 +00003370 uint32_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00003371
Enrico Granata0c489f52012-03-01 04:24:26 +00003372 if (num_children > max_num_children && !options.m_ignore_cap)
Enrico Granata22c55d12011-08-12 02:00:06 +00003373 {
3374 num_children = max_num_children;
3375 print_dotdotdot = true;
3376 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003377
Enrico Granata0c489f52012-03-01 04:24:26 +00003378 ValueObject::DumpValueObjectOptions child_options(options);
3379 child_options.SetFormat().SetSummary().SetRootValueObjectName();
3380 child_options.SetScopeChecked(true)
3381 .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003382 for (uint32_t idx=0; idx<num_children; ++idx)
3383 {
Enrico Granatac482a192011-08-17 22:13:59 +00003384 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003385 if (child_sp.get())
3386 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003387 DumpValueObject_Impl (s,
3388 child_sp.get(),
3389 child_options,
3390 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
3391 curr_depth + 1);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003392 }
3393 }
3394
Enrico Granata0c489f52012-03-01 04:24:26 +00003395 if (!options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003396 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003397 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003398 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003399 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3400 Target *target = exe_ctx.GetTargetPtr();
3401 if (target)
3402 target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003403 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003404 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003405 s.IndentLess();
3406 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003407 }
3408 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003409 else if (has_children)
3410 {
3411 // Aggregate, no children...
3412 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003413 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003414 }
3415 else
3416 {
3417 if (print_valobj)
3418 s.EOL();
3419 }
3420
Greg Clayton1d3afba2010-10-05 00:00:42 +00003421 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003422 else
3423 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003424 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003425 }
3426 }
3427 else
3428 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003429 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003430 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003431 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003432 }
3433 }
3434 }
3435 }
3436}
3437
Enrico Granata0c489f52012-03-01 04:24:26 +00003438void
Greg Claytonf830dbb2012-03-22 18:15:37 +00003439ValueObject::LogValueObject (Log *log,
3440 ValueObject *valobj)
3441{
3442 if (log && valobj)
3443 return LogValueObject (log, valobj, DumpValueObjectOptions::DefaultOptions());
3444}
3445
3446void
3447ValueObject::LogValueObject (Log *log,
3448 ValueObject *valobj,
3449 const DumpValueObjectOptions& options)
3450{
3451 if (log && valobj)
3452 {
3453 StreamString s;
3454 ValueObject::DumpValueObject (s, valobj, options);
3455 if (s.GetSize())
3456 log->PutCString(s.GetData());
3457 }
3458}
3459
3460void
Enrico Granata0c489f52012-03-01 04:24:26 +00003461ValueObject::DumpValueObject (Stream &s,
3462 ValueObject *valobj)
3463{
3464
3465 if (!valobj)
3466 return;
3467
3468 DumpValueObject_Impl(s,
3469 valobj,
3470 DumpValueObjectOptions::DefaultOptions(),
3471 0,
3472 0);
3473}
3474
3475void
3476ValueObject::DumpValueObject (Stream &s,
3477 ValueObject *valobj,
3478 const DumpValueObjectOptions& options)
3479{
3480 DumpValueObject_Impl(s,
3481 valobj,
3482 options,
3483 options.m_max_ptr_depth, // max pointer depth allowed, we will go down from here
3484 0 // current object depth is 0 since we are just starting
3485 );
3486}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003487
3488ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003489ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003490{
3491 ValueObjectSP valobj_sp;
3492
Enrico Granatac3e320a2011-08-02 17:27:39 +00003493 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003494 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003495 ExecutionContext exe_ctx (GetExecutionContextRef());
3496 clang::ASTContext *ast = GetClangAST ();
3497
3498 DataExtractor data;
3499 data.SetByteOrder (m_data.GetByteOrder());
3500 data.SetAddressByteSize(m_data.GetAddressByteSize());
3501
Enrico Granata9f1e2042012-04-24 22:15:37 +00003502 if (IsBitfield())
3503 {
3504 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
3505 m_error = v.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
3506 }
3507 else
3508 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003509
3510 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3511 ast,
3512 GetClangType(),
3513 name,
3514 data,
3515 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003516 }
Jim Ingham6035b672011-03-31 00:19:25 +00003517
3518 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003519 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003520 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003521 }
3522 return valobj_sp;
3523}
3524
Greg Claytonafacd142011-09-02 01:15:17 +00003525ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003526ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003527{
Jim Ingham58b59f92011-04-22 23:53:53 +00003528 if (m_deref_valobj)
3529 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003530
Greg Clayton54979cd2010-12-15 05:08:08 +00003531 const bool is_pointer_type = IsPointerType();
3532 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003533 {
3534 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003535 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003536
3537 std::string child_name_str;
3538 uint32_t child_byte_size = 0;
3539 int32_t child_byte_offset = 0;
3540 uint32_t child_bitfield_bit_size = 0;
3541 uint32_t child_bitfield_bit_offset = 0;
3542 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003543 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003544 const bool transparent_pointers = false;
3545 clang::ASTContext *clang_ast = GetClangAST();
3546 clang_type_t clang_type = GetClangType();
3547 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003548
Greg Claytoncc4d0142012-02-17 07:49:44 +00003549 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003550
3551 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3552 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003553 GetName().GetCString(),
3554 clang_type,
3555 0,
3556 transparent_pointers,
3557 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003558 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003559 child_name_str,
3560 child_byte_size,
3561 child_byte_offset,
3562 child_bitfield_bit_size,
3563 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003564 child_is_base_class,
3565 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003566 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003567 {
3568 ConstString child_name;
3569 if (!child_name_str.empty())
3570 child_name.SetCString (child_name_str.c_str());
3571
Jim Ingham58b59f92011-04-22 23:53:53 +00003572 m_deref_valobj = new ValueObjectChild (*this,
3573 clang_ast,
3574 child_clang_type,
3575 child_name,
3576 child_byte_size,
3577 child_byte_offset,
3578 child_bitfield_bit_size,
3579 child_bitfield_bit_offset,
3580 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003581 child_is_deref_of_parent,
3582 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003583 }
3584 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003585
Jim Ingham58b59f92011-04-22 23:53:53 +00003586 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003587 {
3588 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003589 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003590 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003591 else
3592 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003593 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003594 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003595
3596 if (is_pointer_type)
3597 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3598 else
3599 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003600 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003601 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003602}
3603
Greg Claytonafacd142011-09-02 01:15:17 +00003604ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003605ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003606{
Jim Ingham78a685a2011-04-16 00:01:13 +00003607 if (m_addr_of_valobj_sp)
3608 return m_addr_of_valobj_sp;
3609
Greg Claytone0d378b2011-03-24 21:19:54 +00003610 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003611 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003612 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003613 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003614 if (addr != LLDB_INVALID_ADDRESS)
3615 {
3616 switch (address_type)
3617 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003618 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003619 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003620 {
3621 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003622 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003623 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3624 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003625 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003626
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003627 case eAddressTypeFile:
3628 case eAddressTypeLoad:
3629 case eAddressTypeHost:
3630 {
3631 clang::ASTContext *ast = GetClangAST();
3632 clang_type_t clang_type = GetClangType();
3633 if (ast && clang_type)
3634 {
3635 std::string name (1, '&');
3636 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003637 ExecutionContext exe_ctx (GetExecutionContextRef());
3638 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003639 ast,
3640 ClangASTContext::CreatePointerType (ast, clang_type),
3641 ConstString (name.c_str()),
3642 addr,
3643 eAddressTypeInvalid,
3644 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003645 }
3646 }
3647 break;
3648 }
3649 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003650 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003651}
3652
Greg Clayton9a142cf2012-02-03 05:34:10 +00003653ValueObjectSP
3654ValueObject::Cast (const ClangASTType &clang_ast_type)
3655{
Greg Clayton81e871e2012-02-04 02:27:34 +00003656 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003657}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003658
Greg Claytonafacd142011-09-02 01:15:17 +00003659ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003660ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
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 clang_ast_type);
3674 }
3675 return valobj_sp;
3676}
3677
Greg Claytonafacd142011-09-02 01:15:17 +00003678ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003679ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3680{
Greg Claytonafacd142011-09-02 01:15:17 +00003681 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003682 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003683 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003684
3685 if (ptr_value != LLDB_INVALID_ADDRESS)
3686 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003687 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003688 ExecutionContext exe_ctx (GetExecutionContextRef());
3689 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003690 name,
3691 ptr_addr,
3692 type_sp);
3693 }
3694 return valobj_sp;
3695}
3696
Jim Ingham6035b672011-03-31 00:19:25 +00003697ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003698 m_mod_id(),
3699 m_exe_ctx_ref(),
3700 m_needs_update (true),
3701 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003702{
3703}
3704
3705ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003706 m_mod_id(),
3707 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003708 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003709 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003710{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003711 ExecutionContext exe_ctx(exe_scope);
3712 TargetSP target_sp (exe_ctx.GetTargetSP());
3713 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003714 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003715 m_exe_ctx_ref.SetTargetSP (target_sp);
3716 ProcessSP process_sp (exe_ctx.GetProcessSP());
3717 if (!process_sp)
3718 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003719
Greg Claytoncc4d0142012-02-17 07:49:44 +00003720 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003721 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003722 m_mod_id = process_sp->GetModID();
3723 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003724
Greg Claytoncc4d0142012-02-17 07:49:44 +00003725 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003726
Greg Claytoncc4d0142012-02-17 07:49:44 +00003727 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003728 {
3729 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003730 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003731 }
Jim Ingham6035b672011-03-31 00:19:25 +00003732
Greg Claytoncc4d0142012-02-17 07:49:44 +00003733 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003734 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003735 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003736
Greg Claytoncc4d0142012-02-17 07:49:44 +00003737 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3738 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003739 {
3740 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003741 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003742 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003743 if (frame_sp)
3744 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003745 }
3746 }
3747 }
Jim Ingham6035b672011-03-31 00:19:25 +00003748}
3749
3750ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003751 m_mod_id(),
3752 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3753 m_needs_update (true),
3754 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003755{
3756}
3757
3758ValueObject::EvaluationPoint::~EvaluationPoint ()
3759{
3760}
3761
Jim Ingham6035b672011-03-31 00:19:25 +00003762// This function checks the EvaluationPoint against the current process state. If the current
3763// state matches the evaluation point, or the evaluation point is already invalid, then we return
3764// false, meaning "no change". If the current state is different, we update our state, and return
3765// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3766// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003767// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003768
3769bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003770ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003771{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003772
3773 // 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 +00003774 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00003775
Greg Claytoncc4d0142012-02-17 07:49:44 +00003776 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003777 return false;
3778
Jim Ingham6035b672011-03-31 00:19:25 +00003779 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003780 Process *process = exe_ctx.GetProcessPtr();
3781 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003782 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003783
Jim Ingham6035b672011-03-31 00:19:25 +00003784 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003785 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003786
Jim Ingham78a685a2011-04-16 00:01:13 +00003787 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3788 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003789 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003790 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003791
Greg Clayton23f59502012-07-17 03:23:13 +00003792 bool changed = false;
3793 const bool was_valid = m_mod_id.IsValid();
3794 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003795 {
3796 if (m_mod_id == current_mod_id)
3797 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003798 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003799 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003800 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003801 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003802 else
3803 {
3804 m_mod_id = current_mod_id;
3805 m_needs_update = true;
3806 changed = true;
3807 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003808 }
Jim Ingham6035b672011-03-31 00:19:25 +00003809
Jim Ingham73ca05a2011-12-17 01:35:57 +00003810 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3811 // That way we'll be sure to return a valid exe_scope.
3812 // 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 +00003813
Greg Claytoncc4d0142012-02-17 07:49:44 +00003814 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003815 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003816 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3817 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003818 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003819 if (m_exe_ctx_ref.HasFrameRef())
3820 {
3821 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3822 if (!frame_sp)
3823 {
3824 // We used to have a frame, but now it is gone
3825 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003826 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00003827 }
3828 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003829 }
Jim Ingham6035b672011-03-31 00:19:25 +00003830 else
3831 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003832 // We used to have a thread, but now it is gone
3833 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003834 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00003835 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003836
Jim Ingham6035b672011-03-31 00:19:25 +00003837 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003838 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003839}
3840
Jim Ingham61be0902011-05-02 18:13:59 +00003841void
3842ValueObject::EvaluationPoint::SetUpdated ()
3843{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003844 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3845 if (process_sp)
3846 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003847 m_first_update = false;
3848 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003849}
3850
3851
Greg Claytoncc4d0142012-02-17 07:49:44 +00003852//bool
3853//ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3854//{
3855// if (!IsValid())
3856// return false;
3857//
3858// bool needs_update = false;
3859//
3860// // The target has to be non-null, and the
3861// Target *target = exe_scope->CalculateTarget();
3862// if (target != NULL)
3863// {
3864// Target *old_target = m_target_sp.get();
3865// assert (target == old_target);
3866// Process *process = exe_scope->CalculateProcess();
3867// if (process != NULL)
3868// {
3869// // FOR NOW - assume you can't update variable objects across process boundaries.
3870// Process *old_process = m_process_sp.get();
3871// assert (process == old_process);
3872// ProcessModID current_mod_id = process->GetModID();
3873// if (m_mod_id != current_mod_id)
3874// {
3875// needs_update = true;
3876// m_mod_id = current_mod_id;
3877// }
3878// // See if we're switching the thread or stack context. If no thread is given, this is
3879// // being evaluated in a global context.
3880// Thread *thread = exe_scope->CalculateThread();
3881// if (thread != NULL)
3882// {
3883// user_id_t new_thread_index = thread->GetIndexID();
3884// if (new_thread_index != m_thread_id)
3885// {
3886// needs_update = true;
3887// m_thread_id = new_thread_index;
3888// m_stack_id.Clear();
3889// }
3890//
3891// StackFrame *new_frame = exe_scope->CalculateStackFrame();
3892// if (new_frame != NULL)
3893// {
3894// if (new_frame->GetStackID() != m_stack_id)
3895// {
3896// needs_update = true;
3897// m_stack_id = new_frame->GetStackID();
3898// }
3899// }
3900// else
3901// {
3902// m_stack_id.Clear();
3903// needs_update = true;
3904// }
3905// }
3906// else
3907// {
3908// // If this had been given a thread, and now there is none, we should update.
3909// // Otherwise we don't have to do anything.
3910// if (m_thread_id != LLDB_INVALID_UID)
3911// {
3912// m_thread_id = LLDB_INVALID_UID;
3913// m_stack_id.Clear();
3914// needs_update = true;
3915// }
3916// }
3917// }
3918// else
3919// {
3920// // If there is no process, then we don't need to update anything.
3921// // But if we're switching from having a process to not, we should try to update.
3922// if (m_process_sp.get() != NULL)
3923// {
3924// needs_update = true;
3925// m_process_sp.reset();
3926// m_thread_id = LLDB_INVALID_UID;
3927// m_stack_id.Clear();
3928// }
3929// }
3930// }
3931// else
3932// {
3933// // If there's no target, nothing can change so we don't need to update anything.
3934// // But if we're switching from having a target to not, we should try to update.
3935// if (m_target_sp.get() != NULL)
3936// {
3937// needs_update = true;
3938// m_target_sp.reset();
3939// m_process_sp.reset();
3940// m_thread_id = LLDB_INVALID_UID;
3941// m_stack_id.Clear();
3942// }
3943// }
3944// if (!m_needs_update)
3945// m_needs_update = needs_update;
3946//
3947// return needs_update;
3948//}
Enrico Granataf2bbf712011-07-15 02:26:42 +00003949
3950void
Enrico Granata86cc9822012-03-19 22:58:49 +00003951ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00003952{
Enrico Granata86cc9822012-03-19 22:58:49 +00003953 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
3954 m_value_str.clear();
3955
3956 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
3957 m_location_str.clear();
3958
3959 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
3960 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003961 m_summary_str.clear();
3962 }
3963
3964 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
3965 m_object_desc_str.clear();
3966
3967 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
3968 {
3969 if (m_synthetic_value)
3970 m_synthetic_value = NULL;
3971 }
Johnny Chen44805302011-07-19 19:48:13 +00003972}
Enrico Granata9128ee22011-09-06 19:20:51 +00003973
3974SymbolContextScope *
3975ValueObject::GetSymbolContextScope()
3976{
3977 if (m_parent)
3978 {
3979 if (!m_parent->IsPointerOrReferenceType())
3980 return m_parent->GetSymbolContextScope();
3981 }
3982 return NULL;
3983}