blob: c613965087ee3ac4ab3631cbde9b32524639db6f [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"
Greg Clayton1f746072012-08-29 21:13:06 +000025#include "lldb/Core/Module.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026#include "lldb/Core/StreamString.h"
27#include "lldb/Core/ValueObjectChild.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000028#include "lldb/Core/ValueObjectConstResult.h"
Jim Ingham78a685a2011-04-16 00:01:13 +000029#include "lldb/Core/ValueObjectDynamicValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030#include "lldb/Core/ValueObjectList.h"
Greg Claytonb2dcc362011-05-05 23:32:56 +000031#include "lldb/Core/ValueObjectMemory.h"
Enrico Granatad55546b2011-07-22 00:16:08 +000032#include "lldb/Core/ValueObjectSyntheticFilter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033
Greg Clayton7fb56d02011-02-01 01:31:41 +000034#include "lldb/Host/Endian.h"
35
Enrico Granata61a80ba2011-08-12 16:42:31 +000036#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granataf2bbf712011-07-15 02:26:42 +000037#include "lldb/Interpreter/ScriptInterpreterPython.h"
38
Greg Claytone1a916a2010-07-21 22:12:05 +000039#include "lldb/Symbol/ClangASTType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000040#include "lldb/Symbol/ClangASTContext.h"
41#include "lldb/Symbol/Type.h"
42
Jim Ingham53c47f12010-09-10 23:12:17 +000043#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000044#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000045#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046#include "lldb/Target/Process.h"
47#include "lldb/Target/RegisterContext.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000048#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000050
Enrico Granataf4efecd2011-07-12 22:56:10 +000051#include "lldb/Utility/RefCounter.h"
52
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053using namespace lldb;
54using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000055using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056
Greg Claytonafacd142011-09-02 01:15:17 +000057static user_id_t g_value_obj_uid = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058
59//----------------------------------------------------------------------
60// ValueObject constructor
61//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000062ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000063 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000064 m_parent (&parent),
Stephen Wilson71c21d12011-04-11 19:41:40 +000065 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066 m_name (),
67 m_data (),
68 m_value (),
69 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000070 m_value_str (),
71 m_old_value_str (),
72 m_location_str (),
73 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000074 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +000075 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000076 m_children (),
77 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000078 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000079 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000080 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000081 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000082 m_last_format_mgr_revision(0),
Enrico Granatad8b5fce2011-08-02 23:12:24 +000083 m_last_format_mgr_dynamic(parent.m_last_format_mgr_dynamic),
Enrico Granata0c489f52012-03-01 04:24:26 +000084 m_type_summary_sp(),
85 m_type_format_sp(),
86 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +000087 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +000088 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
Greg Clayton288bdf92010-09-02 02:59:18 +000089 m_value_is_valid (false),
90 m_value_did_change (false),
91 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000092 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +000093 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +000094 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +000095 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +000096 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +000097 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +000098 m_is_getting_summary(false),
99 m_did_calculate_complete_objc_class_type(false)
Jim Ingham6035b672011-03-31 00:19:25 +0000100{
Jim Ingham58b59f92011-04-22 23:53:53 +0000101 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000102}
103
104//----------------------------------------------------------------------
105// ValueObject constructor
106//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000107ValueObject::ValueObject (ExecutionContextScope *exe_scope,
108 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000109 UserID (++g_value_obj_uid), // Unique identifier for every value object
110 m_parent (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000111 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000112 m_name (),
113 m_data (),
114 m_value (),
115 m_error (),
116 m_value_str (),
117 m_old_value_str (),
118 m_location_str (),
119 m_summary_str (),
120 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000121 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000122 m_children (),
123 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000124 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000125 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000126 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000127 m_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000128 m_last_format_mgr_revision(0),
Greg Claytonafacd142011-09-02 01:15:17 +0000129 m_last_format_mgr_dynamic(eNoDynamicValues),
Enrico Granata0c489f52012-03-01 04:24:26 +0000130 m_type_summary_sp(),
131 m_type_format_sp(),
132 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000133 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000134 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Jim Ingham6035b672011-03-31 00:19:25 +0000135 m_value_is_valid (false),
136 m_value_did_change (false),
137 m_children_count_valid (false),
138 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000139 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000140 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000141 m_is_bitfield_for_scalar(false),
Enrico Granatad55546b2011-07-22 00:16:08 +0000142 m_is_expression_path_child(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000143 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000144 m_is_getting_summary(false),
145 m_did_calculate_complete_objc_class_type(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000146{
Jim Ingham58b59f92011-04-22 23:53:53 +0000147 m_manager = new ValueObjectManager();
148 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000149}
150
151//----------------------------------------------------------------------
152// Destructor
153//----------------------------------------------------------------------
154ValueObject::~ValueObject ()
155{
156}
157
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000158bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000159ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000160{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000161 return UpdateValueIfNeeded(m_last_format_mgr_dynamic, update_format);
162}
163
164bool
Greg Claytonafacd142011-09-02 01:15:17 +0000165ValueObject::UpdateValueIfNeeded (DynamicValueType use_dynamic, bool update_format)
Enrico Granatac3e320a2011-08-02 17:27:39 +0000166{
Enrico Granata4becb372011-06-29 22:27:15 +0000167
Enrico Granata9128ee22011-09-06 19:20:51 +0000168 bool did_change_formats = false;
169
Enrico Granata0a3958e2011-07-02 00:25:22 +0000170 if (update_format)
Enrico Granata9128ee22011-09-06 19:20:51 +0000171 did_change_formats = UpdateFormatsIfNeeded(use_dynamic);
Enrico Granata4becb372011-06-29 22:27:15 +0000172
Greg Claytonb71f3842010-10-05 03:13:51 +0000173 // If this is a constant value, then our success is predicated on whether
174 // we have an error or not
175 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000176 {
177 // if you were asked to update your formatters, but did not get a chance to do it
178 // clear your own values (this serves the purpose of faking a stop-id for frozen
179 // objects (which are regarded as constant, but could have changes behind their backs
180 // because of the frozen-pointer depth limit)
181 // TODO: decouple summary from value and then remove this code and only force-clear the summary
182 if (update_format && !did_change_formats)
Enrico Granata86cc9822012-03-19 22:58:49 +0000183 ClearUserVisibleData(eClearUserVisibleDataItemsSummary);
Greg Claytonb71f3842010-10-05 03:13:51 +0000184 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000185 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000186
Jim Ingham6035b672011-03-31 00:19:25 +0000187 bool first_update = m_update_point.IsFirstEvaluation();
188
189 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000190 {
Jim Ingham6035b672011-03-31 00:19:25 +0000191 m_update_point.SetUpdated();
192
193 // Save the old value using swap to avoid a string copy which
194 // also will clear our m_value_str
195 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000196 {
Jim Ingham6035b672011-03-31 00:19:25 +0000197 m_old_value_valid = false;
198 }
199 else
200 {
201 m_old_value_valid = true;
202 m_old_value_str.swap (m_value_str);
Enrico Granata86cc9822012-03-19 22:58:49 +0000203 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham6035b672011-03-31 00:19:25 +0000204 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000205
Enrico Granataf2bbf712011-07-15 02:26:42 +0000206 ClearUserVisibleData();
207
Greg Claytonefbc7d22012-03-09 04:23:44 +0000208 if (IsInScope())
Jim Ingham6035b672011-03-31 00:19:25 +0000209 {
Greg Claytonefbc7d22012-03-09 04:23:44 +0000210 const bool value_was_valid = GetValueIsValid();
211 SetValueDidChange (false);
212
213 m_error.Clear();
214
215 // Call the pure virtual function to update the value
216 bool success = UpdateValue ();
217
218 SetValueIsValid (success);
219
220 if (first_update)
221 SetValueDidChange (false);
222 else if (!m_value_did_change && success == false)
223 {
224 // The value wasn't gotten successfully, so we mark this
225 // as changed if the value used to be valid and now isn't
226 SetValueDidChange (value_was_valid);
227 }
228 }
229 else
230 {
231 m_error.SetErrorString("out of scope");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000232 }
233 }
234 return m_error.Success();
235}
236
Enrico Granata9128ee22011-09-06 19:20:51 +0000237bool
Greg Claytonafacd142011-09-02 01:15:17 +0000238ValueObject::UpdateFormatsIfNeeded(DynamicValueType use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000239{
Enrico Granata6f3533f2011-07-29 19:53:35 +0000240 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
241 if (log)
242 log->Printf("checking for FormatManager revisions. VO named %s is at revision %d, while the format manager is at revision %d",
243 GetName().GetCString(),
Enrico Granata4becb372011-06-29 22:27:15 +0000244 m_last_format_mgr_revision,
Enrico Granata85933ed2011-08-18 16:38:26 +0000245 DataVisualization::GetCurrentRevision());
Enrico Granata9128ee22011-09-06 19:20:51 +0000246
247 bool any_change = false;
248
Enrico Granata85933ed2011-08-18 16:38:26 +0000249 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()) ||
Enrico Granatac3e320a2011-08-02 17:27:39 +0000250 m_last_format_mgr_dynamic != use_dynamic)
Enrico Granata4becb372011-06-29 22:27:15 +0000251 {
Enrico Granata78d06382011-09-09 23:33:14 +0000252 SetValueFormat(DataVisualization::ValueFormats::GetFormat (*this, eNoDynamicValues));
253 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, use_dynamic));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000254#ifndef LLDB_DISABLE_PYTHON
Enrico Granata78d06382011-09-09 23:33:14 +0000255 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, use_dynamic));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000256#endif
Enrico Granata1490c6f2011-07-19 02:34:21 +0000257
Enrico Granata85933ed2011-08-18 16:38:26 +0000258 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
Enrico Granatac3e320a2011-08-02 17:27:39 +0000259 m_last_format_mgr_dynamic = use_dynamic;
Enrico Granata855cd902011-09-06 22:59:55 +0000260
261 any_change = true;
Enrico Granata4becb372011-06-29 22:27:15 +0000262 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000263
264 return any_change;
265
Enrico Granata4becb372011-06-29 22:27:15 +0000266}
267
Jim Ingham16e0c682011-08-12 23:34:31 +0000268void
269ValueObject::SetNeedsUpdate ()
270{
271 m_update_point.SetNeedsUpdate();
272 // We have to clear the value string here so ConstResult children will notice if their values are
273 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000274 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000275}
276
Sean Callanan72772842012-02-22 23:57:45 +0000277ClangASTType
278ValueObject::MaybeCalculateCompleteType ()
279{
280 ClangASTType ret(GetClangASTImpl(), GetClangTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000281
Sean Callanan72772842012-02-22 23:57:45 +0000282 if (m_did_calculate_complete_objc_class_type)
283 {
284 if (m_override_type.IsValid())
285 return m_override_type;
286 else
287 return ret;
288 }
289
290 clang_type_t ast_type(GetClangTypeImpl());
291 clang_type_t class_type;
292 bool is_pointer_type;
293
294 if (ClangASTContext::IsObjCObjectPointerType(ast_type, &class_type))
295 {
296 is_pointer_type = true;
297 }
298 else if (ClangASTContext::IsObjCClassType(ast_type))
299 {
300 is_pointer_type = false;
301 class_type = ast_type;
302 }
303 else
304 {
305 return ret;
306 }
307
308 m_did_calculate_complete_objc_class_type = true;
309
310 if (!class_type)
311 return ret;
312
313 std::string class_name;
314
315 if (!ClangASTContext::GetObjCClassName(class_type, class_name))
316 return ret;
317
318 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
319
320 if (!process_sp)
321 return ret;
322
323 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
324
325 if (!objc_language_runtime)
326 return ret;
327
328 ConstString class_name_cs(class_name.c_str());
329
330 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name_cs);
331
332 if (!complete_objc_class_type_sp)
333 return ret;
334
335 ClangASTType complete_class(complete_objc_class_type_sp->GetClangAST(),
336 complete_objc_class_type_sp->GetClangFullType());
337
338 if (!ClangASTContext::GetCompleteType(complete_class.GetASTContext(),
339 complete_class.GetOpaqueQualType()))
340 return ret;
341
342 if (is_pointer_type)
343 {
344 clang_type_t pointer_type = ClangASTContext::CreatePointerType(complete_class.GetASTContext(),
345 complete_class.GetOpaqueQualType());
346
347 m_override_type = ClangASTType(complete_class.GetASTContext(),
348 pointer_type);
349 }
350 else
351 {
352 m_override_type = complete_class;
353 }
354
Sean Callanan356e17c2012-03-30 02:04:38 +0000355 if (m_override_type.IsValid())
356 return m_override_type;
357 else
358 return ret;
Sean Callanan72772842012-02-22 23:57:45 +0000359}
360
361clang::ASTContext *
362ValueObject::GetClangAST ()
363{
364 ClangASTType type = MaybeCalculateCompleteType();
365
366 return type.GetASTContext();
367}
368
369lldb::clang_type_t
370ValueObject::GetClangType ()
371{
372 ClangASTType type = MaybeCalculateCompleteType();
373
374 return type.GetOpaqueQualType();
375}
376
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000377DataExtractor &
378ValueObject::GetDataExtractor ()
379{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000380 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000381 return m_data;
382}
383
384const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000385ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000386{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000387 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000388 return m_error;
389}
390
391const ConstString &
392ValueObject::GetName() const
393{
394 return m_name;
395}
396
397const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000398ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000399{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000400 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000401 {
402 if (m_location_str.empty())
403 {
404 StreamString sstr;
405
406 switch (m_value.GetValueType())
407 {
408 default:
409 break;
410
411 case Value::eValueTypeScalar:
Greg Clayton526e5af2010-11-13 03:52:47 +0000412 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000413 {
414 RegisterInfo *reg_info = m_value.GetRegisterInfo();
415 if (reg_info)
416 {
417 if (reg_info->name)
418 m_location_str = reg_info->name;
419 else if (reg_info->alt_name)
420 m_location_str = reg_info->alt_name;
421 break;
422 }
423 }
424 m_location_str = "scalar";
425 break;
426
427 case Value::eValueTypeLoadAddress:
428 case Value::eValueTypeFileAddress:
429 case Value::eValueTypeHostAddress:
430 {
431 uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2;
432 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
433 m_location_str.swap(sstr.GetString());
434 }
435 break;
436 }
437 }
438 }
439 return m_location_str.c_str();
440}
441
442Value &
443ValueObject::GetValue()
444{
445 return m_value;
446}
447
448const Value &
449ValueObject::GetValue() const
450{
451 return m_value;
452}
453
454bool
Jim Ingham6035b672011-03-31 00:19:25 +0000455ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000456{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000457 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
458 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000459 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000460 Value tmp_value(m_value);
461 scalar = tmp_value.ResolveValue(&exe_ctx, GetClangAST ());
Greg Claytondcad5022011-12-29 01:26:56 +0000462 if (scalar.IsValid())
463 {
464 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
465 if (bitfield_bit_size)
466 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
467 return true;
468 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000469 }
Greg Claytondcad5022011-12-29 01:26:56 +0000470 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000471}
472
473bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000474ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000475{
Greg Clayton288bdf92010-09-02 02:59:18 +0000476 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000477}
478
479
480void
481ValueObject::SetValueIsValid (bool b)
482{
Greg Clayton288bdf92010-09-02 02:59:18 +0000483 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000484}
485
486bool
Jim Ingham6035b672011-03-31 00:19:25 +0000487ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000488{
Jim Ingham6035b672011-03-31 00:19:25 +0000489 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000490 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000491}
492
493void
494ValueObject::SetValueDidChange (bool value_changed)
495{
Greg Clayton288bdf92010-09-02 02:59:18 +0000496 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000497}
498
499ValueObjectSP
500ValueObject::GetChildAtIndex (uint32_t idx, bool can_create)
501{
502 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000503 // We may need to update our value if we are dynamic
504 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000505 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000506 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000507 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000508 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000509 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000510 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000511 // No we haven't created the child at this index, so lets have our
512 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000513 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000514 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000515
Enrico Granata9d60f602012-03-09 03:09:58 +0000516 ValueObject* child = m_children.GetChildAtIndex(idx);
517 if (child != NULL)
518 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000519 }
520 return child_sp;
521}
522
523uint32_t
524ValueObject::GetIndexOfChildWithName (const ConstString &name)
525{
526 bool omit_empty_base_classes = true;
527 return ClangASTContext::GetIndexOfChildWithName (GetClangAST(),
Greg Clayton1be10fc2010-09-29 01:12:09 +0000528 GetClangType(),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000529 name.GetCString(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000530 omit_empty_base_classes);
531}
532
533ValueObjectSP
534ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
535{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000536 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000537 // classes (which really aren't part of the expression path), so we
538 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000539 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000540
Greg Claytondea8cb42011-06-29 22:09:02 +0000541 // We may need to update our value if we are dynamic
542 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000543 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000544
545 std::vector<uint32_t> child_indexes;
546 clang::ASTContext *clang_ast = GetClangAST();
547 void *clang_type = GetClangType();
548 bool omit_empty_base_classes = true;
549 const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast,
550 clang_type,
551 name.GetCString(),
552 omit_empty_base_classes,
553 child_indexes);
554 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000555 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000556 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
557 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
558
559 child_sp = GetChildAtIndex(*pos, can_create);
560 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000561 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000562 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000563 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000564 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
565 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000566 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000567 else
568 {
569 child_sp.reset();
570 }
571
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000572 }
573 }
574 return child_sp;
575}
576
577
578uint32_t
579ValueObject::GetNumChildren ()
580{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000581 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000582 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000583 {
584 SetNumChildren (CalculateNumChildren());
585 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000586 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000587}
588void
589ValueObject::SetNumChildren (uint32_t num_children)
590{
Greg Clayton288bdf92010-09-02 02:59:18 +0000591 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000592 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000593}
594
595void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000596ValueObject::SetName (const ConstString &name)
597{
598 m_name = name;
599}
600
Jim Ingham58b59f92011-04-22 23:53:53 +0000601ValueObject *
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000602ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index)
603{
Jim Ingham2eec4872011-05-07 00:10:58 +0000604 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000605
Greg Claytondea8cb42011-06-29 22:09:02 +0000606 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000607 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000608 std::string child_name_str;
609 uint32_t child_byte_size = 0;
610 int32_t child_byte_offset = 0;
611 uint32_t child_bitfield_bit_size = 0;
612 uint32_t child_bitfield_bit_offset = 0;
613 bool child_is_base_class = false;
614 bool child_is_deref_of_parent = false;
615
616 const bool transparent_pointers = synthetic_array_member == false;
617 clang::ASTContext *clang_ast = GetClangAST();
618 clang_type_t clang_type = GetClangType();
619 clang_type_t child_clang_type;
620
Greg Claytoncc4d0142012-02-17 07:49:44 +0000621 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000622
623 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
624 clang_ast,
625 GetName().GetCString(),
626 clang_type,
627 idx,
628 transparent_pointers,
629 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +0000630 ignore_array_bounds,
Greg Claytondea8cb42011-06-29 22:09:02 +0000631 child_name_str,
632 child_byte_size,
633 child_byte_offset,
634 child_bitfield_bit_size,
635 child_bitfield_bit_offset,
636 child_is_base_class,
637 child_is_deref_of_parent);
638 if (child_clang_type && child_byte_size)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000639 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000640 if (synthetic_index)
641 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000642
Greg Claytondea8cb42011-06-29 22:09:02 +0000643 ConstString child_name;
644 if (!child_name_str.empty())
645 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000646
Greg Claytondea8cb42011-06-29 22:09:02 +0000647 valobj = new ValueObjectChild (*this,
648 clang_ast,
649 child_clang_type,
650 child_name,
651 child_byte_size,
652 child_byte_offset,
653 child_bitfield_bit_size,
654 child_bitfield_bit_offset,
655 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000656 child_is_deref_of_parent,
657 eAddressTypeInvalid);
658 //if (valobj)
659 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
660 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000661
Jim Ingham58b59f92011-04-22 23:53:53 +0000662 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000663}
664
Enrico Granata0c489f52012-03-01 04:24:26 +0000665bool
666ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
667 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000668{
Enrico Granata0c489f52012-03-01 04:24:26 +0000669 destination.clear();
670
671 // ideally we would like to bail out if passing NULL, but if we do so
672 // we end up not providing the summary for function pointers anymore
673 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
674 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000675
676 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000677
678 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
679 // information that we might care to see in a crash log. might be useful in very specific situations though.
680 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
681 GetTypeName().GetCString(),
682 GetName().GetCString(),
683 summary_ptr->GetDescription().c_str());*/
684
Enrico Granata0c489f52012-03-01 04:24:26 +0000685 if (UpdateValueIfNeeded (false))
686 {
687 if (summary_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000688 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000689 if (HasSyntheticValue())
690 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
691 summary_ptr->FormatObject(this, destination);
Enrico Granata0c489f52012-03-01 04:24:26 +0000692 }
693 else
694 {
695 clang_type_t clang_type = GetClangType();
696
697 // Do some default printout for function pointers
698 if (clang_type)
Enrico Granata4becb372011-06-29 22:27:15 +0000699 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000700 StreamString sstr;
701 clang_type_t elem_or_pointee_clang_type;
702 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
703 GetClangAST(),
704 &elem_or_pointee_clang_type));
705
706 if (ClangASTContext::IsFunctionPointerType (clang_type))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000707 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000708 AddressType func_ptr_address_type = eAddressTypeInvalid;
709 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
710 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000711 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000712 switch (func_ptr_address_type)
Jim Ingham6035b672011-03-31 00:19:25 +0000713 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000714 case eAddressTypeInvalid:
715 case eAddressTypeFile:
716 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000717
Greg Claytoncc4d0142012-02-17 07:49:44 +0000718 case eAddressTypeLoad:
Enrico Granata0c489f52012-03-01 04:24:26 +0000719 {
720 ExecutionContext exe_ctx (GetExecutionContextRef());
721
722 Address so_addr;
723 Target *target = exe_ctx.GetTargetPtr();
724 if (target && target->GetSectionLoadList().IsEmpty() == false)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000725 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000726 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000727 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000728 so_addr.Dump (&sstr,
729 exe_ctx.GetBestExecutionContextScope(),
730 Address::DumpStyleResolvedDescription,
731 Address::DumpStyleSectionNameOffset);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000732 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000733 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000734 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000735 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000736
Greg Claytoncc4d0142012-02-17 07:49:44 +0000737 case eAddressTypeHost:
738 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +0000739 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000740 }
741 if (sstr.GetSize() > 0)
742 {
743 destination.assign (1, '(');
744 destination.append (sstr.GetData(), sstr.GetSize());
745 destination.append (1, ')');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000746 }
747 }
748 }
749 }
750 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000751 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000752 return !destination.empty();
753}
754
755const char *
756ValueObject::GetSummaryAsCString ()
757{
758 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
759 {
760 GetSummaryAsCString(GetSummaryFormat().get(),
761 m_summary_str);
762 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000763 if (m_summary_str.empty())
764 return NULL;
765 return m_summary_str.c_str();
766}
767
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000768bool
769ValueObject::IsCStringContainer(bool check_pointer)
770{
771 clang_type_t elem_or_pointee_clang_type;
772 const Flags type_flags (ClangASTContext::GetTypeInfo (GetClangType(),
773 GetClangAST(),
774 &elem_or_pointee_clang_type));
775 bool is_char_arr_ptr (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
776 ClangASTContext::IsCharType (elem_or_pointee_clang_type));
777 if (!is_char_arr_ptr)
778 return false;
779 if (!check_pointer)
780 return true;
781 if (type_flags.Test(ClangASTContext::eTypeIsArray))
782 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000783 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000784 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000785 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000786 return (cstr_address != LLDB_INVALID_ADDRESS);
787}
788
Enrico Granata9128ee22011-09-06 19:20:51 +0000789size_t
790ValueObject::GetPointeeData (DataExtractor& data,
791 uint32_t item_idx,
792 uint32_t item_count)
793{
794 if (!IsPointerType() && !IsArrayType())
795 return 0;
796
797 if (item_count == 0)
798 return 0;
799
800 uint32_t stride = 0;
801
802 ClangASTType type(GetClangAST(),
803 GetClangType());
804
805 const uint64_t item_type_size = (IsPointerType() ? ClangASTType::GetTypeByteSize(GetClangAST(), type.GetPointeeType()) :
806 ClangASTType::GetTypeByteSize(GetClangAST(), type.GetArrayElementType(stride)));
807
808 const uint64_t bytes = item_count * item_type_size;
809
810 const uint64_t offset = item_idx * item_type_size;
811
812 if (item_idx == 0 && item_count == 1) // simply a deref
813 {
814 if (IsPointerType())
815 {
816 Error error;
817 ValueObjectSP pointee_sp = Dereference(error);
818 if (error.Fail() || pointee_sp.get() == NULL)
819 return 0;
820 return pointee_sp->GetDataExtractor().Copy(data);
821 }
822 else
823 {
824 ValueObjectSP child_sp = GetChildAtIndex(0, true);
825 if (child_sp.get() == NULL)
826 return 0;
827 return child_sp->GetDataExtractor().Copy(data);
828 }
829 return true;
830 }
831 else /* (items > 1) */
832 {
833 Error error;
834 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
835 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
836
837 AddressType addr_type;
838 lldb::addr_t addr = IsPointerType() ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
839
Enrico Granata9128ee22011-09-06 19:20:51 +0000840 switch (addr_type)
841 {
842 case eAddressTypeFile:
843 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000844 ModuleSP module_sp (GetModule());
845 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000846 {
Enrico Granata9c2efe32012-08-07 01:49:34 +0000847 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +0000848 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +0000849 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000850 ExecutionContext exe_ctx (GetExecutionContextRef());
851 Target* target = exe_ctx.GetTargetPtr();
852 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +0000853 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000854 heap_buf_ptr->SetByteSize(bytes);
855 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
856 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +0000857 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000858 data.SetData(data_sp);
859 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +0000860 }
861 }
862 }
863 }
864 break;
865 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +0000866 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000867 ExecutionContext exe_ctx (GetExecutionContextRef());
868 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +0000869 if (process)
870 {
871 heap_buf_ptr->SetByteSize(bytes);
872 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
873 if (error.Success())
874 {
875 data.SetData(data_sp);
876 return bytes_read;
877 }
878 }
879 }
880 break;
881 case eAddressTypeHost:
882 {
883 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes);
884 data.SetData(data_sp);
885 return bytes;
886 }
887 break;
888 case eAddressTypeInvalid:
889 default:
890 break;
891 }
892 }
893 return 0;
894}
895
896size_t
897ValueObject::GetData (DataExtractor& data)
898{
899 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000900 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytone72dfb32012-02-24 01:59:29 +0000901 Error error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +0000902 if (error.Fail())
903 return 0;
904 data.SetAddressByteSize(m_data.GetAddressByteSize());
905 data.SetByteOrder(m_data.GetByteOrder());
906 return data.GetByteSize();
907}
908
909// will compute strlen(str), but without consuming more than
910// maxlen bytes out of str (this serves the purpose of reading
911// chunks of a string without having to worry about
912// missing NULL terminators in the chunk)
913// of course, if strlen(str) > maxlen, the function will return
914// maxlen_value (which should be != maxlen, because that allows you
915// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
916static uint32_t
917strlen_or_inf (const char* str,
918 uint32_t maxlen,
919 uint32_t maxlen_value)
920{
921 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +0000922 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +0000923 {
Greg Clayton8dd5c172011-10-05 22:19:51 +0000924 while(*str)
925 {
926 len++;str++;
927 if (len > maxlen)
928 return maxlen_value;
929 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000930 }
931 return len;
932}
933
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000934void
Greg Claytoncc4d0142012-02-17 07:49:44 +0000935ValueObject::ReadPointedString (Stream& s,
936 Error& error,
937 uint32_t max_length,
938 bool honor_array,
939 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000940{
Greg Claytoncc4d0142012-02-17 07:49:44 +0000941 ExecutionContext exe_ctx (GetExecutionContextRef());
942 Target* target = exe_ctx.GetTargetPtr();
943
944 if (target && max_length == 0)
945 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000946
947 clang_type_t clang_type = GetClangType();
948 clang_type_t elem_or_pointee_clang_type;
949 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
950 GetClangAST(),
951 &elem_or_pointee_clang_type));
952 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
953 ClangASTContext::IsCharType (elem_or_pointee_clang_type))
954 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000955 if (target == NULL)
956 {
957 s << "<no target to read from>";
958 }
959 else
960 {
961 addr_t cstr_address = LLDB_INVALID_ADDRESS;
962 AddressType cstr_address_type = eAddressTypeInvalid;
963
964 size_t cstr_len = 0;
965 bool capped_data = false;
966 if (type_flags.Test (ClangASTContext::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000967 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000968 // We have an array
969 cstr_len = ClangASTContext::GetArraySize (clang_type);
970 if (cstr_len > max_length)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000971 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000972 capped_data = true;
973 cstr_len = max_length;
974 }
975 cstr_address = GetAddressOf (true, &cstr_address_type);
976 }
977 else
978 {
979 // We have a pointer
980 cstr_address = GetPointerValue (&cstr_address_type);
981 }
982 if (cstr_address != 0 && cstr_address != LLDB_INVALID_ADDRESS)
983 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000984 Address cstr_so_addr (cstr_address);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000985 DataExtractor data;
986 size_t bytes_read = 0;
987 if (cstr_len > 0 && honor_array)
988 {
989 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
990 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
991 GetPointeeData(data, 0, cstr_len);
992
993 if ((bytes_read = data.GetByteSize()) > 0)
994 {
995 s << '"';
996 data.Dump (&s,
997 0, // Start offset in "data"
998 item_format,
999 1, // Size of item (1 byte for a char!)
1000 bytes_read, // How many bytes to print?
1001 UINT32_MAX, // num per line
1002 LLDB_INVALID_ADDRESS,// base address
1003 0, // bitfield bit size
1004 0); // bitfield bit offset
1005 if (capped_data)
1006 s << "...";
1007 s << '"';
1008 }
Enrico Granata6f3533f2011-07-29 19:53:35 +00001009 }
1010 else
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001011 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001012 cstr_len = max_length;
1013 const size_t k_max_buf_size = 64;
1014
1015 size_t offset = 0;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001016
Greg Claytoncc4d0142012-02-17 07:49:44 +00001017 int cstr_len_displayed = -1;
1018 bool capped_cstr = false;
1019 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1020 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1021 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001022 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001023 const char *cstr = data.PeekCStr(0);
1024 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1025 if (len > k_max_buf_size)
1026 len = k_max_buf_size;
1027 if (cstr && cstr_len_displayed < 0)
1028 s << '"';
1029
1030 if (cstr_len_displayed < 0)
1031 cstr_len_displayed = len;
1032
1033 if (len == 0)
1034 break;
1035 cstr_len_displayed += len;
1036 if (len > bytes_read)
1037 len = bytes_read;
1038 if (len > cstr_len)
1039 len = cstr_len;
1040
1041 data.Dump (&s,
1042 0, // Start offset in "data"
1043 item_format,
1044 1, // Size of item (1 byte for a char!)
1045 len, // How many bytes to print?
1046 UINT32_MAX, // num per line
1047 LLDB_INVALID_ADDRESS,// base address
1048 0, // bitfield bit size
1049 0); // bitfield bit offset
1050
1051 if (len < k_max_buf_size)
1052 break;
1053
1054 if (len >= cstr_len)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001055 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001056 capped_cstr = true;
1057 break;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001058 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001059
1060 cstr_len -= len;
1061 offset += len;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001062 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001063
1064 if (cstr_len_displayed >= 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001065 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001066 s << '"';
1067 if (capped_cstr)
1068 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001069 }
1070 }
1071 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001072 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001073 }
1074 else
1075 {
1076 error.SetErrorString("impossible to read a string from this object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001077 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001078 }
1079}
1080
Jim Ingham53c47f12010-09-10 23:12:17 +00001081const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001082ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001083{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001084
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001085 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001086 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001087
1088 if (!m_object_desc_str.empty())
1089 return m_object_desc_str.c_str();
1090
Greg Claytoncc4d0142012-02-17 07:49:44 +00001091 ExecutionContext exe_ctx (GetExecutionContextRef());
1092 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001093 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001094 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001095
Jim Ingham53c47f12010-09-10 23:12:17 +00001096 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001097
Greg Claytonafacd142011-09-02 01:15:17 +00001098 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001099 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1100
Jim Inghama2cf2632010-12-23 02:29:54 +00001101 if (runtime == NULL)
1102 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001103 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Jim Inghama2cf2632010-12-23 02:29:54 +00001104 clang_type_t opaque_qual_type = GetClangType();
1105 if (opaque_qual_type != NULL)
1106 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001107 bool is_signed;
1108 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed)
1109 || ClangASTContext::IsPointerType (opaque_qual_type))
1110 {
Greg Claytonafacd142011-09-02 01:15:17 +00001111 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001112 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001113 }
1114 }
1115
Jim Ingham8d543de2011-03-31 23:01:21 +00001116 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001117 {
1118 m_object_desc_str.append (s.GetData());
1119 }
Sean Callanan672ad942010-10-23 00:18:49 +00001120
1121 if (m_object_desc_str.empty())
1122 return NULL;
1123 else
1124 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001125}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001126
Enrico Granata0c489f52012-03-01 04:24:26 +00001127bool
1128ValueObject::GetValueAsCString (lldb::Format format,
1129 std::string& destination)
1130{
1131 if (ClangASTContext::IsAggregateType (GetClangType()) == false &&
1132 UpdateValueIfNeeded(false))
1133 {
1134 const Value::ContextType context_type = m_value.GetContextType();
1135
1136 switch (context_type)
1137 {
1138 case Value::eContextTypeClangType:
1139 case Value::eContextTypeLLDBType:
1140 case Value::eContextTypeVariable:
1141 {
1142 clang_type_t clang_type = GetClangType ();
1143 if (clang_type)
1144 {
1145 StreamString sstr;
1146 ExecutionContext exe_ctx (GetExecutionContextRef());
1147 ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
1148 clang_type, // The clang type to display
1149 &sstr,
1150 format, // Format to display this type with
1151 m_data, // Data to extract from
1152 0, // Byte offset into "m_data"
1153 GetByteSize(), // Byte size of item in "m_data"
1154 GetBitfieldBitSize(), // Bitfield bit size
1155 GetBitfieldBitOffset(), // Bitfield bit offset
1156 exe_ctx.GetBestExecutionContextScope());
1157 // Don't set the m_error to anything here otherwise
1158 // we won't be able to re-format as anything else. The
1159 // code for ClangASTType::DumpTypeValue() should always
1160 // return something, even if that something contains
1161 // an error messsage. "m_error" is used to detect errors
1162 // when reading the valid object, not for formatting errors.
1163 if (sstr.GetString().empty())
1164 destination.clear();
1165 else
1166 destination.swap(sstr.GetString());
1167 }
1168 }
1169 break;
1170
1171 case Value::eContextTypeRegisterInfo:
1172 {
1173 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1174 if (reg_info)
1175 {
1176 ExecutionContext exe_ctx (GetExecutionContextRef());
1177
1178 StreamString reg_sstr;
1179 m_data.Dump (&reg_sstr,
1180 0,
1181 format,
1182 reg_info->byte_size,
1183 1,
1184 UINT32_MAX,
1185 LLDB_INVALID_ADDRESS,
1186 0,
1187 0,
1188 exe_ctx.GetBestExecutionContextScope());
1189 destination.swap(reg_sstr.GetString());
1190 }
1191 }
1192 break;
1193
1194 default:
1195 break;
1196 }
1197 return !destination.empty();
1198 }
1199 else
1200 return false;
1201}
1202
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001203const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001204ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001205{
Enrico Granata0c489f52012-03-01 04:24:26 +00001206 if (UpdateValueIfNeeded(true) && m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001207 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001208 lldb::Format my_format = GetFormat();
1209 if (m_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001210 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001211 if (m_type_format_sp)
1212 my_format = m_type_format_sp->GetFormat();
1213 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001214 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001215 if (m_is_bitfield_for_scalar)
1216 my_format = eFormatUnsigned;
1217 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001218 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001219 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001220 {
1221 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1222 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001223 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001224 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001225 else
1226 {
1227 clang_type_t clang_type = GetClangType ();
1228 my_format = ClangASTType::GetFormat(clang_type);
1229 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001230 }
1231 }
1232 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001233 if (GetValueAsCString(my_format, m_value_str))
1234 {
1235 if (!m_value_did_change && m_old_value_valid)
1236 {
1237 // The value was gotten successfully, so we consider the
1238 // value as changed if the value string differs
1239 SetValueDidChange (m_old_value_str != m_value_str);
1240 }
1241 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001242 }
1243 if (m_value_str.empty())
1244 return NULL;
1245 return m_value_str.c_str();
1246}
1247
Enrico Granatac3e320a2011-08-02 17:27:39 +00001248// if > 8bytes, 0 is returned. this method should mostly be used
1249// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001250uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001251ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001252{
1253 // If our byte size is zero this is an aggregate type that has children
1254 if (ClangASTContext::IsAggregateType (GetClangType()) == false)
1255 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001256 Scalar scalar;
1257 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001258 {
1259 if (success)
1260 *success = true;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001261 return scalar.GetRawBits64(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001262 }
1263 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001264 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001265
1266 if (success)
1267 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001268 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001269}
1270
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001271// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1272// this call up to date by returning true for your new special cases. We will eventually move
1273// to checking this call result before trying to display special cases
1274bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001275ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1276 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001277{
1278 clang_type_t elem_or_pointee_type;
1279 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
1280
1281 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001282 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001283 {
1284 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001285 (custom_format == eFormatCString ||
1286 custom_format == eFormatCharArray ||
1287 custom_format == eFormatChar ||
1288 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001289 return true;
1290
1291 if (flags.Test(ClangASTContext::eTypeIsArray))
1292 {
Greg Claytonafacd142011-09-02 01:15:17 +00001293 if ((custom_format == eFormatBytes) ||
1294 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001295 return true;
1296
Greg Claytonafacd142011-09-02 01:15:17 +00001297 if ((custom_format == eFormatVectorOfChar) ||
1298 (custom_format == eFormatVectorOfFloat32) ||
1299 (custom_format == eFormatVectorOfFloat64) ||
1300 (custom_format == eFormatVectorOfSInt16) ||
1301 (custom_format == eFormatVectorOfSInt32) ||
1302 (custom_format == eFormatVectorOfSInt64) ||
1303 (custom_format == eFormatVectorOfSInt8) ||
1304 (custom_format == eFormatVectorOfUInt128) ||
1305 (custom_format == eFormatVectorOfUInt16) ||
1306 (custom_format == eFormatVectorOfUInt32) ||
1307 (custom_format == eFormatVectorOfUInt64) ||
1308 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001309 return true;
1310 }
1311 }
1312 return false;
1313}
1314
Enrico Granata9fc19442011-07-06 02:13:41 +00001315bool
1316ValueObject::DumpPrintableRepresentation(Stream& s,
1317 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001318 Format custom_format,
Enrico Granata86cc9822012-03-19 22:58:49 +00001319 PrintableRepresentationSpecialCases special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001320{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001321
1322 clang_type_t elem_or_pointee_type;
1323 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001324
Enrico Granata86cc9822012-03-19 22:58:49 +00001325 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1326 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1327
1328 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001329 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001330 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer)
1331 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001332 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001333 // when being asked to get a printable display an array or pointer type directly,
1334 // try to "do the right thing"
1335
1336 if (IsCStringContainer(true) &&
1337 (custom_format == eFormatCString ||
1338 custom_format == eFormatCharArray ||
1339 custom_format == eFormatChar ||
1340 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001341 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001342 Error error;
1343 ReadPointedString(s,
1344 error,
1345 0,
1346 (custom_format == eFormatVectorOfChar) ||
1347 (custom_format == eFormatCharArray));
1348 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001349 }
1350
Enrico Granata86cc9822012-03-19 22:58:49 +00001351 if (custom_format == eFormatEnum)
1352 return false;
1353
1354 // this only works for arrays, because I have no way to know when
1355 // the pointed memory ends, and no special \0 end of data marker
1356 if (flags.Test(ClangASTContext::eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001357 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001358 if ((custom_format == eFormatBytes) ||
1359 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001360 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001361 uint32_t count = GetNumChildren();
1362
1363 s << '[';
1364 for (uint32_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001365 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001366
1367 if (low)
1368 s << ',';
1369
1370 ValueObjectSP child = GetChildAtIndex(low,true);
1371 if (!child.get())
1372 {
1373 s << "<invalid child>";
1374 continue;
1375 }
1376 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1377 }
1378
1379 s << ']';
1380
1381 return true;
1382 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001383
Enrico Granata86cc9822012-03-19 22:58:49 +00001384 if ((custom_format == eFormatVectorOfChar) ||
1385 (custom_format == eFormatVectorOfFloat32) ||
1386 (custom_format == eFormatVectorOfFloat64) ||
1387 (custom_format == eFormatVectorOfSInt16) ||
1388 (custom_format == eFormatVectorOfSInt32) ||
1389 (custom_format == eFormatVectorOfSInt64) ||
1390 (custom_format == eFormatVectorOfSInt8) ||
1391 (custom_format == eFormatVectorOfUInt128) ||
1392 (custom_format == eFormatVectorOfUInt16) ||
1393 (custom_format == eFormatVectorOfUInt32) ||
1394 (custom_format == eFormatVectorOfUInt64) ||
1395 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1396 {
1397 uint32_t count = GetNumChildren();
1398
1399 Format format = FormatManager::GetSingleItemFormat(custom_format);
1400
1401 s << '[';
1402 for (uint32_t low = 0; low < count; low++)
1403 {
1404
1405 if (low)
1406 s << ',';
1407
1408 ValueObjectSP child = GetChildAtIndex(low,true);
1409 if (!child.get())
1410 {
1411 s << "<invalid child>";
1412 continue;
1413 }
1414 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1415 }
1416
1417 s << ']';
1418
1419 return true;
1420 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001421 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001422
1423 if ((custom_format == eFormatBoolean) ||
1424 (custom_format == eFormatBinary) ||
1425 (custom_format == eFormatChar) ||
1426 (custom_format == eFormatCharPrintable) ||
1427 (custom_format == eFormatComplexFloat) ||
1428 (custom_format == eFormatDecimal) ||
1429 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001430 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001431 (custom_format == eFormatFloat) ||
1432 (custom_format == eFormatOctal) ||
1433 (custom_format == eFormatOSType) ||
1434 (custom_format == eFormatUnicode16) ||
1435 (custom_format == eFormatUnicode32) ||
1436 (custom_format == eFormatUnsigned) ||
1437 (custom_format == eFormatPointer) ||
1438 (custom_format == eFormatComplexInteger) ||
1439 (custom_format == eFormatComplex) ||
1440 (custom_format == eFormatDefault)) // use the [] operator
1441 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001442 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001443 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001444
1445 if (only_special)
1446 return false;
1447
Enrico Granata86cc9822012-03-19 22:58:49 +00001448 bool var_success = false;
1449
1450 {
1451 const char * return_value;
1452 std::string alloc_mem;
1453
1454 if (custom_format != eFormatInvalid)
1455 SetFormat(custom_format);
1456
1457 switch(val_obj_display)
1458 {
1459 case eValueObjectRepresentationStyleValue:
1460 return_value = GetValueAsCString();
1461 break;
1462
1463 case eValueObjectRepresentationStyleSummary:
1464 return_value = GetSummaryAsCString();
1465 break;
1466
1467 case eValueObjectRepresentationStyleLanguageSpecific:
1468 return_value = GetObjectDescription();
1469 break;
1470
1471 case eValueObjectRepresentationStyleLocation:
1472 return_value = GetLocationAsCString();
1473 break;
1474
1475 case eValueObjectRepresentationStyleChildrenCount:
1476 {
1477 alloc_mem.resize(512);
1478 return_value = &alloc_mem[0];
1479 int count = GetNumChildren();
1480 snprintf((char*)return_value, 512, "%d", count);
1481 }
1482 break;
1483
1484 case eValueObjectRepresentationStyleType:
1485 return_value = GetTypeName().AsCString();
1486 break;
1487
1488 default:
1489 break;
1490 }
1491
1492 if (!return_value)
1493 {
1494 if (val_obj_display == eValueObjectRepresentationStyleValue)
1495 return_value = GetSummaryAsCString();
1496 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1497 {
1498 if (ClangASTContext::IsAggregateType (GetClangType()) == true)
1499 {
1500 // this thing has no value, and it seems to have no summary
1501 // some combination of unitialized data and other factors can also
1502 // raise this condition, so let's print a nice generic description
1503 {
1504 alloc_mem.resize(684);
1505 return_value = &alloc_mem[0];
1506 snprintf((char*)return_value, 684, "%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1507 }
1508 }
1509 else
1510 return_value = GetValueAsCString();
1511 }
1512 }
1513
1514 if (return_value)
1515 s.PutCString(return_value);
1516 else
1517 {
1518 if (m_error.Fail())
1519 s.Printf("<%s>", m_error.AsCString());
1520 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1521 s.PutCString("<no summary available>");
1522 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1523 s.PutCString("<no value available>");
1524 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1525 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1526 else
1527 s.PutCString("<no printable representation>");
1528 }
1529
1530 // we should only return false here if we could not do *anything*
1531 // even if we have an error message as output, that's a success
1532 // from our callers' perspective, so return true
1533 var_success = true;
1534
1535 if (custom_format != eFormatInvalid)
1536 SetFormat(eFormatDefault);
1537 }
1538
Enrico Granataf4efecd2011-07-12 22:56:10 +00001539 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001540}
1541
Greg Clayton737b9322010-09-13 03:32:57 +00001542addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001543ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001544{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001545 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001546 return LLDB_INVALID_ADDRESS;
1547
Greg Clayton73b472d2010-10-27 03:32:59 +00001548 switch (m_value.GetValueType())
1549 {
1550 case Value::eValueTypeScalar:
1551 if (scalar_is_load_address)
1552 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001553 if(address_type)
1554 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001555 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1556 }
1557 break;
1558
1559 case Value::eValueTypeLoadAddress:
1560 case Value::eValueTypeFileAddress:
1561 case Value::eValueTypeHostAddress:
1562 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001563 if(address_type)
1564 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001565 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1566 }
1567 break;
1568 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001569 if (address_type)
1570 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001571 return LLDB_INVALID_ADDRESS;
1572}
1573
1574addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001575ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001576{
Greg Claytonafacd142011-09-02 01:15:17 +00001577 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001578 if(address_type)
1579 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001580
Enrico Granatac3e320a2011-08-02 17:27:39 +00001581 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001582 return address;
1583
Greg Clayton73b472d2010-10-27 03:32:59 +00001584 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001585 {
1586 case Value::eValueTypeScalar:
Enrico Granata9128ee22011-09-06 19:20:51 +00001587 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001588 break;
1589
Enrico Granata9128ee22011-09-06 19:20:51 +00001590 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001591 case Value::eValueTypeLoadAddress:
1592 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001593 {
1594 uint32_t data_offset = 0;
1595 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001596 }
1597 break;
1598 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001599
Enrico Granata9128ee22011-09-06 19:20:51 +00001600 if (address_type)
1601 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001602
Greg Clayton737b9322010-09-13 03:32:57 +00001603 return address;
1604}
1605
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001606bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001607ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001608{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001609 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001610 // Make sure our value is up to date first so that our location and location
1611 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001612 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001613 {
1614 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001615 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001616 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001617
1618 uint32_t count = 0;
Greg Claytonafacd142011-09-02 01:15:17 +00001619 Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001620
Greg Claytonb1320972010-07-14 00:18:15 +00001621 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001622
Jim Ingham16e0c682011-08-12 23:34:31 +00001623 Value::ValueType value_type = m_value.GetValueType();
1624
1625 if (value_type == Value::eValueTypeScalar)
1626 {
1627 // If the value is already a scalar, then let the scalar change itself:
1628 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1629 }
1630 else if (byte_size <= Scalar::GetMaxByteSize())
1631 {
1632 // If the value fits in a scalar, then make a new scalar and again let the
1633 // scalar code do the conversion, then figure out where to put the new value.
1634 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001635 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1636 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001637 {
Jim Ingham4b536182011-08-09 02:12:22 +00001638 switch (value_type)
1639 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001640 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001641 {
1642 // If it is a load address, then the scalar value is the storage location
1643 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001644 ExecutionContext exe_ctx (GetExecutionContextRef());
1645 Process *process = exe_ctx.GetProcessPtr();
1646 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001647 {
Greg Claytonafacd142011-09-02 01:15:17 +00001648 addr_t target_addr = m_value.GetScalar().GetRawBits64(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001649 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1650 new_scalar,
1651 byte_size,
1652 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001653 if (!error.Success())
1654 return false;
1655 if (bytes_written != byte_size)
1656 {
1657 error.SetErrorString("unable to write value to memory");
1658 return false;
1659 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001660 }
1661 }
Jim Ingham4b536182011-08-09 02:12:22 +00001662 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001663 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001664 {
1665 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1666 DataExtractor new_data;
1667 new_data.SetByteOrder (m_data.GetByteOrder());
1668
1669 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1670 m_data.SetData(buffer_sp, 0);
1671 bool success = new_scalar.GetData(new_data);
1672 if (success)
1673 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001674 new_data.CopyByteOrderedData (0,
1675 byte_size,
1676 const_cast<uint8_t *>(m_data.GetDataStart()),
1677 byte_size,
1678 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001679 }
1680 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1681
1682 }
Jim Ingham4b536182011-08-09 02:12:22 +00001683 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001684 case Value::eValueTypeFileAddress:
1685 case Value::eValueTypeScalar:
Jim Ingham16e0c682011-08-12 23:34:31 +00001686 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001687 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001688 }
1689 else
1690 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001691 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001692 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001693 }
1694 else
1695 {
1696 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001697 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001698 return false;
1699 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001700
1701 // If we have reached this point, then we have successfully changed the value.
1702 SetNeedsUpdate();
1703 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001704}
1705
Greg Clayton81e871e2012-02-04 02:27:34 +00001706bool
1707ValueObject::GetDeclaration (Declaration &decl)
1708{
1709 decl.Clear();
1710 return false;
1711}
1712
Greg Clayton84db9102012-03-26 23:03:23 +00001713ConstString
1714ValueObject::GetTypeName()
1715{
1716 return ClangASTType::GetConstTypeName (GetClangAST(), GetClangType());
1717}
1718
1719ConstString
1720ValueObject::GetQualifiedTypeName()
1721{
1722 return ClangASTType::GetConstQualifiedTypeName (GetClangAST(), GetClangType());
1723}
1724
1725
Greg Claytonafacd142011-09-02 01:15:17 +00001726LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001727ValueObject::GetObjectRuntimeLanguage ()
1728{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001729 return ClangASTType::GetMinimumLanguage (GetClangAST(),
1730 GetClangType());
Jim Ingham5a369122010-09-28 01:25:32 +00001731}
1732
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001733void
Jim Ingham58b59f92011-04-22 23:53:53 +00001734ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001735{
Jim Ingham58b59f92011-04-22 23:53:53 +00001736 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001737}
1738
1739ValueObjectSP
1740ValueObject::GetSyntheticChild (const ConstString &key) const
1741{
1742 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001743 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001744 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001745 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001746 return synthetic_child_sp;
1747}
1748
1749bool
1750ValueObject::IsPointerType ()
1751{
Greg Clayton1be10fc2010-09-29 01:12:09 +00001752 return ClangASTContext::IsPointerType (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001753}
1754
Jim Inghamb7603bb2011-03-18 00:05:18 +00001755bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001756ValueObject::IsArrayType ()
1757{
1758 return ClangASTContext::IsArrayType (GetClangType());
1759}
1760
1761bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001762ValueObject::IsScalarType ()
1763{
1764 return ClangASTContext::IsScalarType (GetClangType());
1765}
1766
1767bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001768ValueObject::IsIntegerType (bool &is_signed)
1769{
1770 return ClangASTContext::IsIntegerType (GetClangType(), is_signed);
1771}
Greg Clayton73b472d2010-10-27 03:32:59 +00001772
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001773bool
1774ValueObject::IsPointerOrReferenceType ()
1775{
Greg Clayton007d5be2011-05-30 00:49:24 +00001776 return ClangASTContext::IsPointerOrReferenceType (GetClangType());
1777}
1778
1779bool
Greg Claytondea8cb42011-06-29 22:09:02 +00001780ValueObject::IsPossibleDynamicType ()
1781{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00001782 ExecutionContext exe_ctx (GetExecutionContextRef());
1783 Process *process = exe_ctx.GetProcessPtr();
1784 if (process)
1785 return process->IsPossibleDynamicValue(*this);
1786 else
Greg Clayton70364252012-08-31 18:56:24 +00001787 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType(), NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00001788}
1789
Greg Claytonafacd142011-09-02 01:15:17 +00001790ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001791ValueObject::GetSyntheticArrayMember (int32_t index, bool can_create)
1792{
1793 if (IsArrayType())
1794 return GetSyntheticArrayMemberFromArray(index, can_create);
1795
1796 if (IsPointerType())
1797 return GetSyntheticArrayMemberFromPointer(index, can_create);
1798
1799 return ValueObjectSP();
1800
1801}
1802
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001803ValueObjectSP
1804ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
1805{
1806 ValueObjectSP synthetic_child_sp;
1807 if (IsPointerType ())
1808 {
1809 char index_str[64];
1810 snprintf(index_str, sizeof(index_str), "[%i]", index);
1811 ConstString index_const_str(index_str);
1812 // Check if we have already created a synthetic array member in this
1813 // valid object. If we have we will re-use it.
1814 synthetic_child_sp = GetSyntheticChild (index_const_str);
1815 if (!synthetic_child_sp)
1816 {
Jim Ingham58b59f92011-04-22 23:53:53 +00001817 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001818 // We haven't made a synthetic array member for INDEX yet, so
1819 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00001820 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001821
1822 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00001823 if (synthetic_child)
1824 {
1825 AddSyntheticChild(index_const_str, synthetic_child);
1826 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001827 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00001828 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00001829 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001830 }
1831 }
1832 return synthetic_child_sp;
1833}
Jim Ingham22777012010-09-23 02:01:19 +00001834
Greg Claytondaf515f2011-07-09 20:12:33 +00001835// This allows you to create an array member using and index
1836// that doesn't not fall in the normal bounds of the array.
1837// Many times structure can be defined as:
1838// struct Collection
1839// {
1840// uint32_t item_count;
1841// Item item_array[0];
1842// };
1843// The size of the "item_array" is 1, but many times in practice
1844// there are more items in "item_array".
1845
1846ValueObjectSP
1847ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create)
1848{
1849 ValueObjectSP synthetic_child_sp;
1850 if (IsArrayType ())
1851 {
1852 char index_str[64];
1853 snprintf(index_str, sizeof(index_str), "[%i]", index);
1854 ConstString index_const_str(index_str);
1855 // Check if we have already created a synthetic array member in this
1856 // valid object. If we have we will re-use it.
1857 synthetic_child_sp = GetSyntheticChild (index_const_str);
1858 if (!synthetic_child_sp)
1859 {
1860 ValueObject *synthetic_child;
1861 // We haven't made a synthetic array member for INDEX yet, so
1862 // lets make one and cache it for any future reference.
1863 synthetic_child = CreateChildAtIndex(0, true, index);
1864
1865 // Cache the value if we got one back...
1866 if (synthetic_child)
1867 {
1868 AddSyntheticChild(index_const_str, synthetic_child);
1869 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001870 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00001871 synthetic_child_sp->m_is_array_item_for_pointer = true;
1872 }
1873 }
1874 }
1875 return synthetic_child_sp;
1876}
1877
Enrico Granata9fc19442011-07-06 02:13:41 +00001878ValueObjectSP
1879ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
1880{
1881 ValueObjectSP synthetic_child_sp;
1882 if (IsScalarType ())
1883 {
1884 char index_str[64];
1885 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1886 ConstString index_const_str(index_str);
1887 // Check if we have already created a synthetic array member in this
1888 // valid object. If we have we will re-use it.
1889 synthetic_child_sp = GetSyntheticChild (index_const_str);
1890 if (!synthetic_child_sp)
1891 {
1892 ValueObjectChild *synthetic_child;
1893 // We haven't made a synthetic array member for INDEX yet, so
1894 // lets make one and cache it for any future reference.
1895 synthetic_child = new ValueObjectChild(*this,
1896 GetClangAST(),
1897 GetClangType(),
1898 index_const_str,
1899 GetByteSize(),
1900 0,
1901 to-from+1,
1902 from,
1903 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001904 false,
1905 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00001906
1907 // Cache the value if we got one back...
1908 if (synthetic_child)
1909 {
1910 AddSyntheticChild(index_const_str, synthetic_child);
1911 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001912 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00001913 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1914 }
1915 }
1916 }
1917 return synthetic_child_sp;
1918}
1919
Greg Claytonafacd142011-09-02 01:15:17 +00001920ValueObjectSP
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001921ValueObject::GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create)
1922{
1923 ValueObjectSP synthetic_child_sp;
1924 if (IsArrayType () || IsPointerType ())
1925 {
1926 char index_str[64];
1927 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
1928 ConstString index_const_str(index_str);
1929 // Check if we have already created a synthetic array member in this
1930 // valid object. If we have we will re-use it.
1931 synthetic_child_sp = GetSyntheticChild (index_const_str);
1932 if (!synthetic_child_sp)
1933 {
1934 ValueObjectSynthetic *synthetic_child;
1935
1936 // We haven't made a synthetic array member for INDEX yet, so
1937 // lets make one and cache it for any future reference.
Enrico Granata061858c2012-02-15 02:34:21 +00001938 SyntheticArrayView *view = new SyntheticArrayView(SyntheticChildren::Flags());
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001939 view->AddRange(from,to);
1940 SyntheticChildrenSP view_sp(view);
1941 synthetic_child = new ValueObjectSynthetic(*this, view_sp);
1942
1943 // Cache the value if we got one back...
1944 if (synthetic_child)
1945 {
1946 AddSyntheticChild(index_const_str, synthetic_child);
1947 synthetic_child_sp = synthetic_child->GetSP();
1948 synthetic_child_sp->SetName(ConstString(index_str));
1949 synthetic_child_sp->m_is_bitfield_for_scalar = true;
1950 }
1951 }
1952 }
1953 return synthetic_child_sp;
1954}
1955
Greg Claytonafacd142011-09-02 01:15:17 +00001956ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00001957ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
1958{
1959
1960 ValueObjectSP synthetic_child_sp;
1961
1962 char name_str[64];
1963 snprintf(name_str, sizeof(name_str), "@%i", offset);
1964 ConstString name_const_str(name_str);
1965
1966 // Check if we have already created a synthetic array member in this
1967 // valid object. If we have we will re-use it.
1968 synthetic_child_sp = GetSyntheticChild (name_const_str);
1969
1970 if (synthetic_child_sp.get())
1971 return synthetic_child_sp;
1972
1973 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00001974 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00001975
1976 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
1977 type.GetASTContext(),
1978 type.GetOpaqueQualType(),
1979 name_const_str,
1980 type.GetTypeByteSize(),
1981 offset,
1982 0,
1983 0,
1984 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00001985 false,
1986 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001987 if (synthetic_child)
1988 {
1989 AddSyntheticChild(name_const_str, synthetic_child);
1990 synthetic_child_sp = synthetic_child->GetSP();
1991 synthetic_child_sp->SetName(name_const_str);
1992 synthetic_child_sp->m_is_child_at_offset = true;
1993 }
1994 return synthetic_child_sp;
1995}
1996
Enrico Granatad55546b2011-07-22 00:16:08 +00001997// your expression path needs to have a leading . or ->
1998// (unless it somehow "looks like" an array, in which case it has
1999// a leading [ symbol). while the [ is meaningful and should be shown
2000// to the user, . and -> are just parser design, but by no means
2001// added information for the user.. strip them off
2002static const char*
2003SkipLeadingExpressionPathSeparators(const char* expression)
2004{
2005 if (!expression || !expression[0])
2006 return expression;
2007 if (expression[0] == '.')
2008 return expression+1;
2009 if (expression[0] == '-' && expression[1] == '>')
2010 return expression+2;
2011 return expression;
2012}
2013
Greg Claytonafacd142011-09-02 01:15:17 +00002014ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002015ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2016{
2017 ValueObjectSP synthetic_child_sp;
2018 ConstString name_const_string(expression);
2019 // Check if we have already created a synthetic array member in this
2020 // valid object. If we have we will re-use it.
2021 synthetic_child_sp = GetSyntheticChild (name_const_string);
2022 if (!synthetic_child_sp)
2023 {
2024 // We haven't made a synthetic array member for expression yet, so
2025 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002026 synthetic_child_sp = GetValueForExpressionPath(expression,
2027 NULL, NULL, NULL,
2028 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
Enrico Granatad55546b2011-07-22 00:16:08 +00002029
2030 // Cache the value if we got one back...
2031 if (synthetic_child_sp.get())
2032 {
2033 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002034 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002035 synthetic_child_sp->m_is_expression_path_child = true;
2036 }
2037 }
2038 return synthetic_child_sp;
2039}
2040
2041void
Enrico Granata86cc9822012-03-19 22:58:49 +00002042ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002043{
Enrico Granata86cc9822012-03-19 22:58:49 +00002044 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002045 return;
2046
Enrico Granatac5bc4122012-03-27 02:35:13 +00002047 TargetSP target_sp(GetTargetSP());
2048 if (target_sp && (target_sp->GetEnableSyntheticValue() == false || target_sp->GetSuppressSyntheticValue() == true))
2049 {
2050 m_synthetic_value = NULL;
2051 return;
2052 }
2053
Enrico Granata86cc9822012-03-19 22:58:49 +00002054 if (!UpdateFormatsIfNeeded(m_last_format_mgr_dynamic) && m_synthetic_value)
2055 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002056
Enrico Granata0c489f52012-03-01 04:24:26 +00002057 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002058 return;
2059
Enrico Granata86cc9822012-03-19 22:58:49 +00002060 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002061}
2062
Jim Ingham78a685a2011-04-16 00:01:13 +00002063void
Greg Claytonafacd142011-09-02 01:15:17 +00002064ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002065{
Greg Claytonafacd142011-09-02 01:15:17 +00002066 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002067 return;
2068
Jim Ingham58b59f92011-04-22 23:53:53 +00002069 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002070 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002071 ExecutionContext exe_ctx (GetExecutionContextRef());
2072 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002073 if (process && process->IsPossibleDynamicValue(*this))
2074 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002075 }
2076}
2077
Jim Ingham58b59f92011-04-22 23:53:53 +00002078ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002079ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002080{
Greg Claytonafacd142011-09-02 01:15:17 +00002081 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002082 return ValueObjectSP();
2083
2084 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002085 {
Jim Ingham2837b762011-05-04 03:43:18 +00002086 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002087 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002088 if (m_dynamic_value)
2089 return m_dynamic_value->GetSP();
2090 else
2091 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002092}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002093
Jim Ingham60dbabb2011-12-08 19:44:08 +00002094ValueObjectSP
2095ValueObject::GetStaticValue()
2096{
2097 return GetSP();
2098}
2099
Enrico Granata886147f2012-05-08 18:47:08 +00002100lldb::ValueObjectSP
2101ValueObject::GetNonSyntheticValue ()
2102{
2103 return GetSP();
2104}
2105
Enrico Granatad55546b2011-07-22 00:16:08 +00002106ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002107ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002108{
Enrico Granata86cc9822012-03-19 22:58:49 +00002109 if (use_synthetic == false)
2110 return ValueObjectSP();
2111
Enrico Granatad55546b2011-07-22 00:16:08 +00002112 CalculateSyntheticValue(use_synthetic);
2113
2114 if (m_synthetic_value)
2115 return m_synthetic_value->GetSP();
2116 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002117 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002118}
2119
Greg Claytone221f822011-01-21 01:59:00 +00002120bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002121ValueObject::HasSyntheticValue()
2122{
2123 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
2124
Enrico Granata0c489f52012-03-01 04:24:26 +00002125 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002126 return false;
2127
Enrico Granata86cc9822012-03-19 22:58:49 +00002128 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002129
2130 if (m_synthetic_value)
2131 return true;
2132 else
2133 return false;
2134}
2135
2136bool
Greg Claytone221f822011-01-21 01:59:00 +00002137ValueObject::GetBaseClassPath (Stream &s)
2138{
2139 if (IsBaseClass())
2140 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002141 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Claytone221f822011-01-21 01:59:00 +00002142 clang_type_t clang_type = GetClangType();
2143 std::string cxx_class_name;
2144 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
2145 if (this_had_base_class)
2146 {
2147 if (parent_had_base_class)
2148 s.PutCString("::");
2149 s.PutCString(cxx_class_name.c_str());
2150 }
2151 return parent_had_base_class || this_had_base_class;
2152 }
2153 return false;
2154}
2155
2156
2157ValueObject *
2158ValueObject::GetNonBaseClassParent()
2159{
Jim Ingham78a685a2011-04-16 00:01:13 +00002160 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002161 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002162 if (GetParent()->IsBaseClass())
2163 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002164 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002165 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002166 }
2167 return NULL;
2168}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002169
2170void
Enrico Granata4becb372011-06-29 22:27:15 +00002171ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002172{
Greg Claytone221f822011-01-21 01:59:00 +00002173 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002174
Enrico Granata86cc9822012-03-19 22:58:49 +00002175 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002176 {
Enrico Granata4becb372011-06-29 22:27:15 +00002177 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2178 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2179 // the eHonorPointers mode is meant to produce strings in this latter format
2180 s.PutCString("*(");
2181 }
Greg Claytone221f822011-01-21 01:59:00 +00002182
Enrico Granata4becb372011-06-29 22:27:15 +00002183 ValueObject* parent = GetParent();
2184
2185 if (parent)
2186 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002187
2188 // if we are a deref_of_parent just because we are synthetic array
2189 // members made up to allow ptr[%d] syntax to work in variable
2190 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002191 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002192 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002193
Greg Claytone221f822011-01-21 01:59:00 +00002194 if (!IsBaseClass())
2195 {
2196 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002197 {
Greg Claytone221f822011-01-21 01:59:00 +00002198 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2199 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002200 {
Greg Claytone221f822011-01-21 01:59:00 +00002201 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
2202 if (non_base_class_parent_clang_type)
2203 {
2204 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
2205
Enrico Granata86cc9822012-03-19 22:58:49 +00002206 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002207 {
2208 s.PutCString("->");
2209 }
Enrico Granata4becb372011-06-29 22:27:15 +00002210 else
2211 {
2212 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
2213 {
2214 s.PutCString("->");
2215 }
2216 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
2217 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
2218 {
2219 s.PutChar('.');
2220 }
Greg Claytone221f822011-01-21 01:59:00 +00002221 }
2222 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002223 }
Greg Claytone221f822011-01-21 01:59:00 +00002224
2225 const char *name = GetName().GetCString();
2226 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002227 {
Greg Claytone221f822011-01-21 01:59:00 +00002228 if (qualify_cxx_base_classes)
2229 {
2230 if (GetBaseClassPath (s))
2231 s.PutCString("::");
2232 }
2233 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002234 }
2235 }
2236 }
2237
Enrico Granata86cc9822012-03-19 22:58:49 +00002238 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002239 {
Greg Claytone221f822011-01-21 01:59:00 +00002240 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002241 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002242}
2243
Greg Claytonafacd142011-09-02 01:15:17 +00002244ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002245ValueObject::GetValueForExpressionPath(const char* expression,
2246 const char** first_unparsed,
2247 ExpressionPathScanEndReason* reason_to_stop,
2248 ExpressionPathEndResultType* final_value_type,
2249 const GetValueForExpressionPathOptions& options,
2250 ExpressionPathAftermath* final_task_on_target)
2251{
2252
2253 const char* dummy_first_unparsed;
2254 ExpressionPathScanEndReason dummy_reason_to_stop;
2255 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002256 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002257
2258 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2259 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2260 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2261 final_value_type ? final_value_type : &dummy_final_value_type,
2262 options,
2263 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2264
Enrico Granata86cc9822012-03-19 22:58:49 +00002265 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002266 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002267
Enrico Granata86cc9822012-03-19 22:58:49 +00002268 if (ret_val.get() && ((final_value_type ? *final_value_type : dummy_final_value_type) == eExpressionPathEndResultTypePlain)) // I can only deref and takeaddress of plain objects
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002269 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002270 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002271 {
2272 Error error;
2273 ValueObjectSP final_value = ret_val->Dereference(error);
2274 if (error.Fail() || !final_value.get())
2275 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002276 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002277 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002278 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002279 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002280 return ValueObjectSP();
2281 }
2282 else
2283 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002284 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002285 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002286 return final_value;
2287 }
2288 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002289 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002290 {
2291 Error error;
2292 ValueObjectSP final_value = ret_val->AddressOf(error);
2293 if (error.Fail() || !final_value.get())
2294 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002295 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002296 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002297 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002298 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002299 return ValueObjectSP();
2300 }
2301 else
2302 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002303 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002304 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002305 return final_value;
2306 }
2307 }
2308 }
2309 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2310}
2311
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002312int
2313ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002314 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002315 const char** first_unparsed,
2316 ExpressionPathScanEndReason* reason_to_stop,
2317 ExpressionPathEndResultType* final_value_type,
2318 const GetValueForExpressionPathOptions& options,
2319 ExpressionPathAftermath* final_task_on_target)
2320{
2321 const char* dummy_first_unparsed;
2322 ExpressionPathScanEndReason dummy_reason_to_stop;
2323 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002324 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002325
2326 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2327 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2328 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2329 final_value_type ? final_value_type : &dummy_final_value_type,
2330 options,
2331 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2332
2333 if (!ret_val.get()) // if there are errors, I add nothing to the list
2334 return 0;
2335
Enrico Granata86ea8d82012-03-29 01:34:34 +00002336 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002337 {
2338 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002339 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002340 {
2341 list->Append(ret_val);
2342 return 1;
2343 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002344 if (ret_val.get() && (final_value_type ? *final_value_type : dummy_final_value_type) == eExpressionPathEndResultTypePlain) // I can only deref and takeaddress of plain objects
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002345 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002346 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002347 {
2348 Error error;
2349 ValueObjectSP final_value = ret_val->Dereference(error);
2350 if (error.Fail() || !final_value.get())
2351 {
Greg Clayton23f59502012-07-17 03:23:13 +00002352 if (reason_to_stop)
2353 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2354 if (final_value_type)
2355 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002356 return 0;
2357 }
2358 else
2359 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002360 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002361 list->Append(final_value);
2362 return 1;
2363 }
2364 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002365 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002366 {
2367 Error error;
2368 ValueObjectSP final_value = ret_val->AddressOf(error);
2369 if (error.Fail() || !final_value.get())
2370 {
Greg Clayton23f59502012-07-17 03:23:13 +00002371 if (reason_to_stop)
2372 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2373 if (final_value_type)
2374 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002375 return 0;
2376 }
2377 else
2378 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002379 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002380 list->Append(final_value);
2381 return 1;
2382 }
2383 }
2384 }
2385 }
2386 else
2387 {
2388 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2389 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2390 ret_val,
2391 list,
2392 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2393 final_value_type ? final_value_type : &dummy_final_value_type,
2394 options,
2395 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2396 }
2397 // in any non-covered case, just do the obviously right thing
2398 list->Append(ret_val);
2399 return 1;
2400}
2401
Greg Claytonafacd142011-09-02 01:15:17 +00002402ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002403ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2404 const char** first_unparsed,
2405 ExpressionPathScanEndReason* reason_to_stop,
2406 ExpressionPathEndResultType* final_result,
2407 const GetValueForExpressionPathOptions& options,
2408 ExpressionPathAftermath* what_next)
2409{
2410 ValueObjectSP root = GetSP();
2411
2412 if (!root.get())
2413 return ValueObjectSP();
2414
2415 *first_unparsed = expression_cstr;
2416
2417 while (true)
2418 {
2419
2420 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2421
Greg Claytonafacd142011-09-02 01:15:17 +00002422 clang_type_t root_clang_type = root->GetClangType();
2423 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002424 Flags root_clang_type_info,pointee_clang_type_info;
2425
2426 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2427 if (pointee_clang_type)
2428 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002429
2430 if (!expression_cstr || *expression_cstr == '\0')
2431 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002432 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002433 return root;
2434 }
2435
2436 switch (*expression_cstr)
2437 {
2438 case '-':
2439 {
2440 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002441 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 +00002442 {
2443 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002444 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2445 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002446 return ValueObjectSP();
2447 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002448 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2449 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002450 options.m_no_fragile_ivar)
2451 {
2452 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002453 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2454 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002455 return ValueObjectSP();
2456 }
2457 if (expression_cstr[1] != '>')
2458 {
2459 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002460 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2461 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002462 return ValueObjectSP();
2463 }
2464 expression_cstr++; // skip the -
2465 }
2466 case '.': // or fallthrough from ->
2467 {
2468 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002469 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 +00002470 {
2471 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002472 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2473 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002474 return ValueObjectSP();
2475 }
2476 expression_cstr++; // skip .
2477 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2478 ConstString child_name;
2479 if (!next_separator) // if no other separator just expand this last layer
2480 {
2481 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002482 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2483
2484 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002485 {
2486 *first_unparsed = '\0';
Enrico Granata86cc9822012-03-19 22:58:49 +00002487 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2488 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002489 return child_valobj_sp;
2490 }
2491 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2492 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002493 if (root->IsSynthetic())
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002494 {
2495 *first_unparsed = expression_cstr;
2496 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2497 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2498 return ValueObjectSP();
2499 }
2500
2501 child_valobj_sp = root->GetSyntheticValue();
Enrico Granata86cc9822012-03-19 22:58:49 +00002502 if (child_valobj_sp.get())
2503 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002504 }
2505
2506 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2507 // so we hit the "else" branch, and return an error
2508 if(child_valobj_sp.get()) // if it worked, just return
2509 {
2510 *first_unparsed = '\0';
Enrico Granata86cc9822012-03-19 22:58:49 +00002511 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2512 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002513 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002514 }
2515 else
2516 {
2517 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002518 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2519 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002520 return ValueObjectSP();
2521 }
2522 }
2523 else // other layers do expand
2524 {
2525 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002526 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2527 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002528 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002529 root = child_valobj_sp;
2530 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002531 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002532 continue;
2533 }
2534 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2535 {
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002536 if (root->IsSynthetic())
2537 {
2538 *first_unparsed = expression_cstr;
2539 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2540 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2541 return ValueObjectSP();
2542 }
2543
Enrico Granata86cc9822012-03-19 22:58:49 +00002544 child_valobj_sp = root->GetSyntheticValue(true);
2545 if (child_valobj_sp)
2546 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002547 }
2548
2549 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2550 // so we hit the "else" branch, and return an error
2551 if(child_valobj_sp.get()) // if it worked, move on
2552 {
2553 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002554 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002555 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002556 continue;
2557 }
2558 else
2559 {
2560 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002561 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2562 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002563 return ValueObjectSP();
2564 }
2565 }
2566 break;
2567 }
2568 case '[':
2569 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002570 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 +00002571 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002572 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002573 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002574 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2575 {
2576 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002577 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2578 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002579 return ValueObjectSP();
2580 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002581 }
2582 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2583 {
2584 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002585 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2586 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002587 return ValueObjectSP();
2588 }
2589 }
2590 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2591 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002592 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002593 {
2594 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002595 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2596 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002597 return ValueObjectSP();
2598 }
2599 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2600 {
2601 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002602 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2603 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002604 return root;
2605 }
2606 }
2607 const char *separator_position = ::strchr(expression_cstr+1,'-');
2608 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2609 if (!close_bracket_position) // if there is no ], this is a syntax error
2610 {
2611 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002612 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2613 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002614 return ValueObjectSP();
2615 }
2616 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2617 {
2618 char *end = NULL;
2619 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2620 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2621 {
2622 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002623 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2624 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002625 return ValueObjectSP();
2626 }
2627 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2628 {
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002629 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002630 {
2631 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002632 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2633 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002634 return root;
2635 }
2636 else
2637 {
2638 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002639 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2640 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002641 return ValueObjectSP();
2642 }
2643 }
2644 // from here on we do have a valid index
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002645 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002646 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002647 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2648 if (!child_valobj_sp)
2649 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002650 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002651 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2652 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002653 if (child_valobj_sp)
2654 {
2655 root = child_valobj_sp;
2656 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002657 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002658 continue;
2659 }
2660 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002661 {
2662 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002663 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2664 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002665 return ValueObjectSP();
2666 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002667 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002668 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002669 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002670 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 +00002671 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002672 {
2673 Error error;
2674 root = root->Dereference(error);
2675 if (error.Fail() || !root.get())
2676 {
2677 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002678 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2679 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002680 return ValueObjectSP();
2681 }
2682 else
2683 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002684 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002685 continue;
2686 }
2687 }
2688 else
2689 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002690 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(),
Greg Clayton84db9102012-03-26 23:03:23 +00002691 root->GetClangType()) == eLanguageTypeObjC
2692 && ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false
2693 && root->HasSyntheticValue()
2694 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002695 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002696 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002697 }
2698 else
2699 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002700 if (!root.get())
2701 {
2702 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002703 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2704 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002705 return ValueObjectSP();
2706 }
2707 else
2708 {
2709 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002710 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002711 continue;
2712 }
2713 }
2714 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002715 else if (ClangASTContext::IsScalarType(root_clang_type))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002716 {
2717 root = root->GetSyntheticBitFieldChild(index, index, true);
2718 if (!root.get())
2719 {
2720 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002721 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2722 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002723 return ValueObjectSP();
2724 }
2725 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2726 {
2727 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002728 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2729 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002730 return root;
2731 }
2732 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002733 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002734 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002735 if (root->HasSyntheticValue())
2736 root = root->GetSyntheticValue();
2737 else if (!root->IsSynthetic())
2738 {
2739 *first_unparsed = expression_cstr;
2740 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2741 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2742 return ValueObjectSP();
2743 }
2744 // if we are here, then root itself is a synthetic VO.. should be good to go
2745
Enrico Granata27b625e2011-08-09 01:04:56 +00002746 if (!root.get())
2747 {
2748 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002749 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2750 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2751 return ValueObjectSP();
2752 }
2753 root = root->GetChildAtIndex(index, true);
2754 if (!root.get())
2755 {
2756 *first_unparsed = expression_cstr;
2757 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2758 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002759 return ValueObjectSP();
2760 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002761 else
2762 {
2763 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002764 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002765 continue;
2766 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002767 }
2768 else
2769 {
2770 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002771 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2772 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002773 return ValueObjectSP();
2774 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002775 }
2776 else // we have a low and a high index
2777 {
2778 char *end = NULL;
2779 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2780 if (!end || end != separator_position) // if something weird is in our way return an error
2781 {
2782 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002783 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2784 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002785 return ValueObjectSP();
2786 }
2787 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2788 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2789 {
2790 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002791 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2792 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002793 return ValueObjectSP();
2794 }
2795 if (index_lower > index_higher) // swap indices if required
2796 {
2797 unsigned long temp = index_lower;
2798 index_lower = index_higher;
2799 index_higher = temp;
2800 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002801 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002802 {
2803 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2804 if (!root.get())
2805 {
2806 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002807 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2808 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002809 return ValueObjectSP();
2810 }
2811 else
2812 {
2813 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002814 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2815 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002816 return root;
2817 }
2818 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002819 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 +00002820 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002821 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002822 {
2823 Error error;
2824 root = root->Dereference(error);
2825 if (error.Fail() || !root.get())
2826 {
2827 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002828 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2829 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002830 return ValueObjectSP();
2831 }
2832 else
2833 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002834 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002835 continue;
2836 }
2837 }
2838 else
2839 {
2840 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002841 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2842 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002843 return root;
2844 }
2845 }
2846 break;
2847 }
2848 default: // some non-separator is in the way
2849 {
2850 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002851 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2852 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002853 return ValueObjectSP();
2854 break;
2855 }
2856 }
2857 }
2858}
2859
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002860int
2861ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
2862 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00002863 ValueObjectSP root,
2864 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002865 ExpressionPathScanEndReason* reason_to_stop,
2866 ExpressionPathEndResultType* final_result,
2867 const GetValueForExpressionPathOptions& options,
2868 ExpressionPathAftermath* what_next)
2869{
2870 if (!root.get())
2871 return 0;
2872
2873 *first_unparsed = expression_cstr;
2874
2875 while (true)
2876 {
2877
2878 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2879
Greg Claytonafacd142011-09-02 01:15:17 +00002880 clang_type_t root_clang_type = root->GetClangType();
2881 clang_type_t pointee_clang_type;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002882 Flags root_clang_type_info,pointee_clang_type_info;
2883
2884 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type));
2885 if (pointee_clang_type)
2886 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL));
2887
2888 if (!expression_cstr || *expression_cstr == '\0')
2889 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002890 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002891 list->Append(root);
2892 return 1;
2893 }
2894
2895 switch (*expression_cstr)
2896 {
2897 case '[':
2898 {
2899 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T*
2900 {
2901 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
2902 {
2903 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002904 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2905 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002906 return 0;
2907 }
2908 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2909 {
2910 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002911 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2912 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002913 return 0;
2914 }
2915 }
2916 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2917 {
2918 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2919 {
2920 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002921 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2922 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002923 return 0;
2924 }
2925 else // expand this into list
2926 {
2927 int max_index = root->GetNumChildren() - 1;
2928 for (int index = 0; index < max_index; index++)
2929 {
2930 ValueObjectSP child =
2931 root->GetChildAtIndex(index, true);
2932 list->Append(child);
2933 }
2934 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002935 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
2936 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002937 return max_index; // tell me number of items I added to the VOList
2938 }
2939 }
2940 const char *separator_position = ::strchr(expression_cstr+1,'-');
2941 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2942 if (!close_bracket_position) // if there is no ], this is a syntax error
2943 {
2944 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002945 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2946 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002947 return 0;
2948 }
2949 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2950 {
2951 char *end = NULL;
2952 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2953 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2954 {
2955 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002956 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2957 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002958 return 0;
2959 }
2960 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2961 {
2962 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2963 {
2964 int max_index = root->GetNumChildren() - 1;
2965 for (int index = 0; index < max_index; index++)
2966 {
2967 ValueObjectSP child =
2968 root->GetChildAtIndex(index, true);
2969 list->Append(child);
2970 }
2971 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002972 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
2973 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002974 return max_index; // tell me number of items I added to the VOList
2975 }
2976 else
2977 {
2978 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002979 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2980 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002981 return 0;
2982 }
2983 }
2984 // from here on we do have a valid index
2985 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray))
2986 {
2987 root = root->GetChildAtIndex(index, true);
2988 if (!root.get())
2989 {
2990 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002991 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2992 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002993 return 0;
2994 }
2995 else
2996 {
2997 list->Append(root);
2998 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002999 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3000 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003001 return 1;
3002 }
3003 }
3004 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer))
3005 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003006 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 +00003007 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3008 {
3009 Error error;
3010 root = root->Dereference(error);
3011 if (error.Fail() || !root.get())
3012 {
3013 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003014 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3015 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003016 return 0;
3017 }
3018 else
3019 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003020 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003021 continue;
3022 }
3023 }
3024 else
3025 {
3026 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3027 if (!root.get())
3028 {
3029 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003030 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3031 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003032 return 0;
3033 }
3034 else
3035 {
3036 list->Append(root);
3037 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003038 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3039 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003040 return 1;
3041 }
3042 }
3043 }
3044 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3045 {
3046 root = root->GetSyntheticBitFieldChild(index, index, true);
3047 if (!root.get())
3048 {
3049 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003050 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3051 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003052 return 0;
3053 }
3054 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3055 {
3056 list->Append(root);
3057 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003058 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3059 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003060 return 1;
3061 }
3062 }
3063 }
3064 else // we have a low and a high index
3065 {
3066 char *end = NULL;
3067 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3068 if (!end || end != separator_position) // if something weird is in our way return an error
3069 {
3070 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003071 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3072 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003073 return 0;
3074 }
3075 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3076 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3077 {
3078 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003079 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3080 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003081 return 0;
3082 }
3083 if (index_lower > index_higher) // swap indices if required
3084 {
3085 unsigned long temp = index_lower;
3086 index_lower = index_higher;
3087 index_higher = temp;
3088 }
3089 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars
3090 {
3091 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3092 if (!root.get())
3093 {
3094 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003095 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3096 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003097 return 0;
3098 }
3099 else
3100 {
3101 list->Append(root);
3102 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003103 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3104 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003105 return 1;
3106 }
3107 }
3108 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 +00003109 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003110 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar))
3111 {
3112 Error error;
3113 root = root->Dereference(error);
3114 if (error.Fail() || !root.get())
3115 {
3116 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003117 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3118 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003119 return 0;
3120 }
3121 else
3122 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003123 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003124 continue;
3125 }
3126 }
3127 else
3128 {
Johnny Chen44805302011-07-19 19:48:13 +00003129 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003130 index <= index_higher; index++)
3131 {
3132 ValueObjectSP child =
3133 root->GetChildAtIndex(index, true);
3134 list->Append(child);
3135 }
3136 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003137 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3138 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003139 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3140 }
3141 }
3142 break;
3143 }
3144 default: // some non-[ separator, or something entirely wrong, is in the way
3145 {
3146 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003147 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3148 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003149 return 0;
3150 break;
3151 }
3152 }
3153 }
3154}
3155
Enrico Granata0c489f52012-03-01 04:24:26 +00003156static void
3157DumpValueObject_Impl (Stream &s,
3158 ValueObject *valobj,
3159 const ValueObject::DumpValueObjectOptions& options,
3160 uint32_t ptr_depth,
3161 uint32_t curr_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003162{
Greg Clayton007d5be2011-05-30 00:49:24 +00003163 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003164 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003165 bool update_success = valobj->UpdateValueIfNeeded (options.m_use_dynamic, true);
Greg Clayton007d5be2011-05-30 00:49:24 +00003166
Enrico Granata0c489f52012-03-01 04:24:26 +00003167 const char *root_valobj_name =
3168 options.m_root_valobj_name.empty() ?
3169 valobj->GetName().AsCString() :
3170 options.m_root_valobj_name.c_str();
3171
3172 if (update_success && options.m_use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00003173 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003174 ValueObject *dynamic_value = valobj->GetDynamicValue(options.m_use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003175 if (dynamic_value)
3176 valobj = dynamic_value;
3177 }
3178
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003179 clang_type_t clang_type = valobj->GetClangType();
3180
Greg Clayton73b472d2010-10-27 03:32:59 +00003181 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003182 const char *err_cstr = NULL;
Greg Clayton73b472d2010-10-27 03:32:59 +00003183 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
3184 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003185
Enrico Granata0c489f52012-03-01 04:24:26 +00003186 const bool print_valobj = options.m_flat_output == false || has_value;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003187
3188 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003189 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003190 if (options.m_show_location)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003191 {
Jim Ingham6035b672011-03-31 00:19:25 +00003192 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003193 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003194
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003195 s.Indent();
Enrico Granata2b2631c2012-08-09 16:51:25 +00003196
3197 bool show_type = true;
3198 // if we are at the root-level and been asked to hide the root's type, then hide it
3199 if (curr_depth == 0 && options.m_hide_root_type)
3200 show_type = false;
3201 else
3202 // otherwise decide according to the usual rules (asked to show types - always at the root level)
3203 show_type = options.m_show_types || (curr_depth == 0 && !options.m_flat_output);
3204
3205 if (show_type)
Enrico Granatac3e320a2011-08-02 17:27:39 +00003206 {
Greg Clayton84db9102012-03-26 23:03:23 +00003207 const char* typeName = valobj->GetQualifiedTypeName().AsCString("<invalid type>");
3208 //const char* typeName = valobj->GetTypeName().AsCString("<invalid type>");
Enrico Granata9910bc82011-08-03 02:18:51 +00003209 s.Printf("(%s", typeName);
3210 // only show dynamic types if the user really wants to see types
Enrico Granata0c489f52012-03-01 04:24:26 +00003211 if (options.m_show_types && options.m_use_dynamic != eNoDynamicValues &&
Enrico Granata9910bc82011-08-03 02:18:51 +00003212 (/*strstr(typeName, "id") == typeName ||*/
Greg Claytonafacd142011-09-02 01:15:17 +00003213 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == eLanguageTypeObjC))
Enrico Granatac3e320a2011-08-02 17:27:39 +00003214 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003215 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3216 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatac3e320a2011-08-02 17:27:39 +00003217 if (process == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003218 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003219 else
3220 {
3221 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime();
3222 if (runtime == NULL)
Enrico Granata9910bc82011-08-03 02:18:51 +00003223 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003224 else
3225 {
3226 ObjCLanguageRuntime::ObjCISA isa = runtime->GetISA(*valobj);
3227 if (!runtime->IsValidISA(isa))
Enrico Granata9910bc82011-08-03 02:18:51 +00003228 s.Printf(", dynamic type: unknown) ");
Enrico Granatac3e320a2011-08-02 17:27:39 +00003229 else
3230 s.Printf(", dynamic type: %s) ",
3231 runtime->GetActualTypeName(isa).GetCString());
3232 }
3233 }
3234 }
3235 else
3236 s.Printf(") ");
3237 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003238
Greg Clayton1d3afba2010-10-05 00:00:42 +00003239
Enrico Granata0c489f52012-03-01 04:24:26 +00003240 if (options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003241 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003242 // If we are showing types, also qualify the C++ base classes
Enrico Granata0c489f52012-03-01 04:24:26 +00003243 const bool qualify_cxx_base_classes = options.m_show_types;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003244 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003245 s.PutCString(" =");
3246 }
3247 else
3248 {
3249 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3250 s.Printf ("%s =", name_cstr);
3251 }
3252
Enrico Granata0c489f52012-03-01 04:24:26 +00003253 if (!options.m_scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003254 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003255 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003256 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003257 }
3258
Enrico Granata0c489f52012-03-01 04:24:26 +00003259 std::string summary_str;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003260 std::string value_str;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003261 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003262 const char *sum_cstr = NULL;
Enrico Granata0c489f52012-03-01 04:24:26 +00003263 TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003264
Enrico Granata0c489f52012-03-01 04:24:26 +00003265 if (options.m_omit_summary_depth > 0)
Enrico Granata0c5ef692011-07-16 01:22:04 +00003266 entry = NULL;
3267
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003268 if (err_cstr == NULL)
3269 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003270 if (options.m_format != eFormatDefault && options.m_format != valobj->GetFormat())
Greg Clayton6efba4f2012-01-26 21:08:30 +00003271 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003272 valobj->GetValueAsCString(options.m_format,
3273 value_str);
Greg Clayton6efba4f2012-01-26 21:08:30 +00003274 }
Enrico Granata0c489f52012-03-01 04:24:26 +00003275 else
Greg Clayton6efba4f2012-01-26 21:08:30 +00003276 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003277 val_cstr = valobj->GetValueAsCString();
3278 if (val_cstr)
3279 value_str = val_cstr;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003280 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003281 err_cstr = valobj->GetError().AsCString();
3282 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003283
3284 if (err_cstr)
3285 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003286 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003287 }
3288 else
3289 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003290 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003291 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003292 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003293 if (options.m_omit_summary_depth == 0)
3294 {
3295 if (options.m_summary_sp)
3296 {
3297 valobj->GetSummaryAsCString(entry, summary_str);
3298 sum_cstr = summary_str.c_str();
3299 }
3300 else
3301 sum_cstr = valobj->GetSummaryAsCString();
3302 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003303
Greg Clayton6efba4f2012-01-26 21:08:30 +00003304 // Make sure we have a value and make sure the summary didn't
3305 // specify that the value should not be printed
3306 if (!value_str.empty() && (entry == NULL || entry->DoesPrintValue() || sum_cstr == NULL))
3307 s.Printf(" %s", value_str.c_str());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003308
Enrico Granata9dd75c82011-07-15 23:30:15 +00003309 if (sum_cstr)
Enrico Granata0c489f52012-03-01 04:24:26 +00003310 s.Printf(" %s", sum_cstr);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003311
Enrico Granata0c489f52012-03-01 04:24:26 +00003312 if (options.m_use_objc)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003313 {
Jim Ingham6035b672011-03-31 00:19:25 +00003314 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003315 if (object_desc)
3316 s.Printf(" %s\n", object_desc);
3317 else
Sean Callanan672ad942010-10-23 00:18:49 +00003318 s.Printf (" [no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003319 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003320 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003321 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003322
Enrico Granata0c489f52012-03-01 04:24:26 +00003323 if (curr_depth < options.m_max_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003324 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003325 // We will show children for all concrete types. We won't show
3326 // pointer contents unless a pointer depth has been specified.
3327 // We won't reference contents unless the reference is the
3328 // root object (depth of zero).
3329 bool print_children = true;
3330
3331 // Use a new temporary pointer depth in case we override the
3332 // current pointer depth below...
3333 uint32_t curr_ptr_depth = ptr_depth;
3334
3335 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
3336 if (is_ptr || is_ref)
3337 {
3338 // We have a pointer or reference whose value is an address.
3339 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003340 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003341 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003342 print_children = false;
3343
3344 else if (is_ref && curr_depth == 0)
3345 {
3346 // If this is the root object (depth is zero) that we are showing
3347 // and it is a reference, and no pointer depth has been supplied
3348 // print out what it references. Don't do this at deeper depths
3349 // otherwise we can end up with infinite recursion...
3350 curr_ptr_depth = 1;
3351 }
3352
3353 if (curr_ptr_depth == 0)
3354 print_children = false;
3355 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003356
Enrico Granata0a3958e2011-07-02 00:25:22 +00003357 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003358 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003359 ValueObject* synth_valobj;
3360 ValueObjectSP synth_valobj_sp = valobj->GetSyntheticValue (options.m_use_synthetic);
3361 synth_valobj = (synth_valobj_sp ? synth_valobj_sp.get() : valobj);
Enrico Granatac5bc4122012-03-27 02:35:13 +00003362
Enrico Granatac482a192011-08-17 22:13:59 +00003363 uint32_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003364 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003365 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003366 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003367 if (options.m_flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003368 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003369 if (print_valobj)
3370 s.EOL();
3371 }
3372 else
3373 {
3374 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003375 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003376 s.IndentMore();
3377 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003378
Greg Claytoncc4d0142012-02-17 07:49:44 +00003379 uint32_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00003380
Enrico Granata0c489f52012-03-01 04:24:26 +00003381 if (num_children > max_num_children && !options.m_ignore_cap)
Enrico Granata22c55d12011-08-12 02:00:06 +00003382 {
3383 num_children = max_num_children;
3384 print_dotdotdot = true;
3385 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003386
Enrico Granata0c489f52012-03-01 04:24:26 +00003387 ValueObject::DumpValueObjectOptions child_options(options);
3388 child_options.SetFormat().SetSummary().SetRootValueObjectName();
3389 child_options.SetScopeChecked(true)
3390 .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003391 for (uint32_t idx=0; idx<num_children; ++idx)
3392 {
Enrico Granatac482a192011-08-17 22:13:59 +00003393 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003394 if (child_sp.get())
3395 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003396 DumpValueObject_Impl (s,
3397 child_sp.get(),
3398 child_options,
3399 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
3400 curr_depth + 1);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003401 }
3402 }
3403
Enrico Granata0c489f52012-03-01 04:24:26 +00003404 if (!options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003405 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003406 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003407 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003408 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3409 Target *target = exe_ctx.GetTargetPtr();
3410 if (target)
3411 target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003412 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003413 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003414 s.IndentLess();
3415 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003416 }
3417 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003418 else if (has_children)
3419 {
3420 // Aggregate, no children...
3421 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003422 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003423 }
3424 else
3425 {
3426 if (print_valobj)
3427 s.EOL();
3428 }
3429
Greg Clayton1d3afba2010-10-05 00:00:42 +00003430 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003431 else
3432 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003433 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003434 }
3435 }
3436 else
3437 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003438 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003439 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003440 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003441 }
3442 }
3443 }
3444 }
3445}
3446
Enrico Granata0c489f52012-03-01 04:24:26 +00003447void
Greg Claytonf830dbb2012-03-22 18:15:37 +00003448ValueObject::LogValueObject (Log *log,
3449 ValueObject *valobj)
3450{
3451 if (log && valobj)
3452 return LogValueObject (log, valobj, DumpValueObjectOptions::DefaultOptions());
3453}
3454
3455void
3456ValueObject::LogValueObject (Log *log,
3457 ValueObject *valobj,
3458 const DumpValueObjectOptions& options)
3459{
3460 if (log && valobj)
3461 {
3462 StreamString s;
3463 ValueObject::DumpValueObject (s, valobj, options);
3464 if (s.GetSize())
3465 log->PutCString(s.GetData());
3466 }
3467}
3468
3469void
Enrico Granata0c489f52012-03-01 04:24:26 +00003470ValueObject::DumpValueObject (Stream &s,
3471 ValueObject *valobj)
3472{
3473
3474 if (!valobj)
3475 return;
3476
3477 DumpValueObject_Impl(s,
3478 valobj,
3479 DumpValueObjectOptions::DefaultOptions(),
3480 0,
3481 0);
3482}
3483
3484void
3485ValueObject::DumpValueObject (Stream &s,
3486 ValueObject *valobj,
3487 const DumpValueObjectOptions& options)
3488{
3489 DumpValueObject_Impl(s,
3490 valobj,
3491 options,
3492 options.m_max_ptr_depth, // max pointer depth allowed, we will go down from here
3493 0 // current object depth is 0 since we are just starting
3494 );
3495}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003496
3497ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003498ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003499{
3500 ValueObjectSP valobj_sp;
3501
Enrico Granatac3e320a2011-08-02 17:27:39 +00003502 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003503 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003504 ExecutionContext exe_ctx (GetExecutionContextRef());
3505 clang::ASTContext *ast = GetClangAST ();
3506
3507 DataExtractor data;
3508 data.SetByteOrder (m_data.GetByteOrder());
3509 data.SetAddressByteSize(m_data.GetAddressByteSize());
3510
Enrico Granata9f1e2042012-04-24 22:15:37 +00003511 if (IsBitfield())
3512 {
3513 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
3514 m_error = v.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
3515 }
3516 else
3517 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003518
3519 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
3520 ast,
3521 GetClangType(),
3522 name,
3523 data,
3524 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003525 }
Jim Ingham6035b672011-03-31 00:19:25 +00003526
3527 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003528 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003529 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003530 }
3531 return valobj_sp;
3532}
3533
Greg Claytonafacd142011-09-02 01:15:17 +00003534ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003535ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003536{
Jim Ingham58b59f92011-04-22 23:53:53 +00003537 if (m_deref_valobj)
3538 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003539
Greg Clayton54979cd2010-12-15 05:08:08 +00003540 const bool is_pointer_type = IsPointerType();
3541 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003542 {
3543 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003544 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003545
3546 std::string child_name_str;
3547 uint32_t child_byte_size = 0;
3548 int32_t child_byte_offset = 0;
3549 uint32_t child_bitfield_bit_size = 0;
3550 uint32_t child_bitfield_bit_offset = 0;
3551 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003552 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003553 const bool transparent_pointers = false;
3554 clang::ASTContext *clang_ast = GetClangAST();
3555 clang_type_t clang_type = GetClangType();
3556 clang_type_t child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003557
Greg Claytoncc4d0142012-02-17 07:49:44 +00003558 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003559
3560 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx,
3561 clang_ast,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003562 GetName().GetCString(),
3563 clang_type,
3564 0,
3565 transparent_pointers,
3566 omit_empty_base_classes,
Greg Claytondaf515f2011-07-09 20:12:33 +00003567 ignore_array_bounds,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003568 child_name_str,
3569 child_byte_size,
3570 child_byte_offset,
3571 child_bitfield_bit_size,
3572 child_bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +00003573 child_is_base_class,
3574 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003575 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003576 {
3577 ConstString child_name;
3578 if (!child_name_str.empty())
3579 child_name.SetCString (child_name_str.c_str());
3580
Jim Ingham58b59f92011-04-22 23:53:53 +00003581 m_deref_valobj = new ValueObjectChild (*this,
3582 clang_ast,
3583 child_clang_type,
3584 child_name,
3585 child_byte_size,
3586 child_byte_offset,
3587 child_bitfield_bit_size,
3588 child_bitfield_bit_offset,
3589 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003590 child_is_deref_of_parent,
3591 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003592 }
3593 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003594
Jim Ingham58b59f92011-04-22 23:53:53 +00003595 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003596 {
3597 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003598 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003599 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003600 else
3601 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003602 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003603 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003604
3605 if (is_pointer_type)
3606 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3607 else
3608 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003609 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003610 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003611}
3612
Greg Claytonafacd142011-09-02 01:15:17 +00003613ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003614ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003615{
Jim Ingham78a685a2011-04-16 00:01:13 +00003616 if (m_addr_of_valobj_sp)
3617 return m_addr_of_valobj_sp;
3618
Greg Claytone0d378b2011-03-24 21:19:54 +00003619 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003620 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003621 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003622 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003623 if (addr != LLDB_INVALID_ADDRESS)
3624 {
3625 switch (address_type)
3626 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003627 default:
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003628 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003629 {
3630 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003631 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003632 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3633 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003634 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003635
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003636 case eAddressTypeFile:
3637 case eAddressTypeLoad:
3638 case eAddressTypeHost:
3639 {
3640 clang::ASTContext *ast = GetClangAST();
3641 clang_type_t clang_type = GetClangType();
3642 if (ast && clang_type)
3643 {
3644 std::string name (1, '&');
3645 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003646 ExecutionContext exe_ctx (GetExecutionContextRef());
3647 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003648 ast,
3649 ClangASTContext::CreatePointerType (ast, clang_type),
3650 ConstString (name.c_str()),
3651 addr,
3652 eAddressTypeInvalid,
3653 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003654 }
3655 }
3656 break;
3657 }
3658 }
Jim Ingham78a685a2011-04-16 00:01:13 +00003659 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003660}
3661
Greg Clayton9a142cf2012-02-03 05:34:10 +00003662ValueObjectSP
3663ValueObject::Cast (const ClangASTType &clang_ast_type)
3664{
Greg Clayton81e871e2012-02-04 02:27:34 +00003665 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003666}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003667
Greg Claytonafacd142011-09-02 01:15:17 +00003668ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003669ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3670{
Greg Claytonafacd142011-09-02 01:15:17 +00003671 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003672 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003673 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003674
3675 if (ptr_value != LLDB_INVALID_ADDRESS)
3676 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003677 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003678 ExecutionContext exe_ctx (GetExecutionContextRef());
3679 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003680 name,
3681 ptr_addr,
3682 clang_ast_type);
3683 }
3684 return valobj_sp;
3685}
3686
Greg Claytonafacd142011-09-02 01:15:17 +00003687ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003688ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3689{
Greg Claytonafacd142011-09-02 01:15:17 +00003690 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003691 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003692 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003693
3694 if (ptr_value != LLDB_INVALID_ADDRESS)
3695 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003696 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003697 ExecutionContext exe_ctx (GetExecutionContextRef());
3698 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003699 name,
3700 ptr_addr,
3701 type_sp);
3702 }
3703 return valobj_sp;
3704}
3705
Jim Ingham6035b672011-03-31 00:19:25 +00003706ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003707 m_mod_id(),
3708 m_exe_ctx_ref(),
3709 m_needs_update (true),
3710 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003711{
3712}
3713
3714ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003715 m_mod_id(),
3716 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003717 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003718 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003719{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003720 ExecutionContext exe_ctx(exe_scope);
3721 TargetSP target_sp (exe_ctx.GetTargetSP());
3722 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003723 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003724 m_exe_ctx_ref.SetTargetSP (target_sp);
3725 ProcessSP process_sp (exe_ctx.GetProcessSP());
3726 if (!process_sp)
3727 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003728
Greg Claytoncc4d0142012-02-17 07:49:44 +00003729 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003730 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003731 m_mod_id = process_sp->GetModID();
3732 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003733
Greg Claytoncc4d0142012-02-17 07:49:44 +00003734 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003735
Greg Claytoncc4d0142012-02-17 07:49:44 +00003736 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003737 {
3738 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003739 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003740 }
Jim Ingham6035b672011-03-31 00:19:25 +00003741
Greg Claytoncc4d0142012-02-17 07:49:44 +00003742 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003743 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003744 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003745
Greg Claytoncc4d0142012-02-17 07:49:44 +00003746 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3747 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003748 {
3749 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003750 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003751 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003752 if (frame_sp)
3753 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003754 }
3755 }
3756 }
Jim Ingham6035b672011-03-31 00:19:25 +00003757}
3758
3759ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003760 m_mod_id(),
3761 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3762 m_needs_update (true),
3763 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003764{
3765}
3766
3767ValueObject::EvaluationPoint::~EvaluationPoint ()
3768{
3769}
3770
Jim Ingham6035b672011-03-31 00:19:25 +00003771// This function checks the EvaluationPoint against the current process state. If the current
3772// state matches the evaluation point, or the evaluation point is already invalid, then we return
3773// false, meaning "no change". If the current state is different, we update our state, and return
3774// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3775// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003776// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003777
3778bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003779ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003780{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003781
3782 // 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 +00003783 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00003784
Greg Claytoncc4d0142012-02-17 07:49:44 +00003785 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003786 return false;
3787
Jim Ingham6035b672011-03-31 00:19:25 +00003788 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003789 Process *process = exe_ctx.GetProcessPtr();
3790 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003791 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003792
Jim Ingham6035b672011-03-31 00:19:25 +00003793 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003794 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003795
Jim Ingham78a685a2011-04-16 00:01:13 +00003796 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3797 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003798 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003799 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003800
Greg Clayton23f59502012-07-17 03:23:13 +00003801 bool changed = false;
3802 const bool was_valid = m_mod_id.IsValid();
3803 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003804 {
3805 if (m_mod_id == current_mod_id)
3806 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003807 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003808 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003809 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003810 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003811 else
3812 {
3813 m_mod_id = current_mod_id;
3814 m_needs_update = true;
3815 changed = true;
3816 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003817 }
Jim Ingham6035b672011-03-31 00:19:25 +00003818
Jim Ingham73ca05a2011-12-17 01:35:57 +00003819 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3820 // That way we'll be sure to return a valid exe_scope.
3821 // 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 +00003822
Greg Claytoncc4d0142012-02-17 07:49:44 +00003823 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003824 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003825 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3826 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003827 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003828 if (m_exe_ctx_ref.HasFrameRef())
3829 {
3830 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
3831 if (!frame_sp)
3832 {
3833 // We used to have a frame, but now it is gone
3834 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003835 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00003836 }
3837 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003838 }
Jim Ingham6035b672011-03-31 00:19:25 +00003839 else
3840 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003841 // We used to have a thread, but now it is gone
3842 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003843 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00003844 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003845
Jim Ingham6035b672011-03-31 00:19:25 +00003846 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003847 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003848}
3849
Jim Ingham61be0902011-05-02 18:13:59 +00003850void
3851ValueObject::EvaluationPoint::SetUpdated ()
3852{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003853 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3854 if (process_sp)
3855 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003856 m_first_update = false;
3857 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003858}
3859
3860
Greg Claytoncc4d0142012-02-17 07:49:44 +00003861//bool
3862//ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope)
3863//{
3864// if (!IsValid())
3865// return false;
3866//
3867// bool needs_update = false;
3868//
3869// // The target has to be non-null, and the
3870// Target *target = exe_scope->CalculateTarget();
3871// if (target != NULL)
3872// {
3873// Target *old_target = m_target_sp.get();
3874// assert (target == old_target);
3875// Process *process = exe_scope->CalculateProcess();
3876// if (process != NULL)
3877// {
3878// // FOR NOW - assume you can't update variable objects across process boundaries.
3879// Process *old_process = m_process_sp.get();
3880// assert (process == old_process);
3881// ProcessModID current_mod_id = process->GetModID();
3882// if (m_mod_id != current_mod_id)
3883// {
3884// needs_update = true;
3885// m_mod_id = current_mod_id;
3886// }
3887// // See if we're switching the thread or stack context. If no thread is given, this is
3888// // being evaluated in a global context.
3889// Thread *thread = exe_scope->CalculateThread();
3890// if (thread != NULL)
3891// {
3892// user_id_t new_thread_index = thread->GetIndexID();
3893// if (new_thread_index != m_thread_id)
3894// {
3895// needs_update = true;
3896// m_thread_id = new_thread_index;
3897// m_stack_id.Clear();
3898// }
3899//
3900// StackFrame *new_frame = exe_scope->CalculateStackFrame();
3901// if (new_frame != NULL)
3902// {
3903// if (new_frame->GetStackID() != m_stack_id)
3904// {
3905// needs_update = true;
3906// m_stack_id = new_frame->GetStackID();
3907// }
3908// }
3909// else
3910// {
3911// m_stack_id.Clear();
3912// needs_update = true;
3913// }
3914// }
3915// else
3916// {
3917// // If this had been given a thread, and now there is none, we should update.
3918// // Otherwise we don't have to do anything.
3919// if (m_thread_id != LLDB_INVALID_UID)
3920// {
3921// m_thread_id = LLDB_INVALID_UID;
3922// m_stack_id.Clear();
3923// needs_update = true;
3924// }
3925// }
3926// }
3927// else
3928// {
3929// // If there is no process, then we don't need to update anything.
3930// // But if we're switching from having a process to not, we should try to update.
3931// if (m_process_sp.get() != NULL)
3932// {
3933// needs_update = true;
3934// m_process_sp.reset();
3935// m_thread_id = LLDB_INVALID_UID;
3936// m_stack_id.Clear();
3937// }
3938// }
3939// }
3940// else
3941// {
3942// // If there's no target, nothing can change so we don't need to update anything.
3943// // But if we're switching from having a target to not, we should try to update.
3944// if (m_target_sp.get() != NULL)
3945// {
3946// needs_update = true;
3947// m_target_sp.reset();
3948// m_process_sp.reset();
3949// m_thread_id = LLDB_INVALID_UID;
3950// m_stack_id.Clear();
3951// }
3952// }
3953// if (!m_needs_update)
3954// m_needs_update = needs_update;
3955//
3956// return needs_update;
3957//}
Enrico Granataf2bbf712011-07-15 02:26:42 +00003958
3959void
Enrico Granata86cc9822012-03-19 22:58:49 +00003960ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00003961{
Enrico Granata86cc9822012-03-19 22:58:49 +00003962 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
3963 m_value_str.clear();
3964
3965 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
3966 m_location_str.clear();
3967
3968 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
3969 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003970 m_summary_str.clear();
3971 }
3972
3973 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
3974 m_object_desc_str.clear();
3975
3976 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
3977 {
3978 if (m_synthetic_value)
3979 m_synthetic_value = NULL;
3980 }
Johnny Chen44805302011-07-19 19:48:13 +00003981}
Enrico Granata9128ee22011-09-06 19:20:51 +00003982
3983SymbolContextScope *
3984ValueObject::GetSymbolContextScope()
3985{
3986 if (m_parent)
3987 {
3988 if (!m_parent->IsPointerOrReferenceType())
3989 return m_parent->GetSymbolContextScope();
3990 }
3991 return NULL;
3992}